Skip to content

Commit 519eb58

Browse files
committed
[WFGP-291] Allow use of AbstractFeaturePackBuildMojo as the primary artifact generator for a maven module
1 parent c52926e commit 519eb58

File tree

8 files changed

+210
-2
lines changed

8 files changed

+210
-2
lines changed

docs/guide/maven-plugins/goals/build-feature-pack/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[[build_feature_pack]]
12
include::../../../../../maven-plugin/target/generated-sources/plugin/build-feature-pack-mojo.adoc[]
23

34
include::packages/index.adoc[]

docs/guide/maven-plugins/goals/build-user-feature-pack/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[[build_user_feature_pack]]
12
include::../../../../../maven-plugin/target/generated-sources/plugin/build-user-feature-pack-mojo.adoc[]
23

34
#### Plugin configuration

docs/guide/maven-plugins/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ include::provision-dist/index.adoc[]
1616

1717
include::goals/index.adoc[]
1818

19+
include::maven-extension/index.adoc[]
20+
1921
include::wildfly-feature-pack-build-xml/index.adoc[]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[[maven-extension]]
2+
### Using the plugin as a Maven Extension
3+
4+
Your project can be configured to use the plugin as a Maven extension. If you do this, Maven will allow you to use one of two new `packaging` types for your Maven module: `galleon-feature-pack` or `galleon-user-feature-pack`. You would use these instead of the `pom` packaging that's typically used.
5+
6+
There are two main benefits of doing this:
7+
8+
* It results in a default `package` phase execution of this plugin's `<<build_feature_pack,build-feature-pack>>` or `<<build_user_feature_pack,build-user-feature-pack>>` goal, saving you the XML boilerplate of specifying executions and an execution id, goal and phase.
9+
* It results in the plugin using the built feature pack as the main artifact of the project build, instead of attaching it as an additional artifact with a `null` Maven classifier. Doing it this way avoids problems some other plugins have with additional attachments with a `null` qualifier.
10+
11+
To tell Maven to use the plugin as a Maven extension, in the plugin declaration include the `extensions` element with a value of `true`:
12+
13+
[source,xml]
14+
----
15+
<plugin>
16+
<groupId>org.wildfly.galleon-plugins</groupId>
17+
<artifactId>wildfly-galleon-maven-plugin</artifactId>
18+
<extensions>true</extensions>
19+
----
20+
21+
#### Packaging type `galleon-feature-pack`
22+
23+
Use this packaging type when you wish to use the `<<build_feature_pack,build-feature-pack>>` goal. To use it, configure the pom's top-level `packaging` element:
24+
25+
[source,xml]
26+
----
27+
<packaging>galleon-feature-pack</packaging>
28+
----
29+
30+
When this packaging type is used, Maven will execute default plugins in the `package`, `install` and `deploy` phases (assuming the command to launch maven enables those phases). It will also execute any other plugins configured in your pom.
31+
32+
WARNING: If you are migrating a pom that used any `packaging` value other than `pom` (for example `jar`), plugin executions for other phases that previously happened by default will no longer happen and will need to be manually declared in the pom.
33+
34+
The important thing here is the default plugin execution for the `package` phase is this plugin's `<<build_feature_pack,build-feature-pack>>` goal. That goal will be executed, using whatever configuration is specified for the `default-build-feature-pack` execution id.
35+
36+
IMPORTANT: If you are using the `galleon-feature-pack` packaging type, use `default-build-feature-pack` as the execution id in the plugin configuration. Better yet, skip the `executions` element boilerplate and place any `configuration` element directly under the `plugin` root.
37+
38+
An example plugin configuration might look like this:
39+
40+
[source,xml]
41+
----
42+
<plugin>
43+
<groupId>org.wildfly.galleon-plugins</groupId>
44+
<artifactId>wildfly-galleon-maven-plugin</artifactId>
45+
<extensions>true</extensions>
46+
<configuration>
47+
<fork-embedded>true</fork-embedded>
48+
<generate-channel-manifest>true</generate-channel-manifest>
49+
<minimum-stability-level>preview</minimum-stability-level>
50+
<config-stability-level>preview</config-stability-level>
51+
<package-stability-level>preview</package-stability-level>
52+
</configuration>
53+
</plugin>
54+
----
55+
56+
57+
#### Packaging type `galleon-user-feature-pack`
58+
59+
Use this packaging type when you wish to use the `<<build_user_feature_pack,build-user-feature-pack>>` goal. To use it, configure the pom's top-level `packaging` element:
60+
61+
[source,xml]
62+
----
63+
<packaging>galleon-user-feature-pack</packaging>
64+
----
65+
66+
When this packaging type is used, Maven will execute default plugins in the `package`, `install` and `deploy` phases (assuming the command to launch maven enables those phases). It will also execute any other plugins configured in your pom.
67+
68+
WARNING: If you are migrating a pom that used any `packaging` value other than `pom` (for example `jar`), plugin executions for other phases that previously happened by default will no longer happen and will need to be manually declared in the pom.
69+
70+
The important thing here is the default plugin execution for the `package` phase is this plugin's `<<build_user_feature_pack,build-user-feature-pack>>` goal. That goal will be executed, using whatever configuration is specified for the `default-build-user-feature-pack` execution id.
71+
72+
IMPORTANT: If you are using the `galleon-user-feature-pack` packaging type, use `default-user-build-feature-pack` as the execution id in the plugin configuration. Better yet, skip the `executions` element boilerplate and place any `configuration` element directly under the `plugin` root.

maven-plugin/src/main/java/org/wildfly/galleon/maven/AbstractFeaturePackBuildMojo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ protected Stability getConfigStabilityLevel() {
330330
return defaultConfigStabilityLevel;
331331
}
332332

333+
/**
334+
* Gets the maven packaging type supported by this mojo if this
335+
* plugin is configured to run as a maven extension.
336+
*
337+
* @return the packaging type. By default returns {@code null}
338+
*/
339+
protected String getPackaging() {
340+
return null;
341+
}
342+
333343
private static void checkStabilityLevels(Stability min, Stability config, Stability pkg) throws MojoExecutionException {
334344
min = min == null ? Stability.DEFAULT : min;
335345
config = config == null ? Stability.DEFAULT : config;
@@ -516,8 +526,18 @@ protected void buildFeaturePack(FeaturePackDescription.Builder fpBuilder, WildFl
516526
throw new RuntimeException(ex);
517527
}
518528
ZipUtils.zip(versionDir, target);
519-
debug("Attaching feature-pack %s as a project artifact", target);
520-
projectHelper.attachArtifact(project, "zip", target.toFile());
529+
if (project.getPackaging().equals(getPackaging())) {
530+
if (project.getArtifact().getFile() != null) {
531+
throw new MojoExecutionException("Cannot set " + target.getFileName()
532+
+ " as the main project artifact file as one is already set.");
533+
} else {
534+
debug("Setting feature-pack %s as the main project artifact", target);
535+
project.getArtifact().setFile(target.toFile());
536+
}
537+
} else {
538+
debug("Attaching feature-pack %s as a project artifact", target);
539+
projectHelper.attachArtifact(project, "zip", target.toFile());
540+
}
521541
final Path offLinerTarget = Paths.get(project.getBuild().getDirectory()).resolve(artifactId + '-'
522542
+ versionDir.getFileName() + "-" + ARTIFACT_LIST_CLASSIFIER + "." + ARTIFACT_LIST_EXTENSION);
523543
debug("Attaching feature-pack artifact list %s as a project artifact", offLinerTarget);

maven-plugin/src/main/java/org/wildfly/galleon/maven/UserFeaturePackBuildMojo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public class UserFeaturePackBuildMojo extends AbstractFeaturePackBuildMojo {
112112
private WildFlyFeaturePackBuild buildConfig;
113113
private boolean generate;
114114

115+
@Override
116+
protected String getPackaging() {
117+
return "galleon-user-feature-pack";
118+
}
119+
115120
@Override
116121
protected void doExecute() throws MojoExecutionException, MojoFailureException {
117122

maven-plugin/src/main/java/org/wildfly/galleon/maven/WfFeaturePackBuildMojo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ protected WildFlyFeaturePackBuild getBuildConfig() throws MojoExecutionException
150150
return buildConfig == null ? buildConfig = Util.loadFeaturePackBuildConfig(configDir, configFile) : buildConfig;
151151
}
152152

153+
@Override
154+
protected String getPackaging() {
155+
return "galleon-feature-pack";
156+
}
157+
153158
@Override
154159
protected void doExecute() throws MojoExecutionException, MojoFailureException {
155160
final Path targetResources = Paths.get(buildName, Constants.RESOURCES);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!--
2+
~ Copyright The WildFly Authors
3+
~ SPDX-License-Identifier: Apache-2.0
4+
-->
5+
6+
<!--
7+
Defines Plexus components to allow this plugin to function as
8+
a Maven extension that defines new packaging types 'galleon-feature-pack' and 'galleon-user-feature-pack'.
9+
10+
When building a module with these types, in the 'package' phase this plugin's 'build-feature-pack' or
11+
'build-user-feature-pack' goals will be invoked, using execution id 'default-build-feature-pack' or
12+
'default-build-feature-pack'. The respective mojos behind these goals will detect this and set the
13+
built feature pack zip as the file for the main project artifact, instead of attaching it as a secondary
14+
artifact.
15+
16+
The assumption is users of these packaging types will be migrating poms that previously used the 'pom'
17+
packaging type. So, each uses the same default lifecycle mappings as the 'pom' type, but adds a mapping
18+
for the `package` phase. This will result in migrated poms getting the same default executions as before,
19+
plus an additional execution in `package`.
20+
-->
21+
<component-set>
22+
<components>
23+
<component>
24+
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
25+
<role-hint>galleon-feature-pack</role-hint>
26+
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
27+
<configuration>
28+
<lifecycles>
29+
<lifecycle>
30+
<id>default</id>
31+
<phases>
32+
<package>
33+
org.wildfly.galleon-plugins:wildfly-galleon-maven-plugin:build-feature-pack
34+
</package>
35+
<install>
36+
org.apache.maven.plugins:maven-install-plugin:install
37+
</install>
38+
<deploy>
39+
org.apache.maven.plugins:maven-deploy-plugin:deploy
40+
</deploy>
41+
</phases>
42+
</lifecycle>
43+
</lifecycles>
44+
</configuration>
45+
</component>
46+
<component>
47+
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
48+
<role-hint>galleon-feature-pack</role-hint>
49+
<implementation>
50+
org.apache.maven.artifact.handler.DefaultArtifactHandler
51+
</implementation>
52+
<configuration>
53+
<!--the extension used by Maven in the repository-->
54+
<extension>zip</extension>
55+
<!--the type used when specifying dependencies etc.-->
56+
<type>zip</type>
57+
<!--the packaging used when declaring an implementation of
58+
the packaging-->
59+
<packaging>galleon-feature-pack</packaging>
60+
</configuration>
61+
</component>
62+
<component>
63+
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
64+
<role-hint>galleon-user-feature-pack</role-hint>
65+
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
66+
<configuration>
67+
<lifecycles>
68+
<lifecycle>
69+
<id>default</id>
70+
<phases>
71+
<package>
72+
org.wildfly.galleon-plugins:wildfly-galleon-maven-plugin:build-user-feature-pack
73+
</package>
74+
<install>
75+
org.apache.maven.plugins:maven-install-plugin:install
76+
</install>
77+
<deploy>
78+
org.apache.maven.plugins:maven-deploy-plugin:deploy
79+
</deploy>
80+
</phases>
81+
</lifecycle>
82+
</lifecycles>
83+
</configuration>
84+
</component>
85+
<component>
86+
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
87+
<role-hint>galleon-user-feature-pack</role-hint>
88+
<implementation>
89+
org.apache.maven.artifact.handler.DefaultArtifactHandler
90+
</implementation>
91+
<configuration>
92+
<!--the extension used by Maven in the repository-->
93+
<extension>zip</extension>
94+
<!--the type used when specifying dependencies etc.-->
95+
<type>zip</type>
96+
<!--the packaging used when declaring an implementation of
97+
the packaging-->
98+
<packaging>galleon-user-feature-pack</packaging>
99+
</configuration>
100+
</component>
101+
</components>
102+
</component-set>

0 commit comments

Comments
 (0)