Search in sources :

Example 1 with Channel

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

the class ProducerRefreshOnNotFoundChannelTestCase method assertProducerChannels.

@SuppressWarnings("unchecked")
private void assertProducerChannels(int... expected) throws ProvisioningException {
    final Collection<Producer<?>> producers = (Collection<Producer<?>>) resolver.getUniverse(getUniverseSpec()).getProducers();
    assertEquals(1, producers.size());
    Collection<Channel> channels = (Collection<Channel>) producers.iterator().next().getChannels();
    final Set<Integer> actual = new HashSet<>(producers.size());
    for (Channel channel : channels) {
        actual.add(Integer.valueOf(channel.getName()));
    }
    final Set<Integer> ec = new HashSet<>(expected.length);
    for (int i : expected) {
        ec.add(i);
    }
    assertEquals(ec, actual);
}
Also used : Producer(org.jboss.galleon.universe.Producer) Channel(org.jboss.galleon.universe.Channel) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 2 with Channel

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

the class UniverseManager method resolveBuiltinUniverse.

/**
 * Universe resolution is done in a separate thread to not impact startup
 * time.
 */
synchronized void resolveBuiltinUniverse() {
    if (closed) {
        return;
    }
    Future<?> f = executorService.submit(() -> {
        synchronized (UniverseManager.this) {
            if (closed) {
                return;
            }
            try {
                List<FeaturePackLocation> deps = new ArrayList<>();
                builtinUniverse = (MavenUniverse) universeResolver.getUniverse(builtinUniverseSpec, true);
                if (closed) {
                    return;
                }
                // speed-up future completion and execution by retrieving producers and channels
                for (Producer<?> p : builtinUniverse.getProducers()) {
                    final MavenProducer mvnProducer = (MavenProducer) p;
                    if (mvnProducer.isResolvedLocally()) {
                        mvnProducer.refresh();
                    }
                    if (closed) {
                        return;
                    }
                    for (Channel c : p.getChannels()) {
                        if (closed) {
                            return;
                        }
                        FeaturePackLocation ploc = new FeaturePackLocation(builtinUniverseSpec, p.getName(), c.getName(), null, null);
                        deps.add(ploc);
                    }
                }
            } catch (Exception ex) {
                CliLogging.exceptionResolvingBuiltinUniverse(ex);
            }
        }
    });
    submited.add(f);
}
Also used : MavenProducer(org.jboss.galleon.universe.maven.MavenProducer) Channel(org.jboss.galleon.universe.Channel) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 3 with Channel

use of org.jboss.galleon.universe.Channel 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 4 with Channel

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

the class UniverseManager method visit.

private static void visit(UniverseVisitor visitor, Universe<?> universe, UniverseSpec universeSpec, boolean allBuilds) throws ProvisioningException {
    for (Producer<?> producer : universe.getProducers()) {
        for (Channel channel : producer.getChannels()) {
            if (allBuilds) {
                List<String> builds = getAllBuilds(universeSpec, producer, channel);
                if (builds != null && !builds.isEmpty()) {
                    for (String build : builds) {
                        visitor.visit(producer, new FeaturePackLocation(universeSpec, producer.getName(), channel.getName(), null, build));
                    }
                }
            }
            for (String freq : producer.getFrequencies()) {
                String build = getBuild(universeSpec, producer, channel, freq);
                // We have a latest build for the frequency.
                if (build != null) {
                    FeaturePackLocation loc = new FeaturePackLocation(universeSpec, producer.getName(), channel.getName(), freq, build);
                    visitor.visit(producer, loc);
                }
            }
        }
    }
}
Also used : Channel(org.jboss.galleon.universe.Channel) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

Example 5 with Channel

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

the class ProvisioningLayout method getFeaturePackUpdate.

/**
 * Query for available version update and patches for the specific producer.
 *
 * @param producer  the producer to check the updates for
 * @return  available updates for the producer
 * @throws ProvisioningException  in case of a failure
 */
public FeaturePackUpdatePlan getFeaturePackUpdate(ProducerSpec producer) throws ProvisioningException {
    final F f = featurePacks.get(producer);
    if (f == null) {
        throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID()));
    }
    final FeaturePackLocation fpl = f.getFPID().getLocation();
    final Universe<?> universe = layoutFactory.getUniverseResolver().getUniverse(fpl.getUniverse());
    final Channel channel = universe.getProducer(fpl.getProducerName()).getChannel(fpl.getChannelName());
    final List<F> patches = fpPatches.get(fpl.getFPID());
    final Set<FPID> patchIds;
    if (patches == null || patches.isEmpty()) {
        patchIds = Collections.emptySet();
    } else if (patches.size() == 1) {
        patchIds = Collections.singleton(patches.get(0).getFPID());
    } else {
        final Set<FPID> tmp = new HashSet<>(patches.size());
        for (F p : patches) {
            tmp.add(p.getFPID());
        }
        patchIds = CollectionUtils.unmodifiable(tmp);
    }
    return channel.getUpdatePlan(FeaturePackUpdatePlan.request(fpl, patchIds, f.isTransitiveDep()));
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisioningException(org.jboss.galleon.ProvisioningException) Channel(org.jboss.galleon.universe.Channel) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation)

Aggregations

Channel (org.jboss.galleon.universe.Channel)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)5 ProvisioningException (org.jboss.galleon.ProvisioningException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 PmSession (org.jboss.galleon.cli.PmSession)1 UniverseManager (org.jboss.galleon.cli.UniverseManager)1 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)1 Producer (org.jboss.galleon.universe.Producer)1 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)1 MavenProducer (org.jboss.galleon.universe.maven.MavenProducer)1