maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r489846 - in /maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src: main/java/org/apache/maven/tools/plugin/scanner/ main/resources/META-INF/plexus/ test/java/org/apache/maven/tools/plugin/scanner/ test/resources/META-INF/plexus/
Date Sat, 23 Dec 2006 03:36:14 GMT
Author: brett
Date: Fri Dec 22 19:36:13 2006
New Revision: 489846

URL: http://svn.apache.org/viewvc?view=rev&rev=489846
Log:
[MPLUGIN-22] Allow specification of mojo extractors to be used
Submitted by: Jochen Kuhnle

Added:
    maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java
  (with props)
Modified:
    maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
    maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
    maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/resources/META-INF/plexus/components.xml
    maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/resources/META-INF/plexus/scannerTestComponents.xml

Modified: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java?view=diff&rev=489846&r1=489845&r2=489846
==============================================================================
--- maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
(original)
+++ maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
Fri Dec 22 19:36:13 2006
@@ -29,9 +29,11 @@
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author jdcasey
@@ -43,6 +45,11 @@
 
     private Map mojoDescriptorExtractors;
 
+    /**
+     * The names of the active extractors
+     */
+    private Set/* <String> */activeExtractors;
+
     public DefaultMojoScanner( Map extractors )
     {
         this.mojoDescriptorExtractors = extractors;
@@ -58,14 +65,19 @@
         throws ExtractionException, InvalidPluginDescriptorException
     {
         Logger logger = getLogger();
+        Set activeExtractors = getActiveExtractors();
 
-        logger.info( "Using " + mojoDescriptorExtractors.size() + " extractors." );
+        logger.info( "Using " + activeExtractors.size() + " extractors." );
 
-        for ( Iterator it = mojoDescriptorExtractors.entrySet().iterator(); it.hasNext();
)
+        for ( Iterator it = activeExtractors.iterator(); it.hasNext(); )
         {
-            Map.Entry entry = (Map.Entry) it.next();
-            String language = (String) entry.getKey();
-            MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) entry.getValue();
+            String language = (String) it.next();
+            MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) mojoDescriptorExtractors.get(
language );
+
+            if ( extractor == null )
+            {
+                throw new ExtractionException( "No extractor for language: " + language );
+            }
 
             logger.info( "Applying extractor for language: " + language );
 
@@ -87,4 +99,45 @@
         }
     }
 
+    /**
+     * Gets the name of the active extractors.
+     *
+     * @return A Set containing the names of the active extractors.
+     */
+    protected Set/* <String> */getActiveExtractors()
+    {
+        Set/* <String> */result = activeExtractors;
+
+        if ( result == null )
+        {
+            result = new HashSet/* <String> */( mojoDescriptorExtractors.keySet() );
+        }
+
+        return result;
+    }
+
+    /**
+     * @see org.apache.maven.tools.plugin.scanner.ExtendedMojoScanner#setActiveExtractors(java.util.Set)
+     */
+    public void setActiveExtractors( Set/* <String> */extractors )
+    {
+        if ( extractors == null )
+        {
+            this.activeExtractors = null;
+        }
+        else
+        {
+            this.activeExtractors = new HashSet/* <String> */();
+
+            for ( Iterator i = extractors.iterator(); i.hasNext(); )
+            {
+                String extractor = (String) i.next();
+
+                if ( extractor != null && extractor.length() > 0 )
+                {
+                    this.activeExtractors.add( extractor );
+                }
+            }
+        }
+    }
 }

Modified: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java?view=diff&rev=489846&r1=489845&r2=489846
==============================================================================
--- maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
(original)
+++ maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
Fri Dec 22 19:36:13 2006
@@ -24,6 +24,8 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
 
+import java.util.Set;
+
 /**
  * @author jdcasey
  */
@@ -33,5 +35,17 @@
 
     void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor
)
         throws ExtractionException, InvalidPluginDescriptorException;
+
+
+    /**
+     * Sets the active extractors.
+     * <p/>
+     * Only the specified extractors will be used, all others will be skipped.
+     *
+     * @param extractors The names of the sctive extractors. If this parameter is <code>null</code>,
+     *                   all the scanner's extractors are considered active. Set entries
that are
+     *                   <code>null</code> or empty ("") will be ignored.
+     */
+    void setActiveExtractors( Set/* <String> */extractors );
 
 }

Modified: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=489846&r1=489845&r2=489846
==============================================================================
--- maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/resources/META-INF/plexus/components.xml
Fri Dec 22 19:36:13 2006
@@ -29,6 +29,7 @@
     <component>
       <role>org.apache.maven.tools.plugin.scanner.MojoScanner</role>
       <implementation>org.apache.maven.tools.plugin.scanner.DefaultMojoScanner</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
       <requirements>
         <requirement>
           <role>org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor</role>

Added: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java?view=auto&rev=489846
==============================================================================
--- maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java
(added)
+++ maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java
Fri Dec 22 19:36:13 2006
@@ -0,0 +1,52 @@
+package org.apache.maven.tools.plugin.scanner;
+
+/*
+ * 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.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author jdcasey
+ */
+public class ScannerTestExtractor
+    implements MojoDescriptorExtractor
+{
+    private final String goal;
+
+    public ScannerTestExtractor( String goal )
+    {
+        this.goal = goal;
+    }
+
+    public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
+    {
+        MojoDescriptor desc = new MojoDescriptor();
+        desc.setPluginDescriptor( pluginDescriptor );
+        desc.setGoal( goal );
+
+        return Collections.singletonList( desc );
+    }
+
+}
\ No newline at end of file

Propchange: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/ScannerTestExtractor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/resources/META-INF/plexus/scannerTestComponents.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/resources/META-INF/plexus/scannerTestComponents.xml?view=diff&rev=489846&r1=489845&r2=489846
==============================================================================
--- maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/resources/META-INF/plexus/scannerTestComponents.xml
(original)
+++ maven/shared/trunk/maven-plugin-tools/maven-plugin-tools-api/src/test/resources/META-INF/plexus/scannerTestComponents.xml
Fri Dec 22 19:36:13 2006
@@ -23,6 +23,7 @@
     <component>
       <role>org.apache.maven.tools.plugin.scanner.MojoScanner</role>
       <implementation>org.apache.maven.tools.plugin.scanner.DefaultMojoScanner</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
       <requirements>
         <requirement>
           <role>org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor</role>



Mime
View raw message