Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect quarkus.class-loading.removed-artifacts when re-augmenting an app #27604

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public boolean test(String path) {
*/
private static boolean includeAppDep(ResolvedDependency appDep, Optional<Set<ArtifactKey>> optionalDependencies,
Set<ArtifactKey> removedArtifacts) {
if (!"jar".equals(appDep.getType())) {
if (!appDep.isJar()) {
return false;
}
if (appDep.isOptional()) {
Expand Down Expand Up @@ -577,7 +577,6 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
} else {
IoUtils.createOrEmptyDir(quarkus);
}
Map<ArtifactKey, List<Path>> copiedArtifacts = new HashMap<>();

Path decompiledOutputDir = null;
boolean wasDecompiledSuccessfully = true;
Expand Down Expand Up @@ -672,14 +671,15 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
}
}
final Set<ArtifactKey> parentFirstKeys = getParentFirstKeys(curateOutcomeBuildItem, classLoadingConfig);
StringBuilder classPath = new StringBuilder();
final StringBuilder classPath = new StringBuilder();
final Set<ArtifactKey> removed = getRemovedKeys(classLoadingConfig);
final Map<ArtifactKey, List<Path>> copiedArtifacts = new HashMap<>();
for (ResolvedDependency appDep : curateOutcomeBuildItem.getApplicationModel().getRuntimeDependencies()) {
if (rebuild) {
appDep.getResolvedPaths().forEach(jars::add);
} else {
if (!rebuild) {
copyDependency(parentFirstKeys, outputTargetBuildItem, copiedArtifacts, mainLib, baseLib, jars, true,
classPath, appDep, transformedClasses, removed);
} else if (includeAppDep(appDep, outputTargetBuildItem.getIncludedOptionalDependencies(), removed)) {
appDep.getResolvedPaths().forEach(jars::add);
}
if (parentFirstKeys.contains(appDep.getKey())) {
appDep.getResolvedPaths().forEach(parentFirst::add);
Expand Down Expand Up @@ -745,15 +745,13 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,

//now copy the deployment artifacts, if required
if (mutableJar) {

Path deploymentLib = libDir.resolve(DEPLOYMENT_LIB);
Files.createDirectories(deploymentLib);
for (ResolvedDependency appDep : curateOutcomeBuildItem.getApplicationModel().getDependencies()) {
copyDependency(parentFirstKeys, outputTargetBuildItem, copiedArtifacts, deploymentLib, baseLib, jars,
false, classPath,
appDep, new TransformedClassesBuildItem(Collections.emptyMap()), removed); //we don't care about transformation here, so just pass in an empty item
appDep, new TransformedClassesBuildItem(Map.of()), removed); //we don't care about transformation here, so just pass in an empty item
}

Map<ArtifactKey, List<String>> relativePaths = new HashMap<>();
for (Map.Entry<ArtifactKey, List<Path>> e : copiedArtifacts.entrySet()) {
relativePaths.put(e.getKey(),
Expand Down Expand Up @@ -804,7 +802,6 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
}
} else {
//if it is a rebuild we might have classes

}
try (Stream<Path> files = Files.walk(buildDir)) {
files.forEach(new Consumer<Path>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static String[] split(String str, String[] parts, int fromIndex) {
if ((parts[1] = parts[3]).isEmpty()) {
throw new IllegalArgumentException("ArtifactId is empty in `" + str + "`");
}
parts[2] = "";
parts[2] = ArtifactCoords.DEFAULT_CLASSIFIER;
parts[3] = null;
return parts;
}
Expand All @@ -86,7 +86,7 @@ public static String[] split(String str, String[] parts, int fromIndex) {
"One of groupId or artifactId is missing from '" + str.substring(0, fromIndex) + "'");
}
if (i == fromIndex - 1) {
parts[2] = "";
parts[2] = ArtifactCoords.DEFAULT_CLASSIFIER;
} else {
parts[2] = str.substring(i + 1, fromIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void launch(TestContext context, String path, File testDir, String outpu
Process process = JarRunnerIT
.doLaunch(new File(testDir, String.format("target/%s%squarkus-app", context.prefix, outputPrefix)),
Paths.get(context.jarFileName), output,
Collections.emptyList())
List.of())
.start();
try {
Assertions.assertEquals(expectedMessage, DevModeTestUtils.getHttpResponse(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ public void testResourcesFromClasspath() throws MavenInvocationException, IOExce
RunningInvoker invoker = new RunningInvoker(testDir, false);

// to properly surface the problem of multiple classpath entries, we need to install the project to the local m2
MavenProcessInvocationResult installInvocation = invoker.execute(Arrays.asList("clean", "install", "-DskipTests"),
MavenProcessInvocationResult installInvocation = invoker.execute(List.of("clean", "install", "-DskipTests"),
Collections.emptyMap());
assertThat(installInvocation.getProcess().waitFor(2, TimeUnit.MINUTES)).isTrue();
assertThat(installInvocation.getExecutionException()).isNull();
Expand All @@ -1185,7 +1185,8 @@ public void testResourcesFromClasspath() throws MavenInvocationException, IOExce
.until(() -> DevModeTestUtils.getHttpResponse("/cp/hello").equals("hello"));

// test that we don't get multiple instances of a resource when loading from the ClassLoader
assertThat(DevModeTestUtils.getHttpResponse("/cp/resourcesCount")).isEqualTo("1");
assertThat(DevModeTestUtils.getHttpResponse("/cp/resourceCount/a.html")).isEqualTo("1");
assertThat(DevModeTestUtils.getHttpResponse("/cp/resourceCount/entry")).isEqualTo("2");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -70,8 +71,8 @@ public void testNonAsciiDir() throws Exception {
File output = new File(testDir, "target/output.log");
output.createNewFile();

Process process = doLaunch(new File(testDir, "target/quarkus-app"), Paths.get("quarkus-run.jar"), output,
Collections.emptyList()).start();
Process process = doLaunch(new File(testDir, "target/quarkus-app"), Paths.get("quarkus-run.jar"), output, List.of())
.start();
try {
// Wait until server up
dumpFileContentOnFailure(() -> {
Expand Down Expand Up @@ -137,7 +138,7 @@ public void testPlatformPropertiesOverridenInApplicationProperties() throws Exce
output.createNewFile();

Process process = doLaunch(new File(testDir, "app/target/quarkus-app"), Paths.get("quarkus-run.jar"), output,
Collections.emptyList()).start();
List.of()).start();
try {
Assertions.assertEquals("builder-image is customized", DevModeTestUtils.getHttpResponse("/hello"));
} finally {
Expand All @@ -162,7 +163,7 @@ public void testPlatformPropertiesOverridenOnCommandLine() throws Exception {
output.createNewFile();

Process process = doLaunch(new File(testDir, "app/target/quarkus-app"), Paths.get("quarkus-run.jar"), output,
Collections.emptyList()).start();
List.of()).start();
try {
Assertions.assertEquals("builder-image is commandline", DevModeTestUtils.getHttpResponse("/hello"));
} finally {
Expand Down Expand Up @@ -252,6 +253,97 @@ public void testThatLegacyJarFormatWorks() throws Exception {
}
}

@Test
public void reaugmentationWithRemovedArtifacts() throws Exception {
File testDir = initProject("projects/multimodule-classpath", "projects/multimodule-resources-classpath-reaugmentation");
RunningInvoker running = new RunningInvoker(testDir, false);

// The default build
MavenProcessInvocationResult result = running
.execute(List.of("package", "-DskipTests", "-Dquarkus.package.type=mutable-jar"), Map.of());
await().atMost(1, TimeUnit.MINUTES).until(() -> result.getProcess() != null && !result.getProcess().isAlive());
assertThat(running.log()).containsIgnoringCase("BUILD SUCCESS");
running.stop();

testDir = testDir.toPath().resolve("runner").toFile();

Path runJar = testDir.toPath().toAbsolutePath().resolve(Paths.get("target/quarkus-app/quarkus-run.jar"));
assertThat(runJar).exists();

File output = new File(testDir, "target/output.log");
output.createNewFile();

Process process = doLaunch(runJar, output).start();
try {
AtomicReference<String> response = new AtomicReference<>();
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> {
String ret = DevModeTestUtils.getHttpResponse("/cp/resourceCount/entry", false);
response.set(ret);
return true;
});

// Test that bean is not resolvable
assertThat(response.get()).isEqualTo("2");
} finally {
process.destroy();
}

// re-augment and exclude html-extra
process = doLaunch(runJar, output,
List.of("-Dquarkus.class-loading.removed-artifacts=cp.acme:multimodule-cp-resources-html-extra",
"-Dquarkus.launch.rebuild=true"))
.start();
try {
assertThat(process.waitFor()).isEqualTo(0);
} finally {
process.destroy();
}

process = doLaunch(runJar, output).start();
try {
AtomicReference<String> response = new AtomicReference<>();
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> {
String ret = DevModeTestUtils.getHttpResponse("/cp/resourceCount/entry", false);
response.set(ret);
return true;
});

// Test that bean is not resolvable
assertThat(response.get()).isEqualTo("1");
} finally {
process.destroy();
}

// re-augment with the original dependencies
process = doLaunch(runJar, output, List.of("-Dquarkus.launch.rebuild=true")).start();
try {
assertThat(process.waitFor()).isEqualTo(0);
} finally {
process.destroy();
}

process = doLaunch(runJar, output).start();
try {
AtomicReference<String> response = new AtomicReference<>();
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> {
String ret = DevModeTestUtils.getHttpResponse("/cp/resourceCount/entry", false);
response.set(ret);
return true;
});

// Test that bean is not resolvable
assertThat(response.get()).isEqualTo("2");
} finally {
process.destroy();
}
}

private void assertThatMutableFastJarWorks(String targetDirSuffix, String providersDir) throws Exception {
File testDir = initProject("projects/classic",
"projects/project-classic-console-output-mutable-fast-jar" + targetDirSuffix);
Expand Down Expand Up @@ -402,7 +494,7 @@ public void testThatAppCDSAreUsable() throws Exception {
// by using '-Xshare:on' we ensure that the JVM will fail if for any reason is cannot use the AppCDS
// '-Xlog:class+path=info' will print diagnostic information that is useful for debugging if something goes wrong
Process process = doLaunch(jar.getFileName(), output,
Arrays.asList("-XX:SharedArchiveFile=app-cds.jsa", "-Xshare:on", "-Xlog:class+path=info"))
List.of("-XX:SharedArchiveFile=app-cds.jsa", "-Xshare:on", "-Xlog:class+path=info"))
.directory(jar.getParent().toFile()).start();
try {
// Wait until server up
Expand Down Expand Up @@ -461,7 +553,7 @@ public void testArcExcludeDependencyOnLocalModule() throws Exception {
}

private ProcessBuilder doLaunch(Path jar, File output) throws IOException {
return doLaunch(null, jar, output, Collections.emptyList());
return doLaunch(null, jar, output, List.of());
}

private ProcessBuilder doLaunch(Path jar, File output, Collection<String> vmArgs) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private List<String> listExtensions()
InvocationOutputHandler outputHandler = new PrintStreamHandler(
new PrintStream(new TeeOutputStream(System.out, Files.newOutputStream(outputLog.toPath())), true, "UTF-8"),
true);
invoker.setOutputHandler(outputHandler);
request.setOutputHandler(outputHandler);

File invokerLog = new File(testDir, "invoker.log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(invokerLog), false, "UTF-8"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>cp.acme</groupId>
<artifactId>multimodule-cp-resources</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>multimodule-cp-resources-html-extra</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<modules>
<module>rest</module>
<module>html</module>
<module>html-extra</module>
<module>runner</module>
</modules>

Expand Down Expand Up @@ -47,6 +48,11 @@
<artifactId>multimodule-cp-resources-html</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cp.acme</groupId>
<artifactId>multimodule-cp-resources-html-extra</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cp.acme</groupId>
<artifactId>multimodule-cp-resources-rest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.jboss.resteasy.reactive.RestPath;

@Path("/cp")
public class ClassPathResource {
Expand All @@ -22,10 +23,10 @@ public String hello() {
}

@GET
@Path("/resourcesCount")
@Path("/resourceCount/{name}")
@Produces(MediaType.TEXT_PLAIN)
public int resourcesCount() throws IOException {
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources("META-INF/resources/a.html");
public int resourceCount(@RestPath String name) throws IOException {
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources("META-INF/resources/" + name);
int count = 0;
while (resources.hasMoreElements()) {
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<groupId>cp.acme</groupId>
<artifactId>multimodule-cp-resources-html</artifactId>
</dependency>
<dependency>
<groupId>cp.acme</groupId>
<artifactId>multimodule-cp-resources-html</artifactId>
<artifactId>multimodule-cp-resources-html-extra</artifactId>
</dependency>
<dependency>
<groupId>cp.acme</groupId>
Expand Down