use of org.jboss.galleon.config.ConfigId in project wildfly-maven-plugin by wildfly.
the class AbstractProvisionConfiguredMojoTestCase method checkStandaloneWildFlyHome.
public void checkStandaloneWildFlyHome(Path wildflyHome, int numDeployments, String[] layers, String[] excludedLayers, boolean stateRecorded, String... configTokens) throws Exception {
Assert.assertTrue(TestEnvironment.isValidWildFlyHome(wildflyHome));
if (numDeployments > 0) {
// Must retrieve all content directories.
Path rootDir = wildflyHome.resolve("standalone/data/content");
List<Path> deployments = new ArrayList<>();
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if ("content".equals(file.getFileName().toString())) {
deployments.add(file);
}
return FileVisitResult.CONTINUE;
}
});
assertEquals(numDeployments, deployments.size());
} else {
// created.
if (Files.exists(wildflyHome.resolve("standalone/data/content"))) {
assertEquals(0, Files.list(wildflyHome.resolve("standalone/data/content")).count());
}
}
Path history = wildflyHome.resolve("standalone").resolve("configuration").resolve("standalone_xml_history");
assertFalse(Files.exists(history));
Path configFile = wildflyHome.resolve("standalone/configuration/standalone.xml");
assertTrue(Files.exists(configFile));
if (layers != null) {
Path provisioning = PathsUtils.getProvisioningXml(wildflyHome);
assertTrue(Files.exists(provisioning));
ProvisioningConfig config = ProvisioningXmlParser.parse(provisioning);
ConfigModel cm = config.getDefinedConfig(new ConfigId("standalone", "standalone.xml"));
assertNotNull(config.getDefinedConfigs().toString(), cm);
assertEquals(layers.length, cm.getIncludedLayers().size());
for (String layer : layers) {
assertTrue(cm.getIncludedLayers().contains(layer));
}
if (excludedLayers != null) {
for (String layer : excludedLayers) {
assertTrue(cm.getExcludedLayers().contains(layer));
}
}
}
if (configTokens != null) {
String str = new String(Files.readAllBytes(configFile), StandardCharsets.UTF_8);
for (String token : configTokens) {
assertTrue(str, str.contains(token));
}
}
assertEquals(Files.exists(wildflyHome.resolve(".galleon")), stateRecorded);
assertEquals(Files.exists(wildflyHome.resolve(".wildfly-maven-plugin-provisioning.xml")), !stateRecorded);
}
use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.
the class AdvancedLayersTestCase method testWithExcludeLayers.
@Test
public void testWithExcludeLayers() throws Exception {
FeaturePackLocation prod = newFpl(PRODUCER4, "1", "1.0.0.Final");
buildFPWithOptionalLayers(cli, universeSpec, PRODUCER4, "1.0.0.Final");
{
Path path = cli.newDir("prod-exclude1", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4);
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
Collection<ConfigId> layers = state.getConfigs().get(0).getLayers();
// contains base, A, B and C.
assertEquals(layers.toString(), 4, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
}
{
Path path = cli.newDir("prod-exclude2", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4 + ",-layerB-" + PRODUCER4);
ProvisionedState state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
Collection<ConfigId> layers = state.getConfigs().get(0).getLayers();
// contains C, A and B are excluded, base, a dependency of A, is transitively excluded.
assertEquals(layers.toString(), 1, layers.size());
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Include layerA
cli.execute("install " + prod + " --dir=" + path + " --layers=layerA-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
// contains C, A and base, a dependency of A.
assertEquals(layers.toString(), 3, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Un-exclude layerB.
cli.execute("install " + prod + " --dir=" + path + " --layers=+layerB-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
assertEquals(layers.toString(), 4, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
// Attempt to un-exclude a layer that is not excluded
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=+layerA-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
// Attempt to exclude layerC that is not a dependency
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerC-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
// Exclude layerB
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerB-" + PRODUCER4);
state = ProvisioningManager.builder().setInstallationHome(path).build().getProvisionedState();
assertEquals(1, state.getConfigs().size());
layers = state.getConfigs().get(0).getLayers();
assertEquals(layers.toString(), 3, layers.size());
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "base-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerA-" + PRODUCER4)));
assertFalse(layers.toString(), layers.contains(new ConfigId("testmodel", "layerB-" + PRODUCER4)));
assertTrue(layers.toString(), layers.contains(new ConfigId("testmodel", "layerC-" + PRODUCER4)));
}
{
// Attempt to exclude a required layer.
Path path = cli.newDir("prod-exclude3", false);
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=layerC-" + PRODUCER4 + ",-base-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
{
// Attempt to exclude a layer that is not a dependency.
Path path = cli.newDir("prod-exclude4", false);
try {
cli.execute("install " + prod + " --dir=" + path + " --layers=layerB-" + PRODUCER4 + ",-layerC-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
{
// Install layerA and layerB, layerA is dependency of layerB
Path path = cli.newDir("prod-exclude5", false);
cli.execute("install " + prod + " --dir=" + path + " --layers=layerA-" + PRODUCER4 + ",layerB-" + PRODUCER4);
try {
// Attempt to exclude layerA, it is not allowed, the layer has been explictly included.
cli.execute("install " + prod + " --dir=" + path + " --layers=-layerA-" + PRODUCER4);
throw new Exception("Should have failed");
} catch (CommandException ex) {
// XXX OK
}
}
}
use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.
the class ChangesTestCase method overwrite.
protected void overwrite(Path home, ProvisionedConfig config) throws ProvisioningException {
Path p = home.resolve(Constants.CONFIGS);
if (config.getModel() != null) {
p = p.resolve(config.getModel());
}
p = p.resolve(config.getName());
try {
Files.createDirectories(p.getParent());
} catch (IOException e1) {
throw new ProvisioningException(Errors.mkdirs(p.getParent()), e1);
}
try (BufferedWriter writer = Files.newBufferedWriter(p)) {
ProvisionedConfigXmlWriter.getInstance().write(config, writer);
} catch (IOException | XMLStreamException e) {
throw new ProvisioningException("Failed to store " + new ConfigId(config.getModel(), config.getName()) + " in a string", e);
}
}
use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.
the class ConfigXml method readConfigDep.
private static void readConfigDep(XMLExtendedStreamReader reader, ConfigModel.Builder builder) throws XMLStreamException {
String id = null;
String name = null;
String model = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i));
switch(attribute) {
case ID:
id = reader.getAttributeValue(i);
break;
case NAME:
name = reader.getAttributeValue(i);
break;
case MODEL:
model = reader.getAttributeValue(i);
break;
default:
throw ParsingUtils.unexpectedContent(reader);
}
}
if (id == null || name == null && model == null) {
if (id == null) {
throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.ID));
}
throw ParsingUtils.missingOneOfAttributes(reader.getLocation(), Attribute.NAME, Attribute.MODEL);
}
builder.setConfigDep(id, new ConfigId(model, name));
ParsingUtils.parseNoContent(reader);
}
use of org.jboss.galleon.config.ConfigId in project galleon by wildfly.
the class PersistChangesTestBase method overwrite.
protected void overwrite(ProvisionedConfig config) throws ProvisioningException {
Path p = this.installHome.resolve(Constants.CONFIGS);
if (config.getModel() != null) {
p = p.resolve(config.getModel());
}
p = p.resolve(config.getName());
try {
Files.createDirectories(p.getParent());
} catch (IOException e1) {
throw new ProvisioningException(Errors.mkdirs(p.getParent()), e1);
}
try (BufferedWriter writer = Files.newBufferedWriter(p)) {
ProvisionedConfigXmlWriter.getInstance().write(config, writer);
} catch (IOException | XMLStreamException e) {
throw new ProvisioningException("Failed to store " + new ConfigId(config.getModel(), config.getName()) + " in a string", e);
}
}
Aggregations