-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MPLUGIN-426] add @Description annotation #152
Draft
bmarwell
wants to merge
9
commits into
master
Choose a base branch
from
MPLUGIN-426_add_description_annotation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9e6a874
[MPLUGIN-426] add @Description annotation
bmarwell 1347955
[MPLUGIN-426] only use content and since for now.
bmarwell 7e1b23e
[MPLUGIN-426] content => value
bmarwell 81b1a8e
[MPLUGIN-426] AnnotationContent is not a bean; add kotlin test.
bmarwell 2f3622a
[MPLUGIN-426] fix issue reported by rat
hboutemy a039f7e
[MPLUGIN-426] define build-helper-m-p version
hboutemy 0dfe9e9
[MPLUGIN-426] remove unused Kotlin build dependency
hboutemy 5935067
[MPLUGIN-426] add documentation
hboutemy acbb811
[MPLUGIN-426] fix javadoc
hboutemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Description.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.apache.maven.plugins.annotations; | ||
|
||
/* | ||
* 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 java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Describes a {@code Mojo} or a Mojo’s {@code Parameter} when JavaDoc extraction is not feasible (because of deviating | ||
* documentation goals) or not possible (e.g. for other JVM languages like Scala, Groovy or Kotlin). | ||
*/ | ||
@Documented | ||
@Retention( RetentionPolicy.CLASS ) | ||
@Target( { ElementType.TYPE, ElementType.FIELD } ) | ||
@Inherited | ||
public @interface Description | ||
{ | ||
/** | ||
* Description content for the {@code Mojo} or Mojo {@code Parameter}. | ||
* | ||
* <p>A "Safe HTML" subset can be used. This is achieved by running | ||
* the content through the <a href="https://github.com/owasp/java-html-sanitizer"<OWASP Java HTML Sanitizer</a> | ||
* before rendering.</p> | ||
* | ||
* @return a description of the Mojo or the parameter. | ||
*/ | ||
String content(); | ||
|
||
/** | ||
* The version of the plugin since when this goal or parameter was introduced (inclusive, optional). | ||
* | ||
* @return The version of the plugin since when this goal or parameter was introduced (inclusive) or an empty string | ||
* of no since version has been given. | ||
*/ | ||
String since() default ""; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,16 +288,19 @@ protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnno | |
MojoAnnotationContent mojoAnnotationContent = entry.getValue().getMojo(); | ||
if ( mojoAnnotationContent != null ) | ||
{ | ||
mojoAnnotationContent.setDescription( javaClass.getComment() ); | ||
if ( StringUtils.isEmpty( mojoAnnotationContent.getDescription() ) ) | ||
{ | ||
mojoAnnotationContent.setDescription( javaClass.getComment() ); | ||
} | ||
|
||
DocletTag since = findInClassHierarchy( javaClass, "since" ); | ||
if ( since != null ) | ||
if ( since != null && StringUtils.isEmpty( mojoAnnotationContent.getSince() ) ) | ||
{ | ||
mojoAnnotationContent.setSince( since.getValue() ); | ||
} | ||
|
||
DocletTag deprecated = findInClassHierarchy( javaClass, "deprecated" ); | ||
if ( deprecated != null ) | ||
if ( deprecated != null && StringUtils.isEmpty( mojoAnnotationContent.getDeprecated() ) ) | ||
{ | ||
Comment on lines
-291
to
304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New behaviour (compatible): Only set from javadoc annotation if not already set by Java annotation.. |
||
mojoAnnotationContent.setDeprecated( deprecated.getValue() ); | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
...ache/maven/tools/plugin/extractor/annotations/datamodel/DescriptionAnnotationContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.apache.maven.tools.plugin.extractor.annotations.datamodel; | ||
|
||
/* | ||
* 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 java.util.StringJoiner; | ||
|
||
/** | ||
* @author Benjamin Marwell | ||
* @since 3.7.0 | ||
*/ | ||
public class DescriptionAnnotationContent | ||
{ | ||
|
||
private String content; | ||
|
||
private String since; | ||
|
||
public String getContent() | ||
{ | ||
return content; | ||
} | ||
|
||
public void setContent( String content ) | ||
{ | ||
this.content = content; | ||
} | ||
|
||
public String getSince() | ||
{ | ||
return since; | ||
} | ||
|
||
public void setSince( String since ) | ||
{ | ||
this.since = since; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return new StringJoiner( ", ", DescriptionAnnotationContent.class.getSimpleName() + "[", "]" ) | ||
.add( "content='" + content + "'" ) | ||
.add( "since='" + since + "'" ) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,13 @@ | |
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Description; | ||
import org.apache.maven.plugins.annotations.Execute; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.tools.plugin.extractor.ExtractionException; | ||
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent; | ||
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.DescriptionAnnotationContent; | ||
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent; | ||
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent; | ||
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent; | ||
|
@@ -285,6 +287,16 @@ protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor ) | |
mojoAnnotatedClass.setMojo( mojoAnnotationContent ); | ||
} | ||
|
||
// @Description annotation | ||
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor( Description.class ); | ||
if ( mojoAnnotationVisitor != null ) | ||
{ | ||
DescriptionAnnotationContent descriptionAnnotationContent = new DescriptionAnnotationContent(); | ||
populateAnnotationContent( descriptionAnnotationContent, mojoAnnotationVisitor ); | ||
|
||
mojoAnnotatedClass.getMojo().setDescription( descriptionAnnotationContent.getContent() ); | ||
} | ||
|
||
// @Execute annotation | ||
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor( Execute.class ); | ||
if ( mojoAnnotationVisitor != null ) | ||
|
@@ -306,6 +318,17 @@ protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor ) | |
|
||
populateAnnotationContent( parameterAnnotationContent, fieldAnnotationVisitor ); | ||
|
||
DescriptionAnnotationContent descriptionAnnotationContent = new DescriptionAnnotationContent(); | ||
final MojoAnnotationVisitor descriptionAnnotationVisitor = | ||
annotationVisitorMap.get( Description.class.getName() ); | ||
if ( descriptionAnnotationVisitor != null ) | ||
{ | ||
populateAnnotationContent( descriptionAnnotationContent, descriptionAnnotationVisitor ); | ||
} | ||
Comment on lines
+322
to
+328
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
parameterAnnotationContent.setDescription( descriptionAnnotationContent.getContent() ); | ||
parameterAnnotationContent.setSince( descriptionAnnotationContent.getSince() ); | ||
|
||
if ( annotationVisitorMap.containsKey( Deprecated.class.getName() ) ) | ||
{ | ||
parameterAnnotationContent.setDeprecated( EMPTY ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this named as
value
, could annotation be used as@Description("xxx yyy")
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was my first idea. But since it contains HTML, I thought it might be a good idea to not use "value". But then, what would value be if added later...
Can change that. Will also add tests.