use of io.quarkus.bootstrap.app.CuratedApplication in project quarkus by quarkusio.
the class DevModeTask method main.
public static Closeable main(Path appRoot) throws Exception {
try (ObjectInputStream in = new ObjectInputStream(Files.newInputStream(appRoot.resolve(LIB).resolve(DEPLOYMENT_LIB).resolve(JarResultBuildStep.APPMODEL_DAT)))) {
Properties buildSystemProperties = new Properties();
try (InputStream buildIn = Files.newInputStream(appRoot.resolve(QUARKUS).resolve(BUILD_SYSTEM_PROPERTIES))) {
buildSystemProperties.load(buildIn);
}
final MutableJarApplicationModel appModel = (MutableJarApplicationModel) in.readObject();
ApplicationModel existingModel = appModel.getAppModel(appRoot);
DevModeContext context = createDevModeContext(appRoot, existingModel);
CuratedApplication bootstrap = QuarkusBootstrap.builder().setAppArtifact(existingModel.getAppArtifact()).setExistingModel(existingModel).setIsolateDeployment(true).setMode(QuarkusBootstrap.Mode.REMOTE_DEV_SERVER).setBuildSystemProperties(buildSystemProperties).setBaseName(appModel.getBaseName()).setApplicationRoot(existingModel.getAppArtifact().getResolvedPaths().getSinglePath()).setTargetDirectory(appRoot.getParent()).setBaseClassLoader(DevModeTask.class.getClassLoader()).build().bootstrap();
Map<String, Object> map = new HashMap<>();
map.put(DevModeContext.class.getName(), context);
map.put(IsolatedDevModeMain.APP_ROOT, appRoot);
map.put(DevModeType.class.getName(), DevModeType.REMOTE_SERVER_SIDE);
return (Closeable) bootstrap.runInAugmentClassLoader(IsolatedDevModeMain.class.getName(), map);
}
}
use of io.quarkus.bootstrap.app.CuratedApplication 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.CuratedApplication in project quarkus by quarkusio.
the class GenerateCodeMojo method generateCode.
void generateCode(PathCollection sourceParents, Consumer<Path> sourceRegistrar, boolean test) throws MojoFailureException, MojoExecutionException {
final LaunchMode launchMode = test ? LaunchMode.TEST : LaunchMode.valueOf(mode);
if (getLog().isDebugEnabled()) {
getLog().debug("Bootstrapping Quarkus application in mode " + launchMode);
}
ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
CuratedApplication curatedApplication = null;
try {
curatedApplication = bootstrapApplication(launchMode);
QuarkusClassLoader deploymentClassLoader = curatedApplication.createDeploymentClassLoader();
Thread.currentThread().setContextClassLoader(deploymentClassLoader);
final Class<?> codeGenerator = deploymentClassLoader.loadClass("io.quarkus.deployment.CodeGenerator");
final Method initAndRun = codeGenerator.getMethod("initAndRun", ClassLoader.class, PathCollection.class, Path.class, Path.class, Consumer.class, ApplicationModel.class, Properties.class, String.class, boolean.class);
initAndRun.invoke(null, deploymentClassLoader, sourceParents, generatedSourcesDir(test), buildDir().toPath(), sourceRegistrar, curatedApplication.getApplicationModel(), mavenProject().getProperties(), launchMode.name(), test);
} catch (Exception any) {
throw new MojoExecutionException("Quarkus code generation phase has failed", any);
} finally {
// in case of test mode, we can't share the bootstrapped app with the testing plugins, so we are closing it right away
if (test && curatedApplication != null) {
curatedApplication.close();
}
Thread.currentThread().setContextClassLoader(originalTccl);
}
}
use of io.quarkus.bootstrap.app.CuratedApplication in project quarkus by quarkusio.
the class QuarkusBuild method buildQuarkus.
@TaskAction
public void buildQuarkus() {
final ApplicationModel appModel;
try {
appModel = extension().getAppModelResolver().resolveModel(new GACTV(getProject().getGroup().toString(), getProject().getName(), getProject().getVersion().toString()));
} catch (AppModelResolverException e) {
throw new GradleException("Failed to resolve Quarkus application model for " + getProject().getPath(), e);
}
final Properties effectiveProperties = getBuildSystemProperties(appModel.getAppArtifact());
if (ignoredEntries != null && ignoredEntries.size() > 0) {
String joinedEntries = String.join(",", ignoredEntries);
effectiveProperties.setProperty("quarkus.package.user-configured-ignored-entries", joinedEntries);
}
exportCustomManifestProperties(effectiveProperties);
try (CuratedApplication appCreationContext = QuarkusBootstrap.builder().setBaseClassLoader(getClass().getClassLoader()).setExistingModel(appModel).setTargetDirectory(getProject().getBuildDir().toPath()).setBaseName(extension().finalName()).setBuildSystemProperties(effectiveProperties).setAppArtifact(appModel.getAppArtifact()).setLocalProjectDiscovery(false).setIsolateDeployment(true).build().bootstrap()) {
// Processes launched from within the build task of Gradle (daemon) lose content
// generated on STDOUT/STDERR by the process (see https://github.com/gradle/gradle/issues/13522).
// We overcome this by letting build steps know that the STDOUT/STDERR should be explicitly
// streamed, if they need to make available that generated data.
// The io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled$Factory
// does the necessary work to generate such a build item which the build step(s) can rely on
appCreationContext.createAugmentor("io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled$Factory", Collections.emptyMap()).createProductionApplication();
} catch (BootstrapException e) {
throw new GradleException("Failed to build a runnable JAR", e);
}
}
use of io.quarkus.bootstrap.app.CuratedApplication 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));
}
}
}
;
}
Aggregations