Search in sources :

Example 56 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class Configuration method parse.

public static Configuration parse(Map<String, String> options) throws ProvisioningException {
    Configuration config = new Configuration();
    Path configFile = getConfigFile();
    if (Files.exists(configFile)) {
        try (BufferedReader reader = Files.newBufferedReader(configFile)) {
            XmlParsers.parse(reader, config);
        } catch (IOException | XMLStreamException e) {
            throw new ProvisioningException(Errors.parseXml(configFile), e);
        }
    }
    return config;
}
Also used : Path(java.nio.file.Path) XMLStreamException(javax.xml.stream.XMLStreamException) ProvisioningException(org.jboss.galleon.ProvisioningException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 57 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class AbstractLayersCommand method getConfiguration.

protected ConfigInfo getConfiguration(State state) throws PathParserException, PathConsumerException, ProvisioningException, Exception {
    String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + configuration + PathParser.PATH_SEPARATOR;
    FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(state.getContainer(), false);
    PathParser.parse(path, consumer);
    ConfigInfo ci = consumer.getConfig();
    if (ci == null) {
        throw new ProvisioningException("Not a valid config " + configuration);
    }
    return ci;
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo)

Example 58 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class StateEditCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    State state;
    try {
        state = new State(invoc.getPmSession(), getInstallationHome(invoc.getConfiguration().getAeshContext()));
    } catch (ProvisioningException | IOException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.readContentFailed(), ex);
    }
    invoc.getPmSession().setState(state);
    invoc.setPrompt(invoc.getPmSession().buildPrompt(state.getPath()));
    invoc.println(WELCOME_STATE_MSG);
}
Also used : State(org.jboss.galleon.cli.model.state.State) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 59 with ProvisioningException

use of org.jboss.galleon.ProvisioningException in project galleon by wildfly.

the class ExportCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    if (file != null) {
        final Path targetFile = file.toPath();
        try {
            getManager(invoc.getPmSession()).exportProvisioningConfig(targetFile);
        } catch (ProvisioningException | IOException e) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
        }
        invoc.println("Provisioning file generated in " + targetFile);
    } else {
        ByteArrayOutputStream output = null;
        try {
            ProvisioningConfig config = getManager(invoc.getPmSession()).getProvisioningConfig();
            output = new ByteArrayOutputStream();
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
            ProvisioningXmlWriter.getInstance().write(config, writer);
        } catch (Exception e) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
        }
        try {
            invoc.println(output.toString(StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException e) {
            throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
        }
    }
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter)

Example 60 with ProvisioningException

use of org.jboss.galleon.ProvisioningException 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

ProvisioningException (org.jboss.galleon.ProvisioningException)101 IOException (java.io.IOException)45 Path (java.nio.file.Path)35 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)24 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)15 XMLStreamException (javax.xml.stream.XMLStreamException)13 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)10 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)10 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)9 ProvisioningManager (org.jboss.galleon.ProvisioningManager)9 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 ConfigId (org.jboss.galleon.config.ConfigId)8 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)8 ProducerSpec (org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)7 BufferedWriter (java.io.BufferedWriter)6