use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.
the class ProvisioningLayoutFactory method resolveFeaturePack.
public <F extends FeaturePackLayout> F resolveFeaturePack(FeaturePackLocation location, int type, FeaturePackLayoutFactory<F> factory) throws ProvisioningException {
final Path fpDir = resolveFeaturePackDir(location);
final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML);
if (!Files.exists(fpXml)) {
throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml));
}
try (BufferedReader reader = Files.newBufferedReader(fpXml)) {
final FeaturePackSpec fpSpec = FeaturePackXmlParser.getInstance().parse(reader);
if (location.isMavenCoordinates()) {
final FPID specId = fpSpec.getFPID();
final FeaturePackLocation fpl = new FeaturePackLocation(specId.getUniverse(), specId.getProducer().getName(), specId.getChannel().getName(), location.getFrequency(), specId.getBuild());
synchronized (this) {
cachedPacks.put(fpl.getFPID(), cachedPacks.get(location.getFPID()));
}
location = fpl;
}
return factory.newFeaturePack(location, fpSpec, fpDir, type);
} catch (IOException | XMLStreamException e) {
throw new ProvisioningException(Errors.parseXml(fpXml), e);
}
}
use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.
the class ProvisioningLayoutFactory method resolveFeaturePackDir.
private synchronized Path resolveFeaturePackDir(FeaturePackLocation fpl) throws ProvisioningException {
final FPID fpid = fpl.getFPID();
FileSystem packFs = cachedPacks.get(fpid);
if (packFs != null) {
return getFpDir(packFs);
}
return put(universeResolver.resolve(fpl), fpid);
}
use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.
the class ProvisioningLayout method loadPatch.
private void loadPatch(FPID patchId) throws ProvisioningException {
final F patchFp = layoutFactory.resolveFeaturePack(patchId.getLocation(), FeaturePackLayout.PATCH, fpFactory);
final FeaturePackSpec spec = patchFp.getSpec();
if (!spec.isPatch()) {
throw new ProvisioningDescriptionException(patchId + " is not a patch but listed as one");
}
allPatches = CollectionUtils.put(allPatches, patchId, patchFp);
if (spec.hasFeaturePackDeps()) {
for (FeaturePackConfig patchDep : spec.getFeaturePackDeps()) {
final FPID patchDepId = patchDep.getLocation().getFPID();
if (allPatches.containsKey(patchDepId)) {
continue;
}
loadPatch(patchDepId);
}
}
final FPID patchFor = spec.getPatchFor();
List<F> patchList = fpPatches.get(patchFor);
if (patchList == null) {
fpPatches = CollectionUtils.put(fpPatches, patchFor, Collections.singletonList(patchFp));
} else if (patchList.size() == 1) {
final List<F> tmp = new ArrayList<>(2);
tmp.add(patchList.get(0));
tmp.add(patchFp);
fpPatches = CollectionUtils.put(fpPatches, patchFor, tmp);
} else {
patchList.add(patchFp);
}
}
use of org.jboss.galleon.universe.FeaturePackLocation.FPID 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.FPID in project galleon by wildfly.
the class GetInfoCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation commandInvocation) throws CommandExecutionException {
if (fpl != null && file != null) {
throw new CommandExecutionException("File and location can't be both set");
}
if (fpl == null && file == null) {
throw new CommandExecutionException("File or location must be set");
}
PmSession session = commandInvocation.getPmSession();
FeaturePackLayout product = null;
List<FeaturePackLocation> dependencies = new ArrayList<>();
ProvisioningConfig provisioning;
ProvisioningLayout<FeaturePackLayout> layout = null;
try {
try {
if (fpl != null) {
FeaturePackLocation loc;
loc = session.getResolvedLocation(null, fpl);
FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
layout = session.getLayoutFactory().newConfigLayout(provisioning);
} else {
layout = session.getLayoutFactory().newConfigLayout(file.toPath(), true);
}
for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) {
boolean isProduct = true;
for (FeaturePackLayout fpLayout2 : layout.getOrderedFeaturePacks()) {
if (fpLayout2.getSpec().hasTransitiveDep(fpLayout.getFPID().getProducer()) || fpLayout2.getSpec().getFeaturePackDep(fpLayout.getFPID().getProducer()) != null) {
isProduct = false;
break;
}
}
if (isProduct) {
product = fpLayout;
} else {
dependencies.add(session.getExposedLocation(null, fpLayout.getFPID().getLocation()));
}
}
} catch (ProvisioningException ex) {
throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
}
if (product == null) {
throw new CommandExecutionException("No feature-pack found");
}
commandInvocation.println("");
StateInfoUtil.printFeaturePack(commandInvocation, session.getExposedLocation(null, product.getFPID().getLocation()));
try {
final FPID patchFor = product.getSpec().getPatchFor();
if (patchFor != null) {
commandInvocation.println("");
commandInvocation.println(PATCH_FOR + patchFor);
}
} catch (ProvisioningException e) {
throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), e);
}
try {
if (type != null) {
commandInvocation.println("");
switch(type) {
case ALL:
{
if (displayDependencies(commandInvocation, dependencies)) {
commandInvocation.println("");
}
if (displayConfigs(commandInvocation, layout)) {
commandInvocation.println("");
}
if (displayLayers(commandInvocation, layout)) {
commandInvocation.println("");
}
if (displayOptionalPackages(commandInvocation, layout)) {
commandInvocation.println("");
}
displayOptions(commandInvocation, layout);
break;
}
case CONFIGS:
{
if (!displayConfigs(commandInvocation, layout)) {
commandInvocation.println(StateInfoUtil.NO_CONFIGURATIONS);
}
break;
}
case DEPENDENCIES:
{
if (!displayDependencies(commandInvocation, dependencies)) {
commandInvocation.println(StateInfoUtil.NO_DEPENDENCIES);
}
break;
}
case LAYERS:
{
if (!displayLayers(commandInvocation, layout)) {
commandInvocation.println(StateInfoUtil.NO_LAYERS);
}
break;
}
case OPTIONS:
{
if (!displayOptions(commandInvocation, layout)) {
commandInvocation.println(StateInfoUtil.NO_OPTIONS);
}
break;
}
case OPTIONAL_PACKAGES:
{
if (!displayOptionalPackages(commandInvocation, layout)) {
commandInvocation.println(StateInfoUtil.NO_OPTIONAL_PACKAGES);
}
break;
}
default:
{
throw new CommandExecutionException(CliErrors.invalidInfoType());
}
}
}
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
}
} finally {
if (layout != null) {
layout.close();
}
}
}
Aggregations