use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.
the class ProvisioningLayout method dependsOn.
private boolean dependsOn(F f, ProducerSpec dep, Set<ProducerSpec> visitedFps) throws ProvisioningException {
final FeaturePackSpec spec = f.getSpec();
if (!spec.hasFeaturePackDeps()) {
return false;
}
if (spec.hasFeaturePackDep(dep) || spec.hasTransitiveDep(dep)) {
return true;
}
for (FeaturePackConfig fpConfig : spec.getFeaturePackDeps()) {
final ProducerSpec producer = fpConfig.getLocation().getProducer();
if (!visitedFps.add(producer)) {
continue;
}
if (dependsOn(featurePacks.get(producer), dep, visitedFps)) {
return true;
}
visitedFps.remove(producer);
}
return false;
}
use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.
the class ProvisioningLayout method install.
private ProvisioningConfig.Builder install(FeaturePackConfig fpConfig, ProvisioningConfig.Builder configBuilder) throws ProvisioningException {
FeaturePackLocation fpl = fpConfig.getLocation();
if (!fpl.hasBuild()) {
fpl = layoutFactory.getUniverseResolver().resolveLatestBuild(fpl);
}
final FeaturePackSpec fpSpec = layoutFactory.resolveFeaturePack(fpl, FeaturePackLayout.DIRECT_DEP, fpFactory).getSpec();
final FPID fpid = fpSpec.getFPID();
if (fpSpec.isPatch()) {
if (allPatches.containsKey(fpid)) {
throw new ProvisioningException(Errors.patchAlreadyApplied(fpid));
}
F patchTarget = featurePacks.get(fpSpec.getPatchFor().getProducer());
if (patchTarget == null || !patchTarget.getFPID().equals(fpSpec.getPatchFor())) {
throw new ProvisioningException(Errors.patchNotApplicable(fpid, fpSpec.getPatchFor()));
}
FeaturePackConfig installedFpConfig = config.getFeaturePackDep(fpSpec.getPatchFor().getProducer());
if (installedFpConfig == null) {
installedFpConfig = config.getTransitiveDep(fpSpec.getPatchFor().getProducer());
}
if (installedFpConfig == null) {
return configBuilder.addFeaturePackDep(FeaturePackConfig.transitiveBuilder(patchTarget.getFPID().getLocation()).addPatch(fpid).build());
}
return configBuilder.updateFeaturePackDep(FeaturePackConfig.builder(installedFpConfig.getLocation()).init(installedFpConfig).addPatch(fpid).build());
}
if (fpl.isMavenCoordinates()) {
fpl = new FeaturePackLocation(fpid.getUniverse(), fpid.getProducer().getName(), fpid.getChannel().getName(), fpl.getFrequency(), fpid.getBuild());
fpConfig = FeaturePackConfig.builder(fpl).init(fpConfig).build();
}
final F installedFp = featurePacks.get(fpid.getProducer());
if (installedFp != null) {
if (installedFp.isTransitiveDep() == fpConfig.isTransitive()) {
return configBuilder.updateFeaturePackDep(fpConfig);
}
if (installedFp.isTransitiveDep()) {
// transitive becomes direct
if (config.hasTransitiveDep(fpid.getProducer())) {
configBuilder.removeTransitiveDep(fpid);
}
return configBuilder.addFeaturePackDep(getIndexForDepToInstall(configBuilder, fpid.getProducer()), fpConfig);
}
// direct becomes transitive
configBuilder.removeFeaturePackDep(fpid.getLocation());
}
return configBuilder.addFeaturePackDep(fpConfig);
}
use of org.jboss.galleon.spec.FeaturePackSpec in project galleon by wildfly.
the class ProvisioningLayout method resolveFeaturePack.
private F resolveFeaturePack(FeaturePackLocation fpl, int type, boolean translateSpecFpl) throws ProvisioningException {
buildTracker.processing(fpl.getFPID());
F fp = layoutFactory.resolveFeaturePack(fpl, type, fpFactory);
buildTracker.processed(fpl.getFPID());
if (!translateSpecFpl) {
return fp;
}
FeaturePackSpec.Builder rebuilder = null;
FeaturePackSpec fpSpec = fp.getSpec();
if (fpSpec.hasTransitiveDeps()) {
int i = 0;
for (FeaturePackConfig dep : fpSpec.getTransitiveDeps()) {
if (dep.getLocation().isMavenCoordinates()) {
final F fpDep = resolveFeaturePack(dep.getLocation(), type, false);
if (fpDep.getFPID().getLocation().isMavenCoordinates()) {
if (rebuilder != null) {
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
}
} else {
if (rebuilder == null) {
rebuilder = getSpecRebuilder(fp.fpid, fpSpec);
if (i > 0) {
int j = 0;
for (FeaturePackConfig d : fpSpec.getTransitiveDeps()) {
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), d);
if (++j == i) {
break;
}
}
}
}
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), FeaturePackConfig.transitiveBuilder(fpDep.getFPID().getLocation()).init(dep).build());
}
} else if (rebuilder != null) {
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
}
i++;
}
}
if (fpSpec.hasFeaturePackDeps()) {
int i = 0;
for (FeaturePackConfig dep : fpSpec.getFeaturePackDeps()) {
if (dep.getLocation().isMavenCoordinates()) {
final F fpDep = resolveFeaturePack(dep.getLocation(), type, false);
if (fpDep.getFPID().getLocation().isMavenCoordinates()) {
if (rebuilder != null) {
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
}
} else {
if (rebuilder == null) {
rebuilder = getSpecRebuilder(fp.fpid, fpSpec);
if (fpSpec.hasTransitiveDeps()) {
for (FeaturePackConfig d : fpSpec.getTransitiveDeps()) {
rebuilder.addFeaturePackDep(fpSpec.originOf(d.getLocation().getProducer()), d);
}
}
if (i > 0) {
int j = 0;
for (FeaturePackConfig d : fpSpec.getFeaturePackDeps()) {
rebuilder.addFeaturePackDep(fpSpec.originOf(d.getLocation().getProducer()), d);
if (++j == i) {
break;
}
}
}
}
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), FeaturePackConfig.builder(fpDep.getFPID().getLocation()).init(dep).build());
}
} else if (rebuilder != null) {
rebuilder.addFeaturePackDep(fpSpec.originOf(dep.getLocation().getProducer()), dep);
}
i++;
}
}
if (rebuilder != null) {
final FeaturePackSpec spec = rebuilder.build();
fp = fpFactory.newFeaturePack(spec.getFPID().getLocation(), spec, fp.getDir(), fp.getType());
}
return fp;
}
use of org.jboss.galleon.spec.FeaturePackSpec 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.spec.FeaturePackSpec 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);
}
}
Aggregations