public void runWithException()

in src/main/java/org/apache/sling/feature/launcher/impl/Bootstrap.java [107:182]


    public void runWithException() throws Exception {
        this.logger.info("");
        this.logger.info("Apache Sling Application Launcher");
        this.logger.info("---------------------------------");


        this.logger.info("Initializing...");
        prepare();

        Iterator<Launcher> iterator = ServiceLoader.load(Launcher.class).iterator();
        if (!iterator.hasNext()) {
            throw new IllegalStateException("Unable to find launcher service.");
        }

        final Launcher launcher = iterator.next();

        try (ArtifactManager artifactManager = ArtifactManager.getArtifactManager(this.config)) {

            this.logger.info("Artifact Repositories: {}", Arrays.toString(this.config.getRepositoryUrls()));
            this.logger.info("Assembling final feature model...");

            try {
                final boolean restart = this.config.getFeatureFiles().isEmpty();

                Map<ArtifactId, Feature> loadedFeatures = new HashMap<>();
                final Feature app = assemble(artifactManager, loadedFeatures);

                this.logger.info("");
                this.logger.info("Assembling launcher...");

                final LauncherPrepareContext ctx = new LauncherPrepareContext() {
                    @Override
                    public Logger getLogger() {
                        return logger;
                    }

                    @Override
                    public URL getArtifactFile(final ArtifactId artifact) throws IOException {
                        final ArtifactHandler handler = artifactManager.getArtifactHandler(":" + artifact.toMvnPath());
                        return handler.getLocalURL();
                    }

                    @Override
                    public void addAppJar(final URL jar) {
                        config.getInstallation().addAppJar(jar);
                    }
                };

                launcher.prepare(ctx, this.getFrameworkArtifactId(app), app);

                FeatureProcessor.prepareLauncher(ctx, this.config, app, loadedFeatures);

                this.logger.info("Using {} local artifacts, {} cached artifacts, and {} downloaded artifacts",
                        this.config.getLocalArtifacts(), this.config.getCachedArtifacts(),
                        this.config.getDownloadedArtifacts());

                if (this.config.getCacheOnly()) {
                    this.logger.info("Finished downloading any requirements...exiting!");
                    System.exit(0);
                }

                if (restart) {
                    this.config.getInstallation().getInstallableArtifacts().clear();
                    this.config.getInstallation().getConfigurations().clear();
                    this.config.getInstallation().getBundleMap().clear();
                }
            } catch ( final Exception iae) {
                throw new IllegalStateException("Error while assembling launcher: " + iae.getMessage(), iae);
            }
        }
        catch (IOException ex) {
            throw new IOException("Unable to setup artifact manager: " + ex.getMessage(), ex);
        }

        run(launcher);
    }