-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25601 from mshima/code-quality
split gradle/code-quality and gradle/jib generators
- Loading branch information
Showing
24 changed files
with
518 additions
and
466 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
generators/gradle/generators/code-quality/__snapshots__/generator.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`generator - gradle:code-quality with gradle build tool should match files snapshot 1`] = ` | ||
{ | ||
"build.gradle": { | ||
"contents": " | ||
dependencies { | ||
// jhipster-needle-gradle-dependency | ||
} | ||
plugins { | ||
id "jhipster.code-quality-conventions" | ||
// jhipster-needle-gradle-plugins | ||
} | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/build.gradle": { | ||
"contents": "plugins { | ||
id 'groovy-gradle-plugin' | ||
} | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
implementation libs.modernizer.plugin | ||
implementation libs.nohttp.plugin | ||
implementation libs.sonarqube.plugin | ||
implementation libs.spotless.plugin | ||
// jhipster-needle-gradle-dependency - JHipster will add additional dependencies for convention plugins here | ||
// jhipster-needle-gradle-build-src-dependency - Deprecated: JHipster will add additional dependencies for convention plugins here | ||
} | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/gradle/libs.versions.toml": { | ||
"contents": "[versions] | ||
# jhipster-needle-gradle-dependency-catalog-version - JHipster will add additional versions for convention plugins heref | ||
# jhipster-needle-gradle-build-src-dependency-catalog-version - Deprecated: JHipster will add additional versions for convention plugins here | ||
[libraries] | ||
modernizer-plugin = { module = "com.github.andygoossens:gradle-modernizer-plugin", version = "'GRADLE-MODERNIZER-PLUGIN-VERSION'" } | ||
nohttp-plugin = { module = "io.spring.nohttp:nohttp-gradle", version = "'NOHTTP-CHECKSTYLE-VERSION'" } | ||
sonarqube-plugin = { module = "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin", version = "'GRADLE-SONARQUBE-VERSION'" } | ||
spotless-plugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "'SPOTLESS-GRADLE-PLUGIN-VERSION'" } | ||
# jhipster-needle-gradle-dependency-catalog-libraries - JHipster will add additional libraries versions | ||
[plugins] | ||
# jhipster-needle-gradle-dependency-catalog-plugins - JHipster will add additional plugins versions | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/src/main/groovy/jhipster.code-quality-conventions.gradle": { | ||
"contents": "plugins { | ||
id "jacoco" | ||
id "org.sonarqube" | ||
id "com.diffplug.spotless" | ||
id "com.github.andygoossens.gradle-modernizer-plugin" | ||
id "io.spring.nohttp" | ||
} | ||
jacoco { | ||
toolVersion = "\${libs.versions.jacoco.get()}" | ||
} | ||
jacocoTestReport { | ||
executionData tasks.withType(Test) | ||
classDirectories.from = files(sourceSets.main.output.classesDirs) | ||
sourceDirectories.from = files(sourceSets.main.java.srcDirs) | ||
reports { | ||
xml.required = true | ||
} | ||
} | ||
file("sonar-project.properties").withReader { | ||
Properties sonarProperties = new Properties() | ||
sonarProperties.load(it) | ||
sonarProperties.each { key, value -> | ||
sonarqube { | ||
properties { | ||
property key, value | ||
} | ||
} | ||
} | ||
} | ||
spotless { | ||
java { | ||
target 'src/*/java/**/*.java' | ||
// removeUnusedImports() | ||
} | ||
} | ||
modernizer { | ||
failOnViolations = true | ||
includeTestClasses = true | ||
} | ||
checkstyle { | ||
toolVersion "\${libs.versions.checkstyle.get()}" | ||
configFile file("checkstyle.xml") | ||
checkstyleTest.enabled = false | ||
} | ||
nohttp { | ||
source.include "build.gradle", "README.md" | ||
} | ||
// workaround for https://github.com/checkstyle/checkstyle/issues/14123 | ||
configurations.checkstyle { | ||
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") { | ||
select("com.google.guava:guava:0") | ||
} | ||
}", | ||
"stateCleared": "modified", | ||
}, | ||
"gradle/libs.versions.toml": { | ||
"contents": "[versions] | ||
jacoco = "'JACOCO-MAVEN-PLUGIN-VERSION'" | ||
checkstyle = "'CHECKSTYLE-VERSION'" | ||
# jhipster-needle-gradle-dependency-catalog-version - JHipster will add additional versions for convention plugins heref | ||
[libraries] | ||
# jhipster-needle-gradle-dependency-catalog-libraries - JHipster will add additional libraries versions | ||
[plugins] | ||
# jhipster-needle-gradle-dependency-catalog-plugins - JHipster will add additional plugins versions | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
} | ||
`; |
27 changes: 27 additions & 0 deletions
27
generators/gradle/generators/code-quality/generator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { basename, dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { before, it, describe, expect } from 'esmocha'; | ||
|
||
import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js'; | ||
import Generator from './index.js'; | ||
import { defaultHelpers as helpers, result } from '../../../../testing/index.js'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`; | ||
|
||
describe(`generator - ${generator}`, () => { | ||
shouldSupportFeatures(Generator); | ||
describe('blueprint support', () => testBlueprintSupport(generator)); | ||
|
||
describe('with gradle build tool', () => { | ||
before(async () => { | ||
await helpers.runJHipster(generator).withGradleBuildTool(); | ||
}); | ||
|
||
it('should match files snapshot', () => { | ||
expect(result.getSnapshot('**/{build.gradle,buildSrc/**,gradle/libs.versions.toml}')).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright 2013-2024 the original author or authors from the JHipster project. | ||
* | ||
* This file is part of the JHipster project, see https://www.jhipster.tech/ | ||
* for more information. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import BaseApplicationGenerator from '../../../base-application/index.js'; | ||
import { GRADLE_BUILD_SRC_MAIN_DIR } from '../../../generator-constants.js'; | ||
import { GENERATOR_GRADLE } from '../../../generator-list.js'; | ||
|
||
export default class CodeQualityGenerator extends BaseApplicationGenerator { | ||
async beforeQueue() { | ||
if (!this.fromBlueprint) { | ||
await this.composeWithBlueprints(); | ||
} | ||
|
||
if (!this.delegateToBlueprint) { | ||
await this.dependsOnBootstrapAplication(); | ||
await this.dependsOnJHipster(GENERATOR_GRADLE); | ||
} | ||
} | ||
|
||
get writing() { | ||
return this.asWritingTaskGroup({ | ||
async writing({ application }) { | ||
await this.writeFiles({ | ||
blocks: [{ templates: [`${GRADLE_BUILD_SRC_MAIN_DIR}/jhipster.code-quality-conventions.gradle`] }], | ||
context: application, | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseApplicationGenerator.WRITING]() { | ||
return this.delegateTasksToBlueprint(() => this.writing); | ||
} | ||
|
||
get postWriting() { | ||
return this.asPostWritingTaskGroup({ | ||
customize({ application, source }) { | ||
const { javaDependencies } = application; | ||
source.addGradleDependencyCatalogVersions!([ | ||
{ name: 'jacoco', version: javaDependencies!['jacoco-maven-plugin'] }, | ||
{ name: 'checkstyle', version: javaDependencies!.checkstyle }, | ||
]); | ||
source.addGradleBuildSrcDependencyCatalogLibraries?.([ | ||
{ | ||
libraryName: 'sonarqube-plugin', | ||
module: 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin', | ||
version: javaDependencies!['gradle-sonarqube'], | ||
scope: 'implementation', | ||
}, | ||
{ | ||
libraryName: 'spotless-plugin', | ||
module: 'com.diffplug.spotless:spotless-plugin-gradle', | ||
version: javaDependencies!['spotless-gradle-plugin'], | ||
scope: 'implementation', | ||
}, | ||
{ | ||
libraryName: 'modernizer-plugin', | ||
module: 'com.github.andygoossens:gradle-modernizer-plugin', | ||
version: javaDependencies!['gradle-modernizer-plugin'], | ||
scope: 'implementation', | ||
}, | ||
{ | ||
libraryName: 'nohttp-plugin', | ||
module: 'io.spring.nohttp:nohttp-gradle', | ||
version: javaDependencies!['nohttp-checkstyle'], | ||
scope: 'implementation', | ||
}, | ||
]); | ||
source.addGradlePlugin?.({ id: 'jhipster.code-quality-conventions' }); | ||
}, | ||
}); | ||
} | ||
|
||
get [BaseApplicationGenerator.POST_WRITING]() { | ||
return this.delegateTasksToBlueprint(() => this.postWriting); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2013-2024 the original author or authors from the JHipster project. | ||
* | ||
* This file is part of the JHipster project, see https://www.jhipster.tech/ | ||
* for more information. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export { default } from './generator.js'; |
File renamed without changes.
96 changes: 96 additions & 0 deletions
96
generators/gradle/generators/jib/__snapshots__/generator.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`generator - gradle:jib with gradle build tool should match files snapshot 1`] = ` | ||
{ | ||
"build.gradle": { | ||
"contents": " | ||
dependencies { | ||
// jhipster-needle-gradle-dependency | ||
} | ||
plugins { | ||
id "jhipster.docker-conventions" | ||
// jhipster-needle-gradle-plugins | ||
} | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/build.gradle": { | ||
"contents": "plugins { | ||
id 'groovy-gradle-plugin' | ||
} | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
implementation libs.jib.plugin | ||
// jhipster-needle-gradle-dependency - JHipster will add additional dependencies for convention plugins here | ||
// jhipster-needle-gradle-build-src-dependency - Deprecated: JHipster will add additional dependencies for convention plugins here | ||
} | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/gradle/libs.versions.toml": { | ||
"contents": "[versions] | ||
# jhipster-needle-gradle-dependency-catalog-version - JHipster will add additional versions for convention plugins heref | ||
# jhipster-needle-gradle-build-src-dependency-catalog-version - Deprecated: JHipster will add additional versions for convention plugins here | ||
[libraries] | ||
jib-plugin = { module = "com.google.cloud.tools:jib-gradle-plugin", version = "'JIB-MAVEN-PLUGIN-VERSION'" } | ||
# jhipster-needle-gradle-dependency-catalog-libraries - JHipster will add additional libraries versions | ||
[plugins] | ||
# jhipster-needle-gradle-dependency-catalog-plugins - JHipster will add additional plugins versions | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
"buildSrc/src/main/groovy/jhipster.docker-conventions.gradle": { | ||
"contents": "plugins { | ||
id "com.google.cloud.tools.jib" | ||
} | ||
jib { | ||
from { | ||
image = "java-jre-placeholder" | ||
platforms { | ||
platform { | ||
architecture = "\${findProperty('jibArchitecture') ?: 'amd64'}" | ||
os = "linux" | ||
} | ||
} | ||
} | ||
to { | ||
image = "jhipster:latest" | ||
} | ||
container { | ||
entrypoint = ["bash", "-c", "/entrypoint.sh"] | ||
ports = ["8080"] | ||
environment = [ | ||
SPRING_OUTPUT_ANSI_ENABLED: "ALWAYS", | ||
JHIPSTER_SLEEP: "0" | ||
] | ||
creationTime = "USE_CURRENT_TIMESTAMP" | ||
user = 1000 | ||
} | ||
extraDirectories { | ||
paths = file("src/main/docker/jib") | ||
permissions = ["/entrypoint.sh": "755"] | ||
} | ||
}", | ||
"stateCleared": "modified", | ||
}, | ||
"gradle/libs.versions.toml": { | ||
"contents": "[versions] | ||
# jhipster-needle-gradle-dependency-catalog-version - JHipster will add additional versions for convention plugins heref | ||
[libraries] | ||
# jhipster-needle-gradle-dependency-catalog-libraries - JHipster will add additional libraries versions | ||
[plugins] | ||
# jhipster-needle-gradle-dependency-catalog-plugins - JHipster will add additional plugins versions | ||
", | ||
"stateCleared": "modified", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.