diff --git a/core/pom.xml b/core/pom.xml index 28e6394e..ce10ca19 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -72,7 +72,11 @@ org.jboss.galleon - galleon-maven-plugin + galleon-core + + + org.jboss.galleon + galleon-maven-universe diff --git a/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java b/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java new file mode 100644 index 00000000..24179b7a --- /dev/null +++ b/core/src/main/java/org/wildfly/plugin/core/ConfigurationId.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.plugin.core; + +import org.jboss.galleon.config.ConfigId; + +/** + * Simple wrapper for configuration ids. + * @author Emmanuel Hugonnet (c) 2018 Red Hat, inc. + */ +public class ConfigurationId { + + private String name; + private String model; + + public ConfigurationId() { + } + + public void setName(String name) { + this.name = name; + } + + public void setModel(String model) { + this.model = model; + } + + public ConfigId getId() { + return new ConfigId(model, name); + } + + public boolean isModelOnly() { + return name == null || name.isEmpty(); + } + + public String toString() { + final StringBuilder buf = new StringBuilder(); + buf.append("{"); + if(model != null) { + buf.append("model=").append(model); + } + if(name != null) { + if(buf.length() > 1) { + buf.append(' '); + } + buf.append("name=").append(name); + } + return buf.append('}').toString(); + } +} diff --git a/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java b/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java new file mode 100644 index 00000000..66c7c5b8 --- /dev/null +++ b/core/src/main/java/org/wildfly/plugin/core/FeaturePack.java @@ -0,0 +1,258 @@ +/* + * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.plugin.core; + +import java.io.File; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.shared.artifact.ArtifactCoordinate; +import org.apache.maven.shared.dependencies.DependableCoordinate; +import org.jboss.galleon.util.StringUtils; + +/** + * + * @author Alexey Loubyanssky + */ +public class FeaturePack implements DependableCoordinate, ArtifactCoordinate { + + private String groupId; + private String artifactId; + private String version; + private String type = "zip"; + private String classifier; + private String extension = "zip"; + + private boolean transitiveDep; + private String location; + + private Boolean inheritConfigs; + private List includedConfigs = Collections.emptyList(); + private List excludedConfigs = Collections.emptyList(); + + private Boolean inheritPackages; + private List excludedPackages = Collections.emptyList(); + private List includedPackages = Collections.emptyList(); + + private Path path; + + @Override + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + assertMavenCoordinates(); + this.groupId = groupId; + } + + @Override + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + assertMavenCoordinates(); + this.artifactId = artifactId; + } + + @Override + public String getVersion() { + return version; + } + + public void setVersion(String version) { + assertMavenCoordinates(); + this.version = version; + } + + @Override + public String getType() { + return type; + } + + public void setType(String type) { + assertMavenCoordinates(); + this.type = type; + } + + @Override + public String getClassifier() { + return classifier; + } + + public void setClassifier(String classifier) { + assertMavenCoordinates(); + this.classifier = classifier; + } + + @Override + public String getExtension() { + return extension; + } + + public void setExtension(String extension) { + assertMavenCoordinates(); + this.extension = extension; + } + + public boolean isTransitive() { + return transitiveDep; + } + + public void setTransitive(boolean transitiveDep) { + this.transitiveDep = transitiveDep; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + assertLocation(); + if (location == null) { + throw new IllegalStateException("Feature-pack location can't be null"); + } + location = location.trim(); + if (location.isEmpty()) { + throw new IllegalStateException("Feature-pack location can't be empty"); + } + this.location = location; + } + + public Boolean isInheritPackages() { + return inheritPackages; + } + + public void setInheritPackages(boolean inheritPackages) { + this.inheritPackages = inheritPackages; + } + + public Boolean isInheritConfigs() { + return inheritConfigs; + } + + public void setInheritConfigs(boolean inheritConfigs) { + this.inheritConfigs = inheritConfigs; + } + + public List getIncludedConfigs() { + return includedConfigs; + } + + public void setIncludedConfigs(List includedConfigs) { + this.includedConfigs = includedConfigs; + } + + public List getExcludedConfigs() { + return excludedConfigs; + } + + public void setExcludedConfigs(List excludedConfigs) { + this.excludedConfigs = excludedConfigs; + } + + public List getExcludedPackages() { + return excludedPackages; + } + + public void setExcludedPackages(List excludedPackages) { + this.excludedPackages = excludedPackages; + } + + public List getIncludedPackages() { + return includedPackages; + } + + public void setIncludedPackages(List includedPackages) { + this.includedPackages = includedPackages; + } + + public void setPath(File path) { + assertPathLocation(); + this.path = path.toPath().normalize(); + } + + public Path getNormalizedPath() { + return path; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder(); + buf.append('{'); + if(transitiveDep) { + buf.append("transitive "); + } + if(location != null) { + buf.append(location); + } else { + buf.append(groupId).append(':').append(artifactId).append(':').append(version); + } + buf.append(" inherit-packages=").append(inheritPackages); + if(!includedPackages.isEmpty()) { + buf.append(" included-packages="); + StringUtils.appendList(buf, includedPackages); + } + if(!excludedPackages.isEmpty()) { + buf.append(" excluded-packages="); + StringUtils.appendList(buf, excludedPackages); + } + buf.append(" inherit-configs=").append(inheritConfigs); + if(!includedConfigs.isEmpty()) { + buf.append(" included-configs="); + StringUtils.appendList(buf, includedConfigs); + } + if(!excludedConfigs.isEmpty()) { + buf.append(" excluded-configs="); + StringUtils.appendList(buf, excludedConfigs); + } + return buf.append('}').toString(); + } + + private void assertPathLocation() { + if (groupId != null || artifactId != null || version != null) { + throw new IllegalStateException("feature-pack Path cannot be used: feature-pack Maven coordinates have already been initialized"); + } + if (location != null) { + throw new IllegalStateException("feature-pack Path cannot be used: location has already been initialized"); + } + } + + private void assertLocation() { + if(groupId != null || artifactId != null || version != null) { + throw new IllegalStateException("Location can't bet set, feature-pack Maven coordinates have already been initialized"); + } + if (path != null) { + throw new IllegalStateException("Location can't bet set, feature-pack Path has already been initialized"); + } + } + + private void assertMavenCoordinates() { + if(location != null) { + throw new IllegalStateException("Feature-pack Maven coordinates cannot be used: feature-pack location has already been initialized"); + } + if (path != null) { + throw new IllegalStateException("Feature-pack Maven coordinates cannot be used: feature-pack Path has already been initialized"); + } + } + + public void set(String location) { + setLocation(location); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java b/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java index 1ac99d39..31b9d522 100644 --- a/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java +++ b/core/src/main/java/org/wildfly/plugin/core/GalleonUtils.java @@ -28,8 +28,6 @@ import org.jboss.galleon.config.ConfigModel; import org.jboss.galleon.config.FeaturePackConfig; import org.jboss.galleon.config.ProvisioningConfig; -import org.jboss.galleon.maven.plugin.util.ConfigurationId; -import org.jboss.galleon.maven.plugin.util.FeaturePack; import org.jboss.galleon.universe.FeaturePackLocation; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.jboss.galleon.xml.ProvisioningXmlParser; 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..1f2fa678 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java @@ -41,7 +41,6 @@ import org.jboss.galleon.ProvisioningException; import org.jboss.galleon.ProvisioningManager; import org.jboss.galleon.config.ProvisioningConfig; -import org.jboss.galleon.maven.plugin.util.FeaturePack; import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager; import org.jboss.galleon.maven.plugin.util.MvnMessageWriter; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; @@ -52,6 +51,7 @@ import org.wildfly.plugin.core.GalleonUtils; import static org.wildfly.plugin.core.Constants.PLUGIN_PROVISIONING_FILE; import static org.wildfly.plugin.core.Constants.STANDALONE_XML; +import org.wildfly.plugin.core.FeaturePack; import org.wildfly.plugin.core.MavenRepositoriesEnricher; @@ -123,30 +123,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") + @Parameter(required = false, alias= "feature-packs", property = PropertyNames.WILDFLY_PROVISIONING_FEATURE_PACKS) List 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 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 +184,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 { @@ -264,5 +278,4 @@ static Path resolvePath(MavenProject project, Path path) { } return path; } - } diff --git a/pom.xml b/pom.xml index 878fd89b..26648479 100644 --- a/pom.xml +++ b/pom.xml @@ -249,6 +249,16 @@ galleon-maven-plugin ${version.org.jboss.galleon} + + org.jboss.galleon + galleon-core + ${version.org.jboss.galleon} + + + org.jboss.galleon + galleon-maven-universe + ${version.org.jboss.galleon} + org.jboss.logging jboss-logging