Skip to content

Commit

Permalink
[MPLUGIN-396] Allow @deprecated annotation without javadoc tag
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 23, 2022
1 parent 0a7c5be commit c9e18b9
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 19 deletions.
@@ -0,0 +1,25 @@
[INFO] help 1.0-SNAPSHOT
Tests generation and compilation of the help mojo.

help:test
Deprecated. No reason given

MOJO-DESCRIPTION. Some 'quotation' marks and backslashes '\\', some important
javadoc
and an inline link to AnotherMojo.

Available parameters:

defaultParam (Default: escape\backslash)
This parameter uses 'quotation' marks and backslashes '\\' in its
description. Those characters must be escaped in Java string literals.

deprecatedParam
Deprecated. No reason given

Parameter description in javadoc.

undocumentedParam

Required: Yes
User property: test.undocumented
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals.1 = clean install
invoker.goals.2 = --log-file help.log org.apache.maven.its.plugin:help:1.0-SNAPSHOT:help
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.plugin</groupId>
<artifactId>help</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<description>
Tests generation and compilation of the help mojo.
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>@mavenVersion@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,67 @@
package test;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
* MOJO-DESCRIPTION. Some "quotation" marks and backslashes '\\', some <strong>important</strong> javadoc<br> and an
* inline link to {@link test.AnotherMojo}.
*
* @since 2.1
*/
@Deprecated
@Mojo( name= "test" )
public class MyMojo
extends AbstractMojo
{

/**
* This parameter uses "quotation" marks and backslashes '\\' in its description. Those characters <em>must</em> be
* escaped in Java string literals.
*
* @since 2.0
*/
@Parameter( defaultValue = "escape\\backslash" )
private String defaultParam;

/**
* Parameter description in javadoc.
*/
@Deprecated
@Parameter
private String deprecatedParam;

@Parameter( property = "test.undocumented", required = true )
private String undocumentedParam;

/**
* Readonly parameter: should not be proposed for configuration.
*/
@Parameter( defaultValue = "not for configuration", readonly = true )
private String readonly;

public void execute()
{
}

}
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

detail = true
goal = test
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

expected = new File( basedir, "expected-help.txt" ).text.trim().replace( "\r", "" )

log = new File( basedir, "help.log" ).text.replace( "\r", "" )
log = log.substring( log.indexOf( "[INFO] help 1.0-SNAPSHOT" ) )
log = log.substring( 0, log.indexOf( "[INFO]", 5 ) ).trim()

assert log == expected

return true
@@ -0,0 +1,43 @@
package org.apache.maven.plugin.coreit;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectHelper;

@Deprecated
@Mojo( name = "mplugin-396" )
public class MPlugin396Mojo
extends AbstractMojo
{
@Deprecated
@Parameter
private String param;

@Component
private MavenProjectHelper projectHelper;

public void execute()
{
}
}
Expand Up @@ -228,4 +228,11 @@ assert new File( basedir, "target/classes/org/apache/maven/plugin/coreit/HelpMoj
assert new File( basedir, "target/generated-sources/plugin/org/apache/maven/plugin/coreit/HelpMojo.java" ).isFile()
assert !new File( basedir, "target/generated-sources/plugin/HelpMojo.java" ).isFile()

// check values set by deprecated annotation only
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "mplugin-396"}[0]
assert mojo.deprecated.text() == 'No reason given'

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "param" }[0]
assert parameter.deprecated.text() == 'No reason given'

return true;
Expand Up @@ -63,7 +63,8 @@ public class DefaultMojoAnnotationsScanner
{
// classes with a dash must be ignored
private static final Pattern SCANNABLE_CLASS = Pattern.compile( "[^-]+\\.class" );

private static final String EMPTY = "";

private Reflector reflector = new Reflector();

@Override
Expand Down Expand Up @@ -271,6 +272,12 @@ protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor )
{
MojoAnnotationContent mojoAnnotationContent = new MojoAnnotationContent();
populateAnnotationContent( mojoAnnotationContent, mojoAnnotationVisitor );

if ( mojoClassVisitor.getAnnotationVisitor( Deprecated.class ) != null )
{
mojoAnnotationContent.setDeprecated( EMPTY );
}

mojoAnnotatedClass.setMojo( mojoAnnotationContent );
}

Expand All @@ -289,10 +296,15 @@ protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor )
{
ParameterAnnotationContent parameterAnnotationContent =
new ParameterAnnotationContent( mojoFieldVisitor.getFieldName(), mojoFieldVisitor.getClassName() );
if ( mojoFieldVisitor.getMojoAnnotationVisitor() != null )

Map<String, MojoAnnotationVisitor> annotationVisitorMap = mojoFieldVisitor.getAnnotationVisitorMap();
MojoAnnotationVisitor fieldAnnotationVisitor = annotationVisitorMap.get( Parameter.class.getName() );

populateAnnotationContent( parameterAnnotationContent, fieldAnnotationVisitor );

if ( annotationVisitorMap.containsKey( Deprecated.class.getName() ) )
{
populateAnnotationContent( parameterAnnotationContent,
mojoFieldVisitor.getMojoAnnotationVisitor() );
parameterAnnotationContent.setDeprecated( EMPTY );
}

mojoAnnotatedClass.getParameters().put( parameterAnnotationContent.getFieldName(),
Expand All @@ -306,7 +318,9 @@ protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor )
ComponentAnnotationContent componentAnnotationContent =
new ComponentAnnotationContent( mojoFieldVisitor.getFieldName() );

MojoAnnotationVisitor annotationVisitor = mojoFieldVisitor.getMojoAnnotationVisitor();
Map<String, MojoAnnotationVisitor> annotationVisitorMap = mojoFieldVisitor.getAnnotationVisitorMap();
MojoAnnotationVisitor annotationVisitor = annotationVisitorMap.get( Component.class.getName() );

if ( annotationVisitor != null )
{
for ( Map.Entry<String, Object> entry : annotationVisitor.getAnnotationValues().entrySet() )
Expand Down
Expand Up @@ -37,9 +37,13 @@ public interface MojoAnnotationsScanner
{
String ROLE = MojoAnnotationsScanner.class.getName();

List<String> CLASS_LEVEL_ANNOTATIONS = Arrays.asList( Mojo.class.getName(), Execute.class.getName() );
List<String> CLASS_LEVEL_ANNOTATIONS = Arrays.asList( Mojo.class.getName(),
Execute.class.getName(),
Deprecated.class.getName() );

List<String> FIELD_LEVEL_ANNOTATIONS = Arrays.asList( Parameter.class.getName(), Component.class.getName() );
List<String> FIELD_LEVEL_ANNOTATIONS = Arrays.asList( Parameter.class.getName(),
Component.class.getName(),
Deprecated.class.getName() );

/**
* Scan classes for mojo annotations.
Expand Down
Expand Up @@ -34,7 +34,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author Olivier Lamy
Expand Down Expand Up @@ -96,13 +95,13 @@ public List<MojoFieldVisitor> findFieldWithAnnotation( Class<?> annotation )
{
String annotationClassName = annotation.getName();

List<MojoFieldVisitor> mojoFieldVisitors = new ArrayList<MojoFieldVisitor>();
List<MojoFieldVisitor> mojoFieldVisitors = new ArrayList<>();

for ( MojoFieldVisitor mojoFieldVisitor : this.fieldVisitors )
{
MojoAnnotationVisitor mojoAnnotationVisitor = mojoFieldVisitor.getMojoAnnotationVisitor();
if ( mojoAnnotationVisitor != null && Objects.equals( annotationClassName,
mojoAnnotationVisitor.getAnnotationClassName() ) )
Map<String, MojoAnnotationVisitor> filedVisitorMap = mojoFieldVisitor.getAnnotationVisitorMap();

if ( filedVisitorMap.containsKey( annotationClassName ) )
{
mojoFieldVisitors.add( mojoFieldVisitor );
}
Expand Down

0 comments on commit c9e18b9

Please sign in to comment.