use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.
the class ProvisioningLayout method uninstall.
private ProvisioningConfig.Builder uninstall(FPID fpid, ProvisioningConfig.Builder configBuilder) throws ProvisioningException {
if (allPatches.containsKey(fpid)) {
final F patchFp = allPatches.get(fpid);
final ProducerSpec patchTarget = patchFp.getSpec().getPatchFor().getProducer();
FeaturePackConfig targetConfig = config.getFeaturePackDep(patchTarget);
if (targetConfig == null) {
targetConfig = config.getTransitiveDep(patchTarget);
if (targetConfig == null) {
throw new ProvisioningException("Target feature-pack for patch " + fpid + " could not be found");
}
}
return configBuilder.updateFeaturePackDep(FeaturePackConfig.builder(targetConfig).removePatch(fpid).build());
}
final F installedFp = featurePacks.get(fpid.getProducer());
if (installedFp == null) {
throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
}
if (fpid.getBuild() != null && !installedFp.getFPID().getBuild().equals(fpid.getBuild())) {
throw new ProvisioningException(Errors.unknownFeaturePack(fpid));
}
final FeaturePackConfig fpConfig = config.getFeaturePackDep(fpid.getProducer());
if (fpConfig == null) {
throw new ProvisioningException(Errors.unsatisfiedFeaturePackDep(fpid.getProducer()));
}
configBuilder.removeFeaturePackDep(fpid.getLocation());
if (!configBuilder.hasFeaturePackDeps()) {
configBuilder.clearFeaturePackDeps();
configBuilder.clearOptions();
}
return configBuilder;
}
use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.
the class ProvisioningLayout method apply.
public void apply(ProvisioningPlan plan, Map<String, String> pluginOptions) throws ProvisioningException {
if (plan.isEmpty()) {
return;
}
final ProvisioningConfig.Builder configBuilder = ProvisioningConfig.builder(config);
if (plan.hasUpdates()) {
Map<ProducerSpec, FeaturePackUpdatePlan> updates = plan.getUpdateMap();
Set<ProducerSpec> processed = new HashSet<>(updates.size());
for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
final ProducerSpec producer = fpConfig.getLocation().getProducer();
final FeaturePackUpdatePlan fpPlan = updates.get(producer);
if (fpPlan != null && !fpPlan.isEmpty()) {
if (!fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
throw new ProvisioningException("Location in the update plan " + fpPlan.getInstalledLocation() + " does not match the installed location " + fpConfig.getLocation());
}
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.builder(fpPlan.getNewLocation()).init(fpConfig);
if (fpPlan.hasNewPatches()) {
for (FPID patchId : fpPlan.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.updateFeaturePackDep(fpBuilder.build());
processed.add(producer);
}
}
for (FeaturePackConfig fpConfig : config.getTransitiveDeps()) {
final ProducerSpec producer = fpConfig.getLocation().getProducer();
final FeaturePackUpdatePlan fpPlan = updates.get(producer);
if (fpPlan != null && !fpPlan.isEmpty()) {
if (fpConfig.getLocation().getBuild() != null && !fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
throw new ProvisioningException("Update plan build " + fpPlan.getInstalledLocation() + " does not match the installed build " + fpConfig.getLocation());
}
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(fpPlan.getNewLocation()).init(fpConfig);
if (fpPlan.hasNewPatches()) {
for (FPID patchId : fpPlan.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.updateFeaturePackDep(fpBuilder.build());
processed.add(producer);
}
}
if (processed.size() < updates.size()) {
for (Map.Entry<ProducerSpec, FeaturePackUpdatePlan> entry : updates.entrySet()) {
if (processed.contains(entry.getKey())) {
continue;
}
final FeaturePackUpdatePlan update = entry.getValue();
final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(update.getNewLocation());
if (update.hasNewPatches()) {
for (FPID patchId : update.getNewPatches()) {
fpBuilder.addPatch(patchId);
}
}
configBuilder.addFeaturePackDep(fpBuilder.build());
}
}
}
if (plan.hasInstall()) {
for (FeaturePackConfig fpConfig : plan.getInstall()) {
install(fpConfig, configBuilder);
}
}
if (plan.hasUninstall()) {
for (ProducerSpec producer : plan.getUninstall()) {
uninstall(producer.getLocation().getFPID(), configBuilder);
}
}
final ProvisioningConfig config = configBuilder.build();
initBuiltInOptions(config, pluginOptions);
rebuild(config, true);
initPluginOptions(pluginOptions, plan.hasUninstall());
}
use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.
the class AbstractFPProvisionedCommand method getProvisionedFP.
public FeaturePackConfig getProvisionedFP(PmSession session) throws CommandExecutionException {
ProducerSpec producer = getProducer(session);
if (producer == null) {
return null;
}
ProvisioningConfig config = session.getState().getConfig();
for (FeaturePackConfig dep : config.getFeaturePackDeps()) {
if (dep.getLocation().getProducer().equals(producer)) {
return dep;
}
}
for (FeaturePackConfig dep : config.getTransitiveDeps()) {
if (dep.getLocation().getProducer().equals(producer)) {
return dep;
}
}
return null;
}
use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.
the class CheckUpdatesCommand method getUpdatesTable.
static Updates getUpdatesTable(ProvisioningManager mgr, PmCommandInvocation session, boolean includeAll, String fp) throws ProvisioningException, CommandExecutionException {
if (includeAll && fp != null) {
throw new CommandExecutionException(CliErrors.onlyOneOptionOf(FP_OPTION_NAME, ALL_DEPENDENCIES_OPTION_NAME));
}
ProvisioningPlan plan;
if (fp == null) {
plan = mgr.getUpdates(includeAll);
} else {
String[] split = fp.split(",+");
List<ProducerSpec> resolved = new ArrayList<>();
List<FeaturePackLocation> locs = new ArrayList<>();
for (String producer : split) {
FeaturePackLocation loc = session.getPmSession().getResolvedLocation(mgr.getInstallationHome(), producer);
if (loc.hasBuild()) {
locs.add(loc);
} else {
resolved.add(loc.getProducer());
}
}
if (!resolved.isEmpty()) {
ProducerSpec[] arr = new ProducerSpec[resolved.size()];
plan = mgr.getUpdates(resolved.toArray(arr));
} else {
plan = ProvisioningPlan.builder();
}
if (!locs.isEmpty()) {
addCustomUpdates(plan, locs, mgr);
}
}
Updates updates = new Updates();
updates.plan = plan;
if (plan.isEmpty()) {
return updates;
}
boolean hasPatches = false;
for (FeaturePackUpdatePlan p : plan.getUpdates()) {
if (p.hasNewPatches()) {
hasPatches = true;
break;
}
}
List<String> headers = new ArrayList<>();
headers.add(Headers.PRODUCT);
headers.add(Headers.CURRENT_BUILD);
headers.add(Headers.UPDATE);
if (hasPatches) {
headers.add(Headers.PATCHES);
}
if (includeAll) {
headers.add(Headers.DEPENDENCY);
}
headers.add(Headers.UPDATE_CHANNEL);
updates.t = new Table(headers);
for (FeaturePackUpdatePlan p : plan.getUpdates()) {
FeaturePackLocation loc = p.getInstalledLocation();
String update = p.hasNewLocation() ? p.getNewLocation().getBuild() : NONE;
Cell patches = null;
if (hasPatches) {
patches = new Cell();
if (p.hasNewPatches()) {
for (FPID id : p.getNewPatches()) {
patches.addLine(id.getBuild());
}
} else {
patches.addLine(NONE);
}
}
List<Cell> line = new ArrayList<>();
line.add(new Cell(loc.getProducerName()));
line.add(new Cell(loc.getBuild()));
line.add(new Cell(update));
if (hasPatches) {
line.add(patches);
}
if (includeAll) {
line.add(new Cell(p.isTransitive() ? "Y" : "N"));
}
FeaturePackLocation newLocation = session.getPmSession().getExposedLocation(mgr.getInstallationHome(), p.getNewLocation());
line.add(new Cell(StateInfoUtil.formatChannel(newLocation)));
updates.t.addCellsLine(line);
}
updates.t.sort(Table.SortType.ASCENDANT);
return updates;
}
use of org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec in project galleon by wildfly.
the class StateInfoUtil method buildOptionalPackages.
public static String buildOptionalPackages(PmSession session, FeatureContainer container, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
String optionValue = container.getProvisioningConfig().getOption(ProvisioningOption.OPTIONAL_PACKAGES.getName());
if (optionValue == null) {
optionValue = Constants.ALL;
}
Table.Tree t = null;
boolean passivePresent = !container.getPassivePackages().isEmpty() || !container.getOrphanPassivePackages().isEmpty();
Set<String> optionalProducers = container.getOptionalPackagesProducers();
if (!optionalProducers.isEmpty()) {
if (passivePresent) {
t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE, Headers.PASSIVE);
} else {
t = new Table.Tree(Headers.PRODUCT, Headers.FEATURE, Headers.PACKAGE);
}
for (String producer : optionalProducers) {
String displayProducer = producer;
try {
ProducerSpec pSpec = FeaturePackLocation.fromString(producer).getProducer();
if (session.getUniverse().getBuiltinUniverseSpec().equals(pSpec.getUniverse())) {
displayProducer = pSpec.getName();
}
} catch (Exception ex) {
// Not a producerSpec, keep original one.
}
Table.Node producerNode = new Table.Node(displayProducer);
t.add(producerNode);
Map<String, Set<String>> optionalPkgs = container.getOptionalPackages().get(producer);
if (optionalPkgs != null && !optionalPkgs.isEmpty()) {
for (Entry<String, Set<String>> entry : optionalPkgs.entrySet()) {
Table.Node feat = new Table.Node(entry.getKey());
producerNode.addNext(feat);
for (String p : entry.getValue()) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
if (passivePresent) {
pkg.addNext(new Table.Node(""));
}
}
Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
if (passivePkgs != null) {
Set<String> passives = passivePkgs.get(entry.getKey());
if (passives != null) {
for (String p : passives) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
} else {
Map<String, Set<String>> passivePkgs = container.getPassivePackages().get(producer);
if (passivePkgs != null && !passivePkgs.isEmpty()) {
for (Entry<String, Set<String>> entry : passivePkgs.entrySet()) {
Table.Node feat = new Table.Node(entry.getKey());
producerNode.addNext(feat);
for (String p : entry.getValue()) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
Set<String> orphanOptionals = container.getOrphanOptionalPackages().get(producer);
Set<String> orphanPassives = container.getOrphanPassivePackages().get(producer);
if (orphanOptionals != null || orphanPassives != null) {
Table.Node feat = new Table.Node("{no-feature}");
producerNode.addNext(feat);
if (orphanOptionals != null) {
for (String p : orphanOptionals) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
if (passivePresent) {
pkg.addNext(new Table.Node(""));
}
}
}
if (orphanPassives != null) {
for (String p : orphanPassives) {
Table.Node pkg = new Table.Node(p);
feat.addNext(pkg);
pkg.addNext(new Table.Node("true"));
}
}
}
}
}
StringBuilder builder = new StringBuilder();
builder.append("Optional packages (Provisioning option: " + optionValue + ")" + Config.getLineSeparator());
if (t == null) {
builder.append(NO_OPTIONAL_PACKAGES);
} else {
builder.append(t.build());
}
return builder.toString();
}
Aggregations