slawekjaranowski commented on a change in pull request #46:
URL: https://github.com/apache/maven-plugin-tools/pull/46#discussion_r734456299



##########
File path: 
maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java
##########
@@ -95,6 +100,25 @@
     @org.codehaus.plexus.component.annotations.Requirement
     private ArchiverManager archiverManager;
 
+    @Override
+    public String getName()
+    {
+        return NAME;
+    }
+
+    @Override
+    public boolean isDeprecated()
+    {
+        return false; // this is the "current way" to write Java Mojos
+    }
+
+    @Override
+    @SuppressWarnings( "checkstyle:magicnumber" )

Review comment:
       is needed?

##########
File path: 
maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/javadoc/JavaJavadocMojoDescriptorExtractor.java
##########
@@ -62,11 +63,34 @@
  *
  * @see org.apache.maven.plugin.descriptor.MojoDescriptor
  */
-@Component( role = MojoDescriptorExtractor.class, hint = "java-javadoc" )
+@Component( role = MojoDescriptorExtractor.class, hint = 
JavaJavadocMojoDescriptorExtractor.NAME )
 public class JavaJavadocMojoDescriptorExtractor
     extends AbstractLogEnabled
     implements MojoDescriptorExtractor, JavadocMojoAnnotation
 {
+    public static final String NAME = "java-javadoc";
+
+    private static final GroupKey GROUP_KEY = new GroupKey( 
GroupKey.JAVA_GROUP, 200 );
+
+    @Override
+    public String getName()
+    {
+        return NAME;
+    }
+
+    @Override
+    public boolean isDeprecated()
+    {
+        return true; // one should use Java5 annotations instead
+    }
+
+    @Override
+    @SuppressWarnings( "checkstyle:magicnumber" )

Review comment:
       is needed?

##########
File path: 
maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/GroupKey.java
##########
@@ -0,0 +1,83 @@
+package org.apache.maven.tools.plugin.extractor;
+
+/*
+ * 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.
+ */
+
+/**
+ * Group key: defines "grouping" for descriptor (based on source of 
extraction) and rank within
+ * group.
+ */
+public final class GroupKey
+    implements Comparable<GroupKey>
+{
+    /**
+     * Java group is handled a bit special: is always first to be scanned.
+     */
+    public static final String JAVA_GROUP = "java";

Review comment:
       why are not defined for other? maybe enum?

##########
File path: 
maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
##########
@@ -77,29 +82,60 @@ public void populatePluginDescriptor( PluginToolsRequest 
request )
         throws ExtractionException, InvalidPluginDescriptorException
     {
         Logger logger = getLogger();
-        Set<String> activeExtractorsInternal = getActiveExtractors();
-
-        logger.debug( "Using " + activeExtractorsInternal.size() + " mojo 
extractors." );
 
         int numMojoDescriptors = 0;
 
-        for ( String extractorId : activeExtractorsInternal )
+        List<MojoDescriptorExtractor> orderedExtractors = 
getOrderedExtractors();
+
+        logger.debug( "Using " + orderedExtractors.size() + " mojo 
extractors." );
+
+        HashMap<String, Integer> groupStats = new HashMap<>();
+
+        for ( MojoDescriptorExtractor extractor : orderedExtractors )
         {
-            MojoDescriptorExtractor extractor = mojoDescriptorExtractors.get( 
extractorId );
+            GroupKey groupKey = extractor.getGroupKey();
+            String extractorId = extractor.getName();
 
-            if ( extractor == null )
+            if ( extractor.isDeprecated() )
             {
-                throw new ExtractionException( "No mojo extractor with '" + 
extractorId + "' id." );
+                if ( groupStats.containsKey( groupKey.getGroup() )
+                      && groupStats.get( groupKey.getGroup() ) != 0 )
+                {
+                    logger.info( extractorId + " deprecated mojo extractor 
skipped as group '" + groupKey.getGroup()
+                        + "' already discovered " + groupStats.get( 
groupKey.getGroup() )
+                        + " mojo descriptor" + ( groupStats.get( 
groupKey.getGroup() ) > 1 ? "s" : "" ) + "." );
+                    continue; // if same group already found descriptors, skip 
rest of the group
+                }
             }
 
             logger.debug( "Applying " + extractorId + " mojo extractor" );
 
             List<MojoDescriptor> extractorDescriptors = extractor.execute( 
request );
 
+            int extractorDescriptorsCount = extractorDescriptors.size();
+
             logger.info( extractorId + " mojo extractor found " + 
extractorDescriptors.size()
                              + " mojo descriptor" + ( 
extractorDescriptors.size() > 1 ? "s" : "" ) + "." );
             numMojoDescriptors += extractorDescriptors.size();
 
+            if ( extractor.isDeprecated() &&  extractorDescriptorsCount > 0 )
+            {
+                logger.warn( "" );
+                logger.warn( "Deprecated extractor extracted descriptors. 
Upgrade your Mojo definitions." );
+                logger.warn( "" );

Review comment:
       useful information to include: 
   - which extractor is deprecated? 
   - what we should use instead?

##########
File path: 
maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
##########
@@ -118,21 +156,38 @@ public void populatePluginDescriptor( PluginToolsRequest 
request )
         }
     }
 
-    /**
-     * Gets the name of the active extractors.
-     *
-     * @return A Set containing the names of the active extractors.
-     */
-    protected Set<String> getActiveExtractors()
+    private List<MojoDescriptorExtractor> getOrderedExtractors() throws 
ExtractionException
     {
-        Set<String> result = activeExtractors;
+        Set<String> extractors = activeExtractors;
 
-        if ( result == null )
+        if ( extractors == null )
         {
-            result = new HashSet<>( mojoDescriptorExtractors.keySet() );
+            extractors = new HashSet<>( mojoDescriptorExtractors.keySet() );
+        }
+
+        ArrayList<MojoDescriptorExtractor> orderedExtractors = new 
ArrayList<>();
+        for ( String extractorId : extractors )
+        {
+            MojoDescriptorExtractor extractor = mojoDescriptorExtractors.get( 
extractorId );
+
+            if ( extractor == null )
+            {
+                throw new ExtractionException( "No mojo extractor with '" + 
extractorId + "' id." );
+            }
+
+            orderedExtractors.add( extractor );
         }
 
-        return result;
+        Collections.sort( orderedExtractors, new 
Comparator<MojoDescriptorExtractor>()
+        {
+            @Override
+            public int compare( final MojoDescriptorExtractor o1, final 
MojoDescriptorExtractor o2 )
+            {
+                return o1.getGroupKey().compareTo( o2.getGroupKey() );
+            }
+        } );

Review comment:
       Maybe make `MojoDescriptorExtractor` comparable?

##########
File path: 
maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/GroupKey.java
##########
@@ -0,0 +1,83 @@
+package org.apache.maven.tools.plugin.extractor;
+
+/*
+ * 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.
+ */
+
+/**
+ * Group key: defines "grouping" for descriptor (based on source of 
extraction) and rank within
+ * group.
+ */
+public final class GroupKey
+    implements Comparable<GroupKey>
+{
+    /**
+     * Java group is handled a bit special: is always first to be scanned.
+     */
+    public static final String JAVA_GROUP = "java";
+
+    private final String group;
+
+    private final int order;
+
+    public GroupKey( final String group, final int order )

Review comment:
       is final need for arguments?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to