Search in sources :

Example 1 with FeatureInfo

use of org.jboss.galleon.cli.model.FeatureInfo in project galleon by wildfly.

the class StateInfoUtil method displayFeature.

private static void displayFeature(PmCommandInvocation session, Group grp) throws ProvisioningException {
    // Feature and spec.
    FeatureInfo f = grp.getFeature();
    session.println("");
    session.println("Type       : " + f.getType());
    session.println("Path       : " + f.getPath());
    session.println("Origin     : " + f.getSpecId().getProducer());
    session.println("Description: " + f.getDescription());
    session.println("");
    session.println("Parameters id");
    if (f.getFeatureId() == null) {
        session.println("NONE");
    } else {
        for (Entry<String, String> entry : f.getFeatureId().getParams().entrySet()) {
            session.println(entry.getKey() + "=" + entry.getValue());
        }
    }
    session.println(Config.getLineSeparator() + "Feature XML extract");
    StringBuilder xmlBuilder = new StringBuilder();
    /**
     * <feature spec="core-service.vault">
     * <param name="core-service" value="vault"/>
     * <param name="module" value="aValue"/>
     * <param name="code" value="aValue"/>
     * </feature>
     */
    xmlBuilder.append("<feature spec=\"" + f.getType() + "\">").append(Config.getLineSeparator());
    String tab = "  ";
    for (Entry<String, Object> p : f.getResolvedParams().entrySet()) {
        if (!Constants.GLN_UNDEFINED.equals(p.getValue())) {
            xmlBuilder.append(tab + "<param name=\"" + p.getKey() + "\"" + " value=\"" + p.getValue() + "\"/>").append(Config.getLineSeparator());
        }
    }
    xmlBuilder.append("</feature>").append(Config.getLineSeparator());
    session.println(xmlBuilder.toString());
    session.println("Unset parameters");
    if (f.getUndefinedParams().isEmpty()) {
        session.println("NONE");
    }
    for (String p : f.getUndefinedParams()) {
        session.println(tab + "<param name=\"" + p + "\"" + " value=\"???\"/>");
    }
}
Also used : FeatureInfo(org.jboss.galleon.cli.model.FeatureInfo)

Example 2 with FeatureInfo

use of org.jboss.galleon.cli.model.FeatureInfo in project galleon by wildfly.

the class StateRemoveFeatureCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc, State session) throws IOException, ProvisioningException, CommandExecutionException {
    try {
        String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + (feature.endsWith("" + PathParser.PATH_SEPARATOR) ? feature : feature + PathParser.PATH_SEPARATOR);
        FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(session.getContainer(), false);
        PathParser.parse(path, consumer);
        ConfigInfo ci = consumer.getConfig();
        if (ci == null) {
            throw new ProvisioningException("Not a valid configuration " + feature);
        }
        Group grp = consumer.getCurrentNode(path);
        if (grp == null) {
            throw new ProvisioningException("Not a valid feature " + feature);
        }
        FeatureInfo fi = grp.getFeature();
        if (fi == null) {
            throw new ProvisioningException("Not a valid feature " + feature);
        }
        session.removeFeature(invoc.getPmSession(), ci, fi);
    } catch (Exception ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.removeFeatureFailed(), ex);
    }
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group) ProvisioningException(org.jboss.galleon.ProvisioningException) FeatureInfo(org.jboss.galleon.cli.model.FeatureInfo) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 3 with FeatureInfo

use of org.jboss.galleon.cli.model.FeatureInfo in project galleon by wildfly.

the class StateSearchCommand method run.

private void run(FeatureContainer container, PmCommandInvocation invoc, boolean dependencySearch) throws PathParserException, PathConsumerException, ProvisioningException {
    if (pkg != null) {
        PackageInfo spec = getPackage(dependencySearch ? container : new AbstractPackageCommand.AllPackagesContainer(container), pkg);
        invoc.println(Config.getLineSeparator() + "As a direct dependency of a package:");
        StringBuilder pBuilder = new StringBuilder();
        for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
            Group root = pkgs.getValue();
            for (Group g : root.getGroups()) {
                for (Group dep : g.getGroups()) {
                    if (dep.getIdentity().equals(spec.getIdentity())) {
                        pBuilder.append("  " + g.getIdentity()).append(Config.getLineSeparator());
                        break;
                    }
                }
            }
        }
        if (pBuilder.length() != 0) {
            invoc.println(pBuilder.toString());
        } else {
            invoc.println("NONE");
        }
        Set<ResolvedSpecId> fspecs = findFeatures(spec, container);
        invoc.println("Reachable from features:");
        if (fspecs.isEmpty()) {
            invoc.println("NONE");
        } else {
            for (ResolvedSpecId id : fspecs) {
                List<FeatureInfo> features = container.getAllFeatures().get(id);
                // Can be null if we have all specs whatever the set of features.
                if (features != null) {
                    for (FeatureInfo fi : features) {
                        invoc.println("  " + fi.getPath());
                    }
                } else {
                    invoc.println("      [spec only] " + toPath(id));
                }
            }
        }
        return;
    }
    invoc.println(Config.getLineSeparator() + "Packages:");
    StringBuilder pBuilder = new StringBuilder();
    for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
        Group root = pkgs.getValue();
        for (Group g : root.getGroups()) {
            PackageInfo p = g.getPackage();
            if (p.getIdentity().toString().contains(query)) {
                pBuilder.append("  " + FeatureContainerPathConsumer.PACKAGES_PATH + p.getIdentity()).append(Config.getLineSeparator());
                if (!dependencySearch) {
                    pBuilder.append("    Reachable from features:").append(Config.getLineSeparator());
                    Set<ResolvedSpecId> fspecs = findFeatures(p, container);
                    if (fspecs.isEmpty()) {
                        pBuilder.append("      NONE" + Config.getLineSeparator());
                    }
                    for (ResolvedSpecId id : fspecs) {
                        List<FeatureInfo> features = container.getAllFeatures().get(id);
                        // Can be null if we have all specs whatever the set of features.
                        if (features != null) {
                            for (FeatureInfo fi : features) {
                                pBuilder.append("      " + fi.getPath()).append(Config.getLineSeparator());
                            }
                        } else {
                            pBuilder.append("  [spec only] " + toPath(id)).append(Config.getLineSeparator());
                        }
                    }
                }
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    invoc.println(Config.getLineSeparator() + "Package dependencies:");
    for (Entry<String, Group> pkgs : container.getPackages().entrySet()) {
        Group root = pkgs.getValue();
        for (Group g : root.getGroups()) {
            StringBuilder depBuilder = new StringBuilder();
            for (Group dep : g.getGroups()) {
                if (dep.getIdentity().toString().contains(query)) {
                    depBuilder.append("  " + dep.getIdentity()).append(Config.getLineSeparator());
                    break;
                }
            }
            if (depBuilder.length() != 0) {
                pBuilder.append("  Found as a direct dependencies of " + g.getIdentity()).append(Config.getLineSeparator());
                pBuilder.append(depBuilder);
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    invoc.println(Config.getLineSeparator() + "Package content:");
    for (Entry<String, Group> entry : container.getPackages().entrySet()) {
        Group root = entry.getValue();
        for (Group g : root.getGroups()) {
            PackageInfo pkginfo = g.getPackage();
            StringBuilder contentBuilder = new StringBuilder();
            for (String c : pkginfo.getContent()) {
                if (c.contains(query)) {
                    contentBuilder.append(c).append(Config.getLineSeparator());
                }
            }
            if (contentBuilder.length() != 0) {
                pBuilder.append("  Found in content of " + g.getIdentity()).append(Config.getLineSeparator());
                pBuilder.append(contentBuilder);
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
    pBuilder = new StringBuilder();
    // Features?
    invoc.println(Config.getLineSeparator() + "Features:");
    for (Entry<ResolvedSpecId, List<FeatureInfo>> features : container.getAllFeatures().entrySet()) {
        ResolvedSpecId id = features.getKey();
        List<FeatureInfo> fs = features.getValue();
        if (fs == null) {
            if (id.getName().contains(query)) {
                pBuilder.append("  [spec only] " + toPath(id)).append(Config.getLineSeparator());
            }
        } else {
            for (FeatureInfo fi : fs) {
                if (fi.getPath().contains(query)) {
                    pBuilder.append("  " + fi.getPath()).append(Config.getLineSeparator());
                }
            }
        }
    }
    if (pBuilder.length() != 0) {
        invoc.println(pBuilder.toString());
    } else {
        invoc.println("NONE");
    }
}
Also used : Group(org.jboss.galleon.cli.model.Group) ResolvedSpecId(org.jboss.galleon.runtime.ResolvedSpecId) PackageInfo(org.jboss.galleon.cli.model.PackageInfo) FeatureInfo(org.jboss.galleon.cli.model.FeatureInfo) List(java.util.List)

Aggregations

FeatureInfo (org.jboss.galleon.cli.model.FeatureInfo)3 Group (org.jboss.galleon.cli.model.Group)2 IOException (java.io.IOException)1 List (java.util.List)1 ProvisioningException (org.jboss.galleon.ProvisioningException)1 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)1 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)1 PackageInfo (org.jboss.galleon.cli.model.PackageInfo)1 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)1 ResolvedSpecId (org.jboss.galleon.runtime.ResolvedSpecId)1