Search in sources :

Example 1 with FeaturePackLayout

use of org.jboss.galleon.layout.FeaturePackLayout 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)

Example 2 with FeaturePackLayout

use of org.jboss.galleon.layout.FeaturePackLayout in project galleon by wildfly.

the class CheckUpdatesCommand method addCustomUpdates.

private static void addCustomUpdates(ProvisioningPlan plan, List<FeaturePackLocation> custom, ProvisioningManager mgr) throws ProvisioningException {
    try (ProvisioningLayout<?> layout = mgr.getLayoutFactory().newConfigLayout(mgr.getProvisioningConfig())) {
        for (FeaturePackLocation loc : custom) {
            FeaturePackLayout fpl = layout.getFeaturePack(loc.getProducer());
            FeaturePackLocation current = fpl.getFPID().getLocation();
            FeaturePackUpdatePlan fpPlan = FeaturePackUpdatePlan.request(current, fpl.isTransitiveDep()).setNewLocation(loc).buildPlan();
            if (fpPlan.hasNewLocation()) {
                plan.update(fpPlan);
            }
        }
    }
}
Also used : FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) FeaturePackUpdatePlan(org.jboss.galleon.layout.FeaturePackUpdatePlan) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

Example 3 with FeaturePackLayout

use of org.jboss.galleon.layout.FeaturePackLayout in project galleon by wildfly.

the class InstalledProducerCompleter method getInstallationLocations.

public static List<FeaturePackLocation> getInstallationLocations(Path installation, PmSession session, boolean transitive, boolean patches) {
    List<FeaturePackLocation> items = new ArrayList<>();
    try {
        PathsUtils.assertInstallationDir(installation);
        ProvisioningManager mgr = session.newProvisioningManager(installation, false);
        try (ProvisioningLayout<FeaturePackLayout> layout = mgr.getLayoutFactory().newConfigLayout(mgr.getProvisioningConfig())) {
            for (FeaturePackLayout fp : layout.getOrderedFeaturePacks()) {
                if (fp.isDirectDep() || (fp.isTransitiveDep() && transitive)) {
                    items.add(fp.getFPID().getLocation());
                }
                if (patches) {
                    List<FeaturePackLayout> appliedPatches = layout.getPatches(fp.getFPID());
                    for (FeaturePackLayout patch : appliedPatches) {
                        items.add(patch.getFPID().getLocation());
                    }
                }
            }
        }
    } catch (Exception ex) {
        CliLogging.completionException(ex);
    }
    return items;
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

Example 4 with FeaturePackLayout

use of org.jboss.galleon.layout.FeaturePackLayout in project galleon by wildfly.

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier = new Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer>() {

            public FeatureContainer apply(ProvisioningLayout<FeaturePackLayout> layout) {
                try {
                    return getFeatureContainer(invoc.getPmSession(), layout);
                } catch (CommandExecutionException | ProvisioningException | IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
        };
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        StateInfoUtil.displayInfo(invoc, mgr.getInstallationHome(), mgr.getProvisioningConfig(), type, supplier);
    } catch (ProvisioningException | CommandExecutionException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.infoFailed(), ex);
    }
}
Also used : Function(java.util.function.Function) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException) ProvisioningLayout(org.jboss.galleon.layout.ProvisioningLayout)

Example 5 with FeaturePackLayout

use of org.jboss.galleon.layout.FeaturePackLayout in project galleon by wildfly.

the class FindCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    if (pattern == null && layerPattern == null) {
        throw new CommandExecutionException(CliErrors.missingPattern());
    } else {
        if (pattern == null) {
            pattern = ".Final";
        }
        Map<UniverseSpec, Set<Result>> results = new HashMap<>();
        Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
        if (!pattern.endsWith("*")) {
            pattern = pattern + "*";
        }
        pattern = pattern.replaceAll("\\*", ".*");
        List<Pattern> layersCompiledPatterns = new ArrayList<>();
        if (layerPattern != null) {
            for (String l : layerPattern.split(",")) {
                if (!l.endsWith("*")) {
                    l = l + "*";
                }
                l = l.replaceAll("\\*", ".*");
                layersCompiledPatterns.add(Pattern.compile(l));
            }
        }
        boolean containsFrequency = pattern.contains("" + FeaturePackLocation.FREQUENCY_START);
        Pattern compiledPattern = Pattern.compile(pattern);
        Integer[] numResults = new Integer[1];
        numResults[0] = 0;
        ProgressTracker<FPID> track = null;
        if (invoc.getPmSession().isTrackersEnabled()) {
            track = ProgressTrackers.newFindTracker(invoc);
        }
        ProgressTracker<FPID> tracker = track;
        invoc.getPmSession().unregisterTrackers();
        // Search for an installation in the context
        Path installation = null;
        try {
            installation = Util.lookupInstallationDir(invoc.getConfiguration().getAeshContext(), null);
        } catch (ProvisioningException ex) {
        // XXX OK, no installation.
        }
        Path finalPath = installation;
        try {
            Comparator<Result> locComparator = new Comparator<Result>() {

                @Override
                public int compare(Result o1, Result o2) {
                    return o1.location.toString().compareTo(o2.location.toString());
                }
            };
            UniverseVisitor visitor = new UniverseVisitor() {

                @Override
                public void visit(Producer<?> producer, FeaturePackLocation loc) {
                    try {
                        if (resolvedOnly && !producer.getChannel(loc.getChannelName()).isResolved(loc)) {
                            return;
                        }
                    } catch (ProvisioningException ex) {
                        exception(loc.getUniverse(), ex);
                        return;
                    }
                    if (tracker != null) {
                        tracker.processing(loc.getFPID());
                    }
                    // Universe could have been set in the pattern, matches on
                    // the canonical and exposed (named universe).
                    FeaturePackLocation exposedLoc = invoc.getPmSession().getExposedLocation(finalPath, loc);
                    boolean canonicalMatch = compiledPattern.matcher(loc.toString()).matches();
                    boolean exposedMatch = compiledPattern.matcher(exposedLoc.toString()).matches();
                    // If no frequency set, matches FPL that don't contain a frequency.
                    if (canonicalMatch || exposedMatch) {
                        if ((containsFrequency && loc.getFrequency() != null) || (!containsFrequency && loc.getFrequency() == null)) {
                            Result result;
                            if (exposedMatch) {
                                result = new Result(exposedLoc);
                            } else {
                                result = new Result(loc);
                            }
                            if (!layersCompiledPatterns.isEmpty()) {
                                try {
                                    FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
                                    ProvisioningConfig provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
                                    Set<ConfigId> layers = new HashSet<>();
                                    try (ProvisioningLayout<FeaturePackLayout> layout = invoc.getPmSession().getLayoutFactory().newConfigLayout(provisioning)) {
                                        for (FeaturePackLayout l : layout.getOrderedFeaturePacks()) {
                                            layers.addAll(l.loadLayers());
                                        }
                                    }
                                    for (ConfigId l : layers) {
                                        for (Pattern p : layersCompiledPatterns) {
                                            if (p.matcher(l.getName()).matches()) {
                                                result.layers.add(l);
                                            }
                                        }
                                    }
                                    if (!result.layers.isEmpty()) {
                                        Set<Result> locations = results.get(loc.getUniverse());
                                        if (locations == null) {
                                            locations = new TreeSet<>(locComparator);
                                            results.put(loc.getUniverse(), locations);
                                        }
                                        locations.add(result);
                                        numResults[0] = numResults[0] + 1;
                                    }
                                } catch (IOException | ProvisioningException ex) {
                                    exception(loc.getUniverse(), ex);
                                }
                            } else {
                                Set<Result> locations = results.get(loc.getUniverse());
                                if (locations == null) {
                                    locations = new TreeSet<>(locComparator);
                                    results.put(loc.getUniverse(), locations);
                                }
                                locations.add(result);
                                numResults[0] = numResults[0] + 1;
                            }
                        }
                    }
                }

                @Override
                public void exception(UniverseSpec spec, Exception ex) {
                    Set<String> set = exceptions.get(spec);
                    if (set == null) {
                        set = new HashSet<>();
                        exceptions.put(spec, set);
                    }
                    set.add(ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage());
                }
            };
            if (tracker != null) {
                tracker.starting(-1);
            }
            if (fromUniverse == null) {
                invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
            } else {
                invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
            }
            if (tracker != null) {
                tracker.complete();
            }
            printExceptions(invoc, exceptions);
            invoc.println(Config.getLineSeparator() + "Found " + numResults[0] + " feature pack location" + (numResults[0] > 1 ? "s." : "."));
            for (Entry<UniverseSpec, Set<Result>> entry : results.entrySet()) {
                for (Result loc : entry.getValue()) {
                    invoc.println(loc.toString());
                }
            }
        } catch (ProvisioningException ex) {
            throw new CommandExecutionException(ex.getLocalizedMessage());
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Comparator(java.util.Comparator) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigId(org.jboss.galleon.config.ConfigId) UniverseVisitor(org.jboss.galleon.cli.UniverseManager.UniverseVisitor) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig) HashSet(java.util.HashSet) Path(java.nio.file.Path) Pattern(java.util.regex.Pattern) IOException(java.io.IOException) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Producer(org.jboss.galleon.universe.Producer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Aggregations

FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)12 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 ArrayList (java.util.ArrayList)5 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)5 IOException (java.io.IOException)4 ProvisioningException (org.jboss.galleon.ProvisioningException)4 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 HashMap (java.util.HashMap)3 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)3 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)3 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Function (java.util.function.Function)2 ProvisioningManager (org.jboss.galleon.ProvisioningManager)2 ConfigId (org.jboss.galleon.config.ConfigId)2 ProvisioningLayout (org.jboss.galleon.layout.ProvisioningLayout)2 Comparator (java.util.Comparator)1