convert compiler mojo to new execute()

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163657 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-22 12:29:30 +00:00
parent 9a11321919
commit d8bed9bc6c
2 changed files with 34 additions and 59 deletions

View File

@ -2,34 +2,28 @@ package org.apache.maven.plugin;
import org.codehaus.plexus.compiler.CompilerError;
import java.util.List;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class CompilationFailureResponse
extends FailureResponse
public class CompilationFailureException
extends PluginExecutionException
{
private String LS = System.getProperty( "line.separator" );
private static final String LS = System.getProperty( "line.separator" );
public CompilationFailureResponse( Object o )
public CompilationFailureException( List messages )
{
super( o );
// TODO: this is a bit nasty
super( messages, "Compilation failure", longMessage( messages ) );
}
public String shortMessage()
{
return "Compilation failure";
}
public String longMessage()
public static String longMessage( List messages )
{
StringBuffer sb = new StringBuffer();
List messages = (List)source;
for ( Iterator it = messages.iterator(); it.hasNext() ; )
{
CompilerError compilerError = (CompilerError) it.next();

View File

@ -51,7 +51,7 @@ import java.util.List;
* expression="#project.compileClasspathElements"
* description=""
* @parameter name="debug"
* type="String"
* type="boolean"
* required="false"
* validator=""
* expression="#maven.compiler.debug"
@ -66,25 +66,26 @@ public class CompilerMojo
{
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;
private String outputDirectory;
private String source;
private String target;
public void execute()
throws PluginExecutionException
{
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
List compileSourceRoots = (List) request.getParameter( "compileSourceRoots" );
String outputDirectory = (String) request.getParameter( "outputDirectory" );
List classpathElements = (List) request.getParameter( "classpathElements" );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
compileSourceRoots = removeEmptyCompileSourceRoots( compileSourceRoots );
if ( compileSourceRoots.isEmpty() )
{
@ -98,50 +99,30 @@ public class CompilerMojo
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 ( Boolean.valueOf( debugAsString ).booleanValue() )
if ( debug != null && "true".equals( debug ) )
{
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.";
messages = compiler.compile( compilerConfiguration );
}
else
catch ( Exception e )
{
message = "Warning! not present in repository!";
}
getLog().debug( "classpathElements[ " + i + " ] = " + classpathElement + ": " + message );
}
// TODO: don't catch Exception
throw new PluginExecutionException( "Fatal error compiling", e );
}
boolean compilationError = false;
@ -158,7 +139,7 @@ public class CompilerMojo
if ( compilationError )
{
response.setExecutionFailure( new CompilationFailureResponse( messages ) );
throw new CompilationFailureException( messages );
}
}