protected void doExecute()

in src/main/java/org/apache/sling/maven/kickstart/run/StartMojo.java [170:238]


    protected void doExecute() throws MojoExecutionException, MojoFailureException {
        // delete properties
        if ( systemPropertiesFile != null && systemPropertiesFile.exists() ) {
            FileUtils.deleteQuietly(this.systemPropertiesFile);
        }

        // get configurations
        final Collection<ServerConfiguration> configurations = getKickstartConfigurations();

        // create the common environment
        getLog().info("Keep kickstart Running: " + this.keepKickstartRunning);
        final KickstartEnvironment env = new KickstartEnvironment(this.findKickstartJar(),
                this.cleanWorkingDirectory,
                !this.keepKickstartRunning,
                this.kickstartReadyTimeOutSec,
                this.debug);

        // create callables
        final Collection<LauncherCallable> tasks = new LinkedList<LauncherCallable>();

        for (final ServerConfiguration kickstartConfiguration : configurations) {
            validateConfiguration(kickstartConfiguration);

            tasks.add(createTask(kickstartConfiguration, env));
        }

        // create the kickstart runner properties
        this.createKickstartRunnerProperties(configurations);

        if (parallelExecution) {
            // ExecutorService for starting kickstart instances in parallel
            final ExecutorService executor = Executors.newCachedThreadPool();
            try {
                final List<Future<ProcessDescription>> resultsCollector = executor.invokeAll(tasks);
                for (final Future<ProcessDescription> future : resultsCollector) {
                    try {
                        if (null == future.get()) {
                            throw new MojoExecutionException("Cannot start all the instances");
                        }
                    } catch (final ExecutionException e) {
                        throw new MojoExecutionException(e.getLocalizedMessage(), e);
                    }
                }
            } catch ( final InterruptedException e) {
                throw new MojoExecutionException(e.getLocalizedMessage(), e);
            }
        } else {
            for (final LauncherCallable task : tasks) {
                try {
                    if (null == task.call()) {
                        throw new MojoExecutionException("Cannot start all the instances");
                    }
                } catch (final Exception e) {
                    throw new MojoExecutionException(e.getLocalizedMessage(), e);
                }
            }
        }
        if (this.keepKickstartRunning) {
            getLog().info("Press CTRL-C to stop kickstart instance(s)...");
            while ( true && this.isRunning(tasks)) {
                try {
                    Thread.sleep(5000);
                } catch (final InterruptedException ie) {
                    break;
                }
            }
        }
        blockIfNecessary();
    }