org.wildfly.swarm.tools.exec.SwarmProcess Java Examples

The following examples show how to use org.wildfly.swarm.tools.exec.SwarmProcess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StopMojo.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if ( this.execution.getExecutionId().equals( "default-cli" ) ) {
        getLog().error( "wildfly-swarm:stop is not usable from the CLI" );
        return;
    }

    List<SwarmProcess> value = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if ( value == null ) {
        getLog().error( "No known processes to stop" );
        return;
    }

    for (SwarmProcess each : value) {
        stop(each);
    }
}
 
Example #2
Source File: StopTask.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@TaskAction
public void stopThorntailProcess() {
    ThorntailExtension extension = getProject().getExtensions().getByType(ThorntailExtension.class);

    SwarmProcess process = (SwarmProcess) getProject().findProperty(PackagePlugin.THORNTAIL_PROCESS_PROPERTY);
    if (process == null) {
        getLogger().error("No Thorntail process was found to stop.");
        return;
    }
    try {
        getLogger().info("Stopping Thorntail process.");
        process.stop(extension.getStopTimeout(), TimeUnit.SECONDS);
    } catch (InterruptedException ie) {
        // Do nothing
    } finally {
        process.destroyForcibly();
    }
}
 
Example #3
Source File: StopMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if ( this.execution.getExecutionId().equals( "default-cli" ) ) {
        getLog().error( "wildfly-swarm:stop is not usable from the CLI" );
        return;
    }

    List<SwarmProcess> value = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if ( value == null ) {
        getLog().error( "No known processes to stop" );
        return;
    }

    for (SwarmProcess each : value) {
        stop(each);
    }
}
 
Example #4
Source File: StopMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected void stop(SwarmProcess process) throws MojoFailureException {
    if (process != null) {
        try {
            process.stop(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new MojoFailureException("unable to stop process", e);
        }
    }
}
 
Example #5
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #6
Source File: StartTask.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void stopProcess(SwarmProcess process) {
    if (process != null && process.isAlive()) {
        try {
            process.stop(extension.getStopTimeout(), TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            // ignore
        } finally {
            process.destroyForcibly();
        }
    }
}
 
Example #7
Source File: StopMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void executeSpecific() throws MojoExecutionException, MojoFailureException {
    if (this.execution.getExecutionId().equals("default-cli")) {
        getLog().error("thorntail:stop is not usable from the CLI");
        return;
    }

    List<SwarmProcess> value = (List<SwarmProcess>) getPluginContext().get("thorntail-process");

    if (value == null) {
        getLog().error("No known processes to stop");
        return;
    }

    for (SwarmProcess each : value) {
        stop(each);
    }

    File tmp = (File) getPluginContext().get("thorntail-cp-file");

    if (tmp != null && tmp.exists()) {
        tmp.delete();
    }

    Path tmpDir = new File(System.getProperty("java.io.tmpdir")).toPath();

    if (tmpDir.toFile().exists()) {
        File[] filesTmp = tmpDir.toFile().listFiles();
        for (File tmpFile : filesTmp) {
            Matcher matcher = tempFilePattern.matcher(tmpFile.getName());
            if (matcher.matches()) {
                TempFileManager.deleteRecursively(tmpFile);
            }
        }
    }
}
 
Example #8
Source File: StopMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected void stop(SwarmProcess process) throws MojoFailureException {
    if (process != null) {
        try {
            process.stop(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new MojoFailureException("unable to stop process", e);
        }
    }
}
 
Example #9
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin(THORNTAIL_MAVEN_PLUGIN);

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(THORNTAIL_PROCESS);

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(THORNTAIL_PROCESS);

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put(THORNTAIL_PROCESS, procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #10
Source File: StopMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected void stop(SwarmProcess process) throws MojoFailureException {
    if (process != null) {
        try {
            process.stop(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new MojoFailureException("unable to stop process", e);
        }
    }
}
 
Example #11
Source File: MultiStartMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process");

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put("swarm-process", procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}