diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
index a3d4f03..5c57b0f 100644
--- a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
+++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
@@ -64,4 +64,16 @@ public @interface Parameter
* @return true if the Mojo should fail when the parameter cannot be injected
*/
boolean required() default false;
+
+ /**
+ * Specifies that this parameter cannot be configured directly by the user (as in the case of POM-specified
+ * configuration). This is useful when you want to force the user to use common POM elements rather than plugin
+ * configurations, as in the case where you want to use the artifact's final name as a parameter. In this case, you
+ * want the user to modify <build><finalName/></build> rather than specifying a value
+ * for finalName directly in the plugin configuration section. It is also useful to ensure that - for example - a
+ * List-typed parameter which expects items of type Artifact doesn't get a List full of Strings.
+ *
+ * @return true if the user should not be allowed to configure the parameter directly
+ */
+ boolean readonly() default false;
}
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
index 68563ad..87ad0dc 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
@@ -42,7 +42,7 @@ public abstract class AbstractFirstMojo
/**
* Project directory.
*/
- @Parameter( defaultValue = "${basedir}" )
+ @Parameter( defaultValue = "${basedir}", readonly = true )
protected File basedir;
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
index d1146ef..b76ba5f 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
@@ -69,7 +69,7 @@ assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.io.File'
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
-assert parameter.editable.text() == 'true'
+assert parameter.editable.text() == 'false'
assert parameter.description.text() == 'Project directory.'
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0]
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java
index 802417e..f0a1263 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java
@@ -42,7 +42,7 @@ public abstract class AbstractFirstMojo
/**
* Project directory.
*/
- @Parameter( defaultValue = "${basedir}" )
+ @Parameter( defaultValue = "${basedir}", readonly = true )
protected File basedir;
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index 0c8cc2e..15dd982 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -53,7 +53,7 @@ public class FirstMojo
@Component( role = "org.apache.maven.project.MavenProjectHelper" )//, roleHint = "default"
private Object projectHelper;
- @Parameter( defaultValue = "${project.artifacts}", required = true )
+ @Parameter( defaultValue = "${project.artifacts}", required = true, readonly = true )
private Set dependencies;
public void execute()
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
index 064ab3a..53f6191 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
@@ -73,7 +73,7 @@ assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.io.File'
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
-assert parameter.editable.text() == 'true'
+assert parameter.editable.text() == 'false'
assert parameter.description.text() == 'Project directory.'
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0]
diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index acf097b..f5814a3 100644
--- a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -45,7 +45,7 @@ public class FirstMojo
/**
* Project directory.
*/
- @Parameter( defaultValue = "${basedir}" )
+ @Parameter( defaultValue = "${basedir}", readonly = true )
private File basedir;
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy
index ee3e464..ff2f74e 100644
--- a/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy
+++ b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy
@@ -67,7 +67,7 @@ assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.io.File'
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
-assert parameter.editable.text() == 'true'
+assert parameter.editable.text() == 'false'
assert parameter.description.text() == 'Project directory.'
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second" }[0]
diff --git a/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java
index 50165fa..9eabcd5 100644
--- a/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java
+++ b/maven-plugin-plugin/src/it/plugin-report-annotations/src/main/java/org/DummyReport.java
@@ -58,7 +58,7 @@ public class DummyReport
/**
* The Maven Project.
*/
- @Parameter( property = "project", required = true )
+ @Parameter( property = "project", readonly = true, required = true )
private MavenProject project;
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
index 878611d..fdc8fb0 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
@@ -490,6 +490,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
parameter.setDefaultValue( parameterAnnotationContent.defaultValue() );
parameter.setDeprecated( parameterAnnotationContent.getDeprecated() );
parameter.setDescription( parameterAnnotationContent.getDescription() );
+ parameter.setEditable( !parameterAnnotationContent.readonly() );
String property = parameterAnnotationContent.property();
if ( StringUtils.contains( property, '$' ) || StringUtils.contains( property, '{' )
|| StringUtils.contains( property, '}' ) )
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java
index e6168f0..a095858 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java
@@ -40,6 +40,8 @@ public class ParameterAnnotationContent
private boolean required = false;
+ private boolean readonly = false;
+
private String className;
public ParameterAnnotationContent( String fieldName, String className )
@@ -49,13 +51,14 @@ public class ParameterAnnotationContent
}
public ParameterAnnotationContent( String fieldName, String alias, String property, String defaultValue,
- boolean required, String className )
+ boolean required, boolean readonly, String className )
{
this( fieldName, className );
this.alias = alias;
this.property = property;
this.defaultValue = defaultValue;
this.required = required;
+ this.readonly = readonly;
}
public String alias()
@@ -98,6 +101,16 @@ public class ParameterAnnotationContent
this.required = required;
}
+ public boolean readonly()
+ {
+ return readonly;
+ }
+
+ public void readonly( boolean readonly )
+ {
+ this.readonly = readonly;
+ }
+
public Class extends Annotation> annotationType()
{
return null;
@@ -123,6 +136,7 @@ public class ParameterAnnotationContent
sb.append( ", property='" ).append( property ).append( '\'' );
sb.append( ", defaultValue='" ).append( defaultValue ).append( '\'' );
sb.append( ", required=" ).append( required );
+ sb.append( ", readonly=" ).append( readonly );
sb.append( '}' );
return sb.toString();
}
@@ -141,6 +155,10 @@ public class ParameterAnnotationContent
ParameterAnnotationContent that = (ParameterAnnotationContent) o;
+ if ( readonly != that.readonly )
+ {
+ return false;
+ }
if ( required != that.required )
{
return false;
@@ -175,6 +193,7 @@ public class ParameterAnnotationContent
result = 31 * result + ( property != null ? property.hashCode() : 0 );
result = 31 * result + ( defaultValue != null ? defaultValue.hashCode() : 0 );
result = 31 * result + ( required ? 1 : 0 );
+ result = 31 * result + ( readonly ? 1 : 0 );
return result;
}
}
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
index 53eef1f..a4738bd 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
@@ -83,7 +83,8 @@ public class TestAnnotationsReader
Collection parameters = mojoAnnotatedClass.getParameters().values();
Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
- new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", true, String.class.getName() ),
- new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", false, String.class.getName() ) );
+ new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", true, false, String.class.getName() ),
+ new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", false, false,
+ String.class.getName() ) );
}
}