Skip to content

Commit 1a34025

Browse files
committed
Introduces gradle-8 profile in the Gradle IT module to re-run certain tests with Gradle 8.14
1 parent 56d7124 commit 1a34025

File tree

5 files changed

+141
-27
lines changed

5 files changed

+141
-27
lines changed

.github/workflows/ci-actions-incremental.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ jobs:
773773
env:
774774
CAPTURE_BUILD_SCAN: true
775775
# Important: keep -pl ... in sync with "Calculate run flags"!
776-
run: ./mvnw $COMMON_MAVEN_ARGS $COMMON_TEST_MAVEN_ARGS $PTS_MAVEN_ARGS $JVM_TEST_MAVEN_ARGS clean install -pl integration-tests/gradle
776+
run: ./mvnw $COMMON_MAVEN_ARGS $COMMON_TEST_MAVEN_ARGS $PTS_MAVEN_ARGS $JVM_TEST_MAVEN_ARGS clean install -pl integration-tests/gradle -Pgradle-8
777777
- name: Prepare build reports archive
778778
if: always()
779779
run: |

integration-tests/gradle/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,37 @@
544544
<maven.test.skip>true</maven.test.skip>
545545
</properties>
546546
</profile>
547+
<profile>
548+
<id>gradle-8</id>
549+
<!-- Adds an execution to the surefire plugin that runs selected tests with Gradle 8 -->
550+
<build>
551+
<pluginManagement>
552+
<plugins>
553+
<plugin>
554+
<groupId>org.apache.maven.plugins</groupId>
555+
<artifactId>maven-surefire-plugin</artifactId>
556+
<executions>
557+
<execution>
558+
<id>gradle-wrapper-8.14</id>
559+
<phase>test</phase>
560+
<goals>
561+
<goal>test</goal>
562+
</goals>
563+
<configuration>
564+
<systemPropertyVariables>
565+
<quarkus-test-gradle-wrapper-version>8.14</quarkus-test-gradle-wrapper-version>
566+
</systemPropertyVariables>
567+
<includes>
568+
<include>BasicMultiModuleQuarkusBuildTest</include>
569+
</includes>
570+
</configuration>
571+
</execution>
572+
</executions>
573+
</plugin>
574+
</plugins>
575+
</pluginManagement>
576+
</build>
577+
</profile>
547578
<profile>
548579
<id>native-image</id>
549580
<!-- Since there is no quarkus-maven-plugin build goal in this pom,

integration-tests/gradle/src/test/java/io/quarkus/gradle/CompileOnlyDependencyFlagsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import io.quarkus.maven.dependency.DependencyFlags;
2121
import io.quarkus.runtime.LaunchMode;
2222

23-
public class CompileOnlyDependencyFlagsTest {
23+
public class CompileOnlyDependencyFlagsTest extends QuarkusGradleTestBase {
2424

2525
@Test
2626
public void compileOnlyFlags() throws Exception {
27-
var projectDir = QuarkusGradleTestBase.getProjectDir("compile-only-dependency-flags");
27+
var projectDir = getProjectDir("compile-only-dependency-flags");
2828

2929
final String componly = ArtifactCoords.jar("org.acme", "componly", "1.0.0-SNAPSHOT").toCompactCoords();
3030
final String common = ArtifactCoords.jar("org.acme", "common", "1.0.0-SNAPSHOT").toCompactCoords();

integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleTestBase.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,59 @@
66
import java.io.IOException;
77
import java.io.InputStream;
88
import java.io.OutputStream;
9+
import java.io.UncheckedIOException;
910
import java.net.URISyntaxException;
1011
import java.net.URL;
1112
import java.nio.file.Files;
1213
import java.nio.file.Path;
1314
import java.nio.file.Paths;
14-
import java.util.ArrayList;
15-
import java.util.Arrays;
16-
import java.util.List;
1715
import java.util.Properties;
1816

17+
import io.quarkus.bootstrap.util.IoUtils;
18+
1919
public class QuarkusGradleTestBase {
2020

21-
protected static File getProjectDir(final String projectName)
22-
throws URISyntaxException, IOException {
23-
final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource(projectName);
21+
protected File getProjectDir(final String projectName) {
22+
return getProjectDir(projectName, null);
23+
}
24+
25+
protected File getProjectDir(final String baseProjectName, String testSuffix) {
26+
final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource(baseProjectName);
2427
if (projectUrl == null) {
25-
throw new IllegalStateException("Failed to locate test project " + projectName);
28+
throw new IllegalStateException("Failed to locate test project " + baseProjectName);
29+
}
30+
File projectDir;
31+
try {
32+
projectDir = new File(projectUrl.toURI());
33+
} catch (URISyntaxException e) {
34+
throw new RuntimeException(e);
2635
}
27-
final File projectDir = new File(projectUrl.toURI());
2836
if (!projectDir.isDirectory()) {
2937
throw new IllegalStateException(projectDir + " is not a directory");
3038
}
3139

40+
if (testSuffix != null && !testSuffix.isBlank()) {
41+
var testProjectName = new StringBuilder().append(projectDir.getName());
42+
if (testSuffix.charAt(0) != '-') {
43+
testProjectName.append("-");
44+
}
45+
testProjectName.append(testSuffix);
46+
Path targetDir = projectDir.getParentFile().toPath().resolve(testProjectName.toString());
47+
try {
48+
IoUtils.copy(projectDir.toPath(), targetDir);
49+
} catch (IOException e) {
50+
throw new RuntimeException(e);
51+
}
52+
projectDir = targetDir.toFile();
53+
}
54+
3255
final Properties props = new Properties();
3356
final File projectProps = new File(projectDir, "gradle.properties");
3457
if (projectProps.exists()) {
3558
try (InputStream is = new FileInputStream(projectProps)) {
3659
props.load(is);
60+
} catch (IOException e) {
61+
throw new UncheckedIOException(e);
3762
}
3863
} else {
3964
props.setProperty("quarkusPlatformGroupId", "io.quarkus");
@@ -45,31 +70,25 @@ protected static File getProjectDir(final String projectName)
4570
props.setProperty("quarkusPluginVersion", quarkusVersion);
4671
try (OutputStream os = new FileOutputStream(projectProps)) {
4772
props.store(os, "Quarkus Gradle TS");
73+
} catch (IOException e) {
74+
throw new UncheckedIOException(e);
4875
}
4976
return projectDir;
5077
}
5178

52-
protected static String getQuarkusVersion() throws IOException {
79+
protected static String getQuarkusVersion() {
5380
final Path curDir = Paths.get("").toAbsolutePath().normalize();
5481
final Path gradlePropsFile = curDir.resolve("gradle.properties");
5582
Properties props = new Properties();
5683
try (InputStream is = Files.newInputStream(gradlePropsFile)) {
5784
props.load(is);
85+
} catch (IOException e) {
86+
throw new UncheckedIOException(e);
5887
}
5988
final String quarkusVersion = props.getProperty("version");
6089
if (quarkusVersion == null) {
6190
throw new IllegalStateException("Failed to locate Quarkus version in " + gradlePropsFile);
6291
}
6392
return quarkusVersion;
6493
}
65-
66-
protected List<String> arguments(String... argument) {
67-
List<String> arguments = new ArrayList<>();
68-
arguments.addAll(Arrays.asList(argument));
69-
String mavenRepoLocal = System.getProperty("maven.repo.local", System.getenv("MAVEN_LOCAL_REPO"));
70-
if (mavenRepoLocal != null) {
71-
arguments.add("-Dmaven.repo.local=" + mavenRepoLocal);
72-
}
73-
return arguments;
74-
}
7594
}

integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.FileWriter;
77
import java.io.IOException;
88
import java.lang.management.ManagementFactory;
9-
import java.nio.file.Paths;
109
import java.util.ArrayList;
1110
import java.util.Arrays;
1211
import java.util.HashMap;
@@ -22,12 +21,39 @@ public class QuarkusGradleWrapperTestBase extends QuarkusGradleTestBase {
2221
private static final String GRADLE_WRAPPER_WINDOWS = "gradlew.bat";
2322
private static final String GRADLE_WRAPPER_UNIX = "./gradlew";
2423
private static final String MAVEN_REPO_LOCAL = "maven.repo.local";
24+
private static final String QUARKUS_TEST_GRADLE_WRAPPER_VERSION = "quarkus-test-gradle-wrapper-version";
2525

2626
private Map<String, String> systemProps;
2727

2828
private boolean configurationCacheEnable = true;
2929
private boolean noWatchFs = true;
3030

31+
@Override
32+
protected File getProjectDir(String projectName) {
33+
return getProjectDir(projectName, getTestProjectNameSuffix());
34+
}
35+
36+
/**
37+
* Returns a suffix for a test project directory name based on the requested Gradle wrapper version.
38+
* If a Gradle wrapper version was not configured, the suffix will be null.
39+
* Otherwise, it will be {@code -wrapper-${quarkus-test-gradle-wrapper-version}}.
40+
*
41+
* @return test project directory suffix or null
42+
*/
43+
private static String getTestProjectNameSuffix() {
44+
var wrapperVersion = getRequestedWrapperVersion();
45+
return wrapperVersion == null ? null : "-wrapper-" + wrapperVersion;
46+
}
47+
48+
/**
49+
* Returns configured Gradle wrapper version for a test or null, in case it wasn't configured.
50+
*
51+
* @return configured Gradle wrapper version or null
52+
*/
53+
private static String getRequestedWrapperVersion() {
54+
return System.getProperty(QUARKUS_TEST_GRADLE_WRAPPER_VERSION);
55+
}
56+
3157
protected void setupTestCommand() {
3258

3359
}
@@ -61,9 +87,12 @@ public BuildResult runGradleWrapper(boolean expectError, File projectDir, boolea
6187
throws IOException, InterruptedException {
6288
boolean isInCiPipeline = "true".equals(System.getenv("CI"));
6389

90+
// install a custom version of the wrapper, in case it's configured
91+
installRequestedWrapper(projectDir);
92+
6493
setupTestCommand();
6594
List<String> command = new ArrayList<>();
66-
command.add(getGradleWrapperCommand());
95+
command.add(getGradleWrapperCommand(projectDir));
6796
addSystemProperties(command);
6897

6998
if (!isInCiPipeline && isDebuggerConnected()) {
@@ -87,7 +116,7 @@ public BuildResult runGradleWrapper(boolean expectError, File projectDir, boolea
87116

88117
File logOutput = new File(projectDir, "command-output.log");
89118

90-
System.out.println("$ " + String.join(" ", command));
119+
logCommandLine(command);
91120
ProcessBuilder pb = new ProcessBuilder()
92121
.directory(projectDir)
93122
.command(command)
@@ -142,15 +171,50 @@ public BuildResult runGradleWrapper(boolean expectError, File projectDir, boolea
142171
return commandResult;
143172
}
144173

174+
private static void logCommandLine(List<String> command) {
175+
System.out.println("$ " + String.join(" ", command));
176+
}
177+
178+
private void installRequestedWrapper(File projectDir) {
179+
String wrapperVersion = getRequestedWrapperVersion();
180+
if (wrapperVersion == null) {
181+
// no specific version was configured, the integration-test/gradle one will be used
182+
return;
183+
}
184+
final String defaultWrapper = getGradleWrapperCommand(projectDir);
185+
186+
final List<String> command = List.of(defaultWrapper, "wrapper", "--gradle-version=" + wrapperVersion);
187+
logCommandLine(command);
188+
189+
final ProcessBuilder pb = new ProcessBuilder()
190+
.directory(projectDir)
191+
.command(command)
192+
.redirectInput(ProcessBuilder.Redirect.INHERIT)
193+
// Should prevent "fragmented" output (parts of stdout and stderr interleaved)
194+
.redirectErrorStream(true);
195+
try {
196+
pb.start().waitFor();
197+
} catch (Exception e) {
198+
throw new RuntimeException("Failed to install Gradle wrapper", e);
199+
}
200+
}
201+
145202
protected void setSystemProperty(String name, String value) {
146203
if (systemProps == null) {
147204
systemProps = new HashMap<>();
148205
}
149206
systemProps.put(name, value);
150207
}
151208

152-
private String getGradleWrapperCommand() {
153-
return Paths.get(getGradleWrapperName()).toAbsolutePath().toString();
209+
private String getGradleWrapperCommand(File projectDir) {
210+
File wrapper = null;
211+
if (projectDir != null) {
212+
wrapper = new File(projectDir, getGradleWrapperName());
213+
}
214+
if (wrapper == null || !wrapper.exists()) {
215+
wrapper = new File(getGradleWrapperName());
216+
}
217+
return wrapper.getAbsolutePath();
154218
}
155219

156220
private String getGradleWrapperName() {

0 commit comments

Comments
 (0)