Skip to content

Commit

Permalink
[CONVERSION COMMIT] Remove WFMP-269, Allow multiple deployments to be…
Browse files Browse the repository at this point in the history
… used for the package goal
  • Loading branch information
jfdenise committed Dec 3, 2024
1 parent f96b12e commit 9b26559
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 174 deletions.
4 changes: 0 additions & 4 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.galleon</groupId>
<artifactId>galleon-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter;
import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
import org.apache.maven.shared.artifact.filter.ScopeArtifactFilter;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.api.GalleonBuilder;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
Expand All @@ -54,16 +43,6 @@

/**
* Provision a server, copy extra content and deploy primary artifact if it exists.
* <p>
* Additional deployments can also be resolved from the dependencies. Use the {@code <included-dependencies/>},
* {@code <excluded-dependencies/>}, {@code <included-dependency-scope/>} and/or {@code <excluded-dependency-scope/>}
* to deploy additional artifacts to the packaged server.
* </p>
* <p>
* Note the {@code <included-dependencies/>}, {@code <excluded-dependencies/>}, {@code included-dependency-scope} and
* {@code <excluded-ependency-scope/>} configuration properties are chained together and all checks must pass to be
* included as additional deployments.
* </p>
*
* @author jfdenise
* @since 3.0
Expand Down Expand Up @@ -190,7 +169,7 @@ public class PackageServerMojo extends AbstractProvisionServerMojo {
private boolean skip;

/**
* Skip deploying the deployments after the server is provisioned ({@code false} by default).
* Skip deploying the deployment after the server is provisioned ({@code false} by default).
*/
@Parameter(defaultValue = "false", property = PropertyNames.SKIP_PACKAGE_DEPLOYMENT)
protected boolean skipDeployment;
Expand Down Expand Up @@ -231,66 +210,6 @@ public class PackageServerMojo extends AbstractProvisionServerMojo {
@Parameter(alias = "bootable-jar-install-artifact-classifier", property = PropertyNames.BOOTABLE_JAR_INSTALL_CLASSIFIER, defaultValue = BootableJarSupport.BOOTABLE_SUFFIX)
private String bootableJarInstallArtifactClassifier;

/**
* A list of the dependencies to include as deployments. These dependencies must be defined as dependencies in the
* project.
*
* <p>
* The pattern is {@code groupId:artifactId:type:classifier:version}. Each type may be left blank. A pattern can
* be prefixed with a {@code !} to negatively match the pattern. Note that it is best practice to place negative
* checks first.
* </p>
*
* <pre>
* &lt;included-dependencies&gt;
* &lt;included&gt;!org.wildfly.examples:*test*&lt;/included&gt;
* &lt;included&gt;::war&lt;/included&gt;
* &lt;included&gt;org.wildfly.examples&lt;/included&gt;
* &lt;/included-dependencies&gt;
* </pre>
*
* @since 5.1
*/
@Parameter(alias = "included-dependencies", property = "wildfly.included.dependencies")
private Set<String> includedDependencies = Set.of();

/**
* A list of the dependencies to exclude as deployments.
*
* <p>
* The pattern is {@code groupId:artifactId:type:classifier:version}. Each type may be left blank. A pattern can
* be prefixed with a {@code !} to negatively match the pattern. Note that it is best practice to place negative
* checks first.
* </p>
*
* <pre>
* &lt;excluded-dependencies&gt;
* &lt;excluded&gt;!org.wildfly.examples:*test*&lt;/excluded&gt;
* &lt;excluded&gt;::jar&lt;/excluded&gt;
* &lt;/excluded-dependencies&gt;
* </pre>
*
* @since 5.1
*/
@Parameter(alias = "excluded-dependencies", property = "wildfly.excluded.dependencies")
private Set<String> excludedDependencies = Set.of();

/**
* Defines the scope of the dependencies to be included as deployments. This will deploy all dependencies defined
* in the scope to the packaged server. However, this does assume the dependency passes the
* {@code <included-dependencies/>}, {@code <excluded-dependencies/>} and {@code <excluded-dependency-scope/>} checks.
*/
@Parameter(alias = "included-dependency-scope", property = "wildfly.included.dependency.scope")
private String includedDependencyScope;

/**
* Defines the scope of the dependencies to be excluded as deployments. This will deploy all dependencies
* <em>not</em> defined in the scope to the packaged server. However, this does assume the dependency passes the
* {@code <included-dependencies/>}, {@code <excluded-dependencies/>} and {@code <included-dependency-scope/>} checks.
*/
@Parameter(alias = "excluded-dependency-scope", property = "wildfly.excluded.dependency.scope")
private String excludedDependencyScope;

@Inject
private OfflineCommandExecutor commandExecutor;

Expand Down Expand Up @@ -340,36 +259,6 @@ private void deploy(Path deploymentContent, String targetName) throws MojoDeploy
}
}

private Map<String, Path> getDeployments() throws MojoExecutionException {
final List<ArtifactFilter> filters = new ArrayList<>();
if (!includedDependencies.isEmpty()) {
filters.add(new PatternIncludesArtifactFilter(includedDependencies));
}
if (!excludedDependencies.isEmpty()) {
filters.add(new PatternExcludesArtifactFilter(excludedDependencies));
}
if (includedDependencyScope != null) {
filters.add(createScopeFilter(includedDependencyScope, true));
}
if (excludedDependencyScope != null) {
filters.add(createScopeFilter(excludedDependencyScope, false));
}
final ArtifactFilter filter = new AndArtifactFilter(filters);
final Set<Artifact> deployments = project.getArtifacts().stream()
.filter(filter::include)
.collect(Collectors.toSet());
final Map<String, Path> deploymentPaths = new LinkedHashMap<>();
for (var artifact : deployments) {
final File f = artifact.getFile();
if (f == null) {
throw new MojoExecutionException("Deployment not found " + artifact);
}
final Path p = f.toPath();
deploymentPaths.put(p.getFileName().toString(), p);
}
return deploymentPaths;
}

@Override
protected void serverProvisioned(Path jbossHome) throws MojoExecutionException, MojoFailureException {
try {
Expand All @@ -391,15 +280,6 @@ protected void serverProvisioned(Path jbossHome) throws MojoExecutionException,
if (primaryDeployment != null) {
deploy(primaryDeployment, getDeploymentTargetName());
}
// Handle extra deployments
try {
Map<String, Path> extraPaths = getDeployments();
for (Entry<String, Path> p : extraPaths.entrySet()) {
deploy(p.getValue(), p.getKey());
}
} catch (Exception ex) {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}
}

// CLI execution
Expand Down Expand Up @@ -585,28 +465,6 @@ private static void cleanupServer(Path jbossHome) throws IOException {
IoUtils.recursiveDelete(log);
}

private static ArtifactFilter createScopeFilter(final String scope, final boolean includeScope) {
final ScopeArtifactFilter filter = new ScopeArtifactFilter();
switch (scope) {
case Artifact.SCOPE_COMPILE:
filter.setIncludeCompileScope(true);
break;
case Artifact.SCOPE_PROVIDED:
filter.setIncludeProvidedScope(true);
break;
case Artifact.SCOPE_RUNTIME:
filter.setIncludeRuntimeScope(true);
break;
case Artifact.SCOPE_TEST:
filter.setIncludeTestScope(true);
break;
case Artifact.SCOPE_SYSTEM:
filter.setIncludeSystemScope(true);
break;
}
return includeScope ? filter : artifact -> !filter.include(artifact);
}

@Override
protected void enrichRepositories() throws MojoExecutionException {
// NO-OP
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
</version.org.apache.maven.plugin-testing.maven-plugin-testing-harness>
<version.org.apache.maven.plugin-tools>3.7.0</version.org.apache.maven.plugin-tools>
<version.org.apache.maven.shared>0.10.1</version.org.apache.maven.shared>
<version.org.apache.maven.shared.filter>3.4.0</version.org.apache.maven.shared.filter>
<version.org.apache.maven.resolver>1.9.18</version.org.apache.maven.resolver>
<version.org.codehaus.plexus>3.5.1</version.org.codehaus.plexus>
<!-- maven dependencies only required by tests -->
Expand Down Expand Up @@ -288,11 +287,6 @@
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${version.org.apache.maven.resolver}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>${version.org.apache.maven.shared.filter}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,4 @@ public void testInvalidDeployment2() throws Exception {
+ "A runtime-name has been set that indicates that a deployment is expected. "));
}
}

@Test
public void testMultipleDeploymentsPackage() throws Exception {
final Mojo packageMojo = lookupConfiguredMojo(
AbstractWildFlyMojoTest.getPomFile("package-multiple-deployments-pom.xml").toFile(), "package");
String[] layers = { "jaxrs-server" };
packageMojo.execute();
Path jbossHome = AbstractWildFlyMojoTest.getBaseDir().resolve("target").resolve("packaged-multiple-deployments-server");
checkStandaloneWildFlyHome(jbossHome, 2, layers, null, true);
}

@Test
public void testMultipleDeploymentsMissingPackage() throws Exception {
final Mojo packageMojo = lookupConfiguredMojo(
AbstractWildFlyMojoTest.getPomFile("package-multiple-deployments-missing-pom.xml").toFile(), "package");
String[] layers = { "jaxrs-server" };
packageMojo.execute();
Path jbossHome = AbstractWildFlyMojoTest.getBaseDir().resolve("target")
.resolve("packaged-multiple-deployments-missing-server");
checkStandaloneWildFlyHome(jbossHome, 1, layers, null, true);
}
}

0 comments on commit 9b26559

Please sign in to comment.