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);
}
}
Aggregations