use of io.quarkus.bootstrap.app.AugmentResult in project quarkus by quarkusio.
the class IsolatedRemoteDevModeMain method generateApplication.
private synchronized JarResult generateApplication() {
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
// ok, we have resolved all the deps
try {
AugmentResult start = augmentAction.createProductionApplication();
if (!start.getJar().getType().equalsIgnoreCase(PackageConfig.MUTABLE_JAR)) {
throw new RuntimeException("remote-dev can only be used with mutable applications generated with the fast-jar format");
}
// now extract the artifacts, to mirror the remote side
DevModeTask.extractDevModeClasses(start.getJar().getPath().getParent(), curatedApplication.getApplicationModel(), null);
return start.getJar();
} catch (Throwable t) {
deploymentProblem = t;
log.error("Failed to generate Quarkus application", t);
return null;
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of io.quarkus.bootstrap.app.AugmentResult in project quarkus by quarkusio.
the class AugmentActionImpl method createProductionApplication.
@Override
public AugmentResult createProductionApplication() {
if (launchMode != LaunchMode.NORMAL) {
throw new IllegalStateException("Can only create a production application when using NORMAL launch mode");
}
ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
BuildResult result = runAugment(true, Collections.emptySet(), null, classLoader, ArtifactResultBuildItem.class, DeploymentResultBuildItem.class);
writeDebugSourceFile(result);
JarBuildItem jarBuildItem = result.consumeOptional(JarBuildItem.class);
NativeImageBuildItem nativeImageBuildItem = result.consumeOptional(NativeImageBuildItem.class);
List<ArtifactResultBuildItem> artifactResultBuildItems = result.consumeMulti(ArtifactResultBuildItem.class);
BuildSystemTargetBuildItem buildSystemTargetBuildItem = result.consume(BuildSystemTargetBuildItem.class);
// this depends on the fact that the order in which we can obtain MultiBuildItems is the same as they are produced
// we want to write result of the final artifact created
ArtifactResultBuildItem lastResult = artifactResultBuildItems.get(artifactResultBuildItems.size() - 1);
writeArtifactResultMetadataFile(buildSystemTargetBuildItem, lastResult);
return new AugmentResult(artifactResultBuildItems.stream().map(a -> new ArtifactResult(a.getPath(), a.getType(), a.getMetadata())).collect(Collectors.toList()), jarBuildItem != null ? jarBuildItem.toJarResult() : null, nativeImageBuildItem != null ? nativeImageBuildItem.getPath() : null);
}
use of io.quarkus.bootstrap.app.AugmentResult in project quarkus by quarkusio.
the class PackageAppTestBase method testBootstrap.
@Override
protected void testBootstrap(QuarkusBootstrap creator) throws Exception {
System.setProperty("quarkus.package.type", "legacy-jar");
try {
CuratedApplication curated = creator.bootstrap();
assertAppModel(curated.getApplicationModel());
final String[] expectedExtensions = expectedExtensionDependencies();
if (expectedExtensions != null) {
assertExtensionDependencies(curated.getApplicationModel(), expectedExtensions);
}
assertDeploymentDeps(curated.getApplicationModel().getDependencies().stream().filter(d -> d.isDeploymentCp() && !d.isRuntimeCp()).map(d -> new ArtifactDependency(d)).collect(Collectors.toSet()));
AugmentAction action = curated.createAugmentor();
AugmentResult outcome = action.createProductionApplication();
final Path libDir = outcome.getJar().getLibraryDir();
assertTrue(Files.isDirectory(libDir));
final Set<String> actualLib = new HashSet<>();
try (Stream<Path> stream = Files.list(libDir)) {
final Iterator<Path> i = stream.iterator();
while (i.hasNext()) {
actualLib.add(i.next().getFileName().toString());
}
}
final Path runnerJar = outcome.getJar().getPath();
assertTrue(Files.exists(runnerJar));
try (JarFile jar = new JarFile(runnerJar.toFile())) {
final Attributes mainAttrs = jar.getManifest().getMainAttributes();
// assert the main class
assertEquals(MAIN_CLS, mainAttrs.getValue("Main-Class"));
// assert the Class-Path contains all the entries in the lib dir
final String cp = mainAttrs.getValue("Class-Path");
assertNotNull(cp);
String[] cpEntries = Arrays.stream(cp.trim().split("\\s+")).filter(s -> !s.trim().isEmpty()).toArray(String[]::new);
assertEquals(actualLib.size(), cpEntries.length);
for (String entry : cpEntries) {
assertTrue(entry.startsWith(LIB_PREFIX));
assertTrue(actualLib.contains(entry.substring(LIB_PREFIX.length())));
}
}
List<String> missingEntries = Collections.emptyList();
for (String entry : expectedLib) {
if (!actualLib.remove(entry)) {
if (missingEntries.isEmpty()) {
missingEntries = new ArrayList<>();
}
missingEntries.add(entry);
}
}
StringBuilder buf = null;
if (!missingEntries.isEmpty()) {
buf = new StringBuilder();
buf.append("Missing entries: ").append(missingEntries.get(0));
for (int i = 1; i < missingEntries.size(); ++i) {
buf.append(", ").append(missingEntries.get(i));
}
}
if (!actualLib.isEmpty()) {
if (buf == null) {
buf = new StringBuilder();
} else {
buf.append("; ");
}
final Iterator<String> i = actualLib.iterator();
buf.append("Extra entries: ").append(i.next());
while (i.hasNext()) {
buf.append(", ").append(i.next());
}
}
if (buf != null) {
fail(buf.toString());
}
} finally {
System.clearProperty("quarkus.package.type");
}
}
use of io.quarkus.bootstrap.app.AugmentResult in project quarkus by quarkusio.
the class RebuildHandler method handlePostAsync.
@Override
protected void handlePostAsync(RoutingContext event, MultiMap form) throws Exception {
QuarkusBootstrap existing = (QuarkusBootstrap) DevConsoleManager.getQuarkusBootstrap();
try (TempSystemProperties properties = new TempSystemProperties()) {
for (Map.Entry<String, String> i : config.entrySet()) {
properties.set(i.getKey(), i.getValue());
}
for (Map.Entry<String, String> i : form.entries()) {
if (!i.getValue().isEmpty()) {
properties.set(i.getKey(), i.getValue());
}
}
QuarkusBootstrap quarkusBootstrap = existing.clonedBuilder().setMode(QuarkusBootstrap.Mode.PROD).setIsolateDeployment(true).build();
try (CuratedApplication bootstrap = quarkusBootstrap.bootstrap()) {
AugmentResult augmentResult = bootstrap.createAugmentor().createProductionApplication();
List<ArtifactResult> containerArtifactResults = augmentResult.resultsMatchingType((s) -> s.contains("container"));
if (containerArtifactResults.size() >= 1) {
flashMessage(event, "Container-image: " + containerArtifactResults.get(0).getMetadata().get("container-image") + " created.", Duration.ofSeconds(10));
}
}
}
;
}
use of io.quarkus.bootstrap.app.AugmentResult in project quarkus-test-framework by quarkus-qe.
the class ProdQuarkusApplicationManagedResourceBuilder method buildArtifact.
private Path buildArtifact() {
try {
createSnapshotOfBuildProperties();
Path appFolder = getApplicationFolder();
JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class).addClasses(getAppClasses());
javaArchive.as(ExplodedExporter.class).exportExplodedInto(appFolder.toFile());
Path testLocation = PathTestHelper.getTestClassesLocation(getContext().getTestContext().getRequiredTestClass());
QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder().setApplicationRoot(appFolder).setMode(QuarkusBootstrap.Mode.PROD).addExcludedPath(testLocation).setIsolateDeployment(true).setProjectRoot(testLocation).setBaseName(getContext().getName()).setTargetDirectory(appFolder);
if (!getForcedDependencies().isEmpty()) {
// The method setForcedDependencies signature changed from `List<AppDependency>` to `List<Dependency>` where
// Dependency is an interface of AppDependency, so it should be fine. However, the compiler fails to cast it,
// so we need to use reflection to sort it out for the most recent version and older versions.
ReflectionUtils.invokeMethod(builder, "setForcedDependencies", getForcedDependencies());
}
// The method `setLocalProjectDiscovery` signature changed from `Boolean` to `boolean` and this might make
// to fail the tests at runtime when using different versions.
// In order to workaround this, we need to invoke this method at runtime to let JVM unbox the arguments properly.
// Note that this is happening because we want to support both 2.x and 1.13.x Quarkus versions.
// Another strategy could be to have our own version of Quarkus bootstrap.
ReflectionUtils.invokeMethod(builder, "setLocalProjectDiscovery", true);
AugmentResult result;
try (CuratedApplication curatedApplication = builder.build().bootstrap()) {
AugmentAction action = curatedApplication.createAugmentor();
result = action.createProductionApplication();
}
return Optional.ofNullable(result.getNativeResult()).orElseGet(() -> result.getJar().getPath());
} catch (Exception ex) {
fail("Failed to build Quarkus artifacts. Caused by " + ex);
}
return null;
}
Aggregations