From 22902d8fcb714cffdf2c44fa610dbc2c437a0df4 Mon Sep 17 00:00:00 2001 From: Antonio Jacob Costa Date: Thu, 10 Nov 2022 16:18:47 +0100 Subject: [PATCH] fix: pass quarkus args to dev mode gradle task --- .../io/quarkus/gradle/tasks/QuarkusDev.java | 1 + .../build.gradle | 38 ++++++++++ .../gradle.properties | 2 + .../settings.gradle | 15 ++++ .../src/main/java/org/acme/EntryPoint.java | 15 ++++ ...cJavaMainApplicationModuleDevModeTest.java | 70 +++++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 integration-tests/gradle/src/main/resources/basic-java-main-application-project/build.gradle create mode 100644 integration-tests/gradle/src/main/resources/basic-java-main-application-project/gradle.properties create mode 100644 integration-tests/gradle/src/main/resources/basic-java-main-application-project/settings.gradle create mode 100644 integration-tests/gradle/src/main/resources/basic-java-main-application-project/src/main/java/org/acme/EntryPoint.java create mode 100644 integration-tests/gradle/src/test/java/io/quarkus/gradle/devmode/BasicJavaMainApplicationModuleDevModeTest.java diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java index 9a3ebcf051b5b..3f64ea80e5d0b 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java @@ -371,6 +371,7 @@ private QuarkusDevModeLauncher newLauncher() throws Exception { .debug(System.getProperty("debug")) .debugHost(System.getProperty("debugHost")) .debugPort(System.getProperty("debugPort")) + .applicationArgs(System.getProperty("quarkus.args")) .suspend(System.getProperty("suspend")); if (System.getProperty(IO_QUARKUS_DEVMODE_ARGS) == null) { builder.jvmArgs("-Dquarkus.test.basic-console=true") diff --git a/integration-tests/gradle/src/main/resources/basic-java-main-application-project/build.gradle b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/build.gradle new file mode 100644 index 0000000000000..b5987d2fda26c --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'java' + id 'io.quarkus' + id 'application' +} + +repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-arc' +} + +compileJava { + options.compilerArgs << '-parameters' +} + +application { + mainClass = 'org.acme.EntryPoint' +} + +run { + // propagate the custom local maven repo, in case it's configured + if (System.properties.containsKey('maven.repo.local')) { + systemProperty 'maven.repo.local', System.properties.get('maven.repo.local') + } +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} diff --git a/integration-tests/gradle/src/main/resources/basic-java-main-application-project/gradle.properties b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/gradle.properties new file mode 100644 index 0000000000000..ec2b6ef199c2c --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/gradle.properties @@ -0,0 +1,2 @@ +quarkusPlatformArtifactId=quarkus-bom +quarkusPlatformGroupId=io.quarkus diff --git a/integration-tests/gradle/src/main/resources/basic-java-main-application-project/settings.gradle b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/settings.gradle new file mode 100644 index 0000000000000..673d02a044226 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + mavenLocal { + content { + includeGroupByRegex 'io.quarkus.*' + } + } + mavenCentral() + gradlePluginPortal() + } + plugins { + id 'io.quarkus' version "${quarkusPluginVersion}" + } +} +rootProject.name='code-with-quarkus' diff --git a/integration-tests/gradle/src/main/resources/basic-java-main-application-project/src/main/java/org/acme/EntryPoint.java b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/src/main/java/org/acme/EntryPoint.java new file mode 100644 index 0000000000000..80d6bee834580 --- /dev/null +++ b/integration-tests/gradle/src/main/resources/basic-java-main-application-project/src/main/java/org/acme/EntryPoint.java @@ -0,0 +1,15 @@ +package org.acme; + +import java.util.Arrays; + +import io.quarkus.runtime.Quarkus; +import io.quarkus.runtime.annotations.QuarkusMain; + +@QuarkusMain +public class EntryPoint { + + public static void main(String[] args) { + System.out.println("basic-java-main-application-project: args.length: " + args.length); + System.out.println("basic-java-main-application-project: args: " + Arrays.toString(args)); + } +} diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/devmode/BasicJavaMainApplicationModuleDevModeTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/devmode/BasicJavaMainApplicationModuleDevModeTest.java new file mode 100644 index 0000000000000..11952c4e4c790 --- /dev/null +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/devmode/BasicJavaMainApplicationModuleDevModeTest.java @@ -0,0 +1,70 @@ +package io.quarkus.gradle.devmode; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +import java.io.BufferedReader; +import java.io.File; +import java.io.RandomAccessFile; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; + +public class BasicJavaMainApplicationModuleDevModeTest extends QuarkusDevGradleTestBase { + private static final String ARGS_LOG_LINE_PREFIX = "basic-java-main-application-project: args"; + + @Override + protected String projectDirectoryName() { + return "basic-java-main-application-project"; + } + + @Override + protected String[] buildArguments() { + return new String[] { "clean", "quarkusDev", "-s", "-Dquarkus.args=param1=1 param2=2" }; + } + + protected void testDevMode() throws Exception { + File logOutput = new File(projectDir, "command-output.log"); + await().atMost(30, TimeUnit.SECONDS).until(() -> { + try { + String logLine; + RandomAccessFile commandOutputLogFile = new RandomAccessFile(logOutput, "r"); + while ((logLine = commandOutputLogFile.readLine()) != null) { + if (logLine.startsWith(ARGS_LOG_LINE_PREFIX)) { + commandOutputLogFile.close(); + return true; + } + } + commandOutputLogFile.close(); + return false; + } catch (Exception e) { + System.out.println(String.format("e: , ", e.getMessage(), e.getCause())); + System.out.println("e: " + Arrays.toString(e.getStackTrace())); + return false; + } + }); + String argsLengthLogLine = null; + String argsLogLine = null; + if (logOutput.exists()) { + try (BufferedReader reader = Files.newBufferedReader(logOutput.toPath())) { + String line = reader.readLine(); + while (line != null) { + if (line.startsWith(ARGS_LOG_LINE_PREFIX)) { + if (line.contains("length")) { + argsLengthLogLine = line; + } else { + argsLogLine = line; + } + } + line = reader.readLine(); + } + } + } + assertThat(argsLengthLogLine).isNotNull(); + assertThat(argsLengthLogLine).isNotEmpty(); + assertThat(argsLogLine).isNotNull(); + assertThat(argsLogLine).isNotEmpty(); + assertThat(argsLengthLogLine).contains("basic-java-main-application-project: args.length: 2"); + assertThat(argsLogLine).contains("basic-java-main-application-project: args: [param1=1, param2=2]"); + } +}