Search in sources :

Example 1 with ProvisioningManager

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

the class AbstractProvisionServerMojo method provisionServer.

private void provisionServer(Path home) throws ProvisioningException, MojoExecutionException, IOException, XMLStreamException {
    try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver).setInstallationHome(home).setMessageWriter(new MvnMessageWriter(getLog())).setLogTime(logProvisioningTime).setRecordState(recordProvisioningState).build()) {
        ProvisioningConfig config = null;
        Path resolvedProvisioningFile = resolvePath(project, provisioningFile.toPath());
        boolean provisioningFileExists = Files.exists(resolvedProvisioningFile);
        if (featurePacks.isEmpty()) {
            if (provisioningFileExists) {
                getLog().info("Provisioning server using " + resolvedProvisioningFile + " file.");
                config = GalleonUtils.buildConfig(resolvedProvisioningFile);
            } else {
                config = getDefaultConfig();
                if (config == null) {
                    throw new MojoExecutionException("No feature-pack has been configured, can't provision a server.");
                }
            }
        } else {
            if (provisioningFileExists) {
                getLog().warn("Galleon provisioning file " + provisioningFile + " is ignored, plugin configuration is used.");
            }
            if (layers.isEmpty() && !STANDALONE_XML.equals(layersConfigurationFileName)) {
                throw new MojoExecutionException("layers-configuration-file-name has been set although no layers are defined.");
            }
            config = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, layersConfigurationFileName);
        }
        getLog().info("Provisioning server in " + home);
        pm.provision(config);
        // Check that at least the standalone or domain directories have been generated.
        if (!Files.exists(home.resolve("standalone")) && !Files.exists(home.resolve("domain"))) {
            getLog().error("Invalid galleon provisioning, no server provisioned in " + home + ". Make sure " + "that the list of Galleon feature-packs and Galleon layers are properly configured.");
            throw new MojoExecutionException("Invalid plugin configuration, no server provisioned.");
        }
        if (!recordProvisioningState) {
            Path file = home.resolve(PLUGIN_PROVISIONING_FILE);
            try (FileWriter writer = new FileWriter(file.toFile())) {
                ProvisioningXmlWriter.getInstance().write(config, writer);
            }
        }
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MvnMessageWriter(org.jboss.galleon.maven.plugin.util.MvnMessageWriter) FileWriter(java.io.FileWriter)

Example 2 with ProvisioningManager

use of org.jboss.galleon.ProvisioningManager 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 3 with ProvisioningManager

use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.

the class PmTestBase method main.

@Test
public void main() throws Throwable {
    final String[] errors = pmErrors();
    boolean failed = false;
    ProvisioningManager pm = null;
    try {
        pm = getPm();
        testPm(pm);
        pmSuccess();
        if (errors != null) {
            Assert.fail("Expected failures: " + Arrays.asList(errors));
        }
        if (isRecordState()) {
            assertProvisionedConfig(pm);
            assertProvisionedState(pm);
        } else if (initialProvisioningConfig != null) {
            pm.close();
            pm = getPm();
            assertProvisionedConfig(pm);
            assertProvisionedState(pm);
        } else {
            assertNoState();
        }
    } catch (AssertionError e) {
        throw e;
    } catch (Throwable t) {
        failed = true;
        if (errors == null) {
            pmFailure(t);
        } else {
            assertErrors(t, errors);
        }
        if (pm != null) {
            if (isRecordState()) {
                assertProvisioningConfig(pm, initialProvisioningConfig);
                assertProvisionedState(pm, initialProvisionedState);
            } else if (initialProvisioningConfig != null) {
                pm.close();
                pm = getPm();
                assertProvisioningConfig(pm, initialProvisioningConfig);
                assertProvisionedState(pm, initialProvisionedState);
            }
        }
    } finally {
        if (pm != null) {
            pm.close();
        }
    }
    DirState expectedHomeDir = provisionedHomeDir();
    if (expectedHomeDir == null) {
        if (!assertProvisionedHomeDir()) {
            return;
        }
        if (failed || initialProvisioningConfig != null) {
            expectedHomeDir = initialHomeDirState;
        } else {
            expectedHomeDir = newDirBuilder().build();
        }
    }
    expectedHomeDir.assertState(installHome);
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) DirState(org.jboss.galleon.test.util.fs.state.DirState) Test(org.junit.Test)

Example 4 with ProvisioningManager

use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.

the class PmTestBase method doBefore.

@Override
protected void doBefore() throws Exception {
    super.doBefore();
    final FeaturePackCreator fpCreator = initCreator();
    createFeaturePacks(fpCreator);
    fpCreator.install();
    initialProvisioningConfig = initialState();
    if (initialProvisioningConfig != null) {
        try (ProvisioningManager pm = getPm()) {
            pm.provision(initialProvisioningConfig);
            initialProvisionedState = pm.getProvisionedState();
        }
    }
    initialHomeDirState = DirState.rootBuilder().init(installHome).build();
}
Also used : FeaturePackCreator(org.jboss.galleon.creator.FeaturePackCreator) ProvisioningManager(org.jboss.galleon.ProvisioningManager)

Example 5 with ProvisioningManager

use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.

the class InstallFpUsingUniverseNameTestCase method getPm.

@Override
protected ProvisioningManager getPm() throws ProvisioningException {
    ProvisioningManager pm = super.getPm();
    pm.addUniverse("custom", LegacyGalleon1Universe.getUniverseSpec());
    return pm;
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager)

Aggregations

ProvisioningManager (org.jboss.galleon.ProvisioningManager)25 ProvisioningException (org.jboss.galleon.ProvisioningException)11 Path (java.nio.file.Path)8 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)8 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)4 MvnMessageWriter (org.jboss.galleon.maven.plugin.util.MvnMessageWriter)3 BufferedReader (java.io.BufferedReader)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 CommandException (org.aesh.command.CommandException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)2 ConfigModel (org.jboss.galleon.config.ConfigModel)2 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)2 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)2 RepositoryArtifactResolver (org.jboss.galleon.repo.RepositoryArtifactResolver)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2