use of org.jboss.galleon.runtime.ResolvedSpecId 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.runtime.ResolvedSpecId in project galleon by wildfly.
the class ProvisionedConfigXmlParser30 method readSpec.
private static void readSpec(XMLExtendedStreamReader reader, ProducerSpec producer, ProvisionedConfigBuilder config) throws XMLStreamException {
String name = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i));
switch(attribute) {
case NAME:
name = reader.getAttributeValue(i);
break;
default:
throw ParsingUtils.unexpectedContent(reader);
}
}
if (name == null) {
throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
}
final ResolvedSpecId specId = new ResolvedSpecId(producer, name);
while (reader.hasNext()) {
switch(reader.nextTag()) {
case XMLStreamConstants.END_ELEMENT:
{
return;
}
case XMLStreamConstants.START_ELEMENT:
{
final Element element = Element.of(reader.getName());
switch(element) {
case FEATURE:
readFeature(reader, specId, config);
break;
default:
throw ParsingUtils.unexpectedContent(reader);
}
break;
}
default:
{
throw ParsingUtils.unexpectedContent(reader);
}
}
}
throw ParsingUtils.endOfDocument(reader.getLocation());
}
use of org.jboss.galleon.runtime.ResolvedSpecId in project galleon by wildfly.
the class IncludeFeatureNotBeloningToFeatureGroupTestCase method pmFailure.
@Override
protected void pmFailure(Throwable e) {
Assert.assertEquals(Errors.failedToResolveConfigSpec(null, "main"), e.getLocalizedMessage());
Assert.assertNotNull(e.getCause());
Throwable t = e.getCause();
Assert.assertEquals(Errors.failedToProcess(FP_GAV, "group1"), t.getLocalizedMessage());
Assert.assertNotNull(t.getCause());
t = t.getCause();
Assert.assertEquals(Errors.featureNotInScope(ResolvedFeatureId.create(new ResolvedSpecId(FP_GAV.getProducer(), "specP"), "parent", "p2"), "group1", FP_GAV), t.getLocalizedMessage());
}
use of org.jboss.galleon.runtime.ResolvedSpecId in project galleon by wildfly.
the class ProvisionedStateXmlWriterTestCase method testFeatureOrder.
@Test
public void testFeatureOrder() throws Exception {
ProvisionedState originalState = ProvisionedState.builder().addConfig(ProvisionedConfigBuilder.builder().addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec1", "create-param", "a")).build()).addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec2", "create-param", "b")).build()).addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec1", "create-param", "c")).build()).addFeature(ProvisionedFeatureBuilder.builder(new ResolvedSpecId(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp2", "1.0").getProducer(), "spec3")).setIdParam("id-param", "b").build()).addFeature(ProvisionedFeatureBuilder.builder(new ResolvedSpecId(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp2", "1.0").getProducer(), "spec3")).setIdParam("id-param", "a").build()).addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec1", "create-param", "c")).build()).build()).build();
// marshall and unmarshall
Path path = marshallToTempFile(originalState);
ProvisionedState newState = validator.validateAndParse(path);
// read features and check the order
ReadFeaturesHandler handler = new ReadFeaturesHandler();
newState.getConfigs().iterator().next().handle(handler);
Iterator<ProvisionedFeature> iterator = handler.features.iterator();
Assert.assertEquals("{org.jboss.group@galleon1}spec1:create-param=a", iterator.next().getId().toString());
Assert.assertEquals("{org.jboss.group@galleon1}spec2:create-param=b", iterator.next().getId().toString());
Assert.assertEquals("{org.jboss.group@galleon1}spec1:create-param=c", iterator.next().getId().toString());
Assert.assertEquals("{org.jboss.group@galleon1}spec3:id-param=b", iterator.next().getId().toString());
Assert.assertEquals("{org.jboss.group@galleon1}spec3:id-param=a", iterator.next().getId().toString());
Assert.assertEquals("{org.jboss.group@galleon1}spec1:create-param=c", iterator.next().getId().toString());
}
use of org.jboss.galleon.runtime.ResolvedSpecId in project galleon by wildfly.
the class ProvisionedStateXmlWriterTestCase method testMarshallUnmarshall.
@Test
public void testMarshallUnmarshall() throws Exception {
ProvisionedState originalState = ProvisionedState.builder().addFeaturePack(ProvisionedFeaturePack.builder(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0")).addPackage("package1").addPackage(ProvisionedPackage.newInstance("package2")).build()).addFeaturePack(ProvisionedFeaturePack.builder(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp2", "1.0")).addPackage("package3").build()).addConfig(ProvisionedConfigBuilder.builder().addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec1", "create-param", "a")).setConfigParam("param", "config").build()).addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec1", "create-param", "b")).build()).addFeature(ProvisionedFeatureBuilder.builder(ResolvedFeatureId.create(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp1", "1.0").getProducer(), "spec2", "create-param", "c")).build()).addFeature(ProvisionedFeatureBuilder.builder(new ResolvedSpecId(LegacyGalleon1Universe.newFPID("org.jboss.group", "fp2", "1.0").getProducer(), "spec3")).setIdParam("id-param", "config").build()).setModel("model").setName("name").setProperty("prop", "value").setProperty("prop2", "value2").build()).addConfig(ProvisionedConfigBuilder.builder().build()).build();
// marshall to XML and then parse again
Path path = marshallToTempFile(originalState);
ProvisionedState newState = validator.validateAndParse(path);
// compare parsed state with the original
Assert.assertEquals(originalState, newState);
}
Aggregations