Search in sources :

Example 6 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID 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);
    }
}
Also used : Path(java.nio.file.Path) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException)

Example 7 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class ProvisioningLayoutFactory method resolveFeaturePackDir.

private synchronized Path resolveFeaturePackDir(FeaturePackLocation fpl) throws ProvisioningException {
    final FPID fpid = fpl.getFPID();
    FileSystem packFs = cachedPacks.get(fpid);
    if (packFs != null) {
        return getFpDir(packFs);
    }
    return put(universeResolver.resolve(fpl), fpid);
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) FileSystem(java.nio.file.FileSystem)

Example 8 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID 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);
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) FeaturePackSpec(org.jboss.galleon.spec.FeaturePackSpec) ArrayList(java.util.ArrayList) List(java.util.List) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 9 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class ProvisioningLayout method apply.

public void apply(ProvisioningPlan plan, Map<String, String> pluginOptions) throws ProvisioningException {
    if (plan.isEmpty()) {
        return;
    }
    final ProvisioningConfig.Builder configBuilder = ProvisioningConfig.builder(config);
    if (plan.hasUpdates()) {
        Map<ProducerSpec, FeaturePackUpdatePlan> updates = plan.getUpdateMap();
        Set<ProducerSpec> processed = new HashSet<>(updates.size());
        for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (!fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Location in the update plan " + fpPlan.getInstalledLocation() + " does not match the installed location " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.builder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        for (FeaturePackConfig fpConfig : config.getTransitiveDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (fpConfig.getLocation().getBuild() != null && !fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Update plan build " + fpPlan.getInstalledLocation() + " does not match the installed build " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        if (processed.size() < updates.size()) {
            for (Map.Entry<ProducerSpec, FeaturePackUpdatePlan> entry : updates.entrySet()) {
                if (processed.contains(entry.getKey())) {
                    continue;
                }
                final FeaturePackUpdatePlan update = entry.getValue();
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(update.getNewLocation());
                if (update.hasNewPatches()) {
                    for (FPID patchId : update.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.addFeaturePackDep(fpBuilder.build());
            }
        }
    }
    if (plan.hasInstall()) {
        for (FeaturePackConfig fpConfig : plan.getInstall()) {
            install(fpConfig, configBuilder);
        }
    }
    if (plan.hasUninstall()) {
        for (ProducerSpec producer : plan.getUninstall()) {
            uninstall(producer.getLocation().getFPID(), configBuilder);
        }
    }
    final ProvisioningConfig config = configBuilder.build();
    initBuiltInOptions(config, pluginOptions);
    rebuild(config, true);
    initPluginOptions(pluginOptions, plan.hasUninstall());
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 10 with FPID

use of org.jboss.galleon.universe.FeaturePackLocation.FPID in project galleon by wildfly.

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation commandInvocation) throws CommandExecutionException {
    if (fpl != null && file != null) {
        throw new CommandExecutionException("File and location can't be both set");
    }
    if (fpl == null && file == null) {
        throw new CommandExecutionException("File or location must be set");
    }
    PmSession session = commandInvocation.getPmSession();
    FeaturePackLayout product = null;
    List<FeaturePackLocation> dependencies = new ArrayList<>();
    ProvisioningConfig provisioning;
    ProvisioningLayout<FeaturePackLayout> layout = null;
    try {
        try {
            if (fpl != null) {
                FeaturePackLocation loc;
                loc = session.getResolvedLocation(null, fpl);
                FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
                provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
                layout = session.getLayoutFactory().newConfigLayout(provisioning);
            } else {
                layout = session.getLayoutFactory().newConfigLayout(file.toPath(), true);
            }
            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) {
                    product = fpLayout;
                } else {
                    dependencies.add(session.getExposedLocation(null, fpLayout.getFPID().getLocation()));
                }
            }
        } catch (ProvisioningException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
        if (product == null) {
            throw new CommandExecutionException("No feature-pack found");
        }
        commandInvocation.println("");
        StateInfoUtil.printFeaturePack(commandInvocation, session.getExposedLocation(null, product.getFPID().getLocation()));
        try {
            final FPID patchFor = product.getSpec().getPatchFor();
            if (patchFor != null) {
                commandInvocation.println("");
                commandInvocation.println(PATCH_FOR + patchFor);
            }
        } catch (ProvisioningException e) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), e);
        }
        try {
            if (type != null) {
                commandInvocation.println("");
                switch(type) {
                    case ALL:
                        {
                            if (displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println("");
                            }
                            if (displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayLayers(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            displayOptions(commandInvocation, layout);
                            break;
                        }
                    case CONFIGS:
                        {
                            if (!displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_CONFIGURATIONS);
                            }
                            break;
                        }
                    case DEPENDENCIES:
                        {
                            if (!displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println(StateInfoUtil.NO_DEPENDENCIES);
                            }
                            break;
                        }
                    case LAYERS:
                        {
                            if (!displayLayers(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_LAYERS);
                            }
                            break;
                        }
                    case OPTIONS:
                        {
                            if (!displayOptions(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONS);
                            }
                            break;
                        }
                    case OPTIONAL_PACKAGES:
                        {
                            if (!displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONAL_PACKAGES);
                            }
                            break;
                        }
                    default:
                        {
                            throw new CommandExecutionException(CliErrors.invalidInfoType());
                        }
                }
            }
        } catch (ProvisioningException | IOException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
    } finally {
        if (layout != null) {
            layout.close();
        }
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) PmSession(org.jboss.galleon.cli.PmSession) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)23 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)14 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)11 ArrayList (java.util.ArrayList)8 ProvisioningException (org.jboss.galleon.ProvisioningException)8 IOException (java.io.IOException)5 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)5 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)4 Table (org.jboss.galleon.cli.cmd.Table)4 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)4 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)4 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)4 HashSet (java.util.HashSet)3 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)3 Cell (org.jboss.galleon.cli.cmd.Table.Cell)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2