Search in sources :

Example 21 with ConfigId

use of org.jboss.galleon.config.ConfigId 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 22 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class InstallCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation session, Map<String, String> options, FeaturePackLocation loc) throws CommandExecutionException {
    try {
        String filePath = (String) getValue(FILE_OPTION_NAME);
        final ProvisioningManager manager = getManager(session);
        String layers = (String) getValue(LAYERS_OPTION_NAME);
        if (filePath != null) {
            Path p = Util.resolvePath(session.getConfiguration().getAeshContext(), filePath);
            loc = session.getPmSession().getLayoutFactory().addLocal(p, true);
        }
        if (layers == null) {
            String configurations = (String) getValue(DEFAULT_CONFIGS_OPTION_NAME);
            if (configurations == null) {
                manager.install(loc, options);
            } else {
                FeaturePackConfig.Builder fpConfig = FeaturePackConfig.builder(loc).setInheritConfigs(false);
                for (ConfigId c : parseConfigurations(configurations)) {
                    fpConfig.includeDefaultConfig(c);
                }
                manager.install(fpConfig.build(), options);
            }
        } else {
            if (!options.containsKey(Constants.OPTIONAL_PACKAGES)) {
                options.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
            }
            String configuration = (String) getValue(CONFIG_OPTION_NAME);
            String model = null;
            String config = null;
            if (configuration != null) {
                List<ConfigId> configs = parseConfigurations(configuration);
                if (configs.size() > 1) {
                    throw new CommandExecutionException(CliErrors.onlyOneConfigurationWithlayers());
                }
                if (!configs.isEmpty()) {
                    ConfigId id = configs.get(0);
                    model = id.getModel();
                    config = id.getName();
                }
            }
            manager.provision(new LayersConfigBuilder(manager, pmSession, layers.split(",+"), model, config, loc).build(), options);
        }
        session.println("Feature pack installed.");
        if (manager.isRecordState() && !loc.isMavenCoordinates()) {
            if (!loc.hasBuild() || loc.getChannelName() == null) {
                loc = manager.getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation();
            }
            StateInfoUtil.printFeaturePack(session, session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc));
        }
    } catch (ProvisioningException | IOException ex) {
        throw new CommandExecutionException(session.getPmSession(), CliErrors.installFailed(), ex);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ConfigId(org.jboss.galleon.config.ConfigId) IOException(java.io.IOException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 23 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class InstallCommand method parseConfigurations.

private static List<ConfigId> parseConfigurations(String configurations) {
    String[] split = configurations.split(",+");
    List<ConfigId> configs = new ArrayList<>();
    if (split.length == 0) {
        return configs;
    }
    for (String c : split) {
        String config = null;
        String model = null;
        c = c.trim();
        if (!c.isEmpty()) {
            int i = c.indexOf("/");
            if (i < 0) {
                config = c.trim();
            } else {
                model = c.substring(0, i).trim();
                if (i < c.length() - 1) {
                    config = c.substring(i + 1, c.length()).trim();
                }
            }
            configs.add(new ConfigId(model, config));
        }
    }
    return configs;
}
Also used : ArrayList(java.util.ArrayList) ConfigId(org.jboss.galleon.config.ConfigId)

Example 24 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class LayersConfigBuilder method build.

ProvisioningConfig build() throws ProvisioningException, IOException {
    // Reuse existing configuration builder.
    ProvisioningConfig existing = mgr.getProvisioningConfig();
    ProvisioningConfig.Builder builder = null;
    FeaturePackConfig.Builder fpBuilder = null;
    ConfigModel.Builder configBuilder = null;
    if (existing != null) {
        builder = ProvisioningConfig.builder(existing);
        ConfigId id = new ConfigId(model, config);
        if (existing.hasDefinedConfig(id)) {
            ConfigModel cmodel = existing.getDefinedConfig(id);
            configBuilder = ConfigModel.builder(cmodel);
            handleLayers(configBuilder, cmodel);
            builder.removeConfig(id);
        }
        if (builder.hasFeaturePackDep(loc.getProducer())) {
            FeaturePackConfig fp = existing.getFeaturePackDep(loc.getProducer());
            fpBuilder = FeaturePackConfig.builder(fp);
            builder.removeFeaturePackDep(fp.getLocation());
        }
    }
    if (builder == null) {
        builder = ProvisioningConfig.builder();
    }
    if (configBuilder == null) {
        configBuilder = ConfigModel.builder(model, config);
        handleLayers(configBuilder, null);
    }
    if (fpBuilder == null) {
        fpBuilder = FeaturePackConfig.builder(loc).setInheritConfigs(false).setInheritPackages(false);
    }
    builder.addConfig(configBuilder.build());
    builder.addFeaturePackDep(fpBuilder.build());
    return builder.build();
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 25 with ConfigId

use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.

the class LayersConfigBuilder method getAllLayers.

private static Map<String, Map<String, Set<String>>> getAllLayers(ProvisioningLayout<FeaturePackLayout> pLayout, boolean includeDependencies) throws ProvisioningException, IOException {
    Map<String, Map<String, Set<String>>> layersMap = new HashMap<>();
    for (FeaturePackLayout fp : pLayout.getOrderedFeaturePacks()) {
        for (ConfigId layer : fp.loadLayers()) {
            String model = layer.getModel();
            Map<String, Set<String>> names = layersMap.get(model);
            if (names == null) {
                names = new HashMap<>();
                layersMap.put(model, names);
            }
            Set<String> dependencies = new TreeSet<>();
            if (includeDependencies) {
                ConfigLayerSpec spec = fp.loadConfigLayerSpec(model, layer.getName());
                for (ConfigLayerDependency dep : spec.getLayerDeps()) {
                    dependencies.add(dep.getName());
                }
            }
            // Case where a layer is redefined in multiple FP. Add all deps.
            Set<String> existingDependencies = names.get(layer.getName());
            if (existingDependencies != null) {
                existingDependencies.addAll(dependencies);
                dependencies = existingDependencies;
            }
            names.put(layer.getName(), dependencies);
        }
    }
    return layersMap;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConfigLayerSpec(org.jboss.galleon.spec.ConfigLayerSpec) ConfigLayerDependency(org.jboss.galleon.spec.ConfigLayerDependency) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) TreeSet(java.util.TreeSet) ConfigId(org.jboss.galleon.config.ConfigId) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConfigId (org.jboss.galleon.config.ConfigId)39 ConfigModel (org.jboss.galleon.config.ConfigModel)12 Path (java.nio.file.Path)11 Map (java.util.Map)10 ProvisioningException (org.jboss.galleon.ProvisioningException)9 IOException (java.io.IOException)7 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)6 HashMap (java.util.HashMap)5 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ElementNode (org.jboss.galleon.xml.util.ElementNode)3 BufferedWriter (java.io.BufferedWriter)2 FileVisitResult (java.nio.file.FileVisitResult)2