Search in sources :

Example 61 with ProvisioningException

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

the class GetChangesCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        FsDiff diff = mgr.getFsDiff();
        if (diff.isEmpty()) {
            invoc.println("No changes detected");
        } else {
            Path workingDir = Paths.get(invoc.getConfiguration().getAeshContext().getCurrentWorkingDirectory().getAbsolutePath());
            Path installation = mgr.getInstallationHome();
            PathResolver resolver = new PathResolver() {

                @Override
                public String resolve(String relativePath) {
                    Path absPath = Paths.get(installation.toString(), relativePath);
                    return workingDir.relativize(absPath).toString();
                }
            };
            FsDiff.log(diff, new Consumer<String>() {

                @Override
                public void accept(String msg) {
                    invoc.println(msg);
                }
            }, resolver);
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
}
Also used : Path(java.nio.file.Path) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) FsDiff(org.jboss.galleon.diff.FsDiff) PathResolver(org.jboss.galleon.diff.FsDiff.PathResolver) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 62 with ProvisioningException

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

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

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

the class ClearHistoryCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        mgr.clearStateHistory();
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.clearHistoryFailed(), ex);
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 65 with ProvisioningException

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

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