Skip to content

Commit

Permalink
Fix for WFMP-148, Support for iterative development workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Mar 21, 2022
1 parent 9957a41 commit 0c78f3d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,30 +124,40 @@ 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<FeaturePack> featurePacks = Collections.emptyList();

/**
* 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<String> 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<String> excludedLayers = Collections.emptyList();

/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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<String> lst = splitArguments(fps);
featurePacks = new ArrayList<>();
for (String fp : lst) {
FeaturePack f = new FeaturePack();
f.setLocation(fp);
featurePacks.add(f);
}
}
}

private static List<String> splitArguments(final String arguments) {
final List<String> args = new ArrayList<>();
String[] items = arguments.split(",");
for (String i : items) {
i = i.trim();
if (!i.isEmpty()) {
args.add(i);
}
}
return args;
}
}

0 comments on commit 0c78f3d

Please sign in to comment.