return exit code for goal failures

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2004-09-10 23:43:35 +00:00
parent 1a509138ef
commit 182d817ff1
2 changed files with 24 additions and 6 deletions

View File

@ -301,6 +301,7 @@ public class Verifier
allGoals.add( "clean:clean" ); allGoals.add( "clean:clean" );
allGoals.addAll( goals ); allGoals.addAll( goals );
int ret = 0;
try try
{ {
String prevUserDir = System.getProperty( "user.dir" ); String prevUserDir = System.getProperty( "user.dir" );
@ -309,14 +310,21 @@ public class Verifier
URL classWorldsUrl = new URL( "file:" + mavenHome + "/core/classworlds-1.1-SNAPSHOT.jar" ); URL classWorldsUrl = new URL( "file:" + mavenHome + "/core/classworlds-1.1-SNAPSHOT.jar" );
ClassLoader cl = URLClassLoader.newInstance( new URL[] { classWorldsUrl } ); ClassLoader cl = URLClassLoader.newInstance( new URL[] { classWorldsUrl } );
Class c = Class.forName( "org.codehaus.classworlds.Launcher", true, cl ); Class c = Class.forName( "org.codehaus.classworlds.Launcher", true, cl );
Method m = c.getMethod( "main", new Class[] { String[].class } ); Method m = c.getMethod( "mainWithExitCode", new Class[] { String[].class } );
m.invoke( null, new Object[] { allGoals.toArray( new String[0] ) } ); Object o = m.invoke( null, new Object[] { allGoals.toArray( new String[0] ) } );
System.setProperty( "user.dir", prevUserDir ); System.setProperty( "user.dir", prevUserDir );
ret = ( ( Integer ) o ).intValue();
} }
catch ( Exception e ) catch ( Exception e )
{ {
throw new VerificationException( e ); throw new VerificationException( e );
} }
if ( ret > 0 )
{
System.err.println( "Exit code: " + ret );
throw new VerificationException();
}
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View File

@ -45,7 +45,7 @@ public class MavenCli
public static final String POMv4 = "pom.xml"; public static final String POMv4 = "pom.xml";
public static void main( String[] args, ClassWorld classWorld ) public static int main( String[] args, ClassWorld classWorld )
throws Exception throws Exception
{ {
CLIManager cliManager = new CLIManager(); CLIManager cliManager = new CLIManager();
@ -85,7 +85,7 @@ public class MavenCli
{ {
cliManager.displayHelp(); cliManager.displayHelp();
return; return 0;
} }
if ( commandLine.hasOption( CLIManager.VERSION ) ) if ( commandLine.hasOption( CLIManager.VERSION ) )
@ -100,7 +100,7 @@ public class MavenCli
// the manifest in plain text and read that back. // the manifest in plain text and read that back.
System.out.println( "Maven version: " ); System.out.println( "Maven version: " );
return; return 0;
} }
if ( commandLine.hasOption( CLIManager.LIST_GOALS ) ) if ( commandLine.hasOption( CLIManager.LIST_GOALS ) )
@ -116,7 +116,7 @@ public class MavenCli
System.out.println( " " + goal.getId() ); System.out.println( " " + goal.getId() );
} }
return; return 0;
} }
ExecutionResponse response = null; ExecutionResponse response = null;
@ -152,6 +152,16 @@ public class MavenCli
{ {
response = maven.execute( projectFile, commandLine.getArgList() ); response = maven.execute( projectFile, commandLine.getArgList() );
} }
// @todo we may wish for more types of error codes - perhaps letting the response define them?
if ( response.isExecutionFailure() )
{
return 1;
}
else
{
return 0;
}
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------