Search in sources :

Example 1 with AdditionalDependency

use of io.quarkus.bootstrap.app.AdditionalDependency in project quarkus by quarkusio.

the class QuarkusDeployableContainer method deploy.

@SuppressWarnings("rawtypes")
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    old = Thread.currentThread().getContextClassLoader();
    if (testClass.get() == null) {
        throw new IllegalStateException("Test class not available");
    }
    Class testJavaClass = testClass.get().getJavaClass();
    // some TCK tests embed random libraries such as old versions of Jackson databind
    // this breaks quarkus, so we just skip them
    boolean skipLibraries = Boolean.getBoolean("io.quarkus.arquillian.skip-libraries");
    try {
        // Export the test archive
        Path tmpLocation = Files.createTempDirectory("quarkus-arquillian-test");
        deploymentLocation.set(tmpLocation);
        archive.as(ExplodedExporter.class).exportExplodedInto(tmpLocation.toFile());
        Path appLocation;
        Set<Path> libraries = new HashSet<>();
        if (archive instanceof WebArchive) {
            // Quarkus does not support the WAR layout and so adapt the layout (similarly to quarkus-war-launcher)
            appLocation = tmpLocation.resolve("app").toAbsolutePath();
            // WEB-INF/lib -> lib/
            if (!skipLibraries) {
                if (Files.exists(tmpLocation.resolve("WEB-INF/lib"))) {
                    Files.move(tmpLocation.resolve("WEB-INF/lib"), tmpLocation.resolve("lib"));
                }
            }
            // WEB-INF/classes -> archive/
            if (Files.exists(tmpLocation.resolve("WEB-INF/classes"))) {
                Files.move(tmpLocation.resolve("WEB-INF/classes"), appLocation);
            } else {
                Files.createDirectory(appLocation);
            }
            // META-INF -> archive/META-INF/
            if (Files.exists(tmpLocation.resolve("META-INF"))) {
                if (Files.exists(appLocation.resolve("META-INF"))) {
                    // Target directory not empty.
                    try (Stream<Path> fileTreeElements = Files.walk(tmpLocation.resolve("META-INF"), 2)) {
                        fileTreeElements.forEach(p -> {
                            try {
                                Files.createFile(p);
                            } catch (FileAlreadyExistsException faee) {
                            // Do Nothing
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        });
                    }
                } else {
                    Files.move(tmpLocation.resolve("META-INF"), appLocation.resolve("META-INF"));
                }
            }
            // WEB-INF -> archive/WEB-INF
            if (Files.exists(tmpLocation.resolve("WEB-INF"))) {
                Files.move(tmpLocation.resolve("WEB-INF"), appLocation.resolve("WEB-INF"));
            }
            // Collect all libraries
            if (Files.exists(tmpLocation.resolve("lib"))) {
                try (Stream<Path> libs = Files.walk(tmpLocation.resolve("lib"), 1)) {
                    libs.forEach((i) -> {
                        if (i.getFileName().toString().endsWith(".jar")) {
                            libraries.add(i);
                        }
                    });
                }
            }
        } else {
            appLocation = tmpLocation;
        }
        List<Consumer<BuildChainBuilder>> customizers = new ArrayList<>();
        // Test class is a bean
        customizers.add(new Consumer<BuildChainBuilder>() {

            @Override
            public void accept(BuildChainBuilder buildChainBuilder) {
                buildChainBuilder.addBuildStep(new BuildStep() {

                    @Override
                    public void execute(BuildContext context) {
                        context.produce(AdditionalBeanBuildItem.unremovableOf(testJavaClass));
                    }
                }).produces(AdditionalBeanBuildItem.class).build();
            }
        });
        QuarkusBootstrap.Builder bootstrapBuilder = QuarkusBootstrap.builder().setApplicationRoot(appLocation).setProjectRoot(appLocation).setIsolateDeployment(false).setFlatClassPath(true).setMode(QuarkusBootstrap.Mode.TEST);
        for (Path i : libraries) {
            bootstrapBuilder.addAdditionalApplicationArchive(new AdditionalDependency(i, false, true));
        }
        // Path testLocation = PathTestHelper.getTestClassesLocation(testJavaClass);
        // bootstrapBuilder.setProjectRoot(PathTestHelper.getTestClassesLocation(testJavaClass));
        CuratedApplication curatedApplication = bootstrapBuilder.build().bootstrap();
        AugmentAction augmentAction = new AugmentActionImpl(curatedApplication, customizers);
        StartupAction app = augmentAction.createInitialRuntimeApplication();
        RunningQuarkusApplication runningQuarkusApplication = app.run();
        appClassloader.set(runningQuarkusApplication.getClassLoader());
        runningApp.set(runningQuarkusApplication);
        Thread.currentThread().setContextClassLoader(runningQuarkusApplication.getClassLoader());
        // Instantiate the real test instance
        testInstance = TestInstantiator.instantiateTest(testJavaClass, runningQuarkusApplication.getClassLoader());
        // its pretty bogus
        if (Boolean.getBoolean("io.quarkus.arquillian.copy-fields")) {
            Class<?> dest = testInstance.getClass();
            Class<?> source = testClass.get().getJavaClass();
            while (source != Object.class) {
                for (Field f : source.getDeclaredFields()) {
                    try {
                        if (Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers())) {
                            Field df = dest.getDeclaredField(f.getName());
                            df.setAccessible(true);
                            f.setAccessible(true);
                            df.set(null, f.get(null));
                        }
                    } catch (Exception e) {
                        LOGGER.error("Failed to copy static field", e);
                    }
                }
                source = source.getSuperclass();
                dest = dest.getSuperclass();
            }
        }
    } catch (Throwable t) {
        // clone the exception into the correct class loader
        Throwable nt;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ObjectOutputStream a = new ObjectOutputStream(out)) {
            a.writeObject(t);
            a.close();
            nt = (Throwable) new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
        } catch (Exception e) {
            throw new DeploymentException("Unable to start the runtime runner", t);
        }
        throw new DeploymentException("Unable to start the runtime runner", nt);
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
    ProtocolMetaData metadata = new ProtocolMetaData();
    // TODO: fix this
    String testUri = TestHTTPResourceManager.getUri(runningApp.get());
    System.setProperty("test.url", testUri);
    URI uri = URI.create(testUri);
    HTTPContext httpContext = new HTTPContext(uri.getHost(), uri.getPort());
    // This is to work around https://github.com/arquillian/arquillian-core/issues/216
    httpContext.add(new Servlet("dummy", "/"));
    metadata.addContext(httpContext);
    return metadata;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.builder.BuildStep) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) Field(java.lang.reflect.Field) Consumer(java.util.function.Consumer) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) ExplodedExporter(org.jboss.shrinkwrap.api.exporter.ExplodedExporter) HashSet(java.util.HashSet) AugmentActionImpl(io.quarkus.runner.bootstrap.AugmentActionImpl) Path(java.nio.file.Path) AugmentAction(io.quarkus.bootstrap.app.AugmentAction) StartupAction(io.quarkus.bootstrap.app.StartupAction) RunningQuarkusApplication(io.quarkus.bootstrap.app.RunningQuarkusApplication) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) TestClass(org.jboss.arquillian.test.spi.TestClass) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with AdditionalDependency

use of io.quarkus.bootstrap.app.AdditionalDependency in project quarkus by quarkusio.

the class ReaugmentTask method main.

public static void main(Path appRoot) throws Exception {
    Path deploymentLib = appRoot.resolve(LIB).resolve(DEPLOYMENT_LIB);
    Path buildSystemProps = appRoot.resolve(QUARKUS).resolve(BUILD_SYSTEM_PROPERTIES);
    try (ObjectInputStream in = new ObjectInputStream(Files.newInputStream(deploymentLib.resolve(JarResultBuildStep.APPMODEL_DAT)))) {
        Properties buildSystemProperties = new Properties();
        try (InputStream buildIn = Files.newInputStream(buildSystemProps)) {
            buildSystemProperties.load(buildIn);
        }
        MutableJarApplicationModel appModel = (MutableJarApplicationModel) in.readObject();
        List<AdditionalDependency> additional = new ArrayList<>();
        if (appModel.getUserProvidersDirectory() != null) {
            // bit of a hack, but keeps things simple
            System.setProperty("quarkus.package.user-providers-directory", appModel.getUserProvidersDirectory());
            try (Stream<Path> files = Files.list(appRoot.resolve(appModel.getUserProvidersDirectory()))) {
                files.forEach(new Consumer<Path>() {

                    @Override
                    public void accept(Path path) {
                        if (path.toString().endsWith(".jar")) {
                            additional.add(new AdditionalDependency(path, false, true));
                        }
                    }
                });
            }
        }
        final ApplicationModel existingModel = appModel.getAppModel(appRoot);
        System.setProperty("quarkus.package.type", "mutable-jar");
        try (CuratedApplication bootstrap = QuarkusBootstrap.builder().setAppArtifact(existingModel.getAppArtifact()).setExistingModel(existingModel).setRebuild(true).setBuildSystemProperties(buildSystemProperties).setBaseName(appModel.getBaseName()).addAdditionalApplicationArchives(additional).setApplicationRoot(existingModel.getAppArtifact().getResolvedPaths().getSinglePath()).setTargetDirectory(appRoot.getParent()).setBaseClassLoader(ReaugmentTask.class.getClassLoader()).build().bootstrap()) {
            bootstrap.createAugmentor().createProductionApplication();
        }
    }
}
Also used : Path(java.nio.file.Path) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MutableJarApplicationModel(io.quarkus.bootstrap.model.MutableJarApplicationModel) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) Properties(java.util.Properties) MutableJarApplicationModel(io.quarkus.bootstrap.model.MutableJarApplicationModel) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with AdditionalDependency

use of io.quarkus.bootstrap.app.AdditionalDependency in project quarkus by quarkusio.

the class AugmentActionImpl method runAugment.

private BuildResult runAugment(boolean firstRun, Set<String> changedResources, ClassChangeInformation classChangeInformation, ClassLoader deploymentClassLoader, Class<? extends BuildItem>... finalOutputs) {
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
        QuarkusClassLoader classLoader = curatedApplication.getAugmentClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        ProfileManager.setLaunchMode(launchMode);
        ProfileManager.setRuntimeDefaultProfile(Optional.ofNullable(quarkusBootstrap.getBuildSystemProperties()).map(properties -> properties.getProperty(ProfileManager.QUARKUS_PROFILE_PROP)).orElse(null));
        QuarkusAugmentor.Builder builder = QuarkusAugmentor.builder().setRoot(quarkusBootstrap.getApplicationRoot()).setClassLoader(classLoader).setTargetDir(quarkusBootstrap.getTargetDirectory()).setDeploymentClassLoader(deploymentClassLoader).setBuildSystemProperties(quarkusBootstrap.getBuildSystemProperties()).setEffectiveModel(curatedApplication.getApplicationModel());
        if (quarkusBootstrap.getBaseName() != null) {
            builder.setBaseName(quarkusBootstrap.getBaseName());
        }
        boolean auxiliaryApplication = curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication();
        builder.setAuxiliaryApplication(auxiliaryApplication);
        builder.setAuxiliaryDevModeType(curatedApplication.getQuarkusBootstrap().isHostApplicationIsTestOnly() ? DevModeType.TEST_ONLY : (auxiliaryApplication ? DevModeType.LOCAL : null));
        builder.setLaunchMode(launchMode);
        builder.setDevModeType(devModeType);
        builder.setTest(curatedApplication.getQuarkusBootstrap().isTest());
        builder.setRebuild(quarkusBootstrap.isRebuild());
        if (firstRun) {
            builder.setLiveReloadState(new LiveReloadBuildItem(false, Collections.emptySet(), reloadContext, classChangeInformation));
        } else {
            builder.setLiveReloadState(new LiveReloadBuildItem(true, changedResources, reloadContext, classChangeInformation));
        }
        for (AdditionalDependency i : quarkusBootstrap.getAdditionalApplicationArchives()) {
            // if it is forced as an app archive
            if (i.isForceApplicationArchive()) {
                builder.addAdditionalApplicationArchive(i.getResolvedPaths());
            }
        }
        builder.excludeFromIndexing(quarkusBootstrap.getExcludeFromClassPath());
        for (Consumer<BuildChainBuilder> i : chainCustomizers) {
            builder.addBuildChainCustomizer(i);
        }
        for (Class<? extends BuildItem> i : finalOutputs) {
            builder.addFinal(i);
        }
        try {
            return builder.build().run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } finally {
        ProfileManager.setRuntimeDefaultProfile(null);
        Thread.currentThread().setContextClassLoader(old);
        QuarkusConfigFactory.setConfig(null);
    }
}
Also used : LiveReloadBuildItem(io.quarkus.deployment.builditem.LiveReloadBuildItem) QuarkusAugmentor(io.quarkus.deployment.QuarkusAugmentor) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 4 with AdditionalDependency

use of io.quarkus.bootstrap.app.AdditionalDependency in project quarkus by quarkusio.

the class JBangAugmentorImpl method accept.

@Override
public void accept(CuratedApplication curatedApplication, Map<String, Object> resultMap) {
    QuarkusClassLoader classLoader = curatedApplication.getAugmentClassLoader();
    QuarkusBootstrap quarkusBootstrap = curatedApplication.getQuarkusBootstrap();
    QuarkusAugmentor.Builder builder = QuarkusAugmentor.builder().setRoot(quarkusBootstrap.getApplicationRoot()).setClassLoader(classLoader).addFinal(ApplicationClassNameBuildItem.class).setTargetDir(quarkusBootstrap.getTargetDirectory()).setDeploymentClassLoader(curatedApplication.createDeploymentClassLoader()).setBuildSystemProperties(quarkusBootstrap.getBuildSystemProperties()).setEffectiveModel(curatedApplication.getApplicationModel());
    if (quarkusBootstrap.getBaseName() != null) {
        builder.setBaseName(quarkusBootstrap.getBaseName());
    }
    boolean auxiliaryApplication = curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication();
    builder.setAuxiliaryApplication(auxiliaryApplication);
    builder.setAuxiliaryDevModeType(curatedApplication.getQuarkusBootstrap().isHostApplicationIsTestOnly() ? DevModeType.TEST_ONLY : (auxiliaryApplication ? DevModeType.LOCAL : null));
    builder.setLaunchMode(LaunchMode.NORMAL);
    builder.setRebuild(quarkusBootstrap.isRebuild());
    builder.setLiveReloadState(new LiveReloadBuildItem(false, Collections.emptySet(), new HashMap<>(), null));
    for (AdditionalDependency i : quarkusBootstrap.getAdditionalApplicationArchives()) {
        // if it is forced as an app archive
        if (i.isForceApplicationArchive()) {
            builder.addAdditionalApplicationArchive(i.getResolvedPaths());
        }
    }
    builder.addBuildChainCustomizer(new Consumer<BuildChainBuilder>() {

        @Override
        public void accept(BuildChainBuilder builder) {
            final BuildStepBuilder stepBuilder = builder.addBuildStep((ctx) -> {
                ctx.produce(new ProcessInheritIODisabledBuildItem());
            });
            stepBuilder.produces(ProcessInheritIODisabledBuildItem.class).build();
        }
    });
    builder.excludeFromIndexing(quarkusBootstrap.getExcludeFromClassPath());
    builder.addFinal(GeneratedClassBuildItem.class);
    builder.addFinal(MainClassBuildItem.class);
    builder.addFinal(GeneratedResourceBuildItem.class);
    builder.addFinal(TransformedClassesBuildItem.class);
    builder.addFinal(DeploymentResultBuildItem.class);
    boolean nativeRequested = "native".equals(System.getProperty("quarkus.package.type"));
    boolean containerBuildRequested = Boolean.getBoolean("quarkus.container-image.build");
    if (nativeRequested) {
        builder.addFinal(NativeImageBuildItem.class);
    }
    if (containerBuildRequested) {
        // TODO: this is a bit ugly
        // we don't nessesarily need these artifacts
        // but if we include them it does mean that you can auto create docker images
        // and deploy to kube etc
        // for an ordinary build with no native and no docker this is a waste
        builder.addFinal(ArtifactResultBuildItem.class);
    }
    try {
        BuildResult buildResult = builder.build().run();
        Map<String, byte[]> result = new HashMap<>();
        for (GeneratedClassBuildItem i : buildResult.consumeMulti(GeneratedClassBuildItem.class)) {
            result.put(i.getName().replace(".", "/") + ".class", i.getClassData());
        }
        for (GeneratedResourceBuildItem i : buildResult.consumeMulti(GeneratedResourceBuildItem.class)) {
            result.put(i.getName(), i.getClassData());
        }
        for (Map.Entry<Path, Set<TransformedClassesBuildItem.TransformedClass>> entry : buildResult.consume(TransformedClassesBuildItem.class).getTransformedClassesByJar().entrySet()) {
            for (TransformedClassesBuildItem.TransformedClass transformed : entry.getValue()) {
                if (transformed.getData() != null) {
                    result.put(transformed.getFileName(), transformed.getData());
                } else {
                    log.warn("Unable to remove resource " + transformed.getFileName() + " as this is not supported in JBangf");
                }
            }
        }
        resultMap.put("files", result);
        final List<String> javaargs = new ArrayList<>();
        javaargs.add("-Djava.util.logging.manager=org.jboss.logmanager.LogManager");
        javaargs.add("-Djava.util.concurrent.ForkJoinPool.common.threadFactory=io.quarkus.bootstrap.forkjoin.QuarkusForkJoinWorkerThreadFactory");
        resultMap.put("java-args", javaargs);
        resultMap.put("main-class", buildResult.consume(MainClassBuildItem.class).getClassName());
        if (nativeRequested) {
            resultMap.put("native-image", buildResult.consume(NativeImageBuildItem.class).getPath());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformedClassesBuildItem(io.quarkus.deployment.builditem.TransformedClassesBuildItem) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) BuildResult(io.quarkus.builder.BuildResult) DevModeType(io.quarkus.dev.spi.DevModeType) Logger(org.jboss.logging.Logger) BuildStepBuilder(io.quarkus.builder.BuildStepBuilder) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) ArrayList(java.util.ArrayList) QuarkusAugmentor(io.quarkus.deployment.QuarkusAugmentor) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Path(java.nio.file.Path) DeploymentResultBuildItem(io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ProcessInheritIODisabledBuildItem(io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabledBuildItem) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ApplicationClassNameBuildItem(io.quarkus.deployment.builditem.ApplicationClassNameBuildItem) Set(java.util.Set) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) Consumer(java.util.function.Consumer) List(java.util.List) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) Collections(java.util.Collections) LiveReloadBuildItem(io.quarkus.deployment.builditem.LiveReloadBuildItem) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) LiveReloadBuildItem(io.quarkus.deployment.builditem.LiveReloadBuildItem) Set(java.util.Set) ProcessInheritIODisabledBuildItem(io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabledBuildItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) Path(java.nio.file.Path) QuarkusAugmentor(io.quarkus.deployment.QuarkusAugmentor) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) TransformedClassesBuildItem(io.quarkus.deployment.builditem.TransformedClassesBuildItem) BuildResult(io.quarkus.builder.BuildResult) BuildStepBuilder(io.quarkus.builder.BuildStepBuilder) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AdditionalDependency

use of io.quarkus.bootstrap.app.AdditionalDependency in project quarkus by quarkusio.

the class IDELauncherImpl method launch.

public static Closeable launch(Path classesDir, Map<String, Object> context) {
    System.setProperty(FORCE_COLOR_SUPPORT, "true");
    // IDE's don't support raw mode
    System.setProperty("quarkus.test.basic-console", "true");
    final Path projectDir = BuildToolHelper.getProjectDir(classesDir);
    if (projectDir == null) {
        throw new IllegalStateException("Failed to locate project dir for " + classesDir);
    }
    try {
        // todo : proper support for everything
        final QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder().setBaseClassLoader(IDELauncherImpl.class.getClassLoader()).setIsolateDeployment(true).setMode(QuarkusBootstrap.Mode.DEV).setTargetDirectory(classesDir.getParent());
        if (BuildToolHelper.isGradleProject(classesDir)) {
            final ApplicationModel quarkusModel = BuildToolHelper.enableGradleAppModelForDevMode(classesDir);
            context.put(BootstrapConstants.SERIALIZED_APP_MODEL, BootstrapUtils.serializeAppModel(quarkusModel, false));
            ArtifactSources mainSources = quarkusModel.getApplicationModule().getMainSources();
            final Path launchingModulePath = mainSources.getSourceDirs().iterator().next().getOutputDir();
            List<Path> applicationRoots = new ArrayList<>();
            applicationRoots.add(launchingModulePath);
            for (SourceDir resourceDir : mainSources.getResourceDirs()) {
                applicationRoots.add(resourceDir.getOutputDir());
            }
            // Gradle uses a different output directory for classes, we override the one used by the IDE
            builder.setProjectRoot(launchingModulePath).setApplicationRoot(PathsCollection.from(applicationRoots)).setTargetDirectory(quarkusModel.getApplicationModule().getBuildDir().toPath());
            for (ResolvedDependency dep : quarkusModel.getDependencies()) {
                final WorkspaceModule module = dep.getWorkspaceModule();
                if (module == null) {
                    continue;
                }
                final ArtifactSources sources = module.getSources(dep.getClassifier());
                for (SourceDir dir : sources.getSourceDirs()) {
                    builder.addAdditionalApplicationArchive(new AdditionalDependency(dir.getOutputDir(), true, false));
                }
                for (SourceDir dir : sources.getResourceDirs()) {
                    builder.addAdditionalApplicationArchive(new AdditionalDependency(dir.getOutputDir(), true, false));
                }
            }
        } else {
            builder.setApplicationRoot(classesDir).setProjectRoot(projectDir);
            final BootstrapMavenContext mvnCtx = new BootstrapMavenContext(BootstrapMavenContext.config().setCurrentProject(projectDir.toString()));
            final MavenArtifactResolver mvnResolver = new MavenArtifactResolver(mvnCtx);
            builder.setMavenArtifactResolver(mvnResolver);
        }
        final CuratedApplication curatedApp = builder.build().bootstrap();
        final Object appInstance = curatedApp.runInAugmentClassLoader("io.quarkus.deployment.dev.IDEDevModeMain", context);
        return new IDELauncherImpl(curatedApp, appInstance == null ? null : appInstance instanceof Closeable ? (Closeable) appInstance : null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) BootstrapMavenContext(io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) IOException(java.io.IOException) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) AdditionalDependency(io.quarkus.bootstrap.app.AdditionalDependency) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)

Aggregations

AdditionalDependency (io.quarkus.bootstrap.app.AdditionalDependency)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)4 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)4 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)4 IOException (java.io.IOException)4 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)3 Consumer (java.util.function.Consumer)3 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)2 BuildContext (io.quarkus.builder.BuildContext)2 BuildStep (io.quarkus.builder.BuildStep)2 QuarkusAugmentor (io.quarkus.deployment.QuarkusAugmentor)2 LiveReloadBuildItem (io.quarkus.deployment.builditem.LiveReloadBuildItem)2 AugmentActionImpl (io.quarkus.runner.bootstrap.AugmentActionImpl)2 ObjectInputStream (java.io.ObjectInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AugmentAction (io.quarkus.bootstrap.app.AugmentAction)1 RunningQuarkusApplication (io.quarkus.bootstrap.app.RunningQuarkusApplication)1 StartupAction (io.quarkus.bootstrap.app.StartupAction)1