Search in sources :

Example 1 with BootstrapException

use of io.quarkus.bootstrap.BootstrapException 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);
    }
}
Also used : CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) GradleException(org.gradle.api.GradleException) BootstrapException(io.quarkus.bootstrap.BootstrapException) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) GACTV(io.quarkus.maven.dependency.GACTV) Properties(java.util.Properties) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with BootstrapException

use of io.quarkus.bootstrap.BootstrapException in project quarkus by quarkusio.

the class QuarkusGenerateCode method prepareQuarkus.

@TaskAction
public void prepareQuarkus() {
    LaunchMode launchMode = test ? LaunchMode.TEST : devMode ? LaunchMode.DEVELOPMENT : LaunchMode.NORMAL;
    final ApplicationModel appModel = extension().getApplicationModel(launchMode);
    final Properties realProperties = getBuildSystemProperties(appModel.getAppArtifact());
    Path buildDir = getProject().getBuildDir().toPath();
    try (CuratedApplication appCreationContext = QuarkusBootstrap.builder().setBaseClassLoader(getClass().getClassLoader()).setExistingModel(appModel).setTargetDirectory(buildDir).setBaseName(extension().finalName()).setBuildSystemProperties(realProperties).setAppArtifact(appModel.getAppArtifact()).setLocalProjectDiscovery(false).setIsolateDeployment(true).build().bootstrap()) {
        final JavaPluginConvention javaConvention = getProject().getConvention().findPlugin(JavaPluginConvention.class);
        if (javaConvention != null) {
            final String generateSourcesDir = test ? QUARKUS_TEST_GENERATED_SOURCES : QUARKUS_GENERATED_SOURCES;
            final SourceSet generatedSources = javaConvention.getSourceSets().findByName(generateSourcesDir);
            List<Path> paths = new ArrayList<>();
            generatedSources.getOutput().filter(f -> f.getName().equals(generateSourcesDir)).forEach(f -> paths.add(f.toPath()));
            if (paths.isEmpty()) {
                throw new GradleException("Failed to create quarkus-generated-sources");
            }
            getLogger().debug("Will trigger preparing sources for source directory: {} buildDir: {}", sourcesDirectories, getProject().getBuildDir().getAbsolutePath());
            QuarkusClassLoader deploymentClassLoader = appCreationContext.createDeploymentClassLoader();
            Class<?> codeGenerator = deploymentClassLoader.loadClass(CodeGenerator.class.getName());
            Optional<Method> initAndRun = Arrays.stream(codeGenerator.getMethods()).filter(m -> m.getName().equals(INIT_AND_RUN)).findAny();
            if (initAndRun.isEmpty()) {
                throw new GradleException("Failed to find " + INIT_AND_RUN + " method in " + CodeGenerator.class.getName());
            }
            initAndRun.get().invoke(null, deploymentClassLoader, PathList.from(sourcesDirectories), paths.get(0), buildDir, sourceRegistrar, appCreationContext.getApplicationModel(), realProperties, launchMode.name(), test);
        }
    } catch (BootstrapException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
        throw new GradleException("Failed to generate sources in the QuarkusPrepare task", e);
    }
}
Also used : Path(java.nio.file.Path) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) Arrays(java.util.Arrays) PathList(io.quarkus.paths.PathList) LaunchMode(io.quarkus.runtime.LaunchMode) InputFiles(org.gradle.api.tasks.InputFiles) OutputDirectory(org.gradle.api.tasks.OutputDirectory) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) TaskAction(org.gradle.api.tasks.TaskAction) Method(java.lang.reflect.Method) Path(java.nio.file.Path) Properties(java.util.Properties) CompileClasspath(org.gradle.api.tasks.CompileClasspath) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) BootstrapException(io.quarkus.bootstrap.BootstrapException) Set(java.util.Set) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) List(java.util.List) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) GradleException(org.gradle.api.GradleException) CodeGenerator(io.quarkus.deployment.CodeGenerator) Optional(java.util.Optional) ArrayList(java.util.ArrayList) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) CodeGenerator(io.quarkus.deployment.CodeGenerator) Method(java.lang.reflect.Method) Properties(java.util.Properties) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) InvocationTargetException(java.lang.reflect.InvocationTargetException) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) LaunchMode(io.quarkus.runtime.LaunchMode) GradleException(org.gradle.api.GradleException) BootstrapException(io.quarkus.bootstrap.BootstrapException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

BootstrapException (io.quarkus.bootstrap.BootstrapException)2 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)2 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)2 Properties (java.util.Properties)2 GradleException (org.gradle.api.GradleException)2 TaskAction (org.gradle.api.tasks.TaskAction)2 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)1 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)1 AppModelResolverException (io.quarkus.bootstrap.resolver.AppModelResolverException)1 CodeGenerator (io.quarkus.deployment.CodeGenerator)1 GACTV (io.quarkus.maven.dependency.GACTV)1 PathList (io.quarkus.paths.PathList)1 LaunchMode (io.quarkus.runtime.LaunchMode)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1