diff --git a/plugin/src/main/java/org/wildfly/plugin/common/PropertyNames.java b/plugin/src/main/java/org/wildfly/plugin/common/PropertyNames.java index 2990fe0a..1862a1cf 100644 --- a/plugin/src/main/java/org/wildfly/plugin/common/PropertyNames.java +++ b/plugin/src/main/java/org/wildfly/plugin/common/PropertyNames.java @@ -113,12 +113,20 @@ public interface PropertyNames { String WILDFLY_PROVISIONING_DIR = "wildfly.provisioning.dir"; + String WILDFLY_PROVISIONING_FEATURE_PACKS = "wildfly.provisioning.feature-packs"; + String WILDFLY_PROVISIONING_FILE = "wildfly.provisioning.file"; + String WILDFLY_PROVISIONING_LAYERS = "wildfly.provisioning.layers"; + + String WILDFLY_PROVISIONING_LAYERS_EXCLUDED = "wildfly.provisioning.layers.excluded"; + String WILDFLY_PROVISIONING_LOG_TIME = "wildfly.provisioning.log.time"; String WILDFLY_PROVISIONING_OFFLINE = "wildfly.provisioning.offline"; + String WILDFLY_PROVISIONING_OVERWRITE_PROVISIONED_SERVER = "wildfly.provisioning.overwrite-provisioned-server"; + String WILDFLY_PROVISIONING_RECORD_STATE = "wildfly.provisioning.record.state"; String WILDFLY_VERSION = "wildfly.version"; diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java index 7ec9b7ed..2100472e 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java @@ -22,6 +22,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -123,14 +124,22 @@ abstract class AbstractProvisionServerMojo extends AbstractMojo { private boolean skip; /** - * The directory name inside the buildDir where to provision the server. By default the server is provisioned into the 'server' directory. + * The path to the directory where to provision the server. Can be an absolute path or a path relative to the buildDir. + * By default the server is provisioned into the {@code target/server} directory. */ @Parameter(alias = "provisioning-dir", property = PropertyNames.WILDFLY_PROVISIONING_DIR, defaultValue = Utils.WILDFLY_DEFAULT_DIR) private String provisioningDir; + /** + * Set to {@code true} if you want to delete the existing server referenced from the {@code provisioningDir} and provision a new one, + * otherwise {@code false}. + */ + @Parameter(alias="overwrite-provisioned-server", defaultValue = "false", property = PropertyNames.WILDFLY_PROVISIONING_OVERWRITE_PROVISIONED_SERVER) + private boolean overwriteProvisionedServer; + /** - * A list of feature-pack configurations to install, can be combined with - * layers. + * A list of feature-pack configurations to install, can be combined with layers. + * Use the System property {@code wildfly.provisioning.feature-packs} to provide a comma separated list of feature-packs. */ @Parameter(required = false, alias= "feature-packs") List featurePacks = Collections.emptyList(); @@ -138,15 +147,17 @@ abstract class AbstractProvisionServerMojo extends AbstractMojo { /** * A list of Galleon layers to provision. Can be used when * feature-pack-location or feature-packs are set. + * Use the System property {@code wildfly.provisioning.layers} to provide a comma separated list of layers. */ - @Parameter(alias = "layers", required = false) + @Parameter(alias = "layers", required = false, property = PropertyNames.WILDFLY_PROVISIONING_LAYERS) List layers = Collections.emptyList(); /** * A list of Galleon layers to exclude. Can be used when * feature-pack-location or feature-packs are set. + * Use the System property {@code wildfly.provisioning.layers.excluded} to provide a comma separated list of layers to exclude. */ - @Parameter(alias = "excluded-layers", required = false) + @Parameter(alias = "excluded-layers", required = false, property = PropertyNames.WILDFLY_PROVISIONING_LAYERS_EXCLUDED) List excludedLayers = Collections.emptyList(); /** @@ -174,14 +185,18 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug(String.format("Skipping " + getGoal() + " of %s:%s", project.getGroupId(), project.getArtifactId())); return; } + Path targetPath = Paths.get(project.getBuild().getDirectory()); + wildflyDir = targetPath.resolve(provisioningDir).normalize(); + if (!overwriteProvisionedServer && Files.exists(wildflyDir)) { + getLog().info(String.format("A server already exists in " + wildflyDir + ", skipping " + getGoal() + + " of %s:%s", project.getGroupId(), project.getArtifactId())); + return; + } enrichRepositories(); artifactResolver = offlineProvisioning ? new MavenArtifactRepositoryManager(repoSystem, repoSession) : new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories); - - Path targetPath = Paths.get(project.getBuild().getDirectory()); - wildflyDir = targetPath.resolve(provisioningDir).normalize(); - if (Paths.get(provisioningDir).isAbsolute() || targetPath.equals(wildflyDir) || !wildflyDir.startsWith(targetPath)) { - throw new MojoExecutionException("provisioning-dir " + provisioningDir + " must be a child directory relative to the project build directory."); + if (!Paths.get(provisioningDir).isAbsolute() && (targetPath.equals(wildflyDir) || !wildflyDir.startsWith(targetPath))) { + throw new MojoExecutionException("provisioning-dir " + provisioningDir + " must be an absolute path or a child directory relative to the project build directory."); } IoUtils.recursiveDelete(wildflyDir); try { @@ -218,6 +233,8 @@ private void provisionServer(Path home) throws ProvisioningException, ProvisioningConfig config = null; Path resolvedProvisioningFile = resolvePath(project, provisioningFile.toPath()); boolean provisioningFileExists = Files.exists(resolvedProvisioningFile); + // Handle feature-packs provided by system property that would override the one in the config + setFeaturePacksFromProperty(); if (featurePacks.isEmpty()) { if (provisioningFileExists) { getLog().info("Provisioning server using " + resolvedProvisioningFile + " file."); @@ -265,4 +282,28 @@ static Path resolvePath(MavenProject project, Path path) { return path; } + public void setFeaturePacksFromProperty() { + String fps = System.getProperty(PropertyNames.WILDFLY_PROVISIONING_FEATURE_PACKS); + if (fps != null) { + List lst = splitArguments(fps); + featurePacks = new ArrayList<>(); + for (String fp : lst) { + FeaturePack f = new FeaturePack(); + f.setLocation(fp); + featurePacks.add(f); + } + } + } + + private static List splitArguments(final String arguments) { + final List args = new ArrayList<>(); + String[] items = arguments.split(","); + for (String i : items) { + i = i.trim(); + if (!i.isEmpty()) { + args.add(i); + } + } + return args; + } }