Search in sources :

Example 1 with MavenArtifactRepositoryManager

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

the class AbstractProvisionServerMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().debug(String.format("Skipping " + getGoal() + " of %s:%s", project.getGroupId(), project.getArtifactId()));
        return;
    }
    Path targetPath = Paths.get(project.getBuild().getDirectory());
    wildflyDir = targetPath.resolve(provisioningDir).normalize();
    if (!overwriteProvisionedServer && Files.exists(wildflyDir)) {
        getLog().info(String.format("A server already exists in " + wildflyDir + ", skipping " + getGoal() + " of %s:%s", project.getGroupId(), project.getArtifactId()));
        return;
    }
    enrichRepositories();
    artifactResolver = offlineProvisioning ? new MavenArtifactRepositoryManager(repoSystem, repoSession) : new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
    if (!Paths.get(provisioningDir).isAbsolute() && (targetPath.equals(wildflyDir) || !wildflyDir.startsWith(targetPath))) {
        throw new MojoExecutionException("provisioning-dir " + provisioningDir + " must be an absolute path or a child directory relative to the project build directory.");
    }
    IoUtils.recursiveDelete(wildflyDir);
    try {
        try {
            provisionServer(wildflyDir);
        } catch (ProvisioningException | IOException | XMLStreamException ex) {
            throw new MojoExecutionException("Provisioning failed", ex);
        }
        serverProvisioned(wildflyDir);
    } finally {
        // Although cli and embedded are run in their own classloader,
        // the module.path system property has been set and needs to be cleared for
        // in same JVM next execution.
        System.clearProperty("module.path");
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XMLStreamException(javax.xml.stream.XMLStreamException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) ProvisioningException(org.jboss.galleon.ProvisioningException) IOException(java.io.IOException)

Example 2 with MavenArtifactRepositoryManager

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

the class RunMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        return;
    }
    MavenRepositoriesEnricher.enrich(mavenSession, project, repositories);
    mavenRepoManager = new MavenArtifactRepositoryManager(repoSystem, session, repositories);
    final Log log = getLog();
    final Path deploymentContent = getDeploymentContent();
    // The deployment must exist before we do anything
    if (Files.notExists(deploymentContent)) {
        throw new MojoExecutionException(String.format("The deployment '%s' could not be found.", deploymentContent.toAbsolutePath()));
    }
    // Validate the environment
    final Path wildflyPath = provisionIfRequired(deploymentContent.getParent().resolve(provisioningDir));
    if (!ServerHelper.isValidHomeDirectory(wildflyPath)) {
        throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", wildflyPath));
    }
    final StandaloneCommandBuilder commandBuilder = createCommandBuilder(wildflyPath);
    // Print some server information
    log.info("JAVA_HOME : " + commandBuilder.getJavaHome());
    log.info("JBOSS_HOME: " + commandBuilder.getWildFlyHome());
    log.info("JAVA_OPTS : " + Utils.toString(commandBuilder.getJavaOptions(), " "));
    try {
        if (addUser != null && addUser.hasUsers()) {
            log.info("Adding users: " + addUser);
            addUser.addUsers(commandBuilder.getWildFlyHome(), commandBuilder.getJavaHome());
        }
        // Start the server
        log.info("Server is starting up. Press CTRL + C to stop the server.");
        Process process = startContainer(commandBuilder);
        try (ModelControllerClient client = createClient()) {
            // Execute commands before the deployment is done
            final CommandConfiguration cmdConfig = CommandConfiguration.of(this::createClient, this::getClientConfiguration).addCommands(commands).addScripts(scripts).setJBossHome(commandBuilder.getWildFlyHome()).setFork(true).setStdout("none").setTimeout(timeout).build();
            commandExecutor.execute(cmdConfig, mavenRepoManager);
            // Create the deployment and deploy
            final Deployment deployment = Deployment.of(deploymentContent).setName(name).setRuntimeName(runtimeName);
            final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
            deploymentManager.forceDeploy(deployment);
        } catch (MojoExecutionException | MojoFailureException e) {
            if (process != null) {
                process.destroyForcibly().waitFor(10L, TimeUnit.SECONDS);
            }
            throw e;
        }
        try {
            // Wait for the process to die
            boolean keepRunning = true;
            while (keepRunning) {
                final int exitCode = process.waitFor();
                // 10 is the magic code used in the scripts to survive a :shutdown(restart=true) operation
                if (exitCode == 10) {
                    // Ensure the current process is destroyed and restart a new one
                    process.destroy();
                    process = startContainer(commandBuilder);
                } else {
                    keepRunning = false;
                }
            }
        } catch (Exception e) {
            throw new MojoExecutionException("The server failed to start", e);
        } finally {
            if (process != null)
                process.destroy();
        }
    } 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) Log(org.apache.maven.plugin.logging.Log) CommandConfiguration(org.wildfly.plugin.cli.CommandConfiguration) DeploymentManager(org.wildfly.plugin.core.DeploymentManager) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Deployment(org.wildfly.plugin.core.Deployment) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProvisioningException(org.jboss.galleon.ProvisioningException) StandaloneCommandBuilder(org.wildfly.core.launcher.StandaloneCommandBuilder) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)

Example 3 with MavenArtifactRepositoryManager

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

the class ExecuteCommandsMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().debug("Skipping commands execution");
        return;
    }
    MavenRepositoriesEnricher.enrich(mavenSession, project, repositories);
    mavenRepoManager = new MavenArtifactRepositoryManager(repoSystem, session, repositories);
    final CommandConfiguration.Builder cmdConfigBuilder = CommandConfiguration.of(this::createClient, this::getClientConfiguration).addCommands(commands).addJvmOptions(javaOpts).addPropertiesFiles(propertiesFiles).addScripts(scripts).addSystemProperties(systemProperties).setBatch(batch).setFailOnError(failOnError).setFork(fork).setJBossHome(jbossHome).setOffline(offline).setStdout(stdout).setTimeout(timeout).setResolveExpression(resolveExpressions);
    // Why is that? fork implies a jboss-home?
    if (fork) {
        cmdConfigBuilder.setJBossHome(getInstallation(buildDir.toPath().resolve(Utils.WILDFLY_DEFAULT_DIR)));
    }
    commandExecutor.execute(cmdConfigBuilder.build(), mavenRepoManager);
}
Also used : MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)

Example 4 with MavenArtifactRepositoryManager

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

the class ProvisionStateMojo method doProvision.

private void doProvision() throws MojoExecutionException, ProvisioningException {
    final ProvisioningConfig.Builder state = ProvisioningConfig.builder();
    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()) {
        for (FeaturePack fp : featurePacks) {
            if (fp.getLocation() == null && (fp.getGroupId() == null || fp.getArtifactId() == null) && fp.getNormalizedPath() == null) {
                throw new MojoExecutionException("Feature-pack location, Maven GAV or feature pack path is missing");
            }
            final FeaturePackLocation fpl;
            if (fp.getNormalizedPath() != null) {
                fpl = pm.getLayoutFactory().addLocal(fp.getNormalizedPath(), false);
            } else if (fp.getGroupId() != null && fp.getArtifactId() != null) {
                Path path = resolveMaven(fp, (MavenRepoManager) artifactResolver);
                fpl = pm.getLayoutFactory().addLocal(path, false);
            } else {
                fpl = FeaturePackLocation.fromString(fp.getLocation());
            }
            final FeaturePackConfig.Builder fpConfig = fp.isTransitive() ? FeaturePackConfig.transitiveBuilder(fpl) : FeaturePackConfig.builder(fpl);
            if (fp.isInheritConfigs() != null) {
                fpConfig.setInheritConfigs(fp.isInheritConfigs());
            }
            if (fp.isInheritPackages() != null) {
                fpConfig.setInheritPackages(fp.isInheritPackages());
            }
            if (!fp.getExcludedConfigs().isEmpty()) {
                for (ConfigurationId configId : fp.getExcludedConfigs()) {
                    if (configId.isModelOnly()) {
                        fpConfig.excludeConfigModel(configId.getId().getModel());
                    } else {
                        fpConfig.excludeDefaultConfig(configId.getId());
                    }
                }
            }
            if (!fp.getIncludedConfigs().isEmpty()) {
                for (ConfigurationId configId : fp.getIncludedConfigs()) {
                    if (configId.isModelOnly()) {
                        fpConfig.includeConfigModel(configId.getId().getModel());
                    } else {
                        fpConfig.includeDefaultConfig(configId.getId());
                    }
                }
            }
            if (!fp.getIncludedPackages().isEmpty()) {
                for (String includedPackage : fp.getIncludedPackages()) {
                    fpConfig.includePackage(includedPackage);
                }
            }
            if (!fp.getExcludedPackages().isEmpty()) {
                for (String excludedPackage : fp.getExcludedPackages()) {
                    fpConfig.excludePackage(excludedPackage);
                }
            }
            state.addFeaturePackDep(fpConfig.build());
        }
        boolean hasLayers = false;
        for (Configuration config : configs) {
            ConfigModel.Builder configBuilder = ConfigModel.builder(config.getModel(), config.getName());
            for (String layer : config.getLayers()) {
                hasLayers = true;
                configBuilder.includeLayer(layer);
            }
            if (config.getExcludedLayers() != null) {
                for (String layer : config.getExcludedLayers()) {
                    configBuilder.excludeLayer(layer);
                }
            }
            state.addConfig(configBuilder.build());
        }
        if (hasLayers) {
            if (pluginOptions.isEmpty()) {
                pluginOptions = Collections.singletonMap(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
            } else if (!pluginOptions.containsKey(Constants.OPTIONAL_PACKAGES)) {
                pluginOptions.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
            }
        }
        if (customConfig != null && customConfig.exists()) {
            try (BufferedReader reader = Files.newBufferedReader(customConfig.toPath())) {
                state.addConfig(ConfigXmlParser.getInstance().parse(reader));
            } catch (XMLStreamException | IOException ex) {
                throw new IllegalArgumentException("Couldn't load the customization configuration " + customConfig, ex);
            }
        }
        for (ResolveLocalItem localResolverItem : resolveLocals) {
            if (localResolverItem.getError() != null) {
                throw new MojoExecutionException(localResolverItem.getError());
            }
        }
        for (ResolveLocalItem localResolverItem : resolveLocals) {
            if (localResolverItem.getNormalizedPath() != null) {
                pm.getLayoutFactory().addLocal(localResolverItem.getNormalizedPath(), localResolverItem.getInstallInUniverse());
            } else if (localResolverItem.hasArtifactCoords()) {
                Path path = resolveMaven(localResolverItem, (MavenRepoManager) artifactResolver);
                pm.getLayoutFactory().addLocal(path, false);
            } else {
                throw new MojoExecutionException("resolve-local element appears to be neither path not maven artifact");
            }
        }
        pm.provision(state.build(), pluginOptions);
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) Configuration(org.jboss.galleon.maven.plugin.util.Configuration) MvnMessageWriter(org.jboss.galleon.maven.plugin.util.MvnMessageWriter) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ConfigModel(org.jboss.galleon.config.ConfigModel) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) ResolveLocalItem(org.jboss.galleon.maven.plugin.util.ResolveLocalItem) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig) Path(java.nio.file.Path) FeaturePack(org.jboss.galleon.maven.plugin.util.FeaturePack) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenRepoManager(org.jboss.galleon.universe.maven.repo.MavenRepoManager) IOException(java.io.IOException) ConfigurationId(org.jboss.galleon.maven.plugin.util.ConfigurationId) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) XMLStreamException(javax.xml.stream.XMLStreamException) RepositoryArtifactResolver(org.jboss.galleon.repo.RepositoryArtifactResolver) BufferedReader(java.io.BufferedReader)

Example 5 with MavenArtifactRepositoryManager

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

the class FeaturePackInstallMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping the install-feature-pack goal.");
        return;
    }
    FeaturePackLocation fpl = null;
    Path localPath = null;
    if (featurePack != null) {
        localPath = resolveMaven(featurePack, new MavenArtifactRepositoryManager(repoSystem, repoSession));
    } else if (location != null) {
        fpl = FeaturePackLocation.fromString(location);
    } else {
        throw new MojoExecutionException("Either 'location' or 'feature-pack' must be configured");
    }
    final FeaturePackInstaller fpInstaller = FeaturePackInstaller.newInstance(repoSession.getLocalRepository().getBasedir().toPath(), installDir.toPath()).setFpl(fpl).setLocalArtifact(localPath).setInheritConfigs(inheritConfigs).includeConfigs(includedConfigs).setInheritPackages(inheritPackages).includePackages(includedPackages).excludePackages(excludedPackages).setPluginOptions(pluginOptions);
    if (customConfig != null) {
        fpInstaller.setCustomConfig(customConfig.toPath().toAbsolutePath());
    }
    final String originalMavenRepoLocal = System.getProperty(MAVEN_REPO_LOCAL);
    System.setProperty(MAVEN_REPO_LOCAL, session.getSettings().getLocalRepository());
    try {
        fpInstaller.install();
    } finally {
        if (originalMavenRepoLocal == null) {
            System.clearProperty(MAVEN_REPO_LOCAL);
        } else {
            System.setProperty(MAVEN_REPO_LOCAL, originalMavenRepoLocal);
        }
    }
}
Also used : Path(java.nio.file.Path) FeaturePackInstaller(org.jboss.galleon.maven.plugin.util.FeaturePackInstaller) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

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