From ff5d3b0b60fa302425b421721bd11ca0541f63c8 Mon Sep 17 00:00:00 2001 From: Adler Fleurant <2609856+AdlerFleurant@users.noreply.github.com> Date: Tue, 20 Sep 2022 10:33:54 -0400 Subject: [PATCH] Avoid using non existing maven settings Null check on mavenSettings. Do not pass non-existent maven settings file to surefire and failsafe plugin. Fix nearby typos, deprecated API usage and perform code cleanup. Use ci settings.xml full path. Fixes #28090 Signed-off-by: Adler Fleurant <2609856+AdlerFleurant@users.noreply.github.com> --- .github/workflows/ci-actions-incremental.yml | 4 +- .github/workflows/ci-actions.yml.disabled | 16 +++---- .github/workflows/ci-fork-mvn-cache.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/deploy-snapshots.yml | 2 +- .github/workflows/doc-build.yml | 4 +- .github/workflows/jakarta-rewrite.yml | 2 +- .github/workflows/jdk-early-access-build.yml | 2 +- .../workflows/native-cron-build.yml.disabled | 2 +- .github/workflows/release-build.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- build-parent/pom.xml | 36 ++++++++++++++- .../main/java/io/quarkus/runtime/Quarkus.java | 3 +- .../quarkus/cli/CliCreateExtensionTest.java | 24 +++++----- .../test/java/io/quarkus/cli/CliDriver.java | 46 ++++++++++--------- .../io/quarkus/cli/CliProjectGradleTest.java | 32 ++++++------- .../io/quarkus/cli/CliProjectJBangTest.java | 26 +++++------ .../io/quarkus/cli/CliProjectMavenTest.java | 20 ++++---- .../cli/RegistryClientBuilderTestBase.java | 17 +++---- 19 files changed, 136 insertions(+), 108 deletions(-) diff --git a/.github/workflows/ci-actions-incremental.yml b/.github/workflows/ci-actions-incremental.yml index eb5f7157ff8be8..62525f777603bc 100644 --- a/.github/workflows/ci-actions-incremental.yml +++ b/.github/workflows/ci-actions-incremental.yml @@ -42,7 +42,7 @@ concurrency: env: # Workaround testsuite locale issue LANG: en_US.UTF-8 - COMMON_MAVEN_ARGS: "-e -B --settings .github/mvn-settings.xml --fail-at-end" + COMMON_MAVEN_ARGS: "-e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml --fail-at-end" NATIVE_TEST_MAVEN_ARGS: "-Dtest-containers -Dstart-containers -Dquarkus.native.native-image-xmx=5g -Dnative -Dnative.surefire.skip -Dformat.skip -Dno-descriptor-tests install -DskipDocs" JVM_TEST_MAVEN_ARGS: "-Dtest-containers -Dstart-containers -Dformat.skip -DskipDocs -Dquarkus.test.hang-detection-timeout=60" DB_USER: hibernate_orm_test @@ -606,7 +606,7 @@ jobs: run: | git clone https://github.com/quarkusio/quarkus-quickstarts.git && cd quarkus-quickstarts git checkout development - export LANG=en_US && ./mvnw -e -B -fae --settings .github/mvn-settings.xml clean verify -DskipTests + export LANG=en_US && ./mvnw -e -B -fae --settings ${{ github.workspace }}/.github/mvn-settings.xml clean verify -DskipTests - name: Upload build reports (if build failed) uses: actions/upload-artifact@v3 if: ${{ failure() || cancelled() }} diff --git a/.github/workflows/ci-actions.yml.disabled b/.github/workflows/ci-actions.yml.disabled index 6dfc23395335a5..cb92ae8c2b16bb 100644 --- a/.github/workflows/ci-actions.yml.disabled +++ b/.github/workflows/ci-actions.yml.disabled @@ -37,8 +37,8 @@ concurrency: env: # Workaround testsuite locale issue LANG: en_US.UTF-8 - NATIVE_TEST_MAVEN_OPTS: "-B --settings .github/mvn-settings.xml --fail-at-end -Dquarkus.native.container-build=true -Dtest-containers -Dstart-containers -Dnative-image.xmx=5g -Dnative -Dnative.surefire.skip -Dformat.skip -Dno-descriptor-tests install -DskipDocs" - JVM_TEST_MAVEN_OPTS: "-e -B --settings .github/mvn-settings.xml -Dtest-containers -Dstart-containers -Dformat.skip -DskipDocs" + NATIVE_TEST_MAVEN_OPTS: "-B --settings ${{ github.workspace }}/.github/mvn-settings.xml --fail-at-end -Dquarkus.native.container-build=true -Dtest-containers -Dstart-containers -Dnative-image.xmx=5g -Dnative -Dnative.surefire.skip -Dformat.skip -Dno-descriptor-tests install -DskipDocs" + JVM_TEST_MAVEN_OPTS: "-e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -Dtest-containers -Dstart-containers -Dformat.skip -DskipDocs" DB_USER: hibernate_orm_test DB_PASSWORD: hibernate_orm_test DB_NAME: hibernate_orm_test @@ -95,11 +95,11 @@ jobs: key: q2maven-${{ steps.get-date.outputs.date }} - name: Build run: | - ./mvnw -T1C -e -B -DskipTests -DskipITs -Dinvoker.skip -Dno-format -Dtcks --settings .github/mvn-settings.xml clean install + ./mvnw -T1C -e -B -DskipTests -DskipITs -Dinvoker.skip -Dno-format -Dtcks --settings ${{ github.workspace }}/.github/mvn-settings.xml clean install - name: Verify extension dependencies shell: bash run: | - ./update-extension-dependencies.sh -B --settings .github/mvn-settings.xml + ./update-extension-dependencies.sh -B --settings ${{ github.workspace }}/.github/mvn-settings.xml if [ `git status -s -u no '*pom.xml' | wc -l` -ne 0 ] then echo -e '\033[0;31mError:\033[0m Dependencies to extension artifacts are outdated! Run ./update-extension-dependencies.sh and add the modified pom.xml files to your commit.' 1>&2 @@ -215,7 +215,7 @@ jobs: run: tar -xzf maven-repo.tgz -C ~ - name: Build with Maven shell: bash - run: ./mvnw -B --settings .github/mvn-settings.xml -DskipDocs -Dformat.skip -pl !integration-tests/gradle -pl !integration-tests/maven -pl !integration-tests/devtools install + run: ./mvnw -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -DskipDocs -Dformat.skip -pl !integration-tests/gradle -pl !integration-tests/maven -pl !integration-tests/devtools install - name: Prepare failure archive (if maven failed) if: failure() shell: bash @@ -498,10 +498,10 @@ jobs: shell: bash run: tar -xzf maven-repo.tgz -C ~ - name: Run RESTEasy Reactive TCK - run: mvn -B --settings ../tcks/.github/mvn-settings.xml install + run: mvn -B --settings ../tcks/${{ github.workspace }}/.github/mvn-settings.xml install working-directory: ./resteasy-reactive-testsuite - name: Verify with Maven - run: ../mvnw -B --settings .github/mvn-settings.xml -f tcks/pom.xml install + run: ../mvnw -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -f tcks/pom.xml install working-directory: ./tcks - name: Prepare failure archive (if maven failed) if: failure() @@ -576,7 +576,7 @@ jobs: # done because there is no good way to pass strings with empty values to the previous command # so this hack is as good as any if [ "$CATEGORY" == "Misc1" ]; then - ./mvnw -Dnative -Dquarkus.native.container-build=true -B --settings .github/mvn-settings.xml -f 'integration-tests/simple with space/' verify + ./mvnw -Dnative -Dquarkus.native.container-build=true -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -f 'integration-tests/simple with space/' verify fi - name: Prepare failure archive (if maven failed) if: failure() diff --git a/.github/workflows/ci-fork-mvn-cache.yml b/.github/workflows/ci-fork-mvn-cache.yml index c048951db82f46..d65f26b6de8233 100644 --- a/.github/workflows/ci-fork-mvn-cache.yml +++ b/.github/workflows/ci-fork-mvn-cache.yml @@ -60,7 +60,7 @@ jobs: key: q2maven-${{ steps.get-date.outputs.date }} - name: Build run: | - ./mvnw -T1C -e -B --settings .github/mvn-settings.xml -Dquickly-ci -Dtcks clean install + ./mvnw -T1C -e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -Dquickly-ci -Dtcks clean install - name: Delete Local Artifacts From Cache shell: bash run: rm -r ~/.m2/repository/io/quarkus diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 4a149f3cf8371a..dae7284835f847 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -52,7 +52,7 @@ jobs: - if: matrix.language == 'java' name: Build Java - run: ./mvnw -B --settings .github/mvn-settings.xml -Dquickly-ci install + run: ./mvnw -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -Dquickly-ci install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/deploy-snapshots.yml b/.github/workflows/deploy-snapshots.yml index a334168533a175..8aa77db0eaafda 100644 --- a/.github/workflows/deploy-snapshots.yml +++ b/.github/workflows/deploy-snapshots.yml @@ -43,7 +43,7 @@ jobs: SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }} SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} run: | - ./mvnw -e -B --settings .github/mvn-settings.xml \ + ./mvnw -e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml \ -DskipTests -DskipITs -Dno-format -Dinvoker.skip=true \ -DretryFailedDeploymentCount=10 \ -pl !integration-tests/gradle \ diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index 321121daa14be2..8eaa59108157b7 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -52,8 +52,8 @@ jobs: key: q2maven-doc-${{ steps.get-date.outputs.date }} - name: Build run: | - ./mvnw -Dquickly-ci -B -DskipDocs=false --settings .github/mvn-settings.xml install + ./mvnw -Dquickly-ci -B -DskipDocs=false --settings ${{ github.workspace }}/.github/mvn-settings.xml install - name: Build Docs run: | - ./mvnw -e -B --settings .github/mvn-settings.xml clean org.asciidoctor:asciidoctor-maven-plugin:process-asciidoc -pl docs -Ddocumentation-pdf + ./mvnw -e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml clean org.asciidoctor:asciidoctor-maven-plugin:process-asciidoc -pl docs -Ddocumentation-pdf diff --git a/.github/workflows/jakarta-rewrite.yml b/.github/workflows/jakarta-rewrite.yml index 7f946fe3583574..764e23d10078eb 100644 --- a/.github/workflows/jakarta-rewrite.yml +++ b/.github/workflows/jakarta-rewrite.yml @@ -43,7 +43,7 @@ jobs: SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }} SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} run: | - ./mvnw -e -B --settings .github/mvn-settings.xml \ + ./mvnw -e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml \ -DskipITs -DskipTests -Dskip.gradle.tests -Dno-format -Dinvoker.skip=true \ -DretryFailedDeploymentCount=10 \ -pl !integration-tests/gradle \ diff --git a/.github/workflows/jdk-early-access-build.yml b/.github/workflows/jdk-early-access-build.yml index 893e49ddcade25..7e15e0cd4b9741 100644 --- a/.github/workflows/jdk-early-access-build.yml +++ b/.github/workflows/jdk-early-access-build.yml @@ -21,7 +21,7 @@ env: # Workaround testsuite locale issue LANG: en_US.UTF-8 MAVEN_OPTS: -Xmx2g -XX:MaxMetaspaceSize=1g - JVM_TEST_MAVEN_OPTS: "-e -B --settings .github/mvn-settings.xml -Dtest-containers -Dstart-containers -Dtest-resteasy-reactive-large-files -Dformat.skip" + JVM_TEST_MAVEN_OPTS: "-e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -Dtest-containers -Dstart-containers -Dtest-resteasy-reactive-large-files -Dformat.skip" DB_USER: hibernate_orm_test DB_PASSWORD: hibernate_orm_test DB_NAME: hibernate_orm_test diff --git a/.github/workflows/native-cron-build.yml.disabled b/.github/workflows/native-cron-build.yml.disabled index 958f21e6aefb37..b8c9c9a7312ace 100644 --- a/.github/workflows/native-cron-build.yml.disabled +++ b/.github/workflows/native-cron-build.yml.disabled @@ -55,7 +55,7 @@ jobs: run: ./mvnw -B install -DskipTests -DskipITs -Dformat.skip - name: Run integration tests in native - run: ./mvnw -B --settings .github/mvn-settings.xml verify -f integration-tests/pom.xml --fail-at-end -Dno-format -Dtest-containers -Dstart-containers -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.2-java${{ matrix.java }} -pl '!io.quarkus:quarkus-integration-test-google-cloud-functions-http,!io.quarkus:quarkus-integration-test-google-cloud-functions,!io.quarkus:quarkus-integration-test-funqy-google-cloud-functions' + run: ./mvnw -B --settings ${{ github.workspace }}/.github/mvn-settings.xml verify -f integration-tests/pom.xml --fail-at-end -Dno-format -Dtest-containers -Dstart-containers -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.2-java${{ matrix.java }} -pl '!io.quarkus:quarkus-integration-test-google-cloud-functions-http,!io.quarkus:quarkus-integration-test-google-cloud-functions,!io.quarkus:quarkus-integration-test-funqy-google-cloud-functions' - name: Report if: always() diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index b865b2b2da716e..4f95fbcb02c1d9 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -28,7 +28,7 @@ jobs: run: mkdir -p $HOME/release/repository - name: Build and Test run: | - ./mvnw --settings .github/mvn-settings.xml \ + ./mvnw --settings ${{ github.workspace }}/.github/mvn-settings.xml \ -B \ -Prelease \ -DskipTests -DskipITs \ diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 2cef27edafde75..02533d46e9f7b3 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -38,4 +38,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./mvnw -e -B --settings .github/mvn-settings.xml -Dquickly-ci install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=quarkusio -Dsonar.projectKey=quarkusio_quarkus -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectName=Quarkus -Dsonar.java.libraries=/home/runner/.m2/repository/**/*.jar + run: ./mvnw -e -B --settings ${{ github.workspace }}/.github/mvn-settings.xml -Dquickly-ci install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=quarkusio -Dsonar.projectKey=quarkusio_quarkus -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectName=Quarkus -Dsonar.java.libraries=/home/runner/.m2/repository/**/*.jar diff --git a/build-parent/pom.xml b/build-parent/pom.xml index 4b5c4a03d1cdb3..55bbf1411a15e9 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -442,7 +442,6 @@ org.jboss.logmanager.LogManager ${maven.home} ${settings.localRepository} - ${session.request.userSettingsFile.path} ${project.version} ${project.groupId} @@ -461,7 +460,6 @@ org.jboss.logmanager.LogManager ${maven.home} ${settings.localRepository} - ${session.request.userSettingsFile.path} ${project.version} ${project.groupId} @@ -1281,5 +1279,39 @@ + + + user-session-settings + + + ${session.request.userSettingsFile.path} + + + + + + + maven-surefire-plugin + ${version.surefire.plugin} + + + + ${session.request.userSettingsFile.path} + + + + + maven-failsafe-plugin + ${failsafe-plugin.version} + + + ${session.request.userSettingsFile.path} + + + + + + + diff --git a/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java b/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java index 123e2047fec22e..8d1115da41347d 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/Quarkus.java @@ -65,7 +65,7 @@ public static void run(Class quarkusApplication, B //we already have an application, run it directly Class appClass = (Class) Class.forName(Application.APP_CLASS_NAME, false, Thread.currentThread().getContextClassLoader()); - Application application = appClass.newInstance(); + Application application = appClass.getDeclaredConstructor().newInstance(); ApplicationLifecycleManager.run(application, quarkusApplication, exitHandler, args); return; } catch (ClassNotFoundException e) { @@ -84,7 +84,6 @@ public static void run(Class quarkusApplication, B //this is not the quarkus:dev path as it will augment before //calling this method launchFromIDE(quarkusApplication, args); - } private static void launchFromIDE(Class quarkusApplication, String... args) { diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliCreateExtensionTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliCreateExtensionTest.java index 160a2edbafe923..0cfc23b4493606 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliCreateExtensionTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliCreateExtensionTest.java @@ -101,7 +101,7 @@ public void testCreateExtensionDefaults() throws Exception { CreateExtension.DEFAULT_QUARKIVERSE_VERSION); Path quarkusExtension = project.resolve("runtime/src/main/resources/META-INF/quarkus-extension.yaml"); Assertions.assertTrue(quarkusExtension.toFile().exists(), - "quarkus-extension.yaml should exist: " + quarkusExtension.toAbsolutePath().toString()); + "quarkus-extension.yaml should exist: " + quarkusExtension.toAbsolutePath()); Path deploymentPom = project.resolve("deployment/pom.xml"); validateBasicIdentifiers(deploymentPom, // pom @@ -112,8 +112,8 @@ public void testCreateExtensionDefaults() throws Exception { "io.quarkiverse.custom", "quarkus-custom-deployment", CreateExtension.DEFAULT_QUARKIVERSE_VERSION); - CliDriver.valdiateGeneratedSourcePackage(project.resolve("deployment"), "io/quarkiverse/custom/deployment"); - CliDriver.valdiateGeneratedTestPackage(project.resolve("deployment"), "io/quarkiverse/custom/test"); + CliDriver.validateGeneratedSourcePackage(project.resolve("deployment"), "io/quarkiverse/custom/deployment"); + CliDriver.validateGeneratedTestPackage(project.resolve("deployment"), "io/quarkiverse/custom/test"); Path itPom = project.resolve("integration-tests/pom.xml"); validateBasicIdentifiers(itPom, // pom @@ -124,8 +124,8 @@ public void testCreateExtensionDefaults() throws Exception { "io.quarkiverse.custom", "quarkus-custom-integration-tests", CreateExtension.DEFAULT_QUARKIVERSE_VERSION); - CliDriver.valdiateGeneratedSourcePackage(project.resolve("integration-tests"), "io/quarkiverse/custom/it"); - CliDriver.valdiateGeneratedTestPackage(project.resolve("integration-tests"), "io/quarkiverse/custom/it"); + CliDriver.validateGeneratedSourcePackage(project.resolve("integration-tests"), "io/quarkiverse/custom/it"); + CliDriver.validateGeneratedTestPackage(project.resolve("integration-tests"), "io/quarkiverse/custom/it"); } @Test @@ -149,30 +149,30 @@ public void testCreateExtension() throws Exception { "org.my", "something", "0.1"); Path quarkusExtension = project.resolve("runtime/src/main/resources/META-INF/quarkus-extension.yaml"); Assertions.assertTrue(quarkusExtension.toFile().exists(), - "quarkus-extension.yaml should exist: " + quarkusExtension.toAbsolutePath().toString()); + "quarkus-extension.yaml should exist: " + quarkusExtension.toAbsolutePath()); Path deploymentPom = project.resolve("deployment/pom.xml"); validateBasicIdentifiers(deploymentPom, // pom "org.my", "something-parent", "0.1"); validateBasicIdentifiers(deploymentPom, "org.my", "something-deployment", "0.1"); - CliDriver.valdiateGeneratedSourcePackage(project.resolve("deployment"), "org/my/something/deployment"); - CliDriver.valdiateGeneratedTestPackage(project.resolve("deployment"), "org/my/something/test"); + CliDriver.validateGeneratedSourcePackage(project.resolve("deployment"), "org/my/something/deployment"); + CliDriver.validateGeneratedTestPackage(project.resolve("deployment"), "org/my/something/test"); Path itPom = project.resolve("integration-tests/pom.xml"); validateBasicIdentifiers(itPom, // pom "org.my", "something-parent", "0.1"); validateBasicIdentifiers(itPom, "org.my", "something-integration-tests", "0.1"); - CliDriver.valdiateGeneratedSourcePackage(project.resolve("integration-tests"), "org/my/something/it"); - CliDriver.valdiateGeneratedTestPackage(project.resolve("integration-tests"), "org/my/something/it"); + CliDriver.validateGeneratedSourcePackage(project.resolve("integration-tests"), "org/my/something/it"); + CliDriver.validateGeneratedTestPackage(project.resolve("integration-tests"), "org/my/something/it"); } String validateBasicIdentifiers(Path pom, String group, String artifact, String version) throws Exception { Assertions.assertTrue(pom.toFile().exists(), - "pom.xml should exist: " + pom.toAbsolutePath().toString()); + "pom.xml should exist: " + pom.toAbsolutePath()); - String pomContent = CliDriver.readFileAsString(project, pom); + String pomContent = CliDriver.readFileAsString(pom); Assertions.assertTrue(pomContent.contains("" + group + ""), pom + " should contain group id " + group + ":\n" + pomContent); Assertions.assertTrue(pomContent.contains("" + artifact + ""), diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java b/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java index ddf060402c37ea..744cd6c783e171 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java @@ -6,6 +6,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -37,9 +38,7 @@ public CliDriverBuilder setStartingDir(Path startingDir) { } public CliDriverBuilder addArgs(String... args) { - for (String s : args) { - this.args.add(s); - } + this.args.addAll(Arrays.asList(args)); return this; } @@ -81,7 +80,7 @@ public Result execute() throws Exception { PrintStream errPs = new PrintStream(err); System.setErr(errPs); - final Map originalProps = collectOverridenProps(newArgs); + final Map originalProps = collectOverriddenProps(newArgs); Result result = new Result(); QuarkusCli cli = new QuarkusCli(); @@ -109,7 +108,7 @@ protected void resetProperties(Map originalProps) { } } - protected Map collectOverridenProps(List newArgs) { + protected Map collectOverriddenProps(List newArgs) { final Map originalProps = new HashMap<>(); for (String s : newArgs) { if (s.startsWith("-D")) { @@ -121,6 +120,8 @@ protected Map collectOverridenProps(List newArgs) { originalProps.put(propName, origValue); } else if (System.getProperties().contains(propName)) { originalProps.put(propName, "true"); + } else { + originalProps.put(propName, null); } } } @@ -221,32 +222,33 @@ public static void deleteDir(Path path) throws Exception { return; } - Files.walk(path) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(f -> retryDelete(f)); + try (var walk = Files.walk(path)) { + walk.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(CliDriver::retryDelete); + } Assertions.assertFalse(path.toFile().exists()); } - public static String readFileAsString(Path projectRoot, Path path) throws Exception { + public static String readFileAsString(Path path) throws Exception { return new String(Files.readAllBytes(path)); } - public static void valdiateGeneratedSourcePackage(Path projectRoot, String name) { + public static void validateGeneratedSourcePackage(Path projectRoot, String name) { Path packagePath = projectRoot.resolve("src/main/java/" + name); Assertions.assertTrue(packagePath.toFile().exists(), - "Package directory should exist: " + packagePath.toAbsolutePath().toString()); + "Package directory should exist: " + packagePath.toAbsolutePath()); Assertions.assertTrue(packagePath.toFile().isDirectory(), - "Package directory should be a directory: " + packagePath.toAbsolutePath().toString()); + "Package directory should be a directory: " + packagePath.toAbsolutePath()); } - public static void valdiateGeneratedTestPackage(Path projectRoot, String name) { + public static void validateGeneratedTestPackage(Path projectRoot, String name) { Path packagePath = projectRoot.resolve("src/test/java/" + name); Assertions.assertTrue(packagePath.toFile().exists(), - "Package directory should exist: " + packagePath.toAbsolutePath().toString()); + "Package directory should exist: " + packagePath.toAbsolutePath()); Assertions.assertTrue(packagePath.toFile().isDirectory(), - "Package directory should be a directory: " + packagePath.toAbsolutePath().toString()); + "Package directory should be a directory: " + packagePath.toAbsolutePath()); } public static Result invokeValidateExtensionList(Path projectRoot) throws Exception { @@ -272,7 +274,7 @@ public static Result invokeExtensionAddQute(Path projectRoot, Path file) throws Assertions.assertTrue(result.stdout.contains("quarkus-qute"), "Expected quarkus-qute to be in the list of extensions. Result:\n" + result); - String content = readFileAsString(projectRoot, file); + String content = readFileAsString(file); Assertions.assertTrue(content.contains("quarkus-qute"), "quarkus-qute should be listed as a dependency. Result:\n" + content); @@ -290,7 +292,7 @@ public static Result invokeExtensionRemoveQute(Path projectRoot, Path file) thro Assertions.assertFalse(result.stdout.contains("quarkus-qute"), "Expected quarkus-qute to be missing from the list of extensions. Result:\n" + result); - String content = readFileAsString(projectRoot, file); + String content = readFileAsString(file); Assertions.assertFalse(content.contains("quarkus-qute"), "quarkus-qute should not be listed as a dependency. Result:\n" + content); @@ -312,7 +314,7 @@ public static Result invokeExtensionAddMultiple(Path projectRoot, Path file) thr Assertions.assertTrue(result.stdout.contains("quarkus-jackson"), "Expected quarkus-jackson to be in the list of extensions. Result:\n" + result); - String content = CliDriver.readFileAsString(projectRoot, file); + String content = CliDriver.readFileAsString(file); Assertions.assertTrue(content.contains("quarkus-qute"), "quarkus-qute should still be listed as a dependency. Result:\n" + content); Assertions.assertTrue(content.contains("quarkus-amazon-lambda-http"), @@ -338,7 +340,7 @@ public static Result invokeExtensionRemoveMultiple(Path projectRoot, Path file) Assertions.assertFalse(result.stdout.contains("quarkus-jackson"), "quarkus-jackson should not be in the list of extensions. Result:\n" + result); - String content = CliDriver.readFileAsString(projectRoot, file); + String content = CliDriver.readFileAsString(file); Assertions.assertFalse(content.contains("quarkus-qute"), "quarkus-qute should not be listed as a dependency. Result:\n" + content); Assertions.assertFalse(content.contains("quarkus-amazon-lambda-http"), @@ -433,8 +435,8 @@ public static Result invokeValidateBuild(Path projectRoot) throws Exception { public static void validateApplicationProperties(Path projectRoot, List configs) throws Exception { Path properties = projectRoot.resolve("src/main/resources/application.properties"); Assertions.assertTrue(properties.toFile().exists(), - "application.properties should exist: " + properties.toAbsolutePath().toString()); - String propertiesFile = CliDriver.readFileAsString(projectRoot, properties); + "application.properties should exist: " + properties.toAbsolutePath()); + String propertiesFile = CliDriver.readFileAsString(properties); configs.forEach(conf -> Assertions.assertTrue(propertiesFile.contains(conf), "Properties file should contain " + conf + ". Found:\n" + propertiesFile)); } diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java index f27bb1a3860bc1..1d1feea595db21 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java @@ -84,7 +84,7 @@ static void stopGradleDaemon() throws Exception { } @Test - public void testNoCode() throws Exception { + public void testNoCode() { // Inspect the no-code project created to hold the gradle wrapper Assertions.assertTrue(gradle.exists(), "Wrapper should exist"); @@ -112,7 +112,7 @@ public void testCreateAppDefaults() throws Exception { Assertions.assertTrue(buildGradleContent.contains("quarkus-resteasy"), "build/gradle should contain quarkus-resteasy:\n" + buildGradleContent); - CliDriver.valdiateGeneratedSourcePackage(project, "org/acme"); + CliDriver.validateGeneratedSourcePackage(project, "org/acme"); CliDriver.invokeValidateBuild(project); } @@ -137,7 +137,7 @@ public void testCreateAppDefaultsWithKotlinDSL() throws Exception { Assertions.assertTrue(packagePath.toFile().isDirectory(), "Java Source directory should exist: " + packagePath.toAbsolutePath()); - CliDriver.valdiateGeneratedSourcePackage(project, "org/acme"); + CliDriver.validateGeneratedSourcePackage(project, "org/acme"); CliDriver.invokeValidateBuild(project); } @@ -169,7 +169,7 @@ public void testCreateAppOverrides() throws Exception { Assertions.assertTrue(buildGradleContent.contains("quarkus-resteasy-reactive"), "build.gradle should contain quarkus-resteasy-reactive:\n" + buildGradleContent); - CliDriver.valdiateGeneratedSourcePackage(project, "custom/pkg"); + CliDriver.validateGeneratedSourcePackage(project, "custom/pkg"); CliDriver.validateApplicationProperties(project, configs); result = CliDriver.invokeValidateDryRunBuild(project); @@ -196,7 +196,7 @@ public void testCreateCliDefaults() throws Exception { Assertions.assertTrue(buildGradleContent.contains("quarkus-picocli"), "build/gradle should contain quarkus-picocli:\n" + buildGradleContent); - CliDriver.valdiateGeneratedSourcePackage(project, "org/acme"); + CliDriver.validateGeneratedSourcePackage(project, "org/acme"); CliDriver.invokeValidateBuild(project); } @@ -207,7 +207,7 @@ public void testExtensionList() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path buildGradle = project.resolve("build.gradle"); - String buildGradleContent = CliDriver.readFileAsString(project, buildGradle); + String buildGradleContent = CliDriver.readFileAsString(buildGradle); Assertions.assertFalse(buildGradleContent.contains("quarkus-qute"), "Dependencies should not contain qute extension by default. Found:\n" + buildGradleContent); @@ -379,7 +379,7 @@ public void testCreateArgJava11() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path buildGradle = project.resolve("build.gradle"); - String buildGradleContent = CliDriver.readFileAsString(project, buildGradle); + String buildGradleContent = CliDriver.readFileAsString(buildGradle); Assertions.assertTrue(buildGradleContent.contains("sourceCompatibility = JavaVersion.VERSION_11"), "Java 11 should be used when specified. Found:\n" + buildGradle); } @@ -394,7 +394,7 @@ public void testCreateArgJava17() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path buildGradle = project.resolve("build.gradle"); - String buildGradleContent = CliDriver.readFileAsString(project, buildGradle); + String buildGradleContent = CliDriver.readFileAsString(buildGradle); Assertions.assertTrue(buildGradleContent.contains("sourceCompatibility = JavaVersion.VERSION_17"), "Java 17 should be used when specified. Found:\n" + buildGradleContent); @@ -403,9 +403,9 @@ public void testCreateArgJava17() throws Exception { String validateBasicGradleGroovyIdentifiers(Path project, String group, String artifact, String version) throws Exception { Path buildGradle = project.resolve("build.gradle"); Assertions.assertTrue(buildGradle.toFile().exists(), - "build.gradle should exist: " + buildGradle.toAbsolutePath().toString()); + "build.gradle should exist: " + buildGradle.toAbsolutePath()); - String buildContent = CliDriver.readFileAsString(project, buildGradle); + String buildContent = CliDriver.readFileAsString(buildGradle); Assertions.assertTrue(buildContent.contains("group '" + group + "'"), "build.gradle should include the group id:\n" + buildContent); Assertions.assertTrue(buildContent.contains("version '" + version + "'"), @@ -413,8 +413,8 @@ String validateBasicGradleGroovyIdentifiers(Path project, String group, String a Path settings = project.resolve("settings.gradle"); Assertions.assertTrue(settings.toFile().exists(), - "settings.gradle should exist: " + settings.toAbsolutePath().toString()); - String settingsContent = CliDriver.readFileAsString(project, settings); + "settings.gradle should exist: " + settings.toAbsolutePath()); + String settingsContent = CliDriver.readFileAsString(settings); Assertions.assertTrue(settingsContent.contains(artifact), "settings.gradle should include the artifact id:\n" + settingsContent); @@ -424,9 +424,9 @@ String validateBasicGradleGroovyIdentifiers(Path project, String group, String a String validateBasicGradleKotlinIdentifiers(Path project, String group, String artifact, String version) throws Exception { Path buildGradle = project.resolve("build.gradle.kts"); Assertions.assertTrue(buildGradle.toFile().exists(), - "build.gradle.kts should exist: " + buildGradle.toAbsolutePath().toString()); + "build.gradle.kts should exist: " + buildGradle.toAbsolutePath()); - String buildContent = CliDriver.readFileAsString(project, buildGradle); + String buildContent = CliDriver.readFileAsString(buildGradle); Assertions.assertTrue(buildContent.contains("group = \"" + group + "\""), "build.gradle.kts should include the group id:\n" + buildContent); Assertions.assertTrue(buildContent.contains("version = \"" + version + "\""), @@ -434,8 +434,8 @@ String validateBasicGradleKotlinIdentifiers(Path project, String group, String a Path settings = project.resolve("settings.gradle.kts"); Assertions.assertTrue(settings.toFile().exists(), - "settings.gradle.kts should exist: " + settings.toAbsolutePath().toString()); - String settingsContent = CliDriver.readFileAsString(project, settings); + "settings.gradle.kts should exist: " + settings.toAbsolutePath()); + String settingsContent = CliDriver.readFileAsString(settings); Assertions.assertTrue(settingsContent.contains(artifact), "settings.gradle.kts should include the artifact id:\n" + settingsContent); diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java index e41807efd05745..92032479b31ffc 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java @@ -51,9 +51,9 @@ public void testCreateAppDefaults() throws Exception { CreateProjectHelper.DEFAULT_ARTIFACT_ID, CreateProjectHelper.DEFAULT_VERSION); - Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name + Path javaMain = validateJBangSourcePackage(project, ""); // no package name - String source = CliDriver.readFileAsString(project, javaMain); + String source = CliDriver.readFileAsString(javaMain); Assertions.assertTrue(source.contains("quarkus-resteasy"), "Generated source should reference resteasy. Found:\n" + source); @@ -87,9 +87,9 @@ public void testCreateAppOverrides() throws Exception { "Wrapper should exist by default"); validateBasicIdentifiers(project, "silly", "my-project", "0.1.0"); - Path javaMain = valdiateJBangSourcePackage(project, ""); + Path javaMain = validateJBangSourcePackage(project, ""); - String source = CliDriver.readFileAsString(project, javaMain); + String source = CliDriver.readFileAsString(javaMain); Assertions.assertTrue(source.contains("quarkus-reactive-routes"), "Generated source should reference quarkus-reactive-routes. Found:\n" + source); @@ -112,9 +112,9 @@ public void testCreateCliDefaults() throws Exception { CreateProjectHelper.DEFAULT_ARTIFACT_ID, CreateProjectHelper.DEFAULT_VERSION); - Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name + Path javaMain = validateJBangSourcePackage(project, ""); // no package name - String source = CliDriver.readFileAsString(project, javaMain); + String source = CliDriver.readFileAsString(javaMain); Assertions.assertFalse(source.contains("quarkus-resteasy"), "Generated source should reference resteasy. Found:\n" + source); Assertions.assertTrue(source.contains("quarkus-picocli"), @@ -176,9 +176,9 @@ public void testCreateArgJava11() throws Exception { // We don't need to retest this, just need to make sure all the arguments were passed through Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); - Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name + Path javaMain = validateJBangSourcePackage(project, ""); // no package name - String source = CliDriver.readFileAsString(project, javaMain); + String source = CliDriver.readFileAsString(javaMain); Assertions.assertTrue(source.contains("//JAVA 11"), "Generated source should contain //JAVA 11. Found:\n" + source); } @@ -192,8 +192,8 @@ public void testCreateArgJava17() throws Exception { // We don't need to retest this, just need to make sure all the arguments were passed through Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); - Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name - String source = CliDriver.readFileAsString(project, javaMain); + Path javaMain = validateJBangSourcePackage(project, ""); // no package name + String source = CliDriver.readFileAsString(javaMain); Assertions.assertTrue(source.contains("//JAVA 17"), "Generated source should contain //JAVA 17. Found:\n" + source); } @@ -206,12 +206,12 @@ void validateBasicIdentifiers(Path project, String group, String artifact, Strin // Should the version be stored in metadata anywhere? Is that useful for script management? } - Path valdiateJBangSourcePackage(Path project, String name) { + Path validateJBangSourcePackage(Path project, String name) { Path packagePath = project.resolve("src/" + name); Assertions.assertTrue(packagePath.toFile().exists(), - "Package directory should exist: " + packagePath.toAbsolutePath().toString()); + "Package directory should exist: " + packagePath.toAbsolutePath()); Assertions.assertTrue(packagePath.toFile().isDirectory(), - "Package directory should be a directory: " + packagePath.toAbsolutePath().toString()); + "Package directory should be a directory: " + packagePath.toAbsolutePath()); return packagePath.resolve("main.java"); } diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java index db8562e3b22f8b..ca426d853a0827 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java @@ -54,9 +54,9 @@ public void testCreateAppDefaults() throws Exception { Assertions.assertTrue(pomContent.contains("quarkus-resteasy-reactive"), "pom.xml should contain quarkus-resteasy-reactive:\n" + pomContent); - CliDriver.valdiateGeneratedSourcePackage(project, "org/acme"); + CliDriver.validateGeneratedSourcePackage(project, "org/acme"); - result = CliDriver.invokeValidateDryRunBuild(project); + CliDriver.invokeValidateDryRunBuild(project); CliDriver.invokeValidateBuild(project); @@ -91,7 +91,7 @@ public void testCreateAppOverrides() throws Exception { Assertions.assertTrue(pomContent.contains("quarkus-resteasy-reactive"), "pom.xml should contain quarkus-resteasy-reactive:\n" + pomContent); - CliDriver.valdiateGeneratedSourcePackage(project, "custom/pkg"); + CliDriver.validateGeneratedSourcePackage(project, "custom/pkg"); CliDriver.validateApplicationProperties(project, configs); result = CliDriver.invokeValidateDryRunBuild(project); @@ -114,7 +114,7 @@ public void testExtensionList() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path pom = project.resolve("pom.xml"); - String pomContent = CliDriver.readFileAsString(project, pom); + String pomContent = CliDriver.readFileAsString(pom); Assertions.assertFalse(pomContent.contains("quarkus-qute"), "Dependencies should not contain qute extension by default. Found:\n" + pomContent); @@ -269,9 +269,9 @@ public void testCreateCliDefaults() throws Exception { Assertions.assertTrue(pomContent.contains("quarkus-picocli"), "pom.xml should contain quarkus-picocli:\n" + pomContent); - CliDriver.valdiateGeneratedSourcePackage(project, "org/acme"); + CliDriver.validateGeneratedSourcePackage(project, "org/acme"); - result = CliDriver.invokeValidateDryRunBuild(project); + CliDriver.invokeValidateDryRunBuild(project); CliDriver.invokeValidateBuild(project); } @@ -319,7 +319,7 @@ public void testCreateArgJava11() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path pom = project.resolve("pom.xml"); - String pomContent = CliDriver.readFileAsString(project, pom); + String pomContent = CliDriver.readFileAsString(pom); Assertions.assertTrue(pomContent.contains("maven.compiler.release>11<"), "Java 11 should be used when specified. Found:\n" + pomContent); @@ -335,7 +335,7 @@ public void testCreateArgJava17() throws Exception { Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result); Path pom = project.resolve("pom.xml"); - String pomContent = CliDriver.readFileAsString(project, pom); + String pomContent = CliDriver.readFileAsString(pom); Assertions.assertTrue(pomContent.contains("maven.compiler.release>17<"), "Java 17 should be used when specified. Found:\n" + pomContent); @@ -345,8 +345,8 @@ String validateBasicIdentifiers(String group, String artifact, String version) t Path pom = project.resolve("pom.xml"); Assertions.assertTrue(pom.toFile().exists(), - "pom.xml should exist: " + pom.toAbsolutePath().toString()); - String pomContent = CliDriver.readFileAsString(project, pom); + "pom.xml should exist: " + pom.toAbsolutePath()); + String pomContent = CliDriver.readFileAsString(pom); Assertions.assertTrue(pomContent.contains("" + group + ""), "pom.xml should contain group id:\n" + pomContent); Assertions.assertTrue(pomContent.contains("" + artifact + ""), diff --git a/devtools/cli/src/test/java/io/quarkus/cli/RegistryClientBuilderTestBase.java b/devtools/cli/src/test/java/io/quarkus/cli/RegistryClientBuilderTestBase.java index 00a402bcda5cad..daa5ba171aedd3 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/RegistryClientBuilderTestBase.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/RegistryClientBuilderTestBase.java @@ -1,9 +1,8 @@ package io.quarkus.cli; -import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; @@ -18,7 +17,6 @@ import org.junit.jupiter.api.BeforeAll; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext; -import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; import io.quarkus.devtools.project.QuarkusProjectHelper; import io.quarkus.devtools.testing.registry.client.TestRegistryClientBuilder; import io.quarkus.registry.config.RegistriesConfigLocator; @@ -59,7 +57,7 @@ static void setup() throws Exception { final BootstrapMavenContext mavenContext = new BootstrapMavenContext( BootstrapMavenContext.config().setWorkspaceDiscovery(false)); - final Settings settings = getBaseMavenSettings(mavenContext.getUserSettings().toPath()); + final Settings settings = getBaseMavenSettings(mavenContext.getUserSettings()); Profile profile = new Profile(); settings.addActiveProfile("qs-test-registry"); @@ -83,8 +81,7 @@ static void setup() throws Exception { testRepo = registryConfigDir.resolve("test-repo"); } - private static Repository configureRepo(String id, String url) - throws MalformedURLException, BootstrapMavenException { + private static Repository configureRepo(String id, String url) { final Repository repo = new Repository(); repo.setId(id); repo.setLayout("default"); @@ -106,11 +103,9 @@ protected static String getCurrentQuarkusVersion() { return v; } - private static Settings getBaseMavenSettings(Path mavenSettings) throws IOException { - if (Files.exists(mavenSettings)) { - try (BufferedReader reader = Files.newBufferedReader(mavenSettings)) { - return new DefaultSettingsReader().read(reader, Map.of()); - } + private static Settings getBaseMavenSettings(File mavenSettings) throws IOException { + if (mavenSettings != null && mavenSettings.exists()) { + return new DefaultSettingsReader().read(mavenSettings, Map.of()); } return new Settings(); }