Search in sources :

Example 1 with ResolveLocalItem

use of org.jboss.galleon.maven.plugin.util.ResolveLocalItem 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)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ProvisioningManager (org.jboss.galleon.ProvisioningManager)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 Configuration (org.jboss.galleon.maven.plugin.util.Configuration)1 ConfigurationId (org.jboss.galleon.maven.plugin.util.ConfigurationId)1 FeaturePack (org.jboss.galleon.maven.plugin.util.FeaturePack)1 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)1 MvnMessageWriter (org.jboss.galleon.maven.plugin.util.MvnMessageWriter)1 ResolveLocalItem (org.jboss.galleon.maven.plugin.util.ResolveLocalItem)1 RepositoryArtifactResolver (org.jboss.galleon.repo.RepositoryArtifactResolver)1 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)1 MavenRepoManager (org.jboss.galleon.universe.maven.repo.MavenRepoManager)1