Skip to content

Commit

Permalink
[MPLUGIN-435] Revert MPLUGIN-410. Drop @Parameter.implementation and …
Browse files Browse the repository at this point in the history
…keep it a corner case for now to stick to a more efficient API.
  • Loading branch information
rmannibucau authored and slawekjaranowski committed Oct 28, 2022
1 parent ebdb063 commit 5b60490
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@
*/
String defaultValue() default "";

/**
* Defines the implementation in the case the parameter type is an interface.
*
* @return the implementation class name
*/
Class<?> implementation() default Object.class;

/**
* is the parameter required?
* @return <code>true</code> if the Mojo should fail when the parameter cannot be injected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def pluginDescriptor = new XmlParser().parse( descriptorFile );
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0]

assert mojo.goal.text() == 'first'
assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo'
assert mojo.language.text() == 'java'
assert mojo.description.text() == 'Touches a test file.'
assert mojo.deprecated.text() == "Don't use!"
Expand All @@ -44,11 +43,9 @@ assert mojo.executePhase.text() == 'package'
assert mojo.executeLifecycle.text() == 'my-lifecycle'

assert mojo.configuration.bar[0].text() == '${thebar}'
assert mojo.configuration.bar[0].'@implementation' == 'java.lang.String'
assert mojo.configuration.bar[0].'@default-value' == 'coolbar'

assert mojo.configuration.beer[0].text() == '${thebeer}'
assert mojo.configuration.beer[0].'@implementation' == 'java.lang.String'
assert mojo.configuration.beer[0].'@default-value' == 'coolbeer'

assert mojo.requirements.requirement.size() == 2
Expand All @@ -61,14 +58,13 @@ assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project
assert mojo.requirements.requirement[1].'role-hint'.text() == ''
assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper'

assert mojo.parameters.parameter.size() == 7
assert mojo.parameters.parameter.size() == 6

def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0]

assert parameter.name.text() == 'aliasedParam'
assert parameter.alias.text() == 'alias'
assert parameter.type.text() == 'java.lang.String'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.text() == 'As of 0.2'
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
Expand All @@ -79,7 +75,6 @@ parameter = mojo.parameters.parameter.findAll{ it.name.text() == "beer"}[0]
assert parameter.name.text() == 'beer'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.text() == "wine is better"
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
Expand All @@ -90,29 +85,16 @@ parameter = mojo.parameters.parameter.findAll{ it.name.text() == "bar"}[0]
assert parameter.name.text() == 'bar'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == 'the cool bar to go'

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "fooInterface"}[0]

assert parameter.name.text() == 'fooInterface'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.tools.plugin.extractor.annotations.FooInterface'
assert parameter.implementation.text() == 'org.apache.maven.tools.plugin.extractor.annotations.FooInterfaceImpl'
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == 'Interface type as parameter.'

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "paramFromSetter"}[0]

assert parameter.name.text() == 'paramFromSetter'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
Expand All @@ -123,7 +105,6 @@ parameter = mojo.parameters.parameter.findAll{ it.name.text() == "paramFromAdd"}
assert parameter.name.text() == 'paramFromAdd'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
Expand All @@ -134,7 +115,6 @@ parameter = mojo.parameters.parameter.findAll{ it.name.text() == "paramFromSette
assert parameter.name.text() == 'paramFromSetterDeprecated'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.util.List'
assert parameter.implementation.isEmpty()
assert parameter.deprecated.text() == 'reason of deprecation'
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass>
parameter.setName( name );
parameter.setAlias( parameterAnnotationContent.alias() );
parameter.setDefaultValue( parameterAnnotationContent.defaultValue() );
parameter.setImplementation( parameterAnnotationContent.getImplementationClassName() );
parameter.setDeprecated( parameterAnnotationContent.getDeprecated() );
parameter.setDescription( parameterAnnotationContent.getDescription() );
parameter.setEditable( !parameterAnnotationContent.readonly() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

import org.apache.maven.plugins.annotations.Parameter;
import org.objectweb.asm.Type;

import java.lang.annotation.Annotation;
import java.util.List;
Expand All @@ -43,8 +42,6 @@ public class ParameterAnnotationContent

private String defaultValue;

private String implementationClassName;

private boolean required = false;

private boolean readonly = false;
Expand All @@ -61,14 +58,13 @@ public ParameterAnnotationContent( String fieldName, String className, List<Stri
}

public ParameterAnnotationContent( String fieldName, String alias, String property, String defaultValue,
Class<?> implementation, boolean required, boolean readonly, String className,
boolean required, boolean readonly, String className,
List<String> typeParameters )
{
this( fieldName, className, typeParameters );
this.alias = alias;
this.property = property;
this.defaultValue = defaultValue;
this.implementationClassName = implementation != null ? implementation.getName() : null;
this.required = required;
this.readonly = readonly;
}
Expand Down Expand Up @@ -117,33 +113,6 @@ public void defaultValue( String defaultValue )
this.defaultValue = defaultValue;
}

public void implementation( Type implementation )
{

implementationClassName = implementation.getClassName();
if ( implementationClassName.equals( Object.class.getName() ) )
{
// Object is default value for implementation attribute
this.implementationClassName = null;
}
}

public String getImplementationClassName()
{
return implementationClassName;
}

@Override
public Class<?> implementation()
{
// needed for implementing @Parameter
// we don't have access to project class path,
// so loading class is not possible without build additional classLoader
// we only operate on classes names
throw new UnsupportedOperationException(
"please use getImplementationClassName instead of implementation method" );
}

@Override
public boolean required()
{
Expand Down Expand Up @@ -201,7 +170,6 @@ public String toString()
sb.append( ", alias='" ).append( alias ).append( '\'' );
sb.append( ", property='" ).append( property ).append( '\'' );
sb.append( ", defaultValue='" ).append( defaultValue ).append( '\'' );
sb.append( ", implementation='" ).append( implementationClassName ).append( '\'' );
sb.append( ", required=" ).append( required );
sb.append( ", readonly=" ).append( readonly );
sb.append( '}' );
Expand Down Expand Up @@ -257,10 +225,6 @@ public boolean equals( Object o )
{
return false;
}
if ( !Objects.equals( implementationClassName, that.implementationClassName ) )
{
return false;
}

return true;
}
Expand All @@ -269,6 +233,6 @@ public boolean equals( Object o )
public int hashCode()
{
return Objects.hash( alias, getFieldName(), getClassName(), typeParameters, property, defaultValue, required,
readonly, implementationClassName );
readonly );
}
}
1 change: 0 additions & 1 deletion maven-plugin-tools-annotations/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public class MyMojo
alias = "myAlias",
property = "a.property",
defaultValue = "an expression, possibly with ${variables}",
implementation = "class of implementation in the case the parameter type is an interface"
readonly = <false|true>,
required = <false|true> )
private String parameter;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public class FooMojo
@Parameter( property = "thebar", required = true, defaultValue = "coolbar" )
protected String bar;

/**
* Interface type as parameter.
*/
@Parameter( property = "fooInterface", implementation = FooInterfaceImpl.class )
protected FooInterface fooInterface;

/**
* beer for non french folks
* @deprecated wine is better
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,19 @@ void testReadMojoClass()
Collection<ParameterAnnotationContent> parameters = mojoAnnotatedClass.getParameters().values();
assertThat( parameters ).isNotNull()
.isNotEmpty()
.hasSize( 6 )
.hasSize( 5 )
.containsExactlyInAnyOrder(
new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", null, true, false,
new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", true, false,
String.class.getName(), Collections.emptyList() ),
new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", null, false, false,
new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", false, false,
String.class.getName(), Collections.emptyList() ),
new ParameterAnnotationContent( "fooInterface", null, "fooInterface", null,
FooInterfaceImpl.class,
false,
false, FooInterface.class.getName(), Collections.emptyList() ),
new ParameterAnnotationContent( "paramFromSetter", null, "props.paramFromSetter", null,
null,
false,
false, String.class.getName(), Collections.emptyList() ),
new ParameterAnnotationContent( "paramFromAdd", null, "props.paramFromAdd", null,
null,
false,
false, String.class.getName(), Collections.emptyList() ),
new ParameterAnnotationContent( "paramFromSetterDeprecated", null, "props.paramFromSetterDeprecated", null,
null,
false,
false, List.class.getName(), Collections.singletonList("java.lang.String") )
);
Expand Down

0 comments on commit 5b60490

Please sign in to comment.