You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:35:19 UTC

[maven-help-plugin] 26/37: PR: MNG-122 exception clean up phase 1

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-help-plugin-2.0
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git

commit 36097bfe8ddd1fcf481d85a6dc6f1ff269fe3ff7
Author: Brett Leslie Porter <br...@apache.org>
AuthorDate: Thu Oct 13 05:30:22 2005 +0000

    PR: MNG-122
    exception clean up phase 1
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-projecthelp-plugin@320668 13f79535-47bb-0310-9956-ffa450edef68
---
 .../maven/plugins/projecthelp/DescribeMojo.java    | 210 ++++++++++++---------
 1 file changed, 121 insertions(+), 89 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
index 2e89f23..b3d1f84 100644
--- a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
@@ -1,8 +1,25 @@
 package org.apache.maven.plugins.projecthelp;
 
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.AbstractMojo;
@@ -29,7 +46,7 @@ import java.util.List;
 
 /**
  * Describes the attributes of a plugin and/or plugin mojo.
- * 
+ *
  * @goal describe
  * @requiresProject false
  * @aggregator
@@ -40,11 +57,11 @@ public class DescribeMojo
 
     /**
      * The plugin/mojo to describe. This must be specified in one of three ways:
-     * 
+     *
      * 1. plugin-prefix
      * 2. groupId:artifactId
      * 3. groupId:artifactId:version
-     * 
+     *
      * @parameter expression="${plugin}" alias="prefix"
      */
     private String plugin;
@@ -53,25 +70,25 @@ public class DescribeMojo
      * The plugin groupId to describe.
      * <br/>
      * (Used with artifactId specification).
-     * 
+     *
      * @parameter expression="${groupId}"
      */
     private String groupId;
 
     /**
-     * The plugin artifactId to describe. 
+     * The plugin artifactId to describe.
      * <br/>
      * (Used with groupId specification).
-     * 
+     *
      * @parameter expression="${artifactId}"
      */
     private String artifactId;
 
     /**
-     * The plugin version to describe. 
+     * The plugin version to describe.
      * <br/>
      * (Used with groupId/artifactId specification).
-     * 
+     *
      * @parameter expression="${version}"
      */
     private String version;
@@ -81,15 +98,15 @@ public class DescribeMojo
      * <br/>
      * If this parameter is specified, only the corresponding mojo will
      * <br/>
-     * be described, rather than the whole plugin.  
-     * 
+     * be described, rather than the whole plugin.
+     *
      * @parameter expression="${mojo}"
      */
     private String mojo;
 
     /**
      * The plugin manager instance used to resolve plugin descriptors.
-     * 
+     *
      * @component role="org.apache.maven.plugin.PluginManager"
      */
     private PluginManager pluginManager;
@@ -100,7 +117,7 @@ public class DescribeMojo
      * in the event there is no current MavenProject instance. Some MavenProject
      * <br/>
      * instance has to be present to use in the plugin manager APIs.
-     * 
+     *
      * @component role="org.apache.maven.project.MavenProjectBuilder"
      */
     private MavenProjectBuilder projectBuilder;
@@ -113,17 +130,17 @@ public class DescribeMojo
      * parameter is empty at execution time, this mojo will instead use the
      * <br/>
      * super-project.
-     * 
+     *
      * @parameter expression="${project}"
      * @readonly
      */
     private MavenProject project;
 
     /**
-     * The current user system settings for use in Maven. This is used for 
+     * The current user system settings for use in Maven. This is used for
      * <br/>
      * plugin manager API calls.
-     * 
+     *
      * @parameter expression="${settings}"
      * @required
      * @readonly
@@ -131,10 +148,10 @@ public class DescribeMojo
     private Settings settings;
 
     /**
-     * The current build session instance. This is used for 
+     * The current build session instance. This is used for
      * <br/>
      * plugin manager API calls.
-     * 
+     *
      * @parameter expression="${session}"
      * @required
      * @readonly
@@ -145,7 +162,7 @@ public class DescribeMojo
      * The local repository ArtifactRepository instance. This is used
      * <br/>
      * for plugin manager API calls.
-     * 
+     *
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -156,16 +173,16 @@ public class DescribeMojo
      * If specified, this parameter will cause the plugin/mojo descriptions
      * <br/>
      * to be written to the path specified, instead of writing to the console.
-     * 
+     *
      * @parameter expression="${output}"
      */
     private File output;
-    
+
     /**
      * This flag specifies that full (verbose) information should be
      * <br/>
      * given. Use true/false.
-     * 
+     *
      * @parameter expression="${full}" default-value="false"
      */
     private boolean full;
@@ -184,11 +201,11 @@ public class DescribeMojo
                 throw new MojoExecutionException( "Error while retrieving the super-project.", e );
             }
         }
-        
+
         PluginInfo pi = new PluginInfo();
-        
+
         parsePluginLookupInfo( pi );
-        
+
         PluginDescriptor descriptor = lookupPluginDescriptor( pi );
 
         StringBuffer descriptionBuffer = new StringBuffer();
@@ -205,7 +222,8 @@ public class DescribeMojo
         writeDescription( descriptionBuffer );
     }
 
-    private void writeDescription( StringBuffer descriptionBuffer ) throws MojoExecutionException
+    private void writeDescription( StringBuffer descriptionBuffer )
+        throws MojoExecutionException
     {
         if ( output != null )
         {
@@ -213,7 +231,7 @@ public class DescribeMojo
             try
             {
                 output.getParentFile().mkdirs();
-                
+
                 out = new FileWriter( output );
 
                 out.write( descriptionBuffer.toString() );
@@ -236,7 +254,7 @@ public class DescribeMojo
                     }
                 }
             }
-            
+
             getLog().info( "Wrote descriptions to: " + output );
         }
         else
@@ -245,16 +263,17 @@ public class DescribeMojo
         }
     }
 
-    private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) throws MojoExecutionException, MojoFailureException
+    private PluginDescriptor lookupPluginDescriptor( PluginInfo pi )
+        throws MojoExecutionException, MojoFailureException
     {
         PluginDescriptor descriptor = null;
-        
+
         Plugin forLookup = null;
-        
+
         if ( pi.prefix != null )
         {
             descriptor = pluginManager.getPluginDescriptorForPrefix( pi.prefix );
-            
+
             if ( descriptor == null )
             {
                 try
@@ -271,7 +290,7 @@ public class DescribeMojo
         else if ( pi.groupId != null && pi.artifactId != null )
         {
             forLookup = new Plugin();
-            
+
             forLookup.setGroupId( pi.groupId );
             forLookup.setArtifactId( pi.artifactId );
 
@@ -282,9 +301,10 @@ public class DescribeMojo
         }
         else
         {
-            throw new MojoFailureException("You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
+            throw new MojoFailureException(
+                "You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
         }
-        
+
         if ( descriptor == null && forLookup != null )
         {
             try
@@ -293,30 +313,36 @@ public class DescribeMojo
             }
             catch ( ArtifactResolutionException e )
             {
-                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
-                    + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
+                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
+                    "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
             }
             catch ( PluginManagerException e )
             {
-                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
-                    + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
+                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
+                    "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
             }
             catch ( PluginVersionResolutionException e )
             {
-                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
-                    + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
+                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
+                    "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
             }
             catch ( ArtifactNotFoundException e )
             {
-                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
-                                                  + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
+                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
+                    "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
+            }
+            catch ( InvalidVersionSpecificationException e )
+            {
+                throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
+                    "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
             }
         }
-        
+
         return descriptor;
     }
 
-    private void parsePluginLookupInfo( PluginInfo pi ) throws MojoFailureException
+    private void parsePluginLookupInfo( PluginInfo pi )
+        throws MojoFailureException
     {
         if ( plugin != null && plugin.length() > 0 )
         {
@@ -346,7 +372,8 @@ public class DescribeMojo
                     }
                     default:
                     {
-                        throw new MojoFailureException("plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
+                        throw new MojoFailureException(
+                            "plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
                     }
                 }
             }
@@ -370,24 +397,24 @@ public class DescribeMojo
         {
             name = pd.getId();
         }
-        
+
         buffer.append( "Plugin: \'" ).append( name ).append( '\'' );
         buffer.append( "\n-----------------------------------------------" );
         buffer.append( "\nGroup Id:  " ).append( pd.getGroupId() );
         buffer.append( "\nArtifact Id: " ).append( pd.getArtifactId() );
         buffer.append( "\nVersion:     " ).append( pd.getVersion() );
         buffer.append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() );
-        
+
         buffer.append( "\nDescription:\n\n" );
         prettyAppend( formatDescription( pd.getDescription() ), buffer );
         buffer.append( "\n" );
-        
+
         if ( full )
         {
             buffer.append( "\nMojos:\n" );
 
             String line = "\n===============================================";
-            
+
             for ( Iterator it = pd.getMojos().iterator(); it.hasNext(); )
             {
                 MojoDescriptor md = (MojoDescriptor) it.next();
@@ -395,9 +422,9 @@ public class DescribeMojo
                 buffer.append( line );
                 buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( '\'' );
                 buffer.append( line );
-                
+
                 describeMojoGuts( md, buffer, true );
-                
+
                 buffer.append( line );
                 buffer.append( "\n\n" );
             }
@@ -410,12 +437,12 @@ public class DescribeMojo
         {
             return null;
         }
-        
+
         String result = description.replaceAll( " ?\\<br\\/?\\> ?", "\n" );
-        
-        result = result.replaceAll(" ?\\<p\\> ?", "" );
-        result = result.replaceAll(" ?\\</p\\> ?", "\n\n" );
-        
+
+        result = result.replaceAll( " ?\\<p\\> ?", "" );
+        result = result.replaceAll( " ?\\</p\\> ?", "\n\n" );
+
         return result;
     }
 
@@ -434,13 +461,13 @@ public class DescribeMojo
     private void describeMojo( MojoDescriptor md, StringBuffer buffer )
     {
         String line = "\n===============================================";
-        
+
         buffer.append( "Mojo: \'" ).append( md.getFullGoalName() ).append( '\'' );
         buffer.append( line );
         buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( "\'" );
 
         describeMojoGuts( md, buffer, full );
-        
+
         buffer.append( line );
         buffer.append( "\n\n" );
     }
@@ -450,14 +477,14 @@ public class DescribeMojo
         buffer.append( "\nDescription:\n\n" );
         prettyAppend( formatDescription( md.getDescription() ), buffer );
         buffer.append( "\n" );
-        
+
         String deprecation = md.getDeprecated();
-        
+
         if ( deprecation != null )
         {
             buffer.append( "\n\nNOTE: This mojo is deprecated.\n" ).append( deprecation ).append( "\n" );
         }
-        
+
         if ( fullDescription )
         {
             buffer.append( "\nImplementation: " ).append( md.getImplementation() );
@@ -502,9 +529,9 @@ public class DescribeMojo
     private void describeMojoRequirements( MojoDescriptor md, StringBuffer buffer )
     {
         buffer.append( "\n" );
-        
+
         List reqs = md.getRequirements();
-        
+
         if ( reqs == null || reqs.isEmpty() )
         {
             buffer.append( "\nThis mojo doesn't have any component requirements." );
@@ -512,28 +539,28 @@ public class DescribeMojo
         else
         {
             buffer.append( "\nComponent Requirements:\n" );
-            
+
             String line = "\n-----------------------------------------------";
-            
+
             int idx = 0;
-            for ( Iterator it = reqs.iterator(); it.hasNext(); )
+            for ( Iterator it = reqs.iterator(); it.hasNext(); idx++ )
             {
                 ComponentRequirement req = (ComponentRequirement) it.next();
-                
+
                 buffer.append( line );
-                
-                buffer.append( "\n[" ).append( idx++ ).append( "] " );
+
+                buffer.append( "\n[" ).append( idx ).append( "] " );
                 buffer.append( "Role: " ).append( req.getRole() );
-                
+
                 String hint = req.getRoleHint();
                 if ( hint != null )
                 {
                     buffer.append( "\nRole-Hint: " ).append( hint );
                 }
-                
+
                 buffer.append( "\n" );
             }
-            
+
             buffer.append( line );
         }
     }
@@ -541,9 +568,9 @@ public class DescribeMojo
     private void describeMojoParameters( MojoDescriptor md, StringBuffer buffer )
     {
         buffer.append( "\n" );
-        
+
         List params = md.getParameters();
-        
+
         if ( params == null || params.isEmpty() )
         {
             buffer.append( "\nThis mojo doesn't use any parameters." );
@@ -551,56 +578,56 @@ public class DescribeMojo
         else
         {
             buffer.append( "\nParameters:" );
-            
+
             String line = "\n-----------------------------------------------";
-            
+
             int idx = 0;
             for ( Iterator it = params.iterator(); it.hasNext(); )
             {
                 Parameter parameter = (Parameter) it.next();
-                
+
                 buffer.append( line );
                 buffer.append( "\n\n[" ).append( idx++ ).append( "] " );
                 buffer.append( "Name: " );
                 prettyAppend( parameter.getName(), buffer );
-                
+
                 String alias = parameter.getAlias();
                 if ( alias != null )
                 {
                     buffer.append( " (Alias: " ).append( alias ).append( ")" );
                 }
-                
+
                 buffer.append( "\nType: " );
                 prettyAppend( parameter.getType(), buffer );
-                
+
                 String expression = parameter.getExpression();
                 if ( expression != null )
                 {
                     buffer.append( "\nExpression: " ).append( expression );
                 }
-                
+
                 String defaultVal = parameter.getDefaultValue();
                 if ( defaultVal != null )
                 {
                     buffer.append( "\nDefault value: \'" ).append( defaultVal );
                 }
-                
+
                 buffer.append( "\nRequired: " ).append( parameter.isRequired() );
                 buffer.append( "\nDirectly editable: " ).append( parameter.isEditable() );
-                
+
                 buffer.append( "\nDescription:\n\n" );
                 prettyAppend( formatDescription( parameter.getDescription() ), buffer );
-                
+
                 String deprecation = parameter.getDeprecated();
-                
+
                 if ( deprecation != null )
                 {
                     buffer.append( "\n\nNOTE: This parameter is deprecated.\n" ).append( deprecation ).append( "\n" );
                 }
-                
+
                 buffer.append( "\n" );
             }
-            
+
             buffer.append( line );
         }
     }
@@ -704,16 +731,21 @@ public class DescribeMojo
     {
         this.version = version;
     }
-    
+
     private static class PluginInfo
     {
         String prefix;
+
         String groupId;
+
         String artifactId;
+
         String version;
+
         String mojo;
-        
+
         Plugin plugin;
+
         PluginDescriptor pluginDescriptor;
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.