@Override public FeaturePackLayout newFeaturePack(FeaturePackLocation fpl, FeaturePackSpec fpSpec, Path dir, int type) { return new FeaturePackLayout(fpl.getFPID(), dir, type) { @Override public FeaturePackSpec getSpec() { return fpSpec; } }; }}, false); }
@Override public FeaturePackRuntimeBuilder newFeaturePack(FeaturePackLocation fpl, FeaturePackSpec spec, Path fpDir, int type) { return new FeaturePackRuntimeBuilder(fpl.getFPID(), spec, fpDir, type); } };
public Path put(UniverseResolver universeResolver, FeaturePackLocation fpl) throws ProvisioningException { Path fpDir = LayoutUtils.getFeaturePackDir(home, fpl.getFPID(), false); if (Files.exists(fpDir)) { if (!overwritePolicy.hasExpired(fpDir, fpl.getFPID())) { return fpDir; } IoUtils.recursiveDelete(fpDir); } unpack(fpDir, universeResolver.resolve(fpl)); overwritePolicy.cached(fpl.getFPID()); return fpDir; }
public static FPID newFPID(String producer, String channel, String build) { return new FeaturePackLocation(getUniverseSpec(), producer, channel, null, build).getFPID(); }
public F getFeaturePack(ProducerSpec producer) throws ProvisioningException { final F p = featurePacks.get(producer); if(p == null) { throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID())); } return p; }
@Override public void undoAction(ProvisioningConfig.Builder builder) throws ProvisioningException { for (Entry<FeaturePackConfig, T> entry : cf.entrySet()) { Integer index = indexes.get(entry.getKey().getLocation().getFPID()); // index could be null if doAction failed or did not execute. if (index != null) { FeaturePackConfig.Builder fpBuilder = entry.getKey().getBuilder(); undoAction(fpBuilder, entry.getValue()); builder.removeFeaturePackDep(entry.getKey().getLocation()); builder.addFeaturePackDep(index, fpBuilder.build()); } } }
@SuppressWarnings("unchecked") public B removeFeaturePackDep(FeaturePackLocation fpl) throws ProvisioningException { fpl = resolveUniverseSpec(fpl); final ProducerSpec producer = fpl.getProducer(); final FeaturePackConfig fpDep = fpDeps.get(producer); if(fpDep == null) { throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID())); } if(!fpDep.getLocation().getFPID().equals(fpl.getFPID())) { throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID())); } if(fpDeps.size() == 1) { fpDeps = Collections.emptyMap(); } else { fpDeps = CollectionUtils.remove(fpDeps, producer); } updateOriginMappings(producer); return (B) this; }
/** * Resolves feature-pack location to a path in a local repository * * @param fpl feature-pack location * @return local feature-pack path * @throws ProvisioningException in case the feature-pack could not be resolved */ public Path resolve(FeaturePackLocation fpl) throws ProvisioningException { if (localFeaturePacks.containsKey(fpl.getFPID())) { return localFeaturePacks.get(fpl.getFPID()); } return getUniverse(fpl.getUniverse()).getProducer(fpl.getProducerName()).getChannel(fpl.getChannelName()).resolve(fpl); }
@Override public void doAction(ProvisioningConfig current, ProvisioningConfig.Builder builder) throws ProvisioningException { for (Entry<FeaturePackConfig, T> entry : cf.entrySet()) { FeaturePackConfig.Builder fpBuilder = entry.getKey().getBuilder(); boolean doit = doAction(fpBuilder, entry.getValue()); // this complexity is due to the fact that some fp could already have the configuration included/excluded/... if (doit) { int index = builder.getFeaturePackDepIndex(entry.getKey().getLocation()); indexes.put(entry.getKey().getLocation().getFPID(), index); builder.removeFeaturePackDep(entry.getKey().getLocation()); builder.addFeaturePackDep(index, fpBuilder.build()); } } }
public State(PmSession pmSession, Path installation) throws ProvisioningException, IOException { ProvisioningConfig conf; if (Files.isRegularFile(installation)) { conf = ProvisioningXmlParser.parse(installation); } else { PathsUtils.assertInstallationDir(installation); conf = ProvisioningXmlParser.parse(PathsUtils.getProvisioningXml(installation)); } Set<FeaturePackLocation.FPID> dependencies = new HashSet<>(); for (FeaturePackConfig cf : conf.getFeaturePackDeps()) { dependencies.add(cf.getLocation().getFPID()); } builder = conf.getBuilder(); config = buildNewConfig(pmSession); path = "" + PathParser.PATH_SEPARATOR; name = installation.getFileName().toString(); }
public int getFeaturePackDepIndex(FeaturePackLocation fpl) throws ProvisioningException { fpl = resolveUniverseSpec(fpl); final ProducerSpec producer = fpl.getProducer(); final FeaturePackConfig fpDep = fpDeps.get(producer); if (fpDep == null) { throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID())); } if (!fpDep.getLocation().equals(fpl)) { throw new ProvisioningException(Errors.unknownFeaturePack(fpl.getFPID())); } int i = 0; for (ProducerSpec depProducer : fpDeps.keySet()) { if (depProducer.equals(producer)) { break; } i += 1; } return i; }
private static FPID readPatch(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> depsBuilder) throws XMLStreamException { FeaturePackLocation fpl = null; for (int i = 0; i < reader.getAttributeCount(); i++) { final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart()); switch (attribute) { case ID: fpl = parseFpl(reader, i); break; default: throw ParsingUtils.unexpectedContent(reader); } } if(fpl == null) { throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.ID)); } ParsingUtils.parseNoContent(reader); fpl = resolveUniverse(depsBuilder, fpl); return fpl.getFPID(); }
private static FPID readPatch(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> depsBuilder) throws XMLStreamException { FeaturePackLocation fpl = null; for (int i = 0; i < reader.getAttributeCount(); i++) { final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart()); switch (attribute) { case ID: fpl = parseFpl(reader, i); break; default: throw ParsingUtils.unexpectedContent(reader); } } if(fpl == null) { throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.ID)); } ParsingUtils.parseNoContent(reader); fpl = resolveUniverse(depsBuilder, fpl); return fpl.getFPID(); }
private FeaturePackLocation.FPID getFPID(PmSession session) throws CommandExecutionException { String fpid = getFPID(); if (fpid == null) { throw new CommandExecutionException("No feature-pack provided"); } try { return session.getResolvedLocation(getInstallationDirectory(session.getAeshContext()), fpid).getFPID(); } catch (Exception e) { throw new CommandExecutionException(session, CliErrors.resolveLocationFailed(), e); } }
@Override protected void runCommand(PmCommandInvocation invoc, State session, FeaturePackConfig config) throws IOException, ProvisioningException, CommandExecutionException { try { session.includePackage(invoc.getPmSession(), PackagesUtil.getPackage(invoc.getPmSession(), config.getLocation().getFPID(), getPackage()), config); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.includeFailed(), ex); } }
@Override protected void runCommand(PmCommandInvocation invoc, State session, FeaturePackConfig config) throws IOException, ProvisioningException, CommandExecutionException { try { session.excludePackage(invoc.getPmSession(), PackagesUtil.getPackage(invoc.getPmSession(), config.getLocation().getFPID(), getPackage()), config); } catch (Exception ex) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.excludeFailed(), ex); } }
public static FeatureContainer fromFeaturePackId(PmSession session, FPID fpid, String name) throws ProvisioningException, IOException { if (fpid.getBuild() == null) { FeaturePackLocation loc = session.getUniverse().resolveLatestBuild(fpid.getLocation()); fpid = loc.getFPID(); } FeatureContainer fp = Caches.getFeaturePackInfo(fpid); if (fp != null) { return fp; } try (ProvisioningRuntime rt = buildFullRuntime(fpid, session)) { fp = new FeaturePackInfo(name, fpid, rt.getProvisioningConfig()); populateFeatureContainer(fp, session, rt, true); Caches.addFeaturePackInfo(fpid, fp); } return fp; }
/** * Uninstalls the specified feature-pack. * * @param fpid feature-pack ID * @param pluginOptions provisioning plugin options * @throws ProvisioningException in case of a failure */ public void uninstall(FeaturePackLocation.FPID fpid, Map<String, String> pluginOptions) throws ProvisioningException { ProvisioningConfig config = getProvisioningConfig(); if(config == null || !config.hasFeaturePackDeps()) { throw new ProvisioningException(Errors.unknownFeaturePack(fpid)); } try(ProvisioningLayout<FeaturePackRuntimeBuilder> layout = getLayoutFactory().newConfigLayout(config, ProvisioningRuntimeBuilder.FP_RT_FACTORY, false)) { layout.uninstall(resolveUniverseSpec(fpid.getLocation()).getFPID(), pluginOptions); doProvision(layout, getFsDiff(), false); } }
@Override protected void runCommand(PmCommandInvocation session) throws CommandExecutionException { try { if (verbose) { session.getPmSession().enableMavenTrace(true); } try { session.getPmSession().downloadFp(session.getPmSession().getResolvedLocation(null, fpl).getFPID()); session.println("artifact installed in local mvn repository " + session.getPmSession(). getPmConfiguration().getMavenConfig().getLocalRepository()); } finally { session.getPmSession().enableMavenTrace(false); } } catch (ProvisioningException ex) { throw new CommandExecutionException(session.getPmSession(), CliErrors.resolveFeaturePackFailed(), ex); } } }
@Override public void handle(ProvisionedConfigHandler handler) throws ProvisioningException { if (!hasFeatures()) { return; } handler.prepare(this); ResolvedSpecId lastHandledSpecId = null; for(ProvisionedFeature feature : features) { if(!feature.getSpecId().equals(lastHandledSpecId)) { if (lastHandledSpecId == null || !feature.getSpecId().getProducer().equals(lastHandledSpecId.getProducer())) { handler.nextFeaturePack(feature.getSpecId().getProducer().getLocation().getFPID()); } // TODO: complete spec isn't available here, but specId is enough for marshalling handler.nextSpec(new ResolvedFeatureSpec(feature.getSpecId(), null, FeatureSpec.builder().build())); lastHandledSpecId = feature.getSpecId(); } handler.nextFeature(feature); } handler.done(); }