Skip to content

Commit ed4774b

Browse files
authored
[MPLUGIN-450] Require goalPrefix to be valid (#240)
1 parent 331cf42 commit ed4774b

File tree

47 files changed

+99
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+99
-23
lines changed

maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ under the License.
9191
<version>@project.version@</version>
9292
<configuration>
9393
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
94+
<goalPrefix>prefix</goalPrefix>
9495
</configuration>
9596
<executions>
9697
<execution>

maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ under the License.
4747
<version>@project.version@</version>
4848
<configuration>
4949
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
50+
<goalPrefix>prefix</goalPrefix>
5051
</configuration>
5152
<executions>
5253
<execution>

maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ under the License.
8787
<version>@project.version@</version>
8888
<configuration>
8989
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
90+
<goalPrefix>prefix</goalPrefix>
9091
</configuration>
9192
<executions>
9293
<execution>

maven-plugin-plugin/src/it/ant-basic/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<artifactId>maven-plugin-plugin</artifactId>
5555
<version>${pluginPluginVersion}</version>
5656
<configuration>
57-
<prefix>antBasic</prefix>
57+
<goalPrefix>antBasic</goalPrefix>
5858
</configuration>
5959
<dependencies>
6060
<dependency>

maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<artifactId>maven-plugin-plugin</artifactId>
5555
<version>${pluginPluginVersion}</version>
5656
<configuration>
57-
<prefix>antSimpleUsage</prefix>
57+
<goalPrefix>antSimpleUsage</goalPrefix>
5858
</configuration>
5959
<dependencies>
6060
<dependency>

maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<version>@project.version@</version>
4343
</dependency>
4444
</dependencies>
45+
<configuration>
46+
<goalPrefix>prefix</goalPrefix>
47+
</configuration>
4548
</plugin>
4649
</plugins>
4750
</build>

maven-plugin-plugin/src/it/asm-failure/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<plugin>
4444
<artifactId>maven-plugin-plugin</artifactId>
4545
<version>@project.version@</version>
46+
<configuration>
47+
<goalPrefix>prefix</goalPrefix>
48+
</configuration>
4649
</plugin>
4750
</plugins>
4851
</build>

maven-plugin-plugin/src/it/beanshell-simple/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<artifactId>maven-plugin-plugin</artifactId>
5454
<version>${pluginPluginVersion}</version>
5555
<configuration>
56-
<prefix>beanshellBasic</prefix>
56+
<goalPrefix>beanshellBasic</goalPrefix>
5757
</configuration>
5858
<dependencies>
5959
<dependency>

maven-plugin-plugin/src/it/help-basic-deprecated-annotation-only/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ under the License.
6565
<groupId>org.apache.maven.plugins</groupId>
6666
<artifactId>maven-plugin-plugin</artifactId>
6767
<version>@project.version@</version>
68+
<configuration>
69+
<goalPrefix>help-deprecated-annotation-only</goalPrefix>
70+
</configuration>
6871
<executions>
6972
<execution>
7073
<id>help-goal</id>

maven-plugin-plugin/src/it/help-basic-jdk11/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ under the License.
7070
<groupId>org.apache.maven.plugins</groupId>
7171
<artifactId>maven-plugin-plugin</artifactId>
7272
<version>@project.version@</version>
73+
<configuration>
74+
<goalPrefix>help-jdk11</goalPrefix>
75+
</configuration>
7376
<executions>
7477
<execution>
7578
<id>default-descriptor</id>

maven-plugin-plugin/src/it/help-basic/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ under the License.
6565
<groupId>org.apache.maven.plugins</groupId>
6666
<artifactId>maven-plugin-plugin</artifactId>
6767
<version>@project.version@</version>
68+
<configuration>
69+
<goalPrefix>help</goalPrefix>
70+
</configuration>
6871
<executions>
6972
<execution>
7073
<id>default-descriptor</id>

maven-plugin-plugin/src/it/help-package/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ under the License.
6161
<version>@project.version@</version>
6262
<configuration>
6363
<helpPackageName>test.help</helpPackageName>
64+
<goalPrefix>prefix</goalPrefix>
6465
</configuration>
6566
<executions>
6667
<execution>

maven-plugin-plugin/src/it/ignore-plugin-class-realm/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ under the License.
5555
<groupId>org.apache.maven.plugins</groupId>
5656
<artifactId>maven-plugin-plugin</artifactId>
5757
<version>@project.version@</version>
58+
<configuration>
59+
<goalPrefix>prefix</goalPrefix>
60+
</configuration>
5861
</plugin>
5962
</plugins>
6063
</pluginManagement>

maven-plugin-plugin/src/it/ignore-plugin-class-realm/test/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ under the License.
5454
<plugin>
5555
<groupId>org.apache.maven.plugins</groupId>
5656
<artifactId>maven-plugin-plugin</artifactId>
57+
<configuration>
58+
<goalPrefix>prefix</goalPrefix>
59+
</configuration>
5760
<dependencies>
5861
<dependency>
5962
<groupId>org.apache.maven.its.plugin</groupId>

maven-plugin-plugin/src/it/java-basic-annotations-jdk8/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ under the License.
8484
<version>@project.version@</version>
8585
<configuration>
8686
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
87+
<goalPrefix>prefix</goalPrefix>
8788
</configuration>
8889
<executions>
8990
<execution>

maven-plugin-plugin/src/it/java-basic-annotations-jdkcurrent/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ under the License.
7979
<version>@project.version@</version>
8080
<configuration>
8181
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
82+
<goalPrefix>prefix</goalPrefix>
8283
</configuration>
8384
<executions>
8485
<execution>

maven-plugin-plugin/src/it/java-basic-annotations/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ under the License.
8181
<version>@project.version@</version>
8282
<configuration>
8383
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
84+
<goalPrefix>prefix</goalPrefix>
8485
</configuration>
8586
<executions>
8687
<execution>

maven-plugin-plugin/src/it/java-basic/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ under the License.
5959
<groupId>org.apache.maven.plugins</groupId>
6060
<artifactId>maven-plugin-plugin</artifactId>
6161
<version>@project.version@</version>
62+
<configuration>
63+
<goalPrefix>prefix</goalPrefix>
64+
</configuration>
6265
</plugin>
6366
</plugins>
6467
</build>

maven-plugin-plugin/src/it/mplugin-223/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<extractor>java-annotations</extractor>
6565
</extractors>
6666
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
67+
<goalPrefix>prefix</goalPrefix>
6768
</configuration>
6869
<executions>
6970
<execution>

maven-plugin-plugin/src/it/mplugin-272_java8/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<goal>descriptor</goal>
6969
</goals>
7070
<configuration>
71+
<goalPrefix>prefix</goalPrefix>
7172
</configuration>
7273
<phase>process-classes</phase>
7374
</execution>

maven-plugin-plugin/src/it/mplugin-299_no-configuration/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ under the License.
6565
<groupId>org.apache.maven.plugins</groupId>
6666
<artifactId>maven-plugin-plugin</artifactId>
6767
<version>@project.version@</version>
68+
<configuration>
69+
<goalPrefix>prefix</goalPrefix>
70+
</configuration>
6871
<executions>
6972
<execution>
7073
<id>default-descriptor</id>

maven-plugin-plugin/src/it/mplugin-305_defaultMojoDependencies/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<extractor>java-annotations</extractor>
6969
</extractors>
7070
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
71+
<goalPrefix>prefix</goalPrefix>
7172
</configuration>
7273
<executions>
7374
<execution>

maven-plugin-plugin/src/it/mplugin-305_emptyMojoDependencies/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<extractor>java-annotations</extractor>
6969
</extractors>
7070
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
71+
<goalPrefix>prefix</goalPrefix>
7172
</configuration>
7273
<executions>
7374
<execution>

maven-plugin-plugin/src/it/mplugin-305_singleMojoDependencies/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<mojoDependencies>
7272
<mojoDependency>org.apache.maven.surefire:maven-surefire-common</mojoDependency>
7373
</mojoDependencies>
74+
<goalPrefix>prefix</goalPrefix>
7475
</configuration>
7576
<executions>
7677
<execution>

maven-plugin-plugin/src/it/mplugin-324_javadoc/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ under the License.
7373
<groupId>org.apache.maven.plugins</groupId>
7474
<artifactId>maven-plugin-plugin</artifactId>
7575
<version>@project.version@</version>
76+
<configuration>
77+
<goalPrefix>prefix</goalPrefix>
78+
</configuration>
7679
<executions>
7780
<execution>
7881
<id>default-descriptor</id>

maven-plugin-plugin/src/it/mplugin-363_help-reproducible/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ under the License.
6565
<groupId>org.apache.maven.plugins</groupId>
6666
<artifactId>maven-plugin-plugin</artifactId>
6767
<version>@project.version@</version>
68+
<configuration>
69+
<goalPrefix>prefix</goalPrefix>
70+
</configuration>
6871
<executions>
6972
<execution>
7073
<id>help-goal</id>

maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ under the License.
7373
<version>@project.version@</version>
7474
<configuration>
7575
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
76+
<goalPrefix>prefix</goalPrefix>
7677
</configuration>
7778
<executions>
7879
<execution>

maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ under the License.
7979
<version>@project.version@</version>
8080
<configuration>
8181
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
82+
<goalPrefix>prefix</goalPrefix>
8283
</configuration>
8384
<executions>
8485
<execution>

maven-plugin-plugin/src/it/mplugin-372-annotation-with-inheritance-from-provided-deps/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ under the License.
9494
<version>@project.version@</version>
9595
<configuration>
9696
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
97+
<goalPrefix>prefix</goalPrefix>
9798
</configuration>
9899
<executions>
99100
<execution>

maven-plugin-plugin/src/it/mplugin-382-exclude-provided-dependency/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ under the License.
8787
<groupId>org.apache.maven.plugins</groupId>
8888
<artifactId>maven-plugin-plugin</artifactId>
8989
<version>@project.version@</version>
90+
<configuration>
91+
<goalPrefix>prefix</goalPrefix>
92+
</configuration>
9093
</plugin>
9194
</plugins>
9295

maven-plugin-plugin/src/it/mplugin-390/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ under the License.
107107
<groupId>org.apache.maven.plugins</groupId>
108108
<artifactId>maven-plugin-plugin</artifactId>
109109
<version>@project.version@</version>
110+
<configuration>
111+
<goalPrefix>prefix</goalPrefix>
112+
</configuration>
110113
</plugin>
111114
</plugins>
112115

maven-plugin-plugin/src/it/packaging-jar/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ under the License.
7272
<packagingTypes>
7373
<packaging>jar</packaging>
7474
</packagingTypes>
75+
<goalPrefix>prefix</goalPrefix>
7576
</configuration>
7677
<executions>
7778
<execution>

maven-plugin-plugin/src/it/skip/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ under the License.
5050
<groupId>org.apache.maven.plugins</groupId>
5151
<artifactId>maven-plugin-plugin</artifactId>
5252
<version>@project.version@</version>
53+
<configuration>
54+
<goalPrefix>prefix</goalPrefix>
55+
</configuration>
5356
</plugin>
5457
</plugins>
5558
</build>

maven-plugin-plugin/src/it/source-encoding/latin-1/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ under the License.
6161
<groupId>org.apache.maven.plugins</groupId>
6262
<artifactId>maven-plugin-plugin</artifactId>
6363
<version>@project.version@</version>
64+
<configuration>
65+
<goalPrefix>prefix</goalPrefix>
66+
</configuration>
6467
</plugin>
6568
</plugins>
6669
</build>

maven-plugin-plugin/src/it/source-encoding/utf-8/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ under the License.
6161
<groupId>org.apache.maven.plugins</groupId>
6262
<artifactId>maven-plugin-plugin</artifactId>
6363
<version>@project.version@</version>
64+
<configuration>
65+
<goalPrefix>prefix</goalPrefix>
66+
</configuration>
6467
</plugin>
6568
</plugins>
6669
</build>

maven-plugin-plugin/src/it/v4api/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ under the License.
6464
<groupId>org.apache.maven.plugins</groupId>
6565
<artifactId>maven-plugin-plugin</artifactId>
6666
<version>@project.version@</version>
67+
<configuration>
68+
<goalPrefix>prefix</goalPrefix>
69+
</configuration>
6770
<executions>
6871
<execution>
6972
<id>help-goal</id>

maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.apache.maven.plugin.AbstractMojo;
2525
import org.apache.maven.plugin.MojoExecutionException;
26-
import org.apache.maven.plugin.descriptor.PluginDescriptor;
2726
import org.apache.maven.plugins.annotations.Parameter;
2827
import org.apache.maven.project.MavenProject;
2928

@@ -81,28 +80,24 @@ public void execute() throws MojoExecutionException {
8180
return;
8281
}
8382

84-
String defaultGoalPrefix = getDefaultGoalPrefix(project);
85-
86-
if (goalPrefix == null) {
87-
goalPrefix = defaultGoalPrefix;
88-
} else if (!goalPrefix.equals(defaultGoalPrefix)) {
89-
getLog().warn(LS + LS + "Goal prefix is specified as: '" + goalPrefix + "'. "
90-
+ "Maven currently expects it to be '" + defaultGoalPrefix + "'." + LS);
83+
if (goalPrefix == null || goalPrefix.isEmpty()) {
84+
goalPrefix = getDefaultGoalPrefix(project);
85+
}
86+
if (goalPrefix == null || goalPrefix.isEmpty()) {
87+
throw new MojoExecutionException("You need to specify a goalPrefix as it can not be correctly computed");
9188
}
9289

9390
generate();
9491
}
9592

9693
static String getDefaultGoalPrefix(MavenProject project) {
97-
String defaultGoalPrefix;
98-
if ("maven-plugin-report-plugin".equalsIgnoreCase(project.getArtifactId())) {
99-
defaultGoalPrefix = "plugin-report";
100-
} else if ("maven-plugin".equalsIgnoreCase(project.getArtifactId())) {
101-
defaultGoalPrefix =
102-
project.getGroupId().substring(project.getGroupId().lastIndexOf('.') + 1);
94+
String artifactId = project.getArtifactId();
95+
if (artifactId.endsWith("-maven-plugin")) {
96+
return artifactId.substring(0, artifactId.length() - "-maven-plugin".length());
97+
} else if (artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) {
98+
return artifactId.substring("maven-".length(), artifactId.length() - "-plugin".length());
10399
} else {
104-
defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId());
100+
return null;
105101
}
106-
return defaultGoalPrefix;
107102
}
108103
}

maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojoTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ public static Stream<Arguments> goalPrefixes() {
3636
arguments(null, "maven-plugin-plugin", "plugin"),
3737
arguments(null, "maven-plugin-report-plugin", "plugin-report"),
3838
arguments(null, "maven-default-plugin", "default"),
39-
arguments(null, "default-maven-plugin", "default"),
40-
arguments(null, "default-maven-plugin", "default"),
41-
arguments("foo.bar", "maven-plugin", "bar"),
42-
arguments("foo", "maven-plugin", "foo"));
39+
arguments(null, "default-maven-plugin", "default"));
4340
}
4441

4542
@ParameterizedTest

maven-plugin-report-plugin/src/it/mplugin-191/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ under the License.
6161
<version>@project.version@</version>
6262
<configuration>
6363
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
64+
<goalPrefix>prefix</goalPrefix>
6465
</configuration>
6566
</plugin>
6667
<plugin>

0 commit comments

Comments
 (0)