protected ElementNode toElement(FeaturePackSpec fpSpec) { final ElementNode fp = addElement(null, Element.FEATURE_PACK); addAttribute(fp, Attribute.LOCATION, fpSpec.getFPID().toString()); if(fpSpec.isPatch()) { final ElementNode patchFor = addElement(fp, Element.PATCH); addAttribute(patchFor, Attribute.FOR, fpSpec.getPatchFor().toString()); if (fpSpec.hasTransitiveDeps()) { final ElementNode transitives = addElement(fp, Element.TRANSITIVE); for(FeaturePackConfig dep : fpSpec.getTransitiveDeps()) { final ElementNode depElement = addElement(transitives, Element.DEPENDENCY); ProvisioningXmlWriter.writeFeaturePackConfig(depElement, fpSpec.getUserConfiguredLocation(dep.getLocation()), dep, fpSpec.originOf(dep.getLocation().getProducer())); if (fpSpec.hasFeaturePackDeps()) { final ElementNode deps = addElement(fp, Element.DEPENDENCIES); for (FeaturePackConfig dep : fpSpec.getFeaturePackDeps()) { final ElementNode depElement = addElement(deps, Element.DEPENDENCY); ProvisioningXmlWriter.writeFeaturePackConfig(depElement, fpSpec.getUserConfiguredLocation(dep.getLocation()), dep, fpSpec.originOf(dep.getLocation().getProducer())); if (fpSpec.hasDefaultPackages()) { final ElementNode pkgs = addElement(fp, Element.DEFAULT_PACKAGES); final String[] pkgNames = fpSpec.getDefaultPackageNames().toArray(new String[0]); Arrays.sort(pkgNames); for (String name : pkgNames) {
FeaturePackRuntimeBuilder getOrigin(final String depName) throws ProvisioningException { if(Constants.THIS.equals(depName)) { if(thisOrigin == null) { throw new ProvisioningException("Feature-pack reference 'this' cannot be used in the current context."); } return thisOrigin; } final FeaturePackLocation fpl = currentOrigin == null ? config.getFeaturePackDep(depName).getLocation() : currentOrigin.getSpec().getFeaturePackDep(depName).getLocation(); return layout.getFeaturePack(fpl.getProducer()); }
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; }
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); } }
config = currentOrigin.getSpec().getDefinedConfig(configId); if(config != null) { configStack.pushConfig(config); if (currentOrigin.getSpec().hasFeaturePackDeps()) { if (currentOrigin.getSpec().hasTransitiveDeps()) { for (FeaturePackConfig fpDep : currentOrigin.getSpec().getTransitiveDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel); for (FeaturePackConfig fpDep : currentOrigin.getSpec().getFeaturePackDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel); if (fpConfig.isInheritPackages() && currentOrigin.getSpec().hasDefaultPackages()) { for (String packageName : currentOrigin.getSpec().getDefaultPackageNames()) { if (fpConfigStack.isPackageFilteredOut(currentOrigin.producer, packageName, false)) { continue;
if (!fpConfig.isTransitive()) { final FeaturePackSpec currentSpec = currentOrigin.getSpec(); if (currentSpec.hasDefinedConfigs()) { for (ConfigModel config : currentSpec.getDefinedConfigs()) { final ConfigId id = config.getId(); if (id.isModelOnly() || fpConfigStack.isFilteredOut(producer, id, false)) { if (currentSpec.hasFeaturePackDeps()) { if (currentSpec.hasTransitiveDeps()) { for (FeaturePackConfig fpDep : currentSpec.getTransitiveDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel); for (FeaturePackConfig fpDep : currentSpec.getFeaturePackDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel);
++pushedCount; config = fp.getSpec().getDefinedConfig(configId); if(config != null) { if(modelOnlyStack == null) { if (fp.getSpec().hasTransitiveDeps()) { for (FeaturePackConfig fpDep : fp.getSpec().getTransitiveDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel); if(fp.getSpec().hasFeaturePackDeps()) { for(FeaturePackConfig fpDep : fp.getSpec().getFeaturePackDeps()) { extendedStackLevel |= fpConfigStack.push(fpDep, extendedStackLevel); if(fpDep.isConfigModelExcluded(configId) || !fpDep.isInheritModelOnlyConfigs() && !fpDep.isConfigModelIncluded(configId)) {
if (p == null) { for (FeaturePackConfig fpdep : currentRuntime.getSpec().getFeaturePackDeps()) { if (currentRuntime.getSpec().originOf(fpdep.getLocation().getProducer()) == null) { FeaturePackRuntime depRuntime = gavs.get(Identity.buildOrigin(fpdep.getLocation().getProducer())); p = depRuntime.getPackage(identity.getName()); FeaturePackConfig fpdep = currentRuntime.getSpec().getFeaturePackDep(identity.getOrigin()); if (fpdep != null) { resolvedIdentity = Identity.fromChannel(fpdep.getLocation().getProducer(), identity.getName());
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; final FPID patchFor = product.getSpec().getPatchFor(); if (patchFor != null) { commandInvocation.println("");
spec = builder.spec.build(); this.packages = CollectionUtils.unmodifiable(builder.packages); for(String name : spec.getDefaultPackageNames()) { if(!packages.containsKey(name)) { throw new ProvisioningDescriptionException(Errors.unknownPackage(fpid, name)); if(!spec.hasFeaturePackDeps() && !notFound.isEmpty()) { throw new ProvisioningDescriptionException(Errors.unsatisfiedPackageDependencies(fpid, pkg.getName(), notFound)); for(String origin : pkg.getPackageOrigins()) { try { spec.getFeaturePackDep(origin); } catch(ProvisioningDescriptionException e) { throw new ProvisioningDescriptionException(Errors.unknownFeaturePackDependencyName(fpid, pkg.getName(), origin), e);
private static String buildDependencies(PmCommandInvocation invoc, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException { Map<FPID, FeaturePackConfig> configs = new HashMap<>(); List<FeaturePackLocation> dependencies = new ArrayList<>(); 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) { FeaturePackLocation loc = invoc.getPmSession().getExposedLocation(null, fpLayout.getFPID().getLocation()); dependencies.add(loc); FeaturePackConfig transitiveConfig = layout.getConfig().getTransitiveDep(fpLayout.getFPID().getProducer()); configs.put(loc.getFPID(), transitiveConfig); } } return buildDependencies(dependencies, configs); }
private void resolveConfigLayer(FeaturePackRuntimeBuilder fp, ConfigModelStack layerStack, ConfigId layerId) throws ProvisioningException { final FeaturePackRuntimeBuilder prevOrigin = currentOrigin; try { final ConfigLayerSpec configLayer = fp.getConfigLayer(layerId); if (configLayer != null) { layerStack.pushGroup(configLayer); } if(fp.getSpec().hasFeaturePackDeps()) { for(FeaturePackConfig depConfig : fp.getSpec().getFeaturePackDeps()) { resolveConfigLayer(layout.getFeaturePack(depConfig.getLocation().getProducer()), layerStack, layerId); } } if(configLayer != null) { setOrigin(fp); processConfigLayer(layerStack, popLayer(layerStack)); } } finally { setOrigin(prevOrigin); } }
if(fpSpec.isPatch()) { 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());
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) {
@Override protected String getId(PmSession session) throws CommandExecutionException { String filePath = (String) getValue(FILE_OPTION_NAME); if (filePath == null) { filePath = getOptionValue(FILE_OPTION_NAME); if (filePath == null) { return super.getId(session); } } Path path; try { path = Util.resolvePath(session.getAeshContext(), filePath); } catch (IOException ex) { throw new CommandExecutionException(ex.getMessage()); } if (!Files.exists(path)) { return null; } try { return FeaturePackDescriber.readSpec(path).getFPID().toString(); } catch (ProvisioningException ex) { throw new CommandExecutionException(session, CliErrors.retrieveFeaturePackID(), ex); } }
@Override public FeaturePackSpec parse(Reader input) throws XMLStreamException, ProvisioningDescriptionException { final FeaturePackSpec.Builder fpBuilder = FeaturePackSpec.builder(); parse(input, fpBuilder); return fpBuilder.build(); } }
public FeaturePackSpec build() throws ProvisioningDescriptionException { try { return new FeaturePackSpec(this); } catch(ProvisioningDescriptionException e) { throw new ProvisioningDescriptionException("Failed to build feature-pack spec for " + fpid, e); } } }
public static String buildPatches(PmCommandInvocation invoc, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException { if (!layout.hasPatches()) { return null; } Table table = new Table(Headers.PATCH, Headers.PATCH_FOR, Headers.UPDATE_CHANNEL); for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) { List<FeaturePackLayout> patches = layout.getPatches(fpLayout.getFPID()); for (FeaturePackLayout patch : patches) { FeaturePackLocation loc = invoc.getPmSession().getExposedLocation(null, patch.getFPID().getLocation()); FPID patchFor = patch.getSpec().getPatchFor(); table.addLine(patch.getFPID().getBuild(), patchFor.getProducer().getName() + FeaturePackLocation.BUILD_START + patchFor.getBuild(), formatChannel(loc)); } } if (!table.isEmpty()) { table.sort(Table.SortType.ASCENDANT); return table.build(); } return null; }
/** * Adds feature-pack archive to the local provisioning feature-pack cache. * Optionally, installs the feature-pack archive to the universe repository. * * @param featurePack feature-pack archive * @param installInUniverse whether to install the feature-pack into the universe repository * @return feature-pack location which was added to the local cache * @throws ProvisioningException in case of a failure */ public synchronized FeaturePackLocation addLocal(Path featurePack, boolean installInUniverse) throws ProvisioningException { final FPID fpid = FeaturePackDescriber.readSpec(featurePack).getFPID(); cacheManager.put(featurePack, fpid); if(!installInUniverse) { return fpid.getLocation(); } if(universeInstallers == null) { universeInstallers = UniverseFeaturePackInstaller.load(); } final Universe<?> universe = universeResolver.getUniverse(fpid.getUniverse()); final UniverseFeaturePackInstaller fpInstaller = universeInstallers.get(universe.getFactoryId()); if(fpInstaller == null) { throw new ProvisioningException(Errors.featurePackInstallerNotFound(universe.getFactoryId(), universeInstallers.keySet())); } fpInstaller.install(universe, fpid, featurePack); return fpid.getLocation(); }
public static FeaturePackDescription describeFeaturePack(Path fpDir, String encoding) throws ProvisioningDescriptionException { assertDirectory(fpDir); final Path fpXml = fpDir.resolve(Constants.FEATURE_PACK_XML); if(!Files.exists(fpXml)) { throw new ProvisioningDescriptionException(Errors.pathDoesNotExist(fpXml)); } final FeaturePackDescription.Builder layoutBuilder; try (Reader is = Files.newBufferedReader(fpXml, Charset.forName(encoding))) { final FeaturePackSpec.Builder specBuilder = FeaturePackSpec.builder(); XmlParsers.parse(is, specBuilder); layoutBuilder = FeaturePackDescription.builder(specBuilder); } catch (IOException e) { throw new ProvisioningDescriptionException(Errors.openFile(fpXml)); } catch (XMLStreamException e) { throw new ProvisioningDescriptionException(Errors.parseXml(fpXml), e); } final Path packagesDir = fpDir.resolve(Constants.PACKAGES); if(Files.exists(packagesDir)) { processPackages(layoutBuilder, packagesDir, encoding); } return layoutBuilder.build(); }