use of org.jboss.galleon.universe.FeaturePackLocation in project galleon by wildfly.
the class ProvisioningLayout method layout.
private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch, int type) throws ProvisioningException {
if (!config.hasFeaturePackDeps()) {
return;
}
List<ProducerSpec> added = Collections.emptyList();
if (config.hasTransitiveDeps()) {
if (transitiveDeps == null) {
transitiveDeps = new HashSet<>();
}
for (FeaturePackConfig transitiveConfig : config.getTransitiveDeps()) {
FeaturePackLocation fpl = transitiveConfig.getLocation();
if (transitiveConfig.hasPatches()) {
addPatches(transitiveConfig);
}
final FPID branchId = branch.get(fpl.getProducer());
if (branchId != null) {
if (!branchId.getChannel().getName().equals(fpl.getChannel().getName())) {
addConflict(fpl.getFPID(), branchId);
}
continue;
}
if (fpl.isMavenCoordinates()) {
final F f = resolveFeaturePack(fpl, FeaturePackLayout.TRANSITIVE_DEP, true);
fpl = f.getSpec().getFPID().getLocation();
registerResolvedVersion(transitiveConfig.getLocation().getProducer(), fpl);
registerMavenProducer(transitiveConfig.getLocation().getProducer(), f);
}
transitiveDeps.add(fpl.getProducer());
branch.put(fpl.getProducer(), fpl.getFPID());
added = CollectionUtils.add(added, fpl.getProducer());
}
}
final Collection<FeaturePackConfig> fpDeps = config.getFeaturePackDeps();
List<F> queue = new ArrayList<>(fpDeps.size());
for (FeaturePackConfig fpConfig : fpDeps) {
FeaturePackLocation fpl = fpConfig.getLocation();
if (fpConfig.hasPatches()) {
addPatches(fpConfig);
}
FPID branchId = branch.get(fpl.getProducer());
fpl = resolveVersion(fpl, branchId);
F fp = null;
if (!fpl.isMavenCoordinates()) {
fp = featurePacks.get(fpl.getProducer());
if (fp != null) {
converge(branchId, fpl.getFPID(), fp.getFPID());
continue;
}
}
fp = resolveFeaturePack(fpl, type, true);
if (fpl.isMavenCoordinates()) {
if (branchId == null) {
branchId = branch.get(fp.getFPID().getProducer());
}
final FeaturePackLocation resolvedFpl = resolveVersion(fp.getFPID().getLocation(), branchId);
F resolvedFp = featurePacks.get(resolvedFpl.getProducer());
if (resolvedFp != null) {
converge(branchId, resolvedFpl.getFPID(), resolvedFp.getFPID());
if (!fpl.equals(resolvedFpl)) {
registerMavenProducer(fpl.getProducer(), resolvedFp);
}
continue;
}
if (!fpl.equals(resolvedFpl)) {
if (branchId != null) {
fp = resolveFeaturePack(resolvedFpl, type, true);
} else {
registerResolvedVersion(fpl.getProducer(), resolvedFpl);
}
registerMavenProducer(fpl.getProducer(), fp);
fpl = resolvedFpl;
}
}
registerFeaturePack(fpl.getProducer(), fp);
queue.add(fp);
if (branchId == null || branchId.getBuild() == null) {
branch.put(fpl.getProducer(), fpl.getFPID());
added = CollectionUtils.add(added, fpl.getProducer());
}
}
if (!queue.isEmpty()) {
for (F p : queue) {
final FeaturePackSpec spec = p.getSpec();
layout(spec, branch, FeaturePackLayout.TRANSITIVE_DEP);
if (spec.hasPlugins()) {
pluginLocations = CollectionUtils.putAll(pluginLocations, spec.getPlugins());
}
handle.copyResources(p.getDir());
ordered.add(p);
}
}
if (!added.isEmpty()) {
for (ProducerSpec producer : added) {
branch.remove(producer);
}
}
}
use of org.jboss.galleon.universe.FeaturePackLocation 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.universe.FeaturePackLocation 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.universe.FeaturePackLocation 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 in project galleon by wildfly.
the class FeaturePackBuilder method build.
void build() throws ProvisioningException {
final FeaturePackLocation fps = fpBuilder.getFPID().getLocation();
if (fps == null) {
throw new ProvisioningDescriptionException("Feature-pack location has not been set");
}
if (fps.getProducerName() == null) {
throw new ProvisioningDescriptionException("Feature-pack producer has not been set");
}
/*
if(fps.getChannelName() == null) {
throw new ProvisioningDescriptionException("Feature-pack channel has not been set");
}
*/
if (fps.getBuild() == null) {
throw new ProvisioningDescriptionException("Feature-pack build number has not been set");
}
final Path fpWorkDir = LayoutUtils.getFeaturePackDir(creator.getWorkDir(), fps.getFPID(), false);
final FeaturePackSpec fpSpec;
try {
ensureDir(fpWorkDir);
for (PackageBuilder pkg : pkgs) {
final PackageSpec pkgDescr = pkg.build(fpWorkDir);
if (pkg.isDefault()) {
fpBuilder.addDefaultPackage(pkgDescr.getName());
}
}
if (!specs.isEmpty()) {
final Path featuresDir = fpWorkDir.resolve(Constants.FEATURES);
final FeatureSpecXmlWriter specWriter = FeatureSpecXmlWriter.getInstance();
for (FeatureSpec spec : specs.values()) {
final Path featureDir = featuresDir.resolve(spec.getName());
ensureDir(featureDir);
specWriter.write(spec, featureDir.resolve(Constants.SPEC_XML));
}
}
if (!featureGroups.isEmpty()) {
final Path fgsDir = fpWorkDir.resolve(Constants.FEATURE_GROUPS);
ensureDir(fgsDir);
final FeatureGroupXmlWriter fgWriter = FeatureGroupXmlWriter.getInstance();
for (FeatureGroup fg : featureGroups.values()) {
fgWriter.write(fg, fgsDir.resolve(fg.getName() + ".xml"));
}
}
if (!classes.isEmpty()) {
createPluginJar(classes, services, fpWorkDir.resolve(Constants.PLUGINS).resolve(pluginFileName));
}
if (!plugins.isEmpty()) {
final Path pluginsDir = fpWorkDir.resolve(Constants.PLUGINS);
ensureDir(pluginsDir);
for (Path plugin : plugins) {
Files.copy(plugin, pluginsDir.resolve(plugin.getFileName()));
}
}
if (!layers.isEmpty()) {
for (Map.Entry<ConfigId, ConfigLayerSpec> entry : layers.entrySet()) {
final ConfigId id = entry.getKey();
final Path xml = LayoutUtils.getLayerSpecXml(fpWorkDir, id.getModel(), id.getName(), false);
if (Files.exists(xml)) {
throw new ProvisioningException("Failed to create feature-pack: " + xml + " already exists");
}
ConfigLayerXmlWriter.getInstance().write(entry.getValue(), xml);
}
}
if (!configs.isEmpty()) {
for (ConfigModel config : configs.values()) {
final Path modelXml = LayoutUtils.getConfigXml(fpWorkDir, config.getId(), false);
if (Files.exists(modelXml)) {
throw new ProvisioningException("Failed to create feature-pack: " + modelXml + " already exists");
}
ConfigXmlWriter.getInstance().write(config, modelXml);
}
}
fpSpec = fpBuilder.build();
final FeaturePackXmlWriter writer = FeaturePackXmlWriter.getInstance();
writer.write(fpSpec, fpWorkDir.resolve(Constants.FEATURE_PACK_XML));
if (tasks != null && !tasks.isEmpty()) {
tasks.execute(FsTaskContext.builder().setTargetRoot(fpWorkDir.resolve(Constants.RESOURCES)).build());
}
creator.install(fps.getFPID(), fpWorkDir);
} catch (ProvisioningDescriptionException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
IoUtils.recursiveDelete(fpWorkDir);
}
}
Aggregations