Search in sources :

Example 6 with MavenArtifactRepositoryManager

use of org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager in project wildfly-maven-plugin by wildfly.

the class StartMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();
    if (skip) {
        log.debug("Skipping server start");
        return;
    }
    MavenRepositoriesEnricher.enrich(mavenSession, project, repositories);
    mavenRepoManager = new MavenArtifactRepositoryManager(repoSystem, session, repositories);
    // Validate the environment
    final Path jbossHome = provisionIfRequired(targetDir.toPath().resolve(provisioningDir));
    if (!ServerHelper.isValidHomeDirectory(jbossHome)) {
        throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", jbossHome));
    }
    // Determine how stdout should be consumed
    try {
        final StandardOutput out = StandardOutput.parse(stdout, true);
        // the maven process may have been finished
        try (ModelControllerClient client = createClient()) {
            if (ServerHelper.isStandaloneRunning(client) || ServerHelper.isDomainRunning(client)) {
                throw new MojoExecutionException(String.format("%s server is already running?", serverType));
            }
            final CommandBuilder commandBuilder = createCommandBuilder(jbossHome);
            log.info(String.format("%s server is starting up.", serverType));
            final Launcher launcher = Launcher.of(commandBuilder).setRedirectErrorStream(true);
            if (env != null) {
                launcher.addEnvironmentVariables(env);
            }
            out.getRedirect().ifPresent(launcher::redirectOutput);
            final Process process = launcher.launch();
            // Note that if this thread is started and no shutdown goal is executed this stop the stdout and stderr
            // from being logged any longer. The user was warned in the documentation.
            out.startConsumer(process);
            if (serverType == ServerType.DOMAIN) {
                ServerHelper.waitForDomain(process, DomainClient.Factory.create(client), startupTimeout);
            } else {
                ServerHelper.waitForStandalone(process, client, startupTimeout);
            }
            if (!process.isAlive()) {
                throw new MojoExecutionException("The process has been terminated before the start goal has completed.");
            }
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("The server failed to start", e);
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Log(org.apache.maven.plugin.logging.Log) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) Launcher(org.wildfly.core.launcher.Launcher) StandardOutput(org.wildfly.plugin.common.StandardOutput) DomainCommandBuilder(org.wildfly.core.launcher.DomainCommandBuilder) StandaloneCommandBuilder(org.wildfly.core.launcher.StandaloneCommandBuilder) CommandBuilder(org.wildfly.core.launcher.CommandBuilder) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 7 with MavenArtifactRepositoryManager

use of org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager in project galleon by wildfly.

the class ProvisionFileStateMojo method doProvision.

private void doProvision() throws MojoExecutionException, ProvisioningException {
    final RepositoryArtifactResolver artifactResolver = offline ? new MavenArtifactRepositoryManager(repoSystem, repoSession) : new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
    final Path home = installDir.toPath();
    if (!recordState) {
        IoUtils.recursiveDelete(home);
    }
    try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver).setInstallationHome(home).setMessageWriter(new MvnMessageWriter(getLog())).setLogTime(logTime).setRecordState(recordState).build()) {
        pm.provision(provisioningFile.toPath(), pluginOptions);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) RepositoryArtifactResolver(org.jboss.galleon.repo.RepositoryArtifactResolver) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) MvnMessageWriter(org.jboss.galleon.maven.plugin.util.MvnMessageWriter)

Example 8 with MavenArtifactRepositoryManager

use of org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager in project galleon by wildfly.

the class CreateProducerMojo method createProducer.

private void createProducer() throws MavenUniverseException, MojoExecutionException {
    final MavenArtifact producerArtifact = new MavenArtifact().setGroupId(groupId).setArtifactId(artifactId).setVersion(version);
    final MavenProducerInstaller installer = new MavenProducerInstaller(name, SimplisticMavenRepoManager.getInstance(Paths.get(project.getBuild().getDirectory()).resolve("local-repo"), new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories)), producerArtifact, featurePackGroupId, featurePackArtifactId);
    for (String frequency : frequencies) {
        installer.addFrequency(frequency);
    }
    final Set<String> names = new HashSet<>(channels.size());
    for (ChannelDescription channel : channels) {
        if (!names.add(channel.name)) {
            throw new MojoExecutionException("Duplicate channel " + channel.name);
        }
        try {
            installer.addChannel(channel.name, channel.versionRange);
        } catch (MavenUniverseException e) {
            throw new MojoExecutionException("Failed to add channel " + channel.name, e);
        }
    }
    try {
        installer.install();
    } catch (MavenUniverseException e) {
        throw new MojoExecutionException("Failed to create producer", e);
    }
    projectHelper.attachArtifact(project, "jar", producerArtifact.getPath().toFile());
}
Also used : MavenProducerInstaller(org.jboss.galleon.universe.maven.MavenProducerInstaller) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) HashSet(java.util.HashSet)

Example 9 with MavenArtifactRepositoryManager

use of org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager in project galleon by wildfly.

the class CreateProducersMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping the create-producers goal.");
        return;
    }
    final MavenArtifact artifact = new MavenArtifact().setGroupId(groupId).setArtifactId(artifactId).setVersion(version);
    final MavenProducers installer = MavenProducers.getInstance(SimplisticMavenRepoManager.getInstance(Paths.get(project.getBuild().getDirectory()).resolve("local-repo"), new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories)), artifact);
    for (ProducerDescription producer : producers) {
        installer.addProducer(producer);
    }
    try {
        installer.install();
    } catch (MavenUniverseException e) {
        throw new MojoExecutionException("Failed to create producers artifact", e);
    }
    projectHelper.attachArtifact(project, "jar", artifact.getPath().toFile());
}
Also used : MavenProducers(org.jboss.galleon.universe.maven.MavenProducers) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException)

Example 10 with MavenArtifactRepositoryManager

use of org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager in project galleon by wildfly.

the class CreateUniverseMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping the create-universe goal.");
        return;
    }
    final MavenArtifact universeArtifact = new MavenArtifact().setGroupId(groupId).setArtifactId(artifactId).setVersion(version);
    final MavenUniverseInstaller installer = new MavenUniverseInstaller(SimplisticMavenRepoManager.getInstance(Paths.get(project.getBuild().getDirectory()).resolve("local-repo"), new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories)), universeArtifact);
    final Set<String> names = new HashSet<>(producers.size());
    for (ProducerSpec producer : producers) {
        if (!names.add(producer.name)) {
            throw new MojoExecutionException("Duplicate producer " + producer.name);
        }
        try {
            installer.addProducer(producer.name, producer.groupId, producer.artifactId, producer.versionRange);
        } catch (MavenUniverseException e) {
            throw new MojoExecutionException("Failed to add producer " + producer.name, e);
        }
    }
    try {
        installer.install();
    } catch (MavenUniverseException e) {
        throw new MojoExecutionException("Failed to create universe", e);
    }
    projectHelper.attachArtifact(project, "jar", universeArtifact.getPath().toFile());
}
Also used : MavenUniverseInstaller(org.jboss.galleon.universe.maven.MavenUniverseInstaller) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) HashSet(java.util.HashSet)

Aggregations

MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 Path (java.nio.file.Path)6 IOException (java.io.IOException)4 ProvisioningException (org.jboss.galleon.ProvisioningException)3 MavenArtifact (org.jboss.galleon.universe.maven.MavenArtifact)3 MavenUniverseException (org.jboss.galleon.universe.maven.MavenUniverseException)3 HashSet (java.util.HashSet)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Log (org.apache.maven.plugin.logging.Log)2 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)2 ProvisioningManager (org.jboss.galleon.ProvisioningManager)2 MvnMessageWriter (org.jboss.galleon.maven.plugin.util.MvnMessageWriter)2 RepositoryArtifactResolver (org.jboss.galleon.repo.RepositoryArtifactResolver)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2 StandaloneCommandBuilder (org.wildfly.core.launcher.StandaloneCommandBuilder)2 BufferedReader (java.io.BufferedReader)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1