use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.
the class StateSearchCommand method findFeatures.
private Set<ResolvedSpecId> findFeatures(PackageInfo spec, FeatureContainer container) {
Set<ResolvedSpecId> fspecs = new HashSet<>();
for (Entry<ResolvedSpecId, FeatureSpecInfo> features : container.getAllSpecs().entrySet()) {
for (PackageInfo info : features.getValue().getPackages()) {
Group grp = container.getAllPackages().get(info.getIdentity());
Set<Identity> identities = new HashSet<>();
visitPkg(grp, identities);
if (identities.contains(spec.getIdentity())) {
fspecs.add(features.getKey());
break;
}
}
}
return fspecs;
}
use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.
the class StateInfoUtil method printContentPath.
public static void printContentPath(PmCommandInvocation session, FeatureContainer fp, String path) throws ProvisioningException, PathParserException, PathConsumerException, IOException {
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(fp, false);
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp != null) {
// entered some content
if (grp.getFeature() != null) {
displayFeature(session, grp);
} else if (grp.getSpec() != null) {
displayFeatureSpec(session, grp);
} else if (grp.getPackage() != null) {
displayPackage(session, grp);
} else if (!grp.getGroups().isEmpty()) {
displayContainmentGroup(session, grp);
}
}
}
use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.
the class StateCdCommand method cdFp.
private void cdFp(PmCommandInvocation session) throws CommandExecutionException, PathParserException, PathConsumerException {
PmSession pm = session.getPmSession();
String currentPath = pm.getCurrentPath();
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(pm.getContainer(), true);
if (path.startsWith("" + PathParser.PATH_SEPARATOR)) {
pm.setCurrentPath(null);
} else if (path.equals("..")) {
if (currentPath == null) {
throw new CommandExecutionException("No path entered");
}
if (currentPath.equals("" + PathParser.PATH_SEPARATOR)) {
return;
}
currentPath = currentPath.substring(0, currentPath.length() - 1);
int i = currentPath.lastIndexOf("" + PathParser.PATH_SEPARATOR);
if (i < 0) {
path = "" + PathParser.PATH_SEPARATOR;
} else {
path = currentPath.substring(0, i);
}
if (path.isEmpty()) {
path = "" + PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(null);
} else {
path = currentPath + path;
}
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
return;
} else {
if (!path.endsWith("" + PathParser.PATH_SEPARATOR)) {
path += PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(path);
}
String prompt;
if (FeatureContainerPathConsumer.ROOT.equals(grp.getIdentity().getName())) {
prompt = "" + PathParser.PATH_SEPARATOR;
} else {
prompt = grp.getIdentity().getName() + PathParser.PATH_SEPARATOR;
}
session.setPrompt(session.getPmSession().buildPrompt(prompt));
}
use of org.jboss.galleon.cli.model.Group 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");
}
}
use of org.jboss.galleon.cli.model.Group in project galleon by wildfly.
the class StateSearchCommand method getPackage.
private PackageInfo getPackage(FeatureContainer container, String id) throws PathParserException, PathConsumerException, ProvisioningException {
String path = FeatureContainerPathConsumer.PACKAGES_PATH + id;
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(container, false);
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
throw new ProvisioningException("Invalid path");
}
if (grp.getPackage() == null) {
throw new ProvisioningException("Path is not a package");
}
return grp.getPackage();
}
Aggregations