use of org.jboss.galleon.config.FeaturePackConfig 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.config.FeaturePackConfig 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.config.FeaturePackConfig in project galleon by wildfly.
the class ProvisioningLayout method doBuild.
private void doBuild(boolean cleanupTransitive, boolean trackProgress) throws ProvisioningException {
buildTracker = getBuildTracker(trackProgress);
buildTracker.starting(-1);
final Map<ProducerSpec, FPID> depBranch = new HashMap<>();
layout(config, depBranch, FeaturePackLayout.DIRECT_DEP);
if (!conflicts.isEmpty()) {
throw new ProvisioningDescriptionException(Errors.fpVersionCheckFailed(conflicts.values()));
}
if (transitiveDeps != null) {
ProvisioningConfig.Builder newConfig = null;
List<ProducerSpec> notUsedTransitive = Collections.emptyList();
for (ProducerSpec producer : transitiveDeps) {
if (featurePacks.containsKey(producer)) {
continue;
}
if (cleanupTransitive && config.hasTransitiveDep(producer)) {
if (newConfig == null) {
newConfig = ProvisioningConfig.builder(config);
}
newConfig.removeTransitiveDep(producer.getLocation().getFPID());
continue;
}
notUsedTransitive = CollectionUtils.add(notUsedTransitive, producer);
}
if (!notUsedTransitive.isEmpty()) {
throw new ProvisioningDescriptionException(Errors.transitiveDependencyNotFound(notUsedTransitive.toArray(new ProducerSpec[notUsedTransitive.size()])));
}
if (newConfig != null) {
config = newConfig.build();
}
transitiveDeps = null;
}
if (resolvedVersions != null) {
final ProvisioningConfig.Builder builder = ProvisioningConfig.builder().addOptions(config.getOptions()).initUniverses(config).initConfigs(config);
addFpDeps(builder, config.getFeaturePackDeps());
if (config.hasTransitiveDeps()) {
addFpDeps(builder, config.getTransitiveDeps());
}
if (!resolvedVersions.isEmpty()) {
for (FeaturePackLocation fpl : resolvedVersions.values()) {
final FeaturePackConfig existing = builder.getTransitiveFeaturePackDep(fpl.getProducer());
if (existing == null) {
builder.addTransitiveDep(fpl);
} else if (!existing.getLocation().hasBuild()) {
builder.updateFeaturePackDep(FeaturePackConfig.builder(fpl).init(existing).build());
}
}
}
config = builder.build();
resolvedVersions = null;
}
// apply patches
if (!fpPatches.isEmpty()) {
for (F f : ordered) {
final List<F> patches = fpPatches.get(f.getFPID());
if (patches == null) {
if (f.getSpec().hasPlugins()) {
pluginLocations = CollectionUtils.putAll(pluginLocations, f.getSpec().getPlugins());
}
final Path fpResources = f.getDir().resolve(Constants.RESOURCES);
if (Files.exists(fpResources)) {
patchDir(getResources(), fpResources);
}
final Path fpPlugins = f.getDir().resolve(Constants.PLUGINS);
if (Files.exists(fpPlugins)) {
patchDir(getPluginsDir(), fpPlugins);
}
continue;
}
final Path fpDir = LayoutUtils.getFeaturePackDir(handle.getPatchedDir(), f.getFPID(), false);
try {
Files.createDirectories(fpDir);
IoUtils.copy(f.getDir(), fpDir);
} catch (IOException e) {
throw new ProvisioningException("Failed to patch feature-pack dir for " + f.getFPID(), e);
}
f.dir = fpDir;
for (F patch : patches) {
final Path patchDir = patch.getDir();
patchFpDir(fpDir, patchDir, Constants.PACKAGES);
patchFpDir(fpDir, patchDir, Constants.FEATURES);
patchFpDir(fpDir, patchDir, Constants.FEATURE_GROUPS);
patchFpDir(fpDir, patchDir, Constants.CONFIGS);
patchFpDir(fpDir, patchDir, Constants.LAYERS);
Path patchContent = patchDir.resolve(Constants.PLUGINS);
if (Files.exists(patchContent)) {
patchDir(fpDir.resolve(Constants.PLUGINS), patchContent);
patchDir(getPluginsDir(), patchContent);
}
patchContent = patchDir.resolve(Constants.RESOURCES);
if (Files.exists(patchContent)) {
patchDir(fpDir.resolve(Constants.RESOURCES), patchContent);
patchDir(getResources(), patchContent);
}
if (patch.getSpec().hasPlugins()) {
pluginLocations = CollectionUtils.putAll(pluginLocations, patch.getSpec().getPlugins());
}
}
}
}
if (!pluginLocations.isEmpty()) {
handle.addPlugins(pluginLocations.values());
}
buildTracker.complete();
}
use of org.jboss.galleon.config.FeaturePackConfig 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.config.FeaturePackConfig 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;
}
Aggregations