use of org.jboss.galleon.ProvisioningManager in project wildfly-maven-plugin by wildfly.
the class AbstractProvisionServerMojo method provisionServer.
private void provisionServer(Path home) throws ProvisioningException, MojoExecutionException, IOException, XMLStreamException {
try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver).setInstallationHome(home).setMessageWriter(new MvnMessageWriter(getLog())).setLogTime(logProvisioningTime).setRecordState(recordProvisioningState).build()) {
ProvisioningConfig config = null;
Path resolvedProvisioningFile = resolvePath(project, provisioningFile.toPath());
boolean provisioningFileExists = Files.exists(resolvedProvisioningFile);
if (featurePacks.isEmpty()) {
if (provisioningFileExists) {
getLog().info("Provisioning server using " + resolvedProvisioningFile + " file.");
config = GalleonUtils.buildConfig(resolvedProvisioningFile);
} else {
config = getDefaultConfig();
if (config == null) {
throw new MojoExecutionException("No feature-pack has been configured, can't provision a server.");
}
}
} else {
if (provisioningFileExists) {
getLog().warn("Galleon provisioning file " + provisioningFile + " is ignored, plugin configuration is used.");
}
if (layers.isEmpty() && !STANDALONE_XML.equals(layersConfigurationFileName)) {
throw new MojoExecutionException("layers-configuration-file-name has been set although no layers are defined.");
}
config = GalleonUtils.buildConfig(pm, featurePacks, layers, excludedLayers, galleonOptions, layersConfigurationFileName);
}
getLog().info("Provisioning server in " + home);
pm.provision(config);
// Check that at least the standalone or domain directories have been generated.
if (!Files.exists(home.resolve("standalone")) && !Files.exists(home.resolve("domain"))) {
getLog().error("Invalid galleon provisioning, no server provisioned in " + home + ". Make sure " + "that the list of Galleon feature-packs and Galleon layers are properly configured.");
throw new MojoExecutionException("Invalid plugin configuration, no server provisioned.");
}
if (!recordProvisioningState) {
Path file = home.resolve(PLUGIN_PROVISIONING_FILE);
try (FileWriter writer = new FileWriter(file.toFile())) {
ProvisioningXmlWriter.getInstance().write(config, writer);
}
}
}
}
use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.
the class ProvisionStateMojo method doProvision.
private void doProvision() throws MojoExecutionException, ProvisioningException {
final ProvisioningConfig.Builder state = ProvisioningConfig.builder();
final RepositoryArtifactResolver artifactResolver = offline ? new MavenArtifactRepositoryManager(repoSystem, repoSession) : new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
final Path home = installDir.toPath();
if (!recordState) {
IoUtils.recursiveDelete(home);
}
try (ProvisioningManager pm = ProvisioningManager.builder().addArtifactResolver(artifactResolver).setInstallationHome(home).setMessageWriter(new MvnMessageWriter(getLog())).setLogTime(logTime).setRecordState(recordState).build()) {
for (FeaturePack fp : featurePacks) {
if (fp.getLocation() == null && (fp.getGroupId() == null || fp.getArtifactId() == null) && fp.getNormalizedPath() == null) {
throw new MojoExecutionException("Feature-pack location, Maven GAV or feature pack path is missing");
}
final FeaturePackLocation fpl;
if (fp.getNormalizedPath() != null) {
fpl = pm.getLayoutFactory().addLocal(fp.getNormalizedPath(), false);
} else if (fp.getGroupId() != null && fp.getArtifactId() != null) {
Path path = resolveMaven(fp, (MavenRepoManager) artifactResolver);
fpl = pm.getLayoutFactory().addLocal(path, false);
} else {
fpl = FeaturePackLocation.fromString(fp.getLocation());
}
final FeaturePackConfig.Builder fpConfig = fp.isTransitive() ? FeaturePackConfig.transitiveBuilder(fpl) : FeaturePackConfig.builder(fpl);
if (fp.isInheritConfigs() != null) {
fpConfig.setInheritConfigs(fp.isInheritConfigs());
}
if (fp.isInheritPackages() != null) {
fpConfig.setInheritPackages(fp.isInheritPackages());
}
if (!fp.getExcludedConfigs().isEmpty()) {
for (ConfigurationId configId : fp.getExcludedConfigs()) {
if (configId.isModelOnly()) {
fpConfig.excludeConfigModel(configId.getId().getModel());
} else {
fpConfig.excludeDefaultConfig(configId.getId());
}
}
}
if (!fp.getIncludedConfigs().isEmpty()) {
for (ConfigurationId configId : fp.getIncludedConfigs()) {
if (configId.isModelOnly()) {
fpConfig.includeConfigModel(configId.getId().getModel());
} else {
fpConfig.includeDefaultConfig(configId.getId());
}
}
}
if (!fp.getIncludedPackages().isEmpty()) {
for (String includedPackage : fp.getIncludedPackages()) {
fpConfig.includePackage(includedPackage);
}
}
if (!fp.getExcludedPackages().isEmpty()) {
for (String excludedPackage : fp.getExcludedPackages()) {
fpConfig.excludePackage(excludedPackage);
}
}
state.addFeaturePackDep(fpConfig.build());
}
boolean hasLayers = false;
for (Configuration config : configs) {
ConfigModel.Builder configBuilder = ConfigModel.builder(config.getModel(), config.getName());
for (String layer : config.getLayers()) {
hasLayers = true;
configBuilder.includeLayer(layer);
}
if (config.getExcludedLayers() != null) {
for (String layer : config.getExcludedLayers()) {
configBuilder.excludeLayer(layer);
}
}
state.addConfig(configBuilder.build());
}
if (hasLayers) {
if (pluginOptions.isEmpty()) {
pluginOptions = Collections.singletonMap(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
} else if (!pluginOptions.containsKey(Constants.OPTIONAL_PACKAGES)) {
pluginOptions.put(Constants.OPTIONAL_PACKAGES, Constants.PASSIVE_PLUS);
}
}
if (customConfig != null && customConfig.exists()) {
try (BufferedReader reader = Files.newBufferedReader(customConfig.toPath())) {
state.addConfig(ConfigXmlParser.getInstance().parse(reader));
} catch (XMLStreamException | IOException ex) {
throw new IllegalArgumentException("Couldn't load the customization configuration " + customConfig, ex);
}
}
for (ResolveLocalItem localResolverItem : resolveLocals) {
if (localResolverItem.getError() != null) {
throw new MojoExecutionException(localResolverItem.getError());
}
}
for (ResolveLocalItem localResolverItem : resolveLocals) {
if (localResolverItem.getNormalizedPath() != null) {
pm.getLayoutFactory().addLocal(localResolverItem.getNormalizedPath(), localResolverItem.getInstallInUniverse());
} else if (localResolverItem.hasArtifactCoords()) {
Path path = resolveMaven(localResolverItem, (MavenRepoManager) artifactResolver);
pm.getLayoutFactory().addLocal(path, false);
} else {
throw new MojoExecutionException("resolve-local element appears to be neither path not maven artifact");
}
}
pm.provision(state.build(), pluginOptions);
}
}
use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.
the class PmTestBase method main.
@Test
public void main() throws Throwable {
final String[] errors = pmErrors();
boolean failed = false;
ProvisioningManager pm = null;
try {
pm = getPm();
testPm(pm);
pmSuccess();
if (errors != null) {
Assert.fail("Expected failures: " + Arrays.asList(errors));
}
if (isRecordState()) {
assertProvisionedConfig(pm);
assertProvisionedState(pm);
} else if (initialProvisioningConfig != null) {
pm.close();
pm = getPm();
assertProvisionedConfig(pm);
assertProvisionedState(pm);
} else {
assertNoState();
}
} catch (AssertionError e) {
throw e;
} catch (Throwable t) {
failed = true;
if (errors == null) {
pmFailure(t);
} else {
assertErrors(t, errors);
}
if (pm != null) {
if (isRecordState()) {
assertProvisioningConfig(pm, initialProvisioningConfig);
assertProvisionedState(pm, initialProvisionedState);
} else if (initialProvisioningConfig != null) {
pm.close();
pm = getPm();
assertProvisioningConfig(pm, initialProvisioningConfig);
assertProvisionedState(pm, initialProvisionedState);
}
}
} finally {
if (pm != null) {
pm.close();
}
}
DirState expectedHomeDir = provisionedHomeDir();
if (expectedHomeDir == null) {
if (!assertProvisionedHomeDir()) {
return;
}
if (failed || initialProvisioningConfig != null) {
expectedHomeDir = initialHomeDirState;
} else {
expectedHomeDir = newDirBuilder().build();
}
}
expectedHomeDir.assertState(installHome);
}
use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.
the class PmTestBase method doBefore.
@Override
protected void doBefore() throws Exception {
super.doBefore();
final FeaturePackCreator fpCreator = initCreator();
createFeaturePacks(fpCreator);
fpCreator.install();
initialProvisioningConfig = initialState();
if (initialProvisioningConfig != null) {
try (ProvisioningManager pm = getPm()) {
pm.provision(initialProvisioningConfig);
initialProvisionedState = pm.getProvisionedState();
}
}
initialHomeDirState = DirState.rootBuilder().init(installHome).build();
}
use of org.jboss.galleon.ProvisioningManager in project galleon by wildfly.
the class InstallFpUsingUniverseNameTestCase method getPm.
@Override
protected ProvisioningManager getPm() throws ProvisioningException {
ProvisioningManager pm = super.getPm();
pm.addUniverse("custom", LegacyGalleon1Universe.getUniverseSpec());
return pm;
}
Aggregations