Search in sources :

Example 16 with UniverseSpec

use of org.jboss.galleon.universe.UniverseSpec in project galleon by wildfly.

the class StateInfoUtil method buildUniverses.

private static String buildUniverses(ProvisioningConfig config) throws ProvisioningException {
    UniverseSpec defaultUniverse = config.getDefaultUniverse();
    StringBuilder builder = new StringBuilder();
    if (defaultUniverse != null || !config.getUniverseNamedSpecs().isEmpty()) {
        builder.append("Universes").append(Config.getLineSeparator());
        Table t = new Table(Headers.NAME, Headers.UNIVERSE_FACTORY, Headers.UNIVERSE_LOCATION);
        if (defaultUniverse != null) {
            t.addLine("<default>", defaultUniverse.getFactory(), defaultUniverse.getLocation());
        }
        for (Entry<String, UniverseSpec> entry : config.getUniverseNamedSpecs().entrySet()) {
            t.addLine(entry.getKey(), entry.getValue().getFactory(), entry.getValue().getLocation());
        }
        t.sort(Table.SortType.ASCENDANT);
        builder.append(t.build());
    }
    return builder.length() == 0 ? null : builder.toString();
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Example 17 with UniverseSpec

use of org.jboss.galleon.universe.UniverseSpec 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)

Example 18 with UniverseSpec

use of org.jboss.galleon.universe.UniverseSpec in project galleon by wildfly.

the class FPLocationCompleter method doComplete.

private void doComplete(PmCompleterInvocation completerInvocation) throws ProvisioningException {
    // Legacy completer first
    PmSession pmSession = completerInvocation.getPmSession();
    UniverseManager resolver = pmSession.getUniverse();
    installation = completerInvocation.getCommand() instanceof CommandWithInstallationDirectory ? ((CommandWithInstallationDirectory) completerInvocation.getCommand()).getInstallationDirectory(completerInvocation.getAeshContext()) : null;
    UniverseSpec defaultUniverse = pmSession.getUniverse().getDefaultUniverseSpec(installation);
    Set<String> aliases = pmSession.getUniverse().getUniverseNames(installation);
    // producer[@universe]:channel/frequency#build
    // producer[@factory-id/location]:channel/frequency#build
    String buffer = completerInvocation.getGivenCompleteValue();
    List<String> candidates = new ArrayList<>();
    FPLocationParser.ParsedFPLocation loc = null;
    try {
        if (buffer.isEmpty()) {
            if (defaultUniverse != null) {
                getAllProducers(null, defaultUniverse, resolver.getUniverse(defaultUniverse), candidates);
            }
            for (String name : aliases) {
                UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
                if (u.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
                    continue;
                }
                if (!u.equals(defaultUniverse)) {
                    getAllProducers(u.toString(), u, resolver.getUniverse(u), candidates);
                }
            }
        } else {
            loc = FPLocationParser.parse(buffer, new FPLocationParser.FPLocationCompletionConsumer() {

                @Override
                public void completeProducer(String producer) throws FPLocationParserException, ProvisioningException {
                    // Lookup in all universes for a producer, we don't know the universe yet
                    if (defaultUniverse != null) {
                        getProducers(producer, null, resolver.getUniverse(defaultUniverse), candidates);
                    }
                    for (String name : aliases) {
                        UniverseSpec u = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (!u.equals(defaultUniverse)) {
                            getProducers(producer, name, resolver.getUniverse(u), candidates);
                        }
                    }
                }

                @Override
                public void completeUniverse(FPLocationParser.ParsedFPLocation parsedLocation, String universe) throws FPLocationParserException, ProvisioningException {
                    for (String name : aliases) {
                        UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (spec != null && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
                            if (name.equals(universe)) {
                                candidates.add(name + FeaturePackLocation.CHANNEL_START);
                            } else if (name.startsWith(universe)) {
                                candidates.add(name);
                            }
                        }
                    }
                }

                @Override
                public void completeUniverseLocation(FPLocationParser.ParsedFPLocation parsedLocation, String universeLocation) throws FPLocationParserException, ProvisioningException {
                    for (String name : aliases) {
                        UniverseSpec spec = pmSession.getUniverse().getUniverseSpec(installation, name);
                        if (spec == null || spec.getFactory().equals(LegacyGalleon1UniverseFactory.ID)) {
                            continue;
                        }
                        if (!candidates.contains(spec.getLocation())) {
                            if (spec.getFactory().equals(parsedLocation.getUniverseFactory()) && resolver.getUniverse(spec).hasProducer(parsedLocation.getProducer())) {
                                if (spec.getLocation().equals(universeLocation)) {
                                    candidates.add(spec.getLocation() + FeaturePackLocation.UNIVERSE_LOCATION_END);
                                } else if (spec.getLocation().startsWith(universeLocation)) {
                                    candidates.add(spec.getLocation());
                                }
                                break;
                            }
                        }
                    }
                }

                @Override
                public void completeChannel(FPLocationParser.ParsedFPLocation parsedLocation, String channel) throws FPLocationParserException, ProvisioningException {
                    Producer<?> p = getProducer(parsedLocation, pmSession);
                    if (p == null) {
                        return;
                    }
                    for (Channel c : p.getChannels()) {
                        if (c.getName().equals(channel)) {
                            // Do nothing, do not inline separators. Separators are to be added explicitly
                            // this could be revisited.
                            candidates.add(channel);
                        } else if (c.getName().startsWith(channel)) {
                            candidates.add(c.getName());
                        }
                    }
                }

                @Override
                public void completeFrequency(FPLocationParser.ParsedFPLocation parsedLocation, String frequency) throws FPLocationParserException, ProvisioningException {
                    Producer<?> p = getProducer(parsedLocation, pmSession);
                    if (p == null) {
                        return;
                    }
                    for (String freq : p.getFrequencies()) {
                        if (freq.equals(frequency)) {
                            // Do not inline the build separator, separator is to be added explicitly
                            // this could be revisited.
                            candidates.add(freq);
                        } else if (freq.startsWith(frequency)) {
                            candidates.add(freq);
                        }
                    }
                }

                @Override
                public void completeChannelSeparator(FPLocationParser.ParsedFPLocation parsedLocation) throws FPLocationParserException, ProvisioningException {
                    candidates.add("" + FeaturePackLocation.CHANNEL_START);
                }

                @Override
                public void completeBuild(FPLocationParser.ParsedFPLocation parsedLocation, String build) throws FPLocationParserException, ProvisioningException {
                    UniverseSpec spec = null;
                    if (parsedLocation.getUniverseName() != null) {
                        spec = pmSession.getUniverse().getUniverseSpec(installation, parsedLocation.getUniverseName());
                    } else if (parsedLocation.getUniverseFactory() == null) {
                        spec = pmSession.getUniverse().getDefaultUniverseSpec(installation);
                    } else {
                        spec = new UniverseSpec(parsedLocation.getUniverseFactory(), parsedLocation.getUniverseLocation());
                    }
                    if (spec != null) {
                        String latestBuild = null;
                        // FPID
                        if (parsedLocation.getFrequency() == null) {
                            FeaturePackLocation.FPID id = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), null, null).getFPID();
                            latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(id);
                        } else {
                            FeaturePackLocation loc = new FeaturePackLocation(spec, parsedLocation.getProducer(), parsedLocation.getChannel(), parsedLocation.getFrequency(), null);
                            latestBuild = pmSession.getUniverse().getUniverse(spec).getProducer(parsedLocation.getProducer()).getChannel(parsedLocation.getChannel()).getLatestBuild(loc);
                        }
                        if (latestBuild != null) {
                            if (latestBuild.startsWith(build)) {
                                candidates.add(latestBuild);
                            }
                        }
                    }
                }
            });
        }
    } catch (Exception ex) {
        CliLogging.completionException(ex);
        return;
    }
    completerInvocation.addAllCompleterValues(candidates);
    if (candidates.size() == 1) {
        if (completerInvocation.getGivenCompleteValue().endsWith(candidates.get(0))) {
            completerInvocation.setAppendSpace(true);
        } else {
            completerInvocation.setAppendSpace(false);
        }
        completerInvocation.setOffset(completerInvocation.getGivenCompleteValue().length() - (loc == null ? 0 : (loc.getMarker() + 1)));
    }
}
Also used : UniverseManager(org.jboss.galleon.cli.UniverseManager) Channel(org.jboss.galleon.universe.Channel) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningException(org.jboss.galleon.ProvisioningException) PmSession(org.jboss.galleon.cli.PmSession) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Example 19 with UniverseSpec

use of org.jboss.galleon.universe.UniverseSpec in project galleon by wildfly.

the class PmSession method getExposedLocation.

public FeaturePackLocation getExposedLocation(Path installation, FeaturePackLocation fplocation) {
    // Expose the default or name.
    UniverseSpec spec = fplocation.getUniverse();
    boolean rewrite = false;
    String name = getUniverse().getUniverseName(installation, spec);
    if (name != null) {
        rewrite = true;
        spec = new UniverseSpec(name, null);
    } else if (getUniverse().getDefaultUniverseSpec(installation).equals(spec)) {
        rewrite = true;
        spec = null;
    }
    if (rewrite) {
        fplocation = new FeaturePackLocation(spec, fplocation.getProducerName(), fplocation.getChannelName(), fplocation.getFrequency(), fplocation.getBuild());
    }
    return fplocation;
}
Also used : FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Example 20 with UniverseSpec

use of org.jboss.galleon.universe.UniverseSpec in project galleon by wildfly.

the class UniverseManager method getDefaultUniverseSpec.

public UniverseSpec getDefaultUniverseSpec(Path installation) {
    UniverseSpec defaultUniverse = null;
    if (pmSession.getState() != null) {
        defaultUniverse = pmSession.getState().getConfig().getDefaultUniverse();
    } else {
        try {
            ProvisioningManager mgr = getProvisioningManager(installation);
            defaultUniverse = mgr.getProvisioningConfig().getDefaultUniverse();
        } catch (ProvisioningException ex) {
        // OK, not an installation
        }
    }
    return defaultUniverse == null ? builtinUniverseSpec : defaultUniverse;
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Aggregations

UniverseSpec (org.jboss.galleon.universe.UniverseSpec)29 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)18 Test (org.junit.Test)14 ProvisioningException (org.jboss.galleon.ProvisioningException)6 ProvisioningManager (org.jboss.galleon.ProvisioningManager)4 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)4 Path (java.nio.file.Path)3 ChannelSpec (org.jboss.galleon.universe.FeaturePackLocation.ChannelSpec)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)2 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)2 UniverseVisitor (org.jboss.galleon.cli.UniverseManager.UniverseVisitor)2 Table (org.jboss.galleon.cli.cmd.Table)2 Producer (org.jboss.galleon.universe.Producer)2 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1