use of org.jboss.galleon.universe.FeaturePackLocation in project wildfly-maven-plugin by wildfly.
the class GalleonUtils method buildConfig.
/**
* Build a Galleon provisioning configuration.
*
* @param pm The Galleon provisioning runtime.
* @param featurePacks The list of feature-packs.
* @param layers Layers to include.
* @param excludedLayers Layers to exclude.
* @param pluginOptions Galleon plugin options.
* @param layersConfigFileName The name of the configuration generated from layers
* @return The provisioning config.
* @throws ProvisioningException
*/
public static ProvisioningConfig buildConfig(ProvisioningManager pm, List<FeaturePack> featurePacks, List<String> layers, List<String> excludedLayers, Map<String, String> pluginOptions, String layersConfigFileName) throws ProvisioningException, IllegalArgumentException {
final ProvisioningConfig.Builder state = ProvisioningConfig.builder();
boolean hasLayers = !layers.isEmpty();
boolean fpWithDefaults = true;
if (!hasLayers) {
// Check we have all feature-packs with default values only.
for (FeaturePack fp : featurePacks) {
if (fp.isInheritConfigs() != null || fp.isInheritPackages() != null || !fp.getIncludedConfigs().isEmpty() || !fp.getExcludedConfigs().isEmpty() || fp.isTransitive() || !fp.getExcludedPackages().isEmpty() || !fp.getIncludedPackages().isEmpty()) {
fpWithDefaults = false;
break;
}
}
}
for (FeaturePack fp : featurePacks) {
if (fp.getLocation() == null && (fp.getGroupId() == null || fp.getArtifactId() == null) && fp.getNormalizedPath() == null) {
throw new IllegalArgumentException("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) {
String coords = getMavenCoords(fp);
fpl = FeaturePackLocation.fromString(coords);
} else {
fpl = FeaturePackLocation.fromString(fp.getLocation());
}
final FeaturePackConfig.Builder fpConfig = fp.isTransitive() ? FeaturePackConfig.transitiveBuilder(fpl) : FeaturePackConfig.builder(fpl);
if (fp.isInheritConfigs() == null) {
if (hasLayers) {
fpConfig.setInheritConfigs(false);
} else {
if (fpWithDefaults) {
fpConfig.setInheritConfigs(true);
}
}
} else {
fpConfig.setInheritConfigs(fp.isInheritConfigs());
}
if (fp.isInheritPackages() == null) {
if (hasLayers) {
fpConfig.setInheritPackages(false);
} else {
if (fpWithDefaults) {
fpConfig.setInheritConfigs(true);
}
}
} else {
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());
}
if (!layers.isEmpty()) {
ConfigModel.Builder configBuilder = ConfigModel.builder(STANDALONE, layersConfigFileName);
for (String layer : layers) {
configBuilder.includeLayer(layer);
}
for (String layer : excludedLayers) {
configBuilder.excludeLayer(layer);
}
state.addConfig(configBuilder.build());
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);
}
}
state.addOptions(pluginOptions);
return state.build();
}
use of org.jboss.galleon.universe.FeaturePackLocation 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);
}
}
use of org.jboss.galleon.universe.FeaturePackLocation in project galleon by wildfly.
the class AdvancedLayersTestCase method buildFP.
private static void buildFP(CliWrapper cli, UniverseSpec universeSpec, String producer, String version) throws ProvisioningException {
FeaturePackCreator creator = FeaturePackCreator.getInstance().addArtifactResolver(cli.getSession().getMavenRepoManager());
FeaturePackLocation fp1 = new FeaturePackLocation(universeSpec, producer, "1", null, version);
creator.newFeaturePack(fp1.getFPID()).addFeatureSpec(FeatureSpec.builder().addPackageDep("p1-required").addPackageDep("p1-optional", true).addPackageDep(PackageDependencySpec.newInstance("p1-passive", PackageDependencySpec.PASSIVE)).addPackageDep(PackageDependencySpec.newInstance("p2-passive", PackageDependencySpec.PASSIVE)).setName("feat1").addParam(FeatureParameterSpec.createId("p1")).build()).addFeatureSpec(FeatureSpec.builder().addPackageDep("p2-required").addPackageDep("p2-optional", true).setName("feat2").addParam(FeatureParameterSpec.createId("p2")).build()).addConfigLayer(ConfigLayerSpec.builder().setModel("testmodel").setName("base-" + producer).build()).addConfigLayer(ConfigLayerSpec.builder().setModel("testmodel").setName("layerA-" + producer).addLayerDep("base-" + producer).addFeature(FeatureConfig.newConfig("feat1").setParam("p1", "1")).build()).addConfigLayer(ConfigLayerSpec.builder().setModel("testmodel").setName("layerB-" + producer).addLayerDep("base-" + producer).addFeature(FeatureConfig.newConfig("feat2").setParam("p2", "1")).build()).addConfigLayer(ConfigLayerSpec.builder().setModel("testmodel").setName("layerD-" + producer).addLayerDep("layerE-" + producer).addFeature(FeatureConfig.newConfig("feat1").setParam("p1", "1")).build()).addConfigLayer(ConfigLayerSpec.builder().setModel("testmodel").setName("layerE-" + producer).addLayerDep("layerD-" + producer, true).addFeature(FeatureConfig.newConfig("feat1").setParam("p1", "1")).build()).addConfig(ConfigModel.builder("testmodel", "foo.xml").includeLayer("layerA-" + producer).includeLayer("layerB-" + producer).build(), true).newPackage("p1-required", false).addDependency("p1-ref-from-required").writeContent("fp1/p1-required.txt", "fp1 p1").getFeaturePack().newPackage("p1-ref-from-required", false).writeContent("fp1/p1-ref-from-required.txt", "fp1 p1").getFeaturePack().newPackage("p1-optional", false).addDependency("p1-ref-from-optional1").addDependency("p1-ref-from-optional2", true).writeContent("fp1/p1-optional.txt", "fp1 p1").getFeaturePack().newPackage("p1-ref-from-optional1", false).writeContent("fp1/p1-ref-from-optional1.txt", "fp1 p1").getFeaturePack().newPackage("p1-ref-from-optional2", false).writeContent("fp1/p1-ref-from-optional2.txt", "fp1 p1").getFeaturePack().newPackage("p1-passive", false).addDependency("p2-required").addDependency("p2-passive").writeContent("fp1/p1-passive.txt", "fp1 p1").getFeaturePack().newPackage("p2-passive", false).addDependency("p1-required").writeContent("fp1/p2-passive.txt", "fp1 p1").getFeaturePack().newPackage("p2-required", false).writeContent("fp1/p2-required.txt", "fp1 p1").getFeaturePack().newPackage("p2-optional", false).writeContent("fp1/p2-optional.txt", "fp1 p1").getFeaturePack();
creator.install();
}
use of org.jboss.galleon.universe.FeaturePackLocation in project galleon by wildfly.
the class AdvancedLayersTestCase method testWithExcludeLayers.
@Test
public void testWithExcludeLayers() throws Exception {
FeaturePackLocation prod = newFpl(PRODUCER4, "1", "1.0.0.Final");
buildFPWithOptionalLayers(cli, universeSpec, PRODUCER4, "1.0.0.Final");
{
Path path = cli.newDir("prod-exclude1", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4);
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
Collection<ConfigId> layers = state.getConfigs().get(0).getLayers();
// contains base, A, B and C.
assertEquals(layers.toString(), 4, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
}
{
Path path = cli.newDir("prod-exclude2", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4 + ",-layerB-" + PRODUCER4);
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
Collection<ConfigId> layers = state.getConfigs().get(0).getLayers();
// contains C, A and B are excluded, base, a dependency of A, is transitively excluded.
assertEquals(layers.toString(), 1, layers.size());
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Include layerA
cli.execute("install " + prod + " --dir=" + path + " --layers=layerA-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
// contains C, A and base, a dependency of A.
assertEquals(layers.toString(), 3, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Un-exclude layerB.
cli.execute("install " + prod + " --dir=" + path + " --layers=+layerB-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
assertEquals(layers.toString(), 4, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Attempt to un-exclude a layer that is not excluded
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=+layerA-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
// Attempt to exclude layerC that is not a dependency
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerC-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
// Exclude layerB
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerB-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
assertEquals(layers.toString(), 3, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
}
{
// Attempt to exclude a required layer.
Path path = cli.newDir("prod-exclude3", false);
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4 + ",-base-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
{
// Attempt to exclude a layer that is not a dependency.
Path path = cli.newDir("prod-exclude4", false);
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=layerB-" + PRODUCER4 + ",-layerC-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
{
// Install layerA and layerB, layerA is dependency of layerB
Path path = cli.newDir("prod-exclude5", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerA-" + PRODUCER4 + ",layerB-" + PRODUCER4);
try {
// Attempt to exclude layerA, it is not allowed, the layer has been explictly included.
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerA-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
}
use of org.jboss.galleon.universe.FeaturePackLocation in project galleon by wildfly.
the class AdvancedLayersTestCase method testWithFPDependency.
@Test
public void testWithFPDependency() throws Exception {
FeaturePackLocation prod2 = newFpl(PRODUCER2, "1", "1.0.0.Final");
buildFPWithDependency(cli, universeSpec, PRODUCER2, "1.0.0.Final");
{
Path path = cli.newDir("prod3", false);
cli.execute("install " + prod2 + " --dir=" + path + " --layers=layerA-" + PRODUCER2 + " --optional-packages=passive+");
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
Set<String> pkgs = state.getFeaturePack(prod2.getProducer()).getPackageNames();
assertTrue(pkgs.toString(), pkgs.contains("p1-required"));
assertTrue(pkgs.toString(), pkgs.contains("p1-ref-from-required"));
assertTrue(pkgs.toString(), pkgs.contains("p1-optional"));
assertTrue(pkgs.toString(), pkgs.contains("p1-ref-from-optional"));
assertFalse(pkgs.toString(), pkgs.contains("p1-passive"));
FeaturePackLocation dep = newFpl(PRODUCER3, "1", "1.0.0.Final");
Set<String> pkgs2 = state.getFeaturePack(dep.getProducer()).getPackageNames();
assertTrue(pkgs2.toString(), pkgs2.contains("p0-required1"));
assertTrue(pkgs2.toString(), pkgs2.contains("p0-required2"));
assertFalse(pkgs2.toString(), pkgs2.contains("p0-required3"));
}
{
Path path = cli.newDir("prod3", false);
cli.execute("install " + prod2 + " --dir=" + path + " --layers=layerA-" + PRODUCER2 + ",layer0-" + PRODUCER3 + " --optional-packages=passive+");
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
Set<String> pkgs = state.getFeaturePack(prod2.getProducer()).getPackageNames();
assertTrue(pkgs.toString(), pkgs.contains("p1-required"));
assertTrue(pkgs.toString(), pkgs.contains("p1-ref-from-required"));
assertTrue(pkgs.toString(), pkgs.contains("p1-optional"));
assertTrue(pkgs.toString(), pkgs.contains("p1-ref-from-optional"));
assertTrue(pkgs.toString(), pkgs.contains("p1-passive"));
FeaturePackLocation dep = newFpl(PRODUCER3, "1", "1.0.0.Final");
Set<String> pkgs2 = state.getFeaturePack(dep.getProducer()).getPackageNames();
assertTrue(pkgs2.toString(), pkgs2.contains("p0-required1"));
assertTrue(pkgs2.toString(), pkgs2.contains("p0-required2"));
assertTrue(pkgs2.toString(), pkgs2.contains("p0-required3"));
}
}
Aggregations