You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by br...@apache.org on 2005/03/22 13:29:30 UTC

cvs commit: maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin CompilationFailureException.java CompilerMojo.java CompilationFailureResponse.java

brett       2005/03/22 04:29:30

  Modified:    maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin
                        CompilerMojo.java
  Added:       maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin
                        CompilationFailureException.java
  Removed:     maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin
                        CompilationFailureResponse.java
  Log:
  convert compiler mojo to new execute()
  
  Revision  Changes    Path
  1.24      +24 -43    maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
  
  Index: CompilerMojo.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CompilerMojo.java	21 Mar 2005 00:07:39 -0000	1.23
  +++ CompilerMojo.java	22 Mar 2005 12:29:30 -0000	1.24
  @@ -51,7 +51,7 @@
    * expression="#project.compileClasspathElements"
    * description=""
    * @parameter name="debug"
  - * type="String"
  + * type="boolean"
    * required="false"
    * validator=""
    * expression="#maven.compiler.debug"
  @@ -66,21 +66,22 @@
   {
       private Compiler compiler = new JavacCompiler();
   
  -    private boolean debug = false;
  +    // TODO: use boolean when supported
  +    private String debug = Boolean.FALSE.toString();
   
  -    public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
  -        throws Exception
  -    {
  -        // ----------------------------------------------------------------------
  -        //
  -        // ----------------------------------------------------------------------
  +    private List compileSourceRoots;
  +
  +    private List classpathElements;
   
  -        List compileSourceRoots = (List) request.getParameter( "compileSourceRoots" );
  +    private String outputDirectory;
   
  -        String outputDirectory = (String) request.getParameter( "outputDirectory" );
  +    private String source;
   
  -        List classpathElements = (List) request.getParameter( "classpathElements" );
  +    private String target;
   
  +    public void execute()
  +        throws PluginExecutionException
  +    {
           // ----------------------------------------------------------------------
           //
           // ----------------------------------------------------------------------
  @@ -98,50 +99,30 @@
           compilerConfiguration.setClasspathEntries( classpathElements );
           compilerConfiguration.setSourceLocations( compileSourceRoots );
   
  -        String source = ( String ) request.getParameter( "source" );
           if ( source != null )
           {
               compilerConfiguration.addCompilerOption( "-source", source );
           }
           
  -        String target = ( String ) request.getParameter( "target" );
           if ( target != null )
           {
               compilerConfiguration.addCompilerOption( "-target", target );
           }
  -        
  -        /* Compile with debugging info */
  -        String debugAsString = (String) request.getParameter( "debug" );
   
  -        if ( debugAsString != null )
  +        if ( debug != null && "true".equals( debug ) )
           {
  -            if ( Boolean.valueOf( debugAsString ).booleanValue() )
  -            {
  -                compilerConfiguration.setDebug( true );
  -            }
  +            compilerConfiguration.setDebug( true );
           }
   
  -        List messages = compiler.compile( compilerConfiguration );
  -
  -        // TODO: doesn't appear to be called
  -        if ( debug )
  +        List messages = null;
  +        try
           {
  -            for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
  -            {
  -                String message;
  -
  -                String classpathElement = (String) i.next();
  -                if ( new File( classpathElement ).exists() )
  -                {
  -                    message = "present in repository.";
  -                }
  -                else
  -                {
  -                    message = "Warning! not present in repository!";
  -                }
  -
  -                getLog().debug( "classpathElements[ " + i + " ] = " + classpathElement + ": " + message );
  -            }
  +            messages = compiler.compile( compilerConfiguration );
  +        }
  +        catch ( Exception e )
  +        {
  +            // TODO: don't catch Exception
  +            throw new PluginExecutionException( "Fatal error compiling", e );
           }
   
           boolean compilationError = false;
  @@ -158,7 +139,7 @@
   
           if ( compilationError )
           {
  -            response.setExecutionFailure( new CompilationFailureResponse( messages ) );
  +            throw new CompilationFailureException( messages );
           }
       }
   
  
  
  
  1.1                  maven-components/maven-plugins/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java
  
  Index: CompilationFailureException.java
  ===================================================================
  package org.apache.maven.plugin;
  
  import org.codehaus.plexus.compiler.CompilerError;
  
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: CompilationFailureException.java,v 1.1 2005/03/22 12:29:30 brett Exp $
   */
  public class CompilationFailureException
      extends PluginExecutionException
  {
      private static final String LS = System.getProperty( "line.separator" );
  
      public CompilationFailureException( List messages )
      {
          // TODO: this is a bit nasty
          super( messages, "Compilation failure", longMessage( messages ) );
      }
  
      public static String longMessage( List messages )
      {
          StringBuffer sb = new StringBuffer();
  
          for ( Iterator it = messages.iterator(); it.hasNext() ; )
          {
              CompilerError compilerError = (CompilerError) it.next();
  
              sb.append( compilerError ).append( LS );
          }
  
          return sb.toString();
      }
  }