Skip to content

Commit

Permalink
Merge pull request #19213 from stuartwdouglas/reaug-fixes
Browse files Browse the repository at this point in the history
Reaugment removes build-system.properties
  • Loading branch information
gsmet authored Aug 4, 2021
2 parents a1a1e7d + f5f8c6e commit 44e7029
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void accept(Path path) {
}

AppModel existingModel = appModel.getAppModel(appRoot);
System.setProperty("quarkus.package.type", "fast-jar");
System.setProperty("quarkus.package.type", "mutable-jar");
try (CuratedApplication bootstrap = QuarkusBootstrap.builder()
.setAppArtifact(existingModel.getAppArtifact())
.setExistingModel(existingModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,21 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,

runnerJar.toFile().setReadable(true, false);
Path initJar = buildDir.resolve(QUARKUS_RUN_JAR);
boolean mutableJar = packageConfig.type.equalsIgnoreCase(PackageConfig.MUTABLE_JAR);
if (mutableJar) {
//we output the properties in a reproducible manner, so we remove the date comment
//and sort them
//we still use Properties to get the escaping right though, so basically we write out the lines
//to memory, split them, discard comments, sort them, then write them to disk
ByteArrayOutputStream out = new ByteArrayOutputStream();
outputTargetBuildItem.getBuildSystemProperties().store(out, null);
List<String> lines = Arrays.stream(new String(out.toByteArray(), StandardCharsets.UTF_8).split("\n"))
.filter(s -> !s.startsWith("#")).sorted().collect(Collectors.toList());
Path buildSystemProps = quarkus.resolve(BUILD_SYSTEM_PROPERTIES);
try (OutputStream fileOutput = Files.newOutputStream(buildSystemProps)) {
fileOutput.write(String.join("\n", lines).getBytes(StandardCharsets.UTF_8));
}
}
if (!rebuild) {
try (FileSystem runnerZipFs = ZipUtils.newZip(initJar)) {
AppArtifact appArtifact = curateOutcomeBuildItem.getEffectiveModel().getAppArtifact();
Expand All @@ -707,10 +722,9 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
}

//now copy the deployment artifacts, if required
if (packageConfig.type.equalsIgnoreCase(PackageConfig.MUTABLE_JAR)) {
if (mutableJar) {

Path deploymentLib = libDir.resolve(DEPLOYMENT_LIB);
Path buildSystemProps = quarkus.resolve(BUILD_SYSTEM_PROPERTIES);
Files.createDirectories(deploymentLib);
for (AppDependency appDep : curateOutcomeBuildItem.getEffectiveModel().getFullDeploymentDeps()) {
copyDependency(parentFirstKeys, outputTargetBuildItem, copiedArtifacts, deploymentLib, baseLib, jars,
Expand Down Expand Up @@ -754,18 +768,6 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
obj.writeObject(paths);
obj.close();
}
//we output the properties in a reproducible manner, so we remove the date comment
//and sort them
//we still use Properties to get the escaping right though, so basically we write out the lines
//to memory, split them, discard comments, sort them, then write them to disk
ByteArrayOutputStream out = new ByteArrayOutputStream();
outputTargetBuildItem.getBuildSystemProperties().store(out, null);
List<String> lines = Arrays.stream(new String(out.toByteArray(), StandardCharsets.UTF_8).split("\n"))
.filter(s -> !s.startsWith("#")).sorted().collect(Collectors.toList());

try (OutputStream fileOutput = Files.newOutputStream(buildSystemProps)) {
fileOutput.write(String.join("\n", lines).getBytes(StandardCharsets.UTF_8));
}
}

if (packageConfig.includeDependencyList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ private void assertThatMutableFastJarWorks(String targetDirSuffix, String provid
}

//add a user jar to the providers dir, and make sure it is picked up in re-augmentation
File addedJar = providers.resolve("added.jar").toFile();
ShrinkWrap.create(JavaArchive.class).addClass(AddedRestEndpoint.class)
.as(ZipExporter.class).exportTo(providers.resolve("added.jar").toFile());
.as(ZipExporter.class).exportTo(addedJar);

//now reaugment
List<String> commands = new ArrayList<>();
Expand Down Expand Up @@ -337,6 +338,46 @@ private void assertThatMutableFastJarWorks(String targetDirSuffix, String provid
} finally {
process.destroy();
}

//now remove it, and make sure everything is back to the way it was

//add a user jar to the providers dir, and make sure it is picked up in re-augmentation
addedJar.delete();

//now reaugment
commands = new ArrayList<>();
commands.add(JavaBinFinder.findBin());
commands.add("-Dquarkus.http.root-path=/anothermove");
commands.add("-Dquarkus.launch.rebuild=true");
commands.add("-jar");
commands.add(jar.toString());
processBuilder = new ProcessBuilder(commands.toArray(new String[0]));
processBuilder.redirectOutput(output);
processBuilder.redirectError(output);
Assertions.assertEquals(0, processBuilder.start().waitFor());

process = doLaunch(jar, output).start();
try {
// Wait until server up
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/anothermove/app/hello/package", 200));

String logs = FileUtils.readFileToString(output, "UTF-8");

assertThatOutputWorksCorrectly(logs);

// test that the application name and version are properly set
assertApplicationPropertiesSetCorrectly("/anothermove");

assertResourceReadingFromClassPathWorksCorrectly("/anothermove");
assertUsingProtectionDomainWorksCorrectly("/anothermove");
performRequest("/anothermove/app/added", 404);
} finally {
process.destroy();
}

}

@Test
Expand Down

0 comments on commit 44e7029

Please sign in to comment.