MNG-3183

First cleanup of the logging code (it is still a mess), but all the console logging has been removed from the Maven component and pushed back
into the CLI code. As a result we now have a way to log to a file easily.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@572408 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-03 19:33:10 +00:00
parent 441b918f80
commit 2a241710f0
8 changed files with 527 additions and 445 deletions

View File

@ -25,7 +25,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.context.BuildContextManager;
import org.apache.maven.context.SystemBuildContext;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.ExecutionBuildContext;
import org.apache.maven.execution.MavenExecutionRequest;
@ -63,14 +62,11 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
/**
* @author jason van zyl
@ -100,12 +96,6 @@ public class DefaultMaven
private BuildExtensionScanner buildExtensionScanner;
private static final long MB = 1024 * 1024;
private static final int MS_PER_SEC = 1000;
private static final int SEC_PER_MIN = 60;
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
@ -144,6 +134,8 @@ public class DefaultMaven
reactorManager = new ReactorManager(
projects,
request.getReactorFailureBehavior() );
result.setReactorManager( reactorManager );
}
catch ( CycleDetectedException e )
{
@ -242,75 +234,6 @@ public class DefaultMaven
return result;
}
// old doExecute
if ( result.hasExceptions() )
{
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
{
Exception e = (Exception) i.next();
dispatcher.dispatchError(
event,
request.getBaseDirectory(),
e );
logError(
e,
request.isShowErrors() );
stats( request.getStartTime() );
line();
}
}
// Either the build was successful, or it was a fail_at_end/fail_never reactor build
// TODO: should all the logging be left to the CLI?
logReactorSummary( reactorManager );
if ( reactorManager != null && reactorManager.hasBuildFailures() )
{
logErrors(
reactorManager,
request.isShowErrors() );
if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
{
dispatcher.dispatchError(
event,
request.getBaseDirectory(),
null );
getLogger().info( "BUILD ERRORS" );
line();
stats( request.getStartTime() );
line();
result.addException( new MavenExecutionException( "Some builds failed" ) );
return result;
}
else
{
getLogger().info( " + Ignoring failures" );
}
}
logSuccess( reactorManager );
stats( request.getStartTime() );
line();
dispatcher.dispatchEnd(
event,
request.getBaseDirectory() );
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
result.setProject( reactorManager.getTopLevelProject() );
@ -335,38 +258,6 @@ public class DefaultMaven
systemContext.store( buildContextManager );
}
private void logErrors( ReactorManager rm,
boolean showErrors )
{
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
BuildFailure buildFailure = rm.getBuildFailure( project );
getLogger().info(
"Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
line();
logDiagnostics( buildFailure.getCause() );
logTrace(
buildFailure.getCause(),
showErrors );
}
}
if ( !showErrors )
{
getLogger().info( "For more information, run Maven with the -e switch" );
line();
}
}
private List getProjects( MavenExecutionRequest request )
throws MavenExecutionException, BuildFailureException
{
@ -432,66 +323,6 @@ public class DefaultMaven
return projects;
}
private void logReactorSummaryLine( String name,
String status )
{
logReactorSummaryLine(
name,
status,
-1 );
}
private void logReactorSummaryLine( String name,
String status,
long time )
{
StringBuffer messageBuffer = new StringBuffer();
messageBuffer.append( name );
int dotCount = 54;
dotCount -= name.length();
messageBuffer.append( " " );
for ( int i = 0; i < dotCount; i++ )
{
messageBuffer.append( '.' );
}
messageBuffer.append( " " );
messageBuffer.append( status );
if ( time >= 0 )
{
messageBuffer.append( " [" );
messageBuffer.append( getFormattedTime( time ) );
messageBuffer.append( "]" );
}
getLogger().info( messageBuffer.toString() );
}
private static String getFormattedTime( long time )
{
String pattern = "s.SSS's'";
if ( time / 60000L > 0 )
{
pattern = "m:s" + pattern;
if ( time / 3600000L > 0 )
{
pattern = "H:m" + pattern;
}
}
DateFormat fmt = new SimpleDateFormat( pattern );
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
return fmt.format( new Date( time ) );
}
private List collectProjects( List files,
ArtifactRepository localRepository,
boolean recursive,
@ -644,223 +475,6 @@ public class DefaultMaven
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
// ----------------------------------------------------------------------
// Reporting / Logging
// ----------------------------------------------------------------------
protected void logFatal( Throwable error )
{
line();
getLogger().error( "FATAL ERROR" );
line();
logDiagnostics( error );
logTrace(
error,
true );
}
protected void logError( Exception e,
boolean showErrors )
{
line();
getLogger().error( "BUILD ERROR" );
line();
logDiagnostics( e );
logTrace(
e,
showErrors );
if ( !showErrors )
{
getLogger().info( "For more information, run Maven with the -e switch" );
line();
}
}
protected void logFailure( BuildFailureException e,
boolean showErrors )
{
line();
getLogger().error( "BUILD FAILURE" );
line();
logDiagnostics( e );
logTrace(
e,
showErrors );
}
private void logTrace( Throwable t,
boolean showErrors )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Trace",
t );
line();
}
else if ( showErrors )
{
getLogger().info(
"Trace",
t );
line();
}
}
private void logDiagnostics( Throwable t )
{
String message = null;
if ( errorDiagnostics != null )
{
message = errorDiagnostics.diagnose( t );
}
if ( message == null )
{
message = t.getMessage();
}
getLogger().info( message );
line();
}
protected void logSuccess( ReactorManager rm )
{
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
}
private void logReactorSummary( ReactorManager rm )
{
if ( rm != null && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
{
getLogger().info( "" );
getLogger().info( "" );
// -------------------------
// Reactor Summary:
// -------------------------
// o project-name...........FAILED
// o project2-name..........SKIPPED (dependency build failed or was skipped)
// o project-3-name.........SUCCESS
line();
getLogger().info( "Reactor Summary:" );
line();
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
logReactorSummaryLine(
project.getName(),
"FAILED",
rm.getBuildFailure( project ).getTime() );
}
else if ( rm.isBlackListed( project ) )
{
logReactorSummaryLine(
project.getName(),
"SKIPPED (dependency build failed or was skipped)" );
}
else if ( rm.hasBuildSuccess( project ) )
{
logReactorSummaryLine(
project.getName(),
"SUCCESS",
rm.getBuildSuccess( project ).getTime() );
}
else
{
logReactorSummaryLine(
project.getName(),
"NOT BUILT" );
}
}
line();
}
}
protected void stats( Date start )
{
Date finish = new Date();
long time = finish.getTime() - start.getTime();
getLogger().info( "Total time: " + formatTime( time ) );
getLogger().info( "Finished at: " + finish );
//noinspection CallToSystemGC
System.gc();
Runtime r = Runtime.getRuntime();
getLogger().info(
"Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/" + r.totalMemory() / MB + "M" );
}
protected void line()
{
getLogger().info( "------------------------------------------------------------------------" );
}
protected static String formatTime( long ms )
{
long secs = ms / MS_PER_SEC;
long min = secs / SEC_PER_MIN;
secs = secs % SEC_PER_MIN;
String msg = "";
if ( min > 1 )
{
msg = min + " minutes ";
}
else if ( min == 1 )
{
msg = "1 minute ";
}
if ( secs > 1 )
{
msg += secs + " seconds";
}
else if ( secs == 1 )
{
msg += "1 second";
}
else if ( min == 0 )
{
msg += "< 1 second";
}
return msg;
}
private List getProjectFiles( MavenExecutionRequest request )
throws IOException
{

View File

@ -37,6 +37,8 @@ public class DefaultMavenExecutionResult
private List exceptions;
private ReactorManager reactorManager;
public MavenExecutionResult setProject( MavenProject project )
{
this.project = project;
@ -94,4 +96,16 @@ public class DefaultMavenExecutionResult
{
return (exceptions != null && exceptions.size() > 0 );
}
public ReactorManager getReactorManager()
{
return reactorManager;
}
public MavenExecutionResult setReactorManager( ReactorManager reactorManager )
{
this.reactorManager = reactorManager;
return this;
}
}

View File

@ -30,25 +30,23 @@ import java.util.List;
public interface MavenExecutionResult
{
MavenExecutionResult setProject( MavenProject project );
MavenProject getProject();
MavenExecutionResult setTopologicallySortedProjects( List projects );
List getTopologicallySortedProjects();
MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult result );
ArtifactResolutionResult getArtifactResolutionResult();
MavenExecutionResult setReactorManager( ReactorManager reactorManager );
ReactorManager getReactorManager();
// for each exception
// - knowing what artifacts are missing
// - project building exception
// - invalid project model exception: list of markers
// - xmlpull parser exception
List getExceptions();
MavenExecutionResult addException( Throwable t );
boolean hasExceptions();
}

View File

@ -84,6 +84,8 @@ public class CLIManager
public static final String FAIL_NEVER = "fn";
public static final String LOG_FILE = "l";
private Options options;
public CLIManager()
@ -156,6 +158,9 @@ public class CLIManager
options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription(
"NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription(
"Log file to where all build output will go." ).create( LOG_FILE ) );
}
public CommandLine parse( String[] args )
@ -179,8 +184,6 @@ public class CLIManager
{
String arg = args[i];
// System.out.println( "Processing raw arg: " + arg );
boolean addedToBuffer = false;
if ( arg.startsWith( "\"" ) )
@ -189,7 +192,6 @@ public class CLIManager
// this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
if ( currentArg != null )
{
// System.out.println( "Flushing last arg buffer: \'" + currentArg + "\' to cleaned list." );
cleaned.add( currentArg.toString() );
}
@ -209,32 +211,24 @@ public class CLIManager
// if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
if ( addedToBuffer )
{
// System.out.println( "Adjusting argument already appended to the arg buffer." );
currentArg.setLength( currentArg.length() - 1 );
}
// otherwise, we trim the trailing " and append to the buffer.
else
{
// System.out.println( "Appending arg part: \'" + cleanArgPart + "\' with preceding space to arg buffer." );
// TODO: introducing a space here...not sure what else to do but collapse whitespace
currentArg.append( ' ' ).append( cleanArgPart );
}
// System.out.println( "Flushing completed arg buffer: \'" + currentArg + "\' to cleaned list." );
// we're done with this argument, so add it.
cleaned.add( currentArg.toString() );
}
else
{
// System.out.println( "appending cleaned arg: \'" + cleanArgPart + "\' directly to cleaned list." );
// this is a simple argument...just add it.
cleaned.add( cleanArgPart );
}
// System.out.println( "Clearing arg buffer." );
// the currentArg MUST be finished when this completes.
currentArg = null;
continue;
}
@ -244,39 +238,32 @@ public class CLIManager
// NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
if ( !addedToBuffer )
{
// append to the argument we're building, collapsing whitespace to a single space.
if ( currentArg != null )
{
// System.out.println( "Append unquoted arg part: \'" + arg + "\' to arg buffer." );
currentArg.append( ' ' ).append( arg );
}
// this is a loner, just add it directly.
else
{
// System.out.println( "Append unquoted arg part: \'" + arg + "\' directly to cleaned list." );
cleaned.add( arg );
}
}
}
// clean up.
if ( currentArg != null )
{
// System.out.println( "Adding unterminated arg buffer: \'" + currentArg + "\' to cleaned list." );
cleaned.add( currentArg.toString() );
}
int cleanedSz = cleaned.size();
String[] cleanArgs = null;
if ( cleanedSz == 0 )
{
// if we didn't have any arguments to clean, simply pass the original array through
cleanArgs = args;
}
else
{
// System.out.println( "Cleaned argument list:\n" + cleaned );
cleanArgs = (String[]) cleaned.toArray( new String[cleanedSz] );
}

View File

@ -23,23 +23,35 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.MavenEmbedderFileLogger;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.TimeZone;
/**
* @author jason van zyl
@ -68,6 +80,14 @@ public class MavenCli
/** @noinspection ConfusingMainMethod */
public static int main( String[] args,
ClassWorld classWorld )
{
MavenCli cli = new MavenCli();
return cli.doMain( args, classWorld );
}
public int doMain( String[] args,
ClassWorld classWorld )
{
// ----------------------------------------------------------------------
// Setup the command line parser
@ -121,6 +141,7 @@ public class MavenCli
if ( commandLine.hasOption( CLIManager.HELP ) )
{
cliManager.displayHelp();
return 0;
}
@ -344,6 +365,19 @@ public class MavenCli
.setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE )
.setClassWorld( classWorld );
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
{
File logFile = new File(
baseDirectory,
commandLine.getOptionValue( CLIManager.LOG_FILE ) );
configuration.setMavenEmbedderLogger( new MavenEmbedderFileLogger( logFile ) );
}
else
{
configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
}
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
@ -372,6 +406,8 @@ public class MavenCli
try
{
mavenEmbedder = new MavenEmbedder( configuration );
logger = mavenEmbedder.getLogger();
}
catch ( MavenEmbedderException e )
{
@ -382,42 +418,22 @@ public class MavenCli
MavenExecutionResult result = mavenEmbedder.execute( request );
logResult( request, result );
if ( result.hasExceptions() )
{
showError( (Exception) result.getExceptions().get( 0 ), showErrors );
logger.close();
return 1;
}
logger.close();
return 0;
}
private static void showError( Exception e,
boolean show )
{
showError( e.getMessage(), e, show );
}
private static void showError( String message,
Exception e,
boolean show )
{
System.err.println();
System.err.println( message );
System.err.println();
if ( show )
{
System.err.println( "Error stacktrace:" );
e.printStackTrace();
}
else
{
System.err.println( "For more information, run with the -e flag" );
}
}
private static void showVersion()
{
InputStream resourceAsStream;
@ -509,4 +525,314 @@ public class MavenCli
System.setProperty( name, value );
}
// ----------------------------------------------------------------------
// Reporting / Logging
// ----------------------------------------------------------------------
private static final long MB = 1024 * 1024;
private static final int MS_PER_SEC = 1000;
private static final int SEC_PER_MIN = 60;
private MavenEmbedderLogger logger;
private MavenEmbedderLogger getLogger()
{
return logger;
}
private void logResult( MavenExecutionRequest request, MavenExecutionResult result )
{
ReactorManager reactorManager = result.getReactorManager();
// TODO: should all the logging be left to the CLI?
logReactorSummary( reactorManager );
if ( reactorManager != null && reactorManager.hasBuildFailures() )
{
logErrors(
reactorManager,
request.isShowErrors() );
if ( !ReactorManager.FAIL_NEVER.equals( reactorManager.getFailureBehavior() ) )
{
getLogger().info( "BUILD ERRORS" );
line();
stats( request.getStartTime() );
line();
}
else
{
getLogger().info( " + Ignoring failures" );
}
}
logSuccess( reactorManager );
stats( request.getStartTime() );
line();
}
private void logErrors( ReactorManager rm,
boolean showErrors )
{
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
BuildFailure buildFailure = rm.getBuildFailure( project );
getLogger().info(
"Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
line();
logTrace(
buildFailure.getCause(),
showErrors );
}
}
if ( !showErrors )
{
getLogger().info( "For more information, run Maven with the -e switch" );
line();
}
}
private static void showError( Exception e,
boolean show )
{
showError( e.getMessage(), e, show );
}
private static void showError( String message,
Exception e,
boolean show )
{
System.err.println();
System.err.println( message );
System.err.println();
if ( show )
{
System.err.println( "Error stacktrace:" );
e.printStackTrace();
}
else
{
System.err.println( "For more information, run with the -e flag" );
}
}
private void logTrace( Throwable t,
boolean showErrors )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Trace",
t );
line();
}
else if ( showErrors )
{
getLogger().info(
"Trace",
t );
line();
}
}
private void logSuccess( ReactorManager rm )
{
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
}
private void logReactorSummary( ReactorManager rm )
{
if ( rm != null && rm.hasMultipleProjects() && rm.executedMultipleProjects() )
{
getLogger().info( "" );
getLogger().info( "" );
// -------------------------
// Reactor Summary:
// -------------------------
// o project-name...........FAILED
// o project2-name..........SKIPPED (dependency build failed or was skipped)
// o project-3-name.........SUCCESS
line();
getLogger().info( "Reactor Summary:" );
line();
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
logReactorSummaryLine(
project.getName(),
"FAILED",
rm.getBuildFailure( project ).getTime() );
}
else if ( rm.isBlackListed( project ) )
{
logReactorSummaryLine(
project.getName(),
"SKIPPED (dependency build failed or was skipped)" );
}
else if ( rm.hasBuildSuccess( project ) )
{
logReactorSummaryLine(
project.getName(),
"SUCCESS",
rm.getBuildSuccess( project ).getTime() );
}
else
{
logReactorSummaryLine(
project.getName(),
"NOT BUILT" );
}
}
line();
}
}
private void stats( Date start )
{
Date finish = new Date();
long time = finish.getTime() - start.getTime();
getLogger().info( "Total time: " + formatTime( time ) );
getLogger().info( "Finished at: " + finish );
//noinspection CallToSystemGC
System.gc();
Runtime r = Runtime.getRuntime();
getLogger().info(
"Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/" + r.totalMemory() / MB + "M" );
}
private void line()
{
getLogger().info( "------------------------------------------------------------------------" );
}
private static String formatTime( long ms )
{
long secs = ms / MS_PER_SEC;
long min = secs / SEC_PER_MIN;
secs = secs % SEC_PER_MIN;
String msg = "";
if ( min > 1 )
{
msg = min + " minutes ";
}
else if ( min == 1 )
{
msg = "1 minute ";
}
if ( secs > 1 )
{
msg += secs + " seconds";
}
else if ( secs == 1 )
{
msg += "1 second";
}
else if ( min == 0 )
{
msg += "< 1 second";
}
return msg;
}
private void logReactorSummaryLine( String name,
String status )
{
logReactorSummaryLine(
name,
status,
-1 );
}
private void logReactorSummaryLine( String name,
String status,
long time )
{
StringBuffer messageBuffer = new StringBuffer();
messageBuffer.append( name );
int dotCount = 54;
dotCount -= name.length();
messageBuffer.append( " " );
for ( int i = 0; i < dotCount; i++ )
{
messageBuffer.append( '.' );
}
messageBuffer.append( " " );
messageBuffer.append( status );
if ( time >= 0 )
{
messageBuffer.append( " [" );
messageBuffer.append( getFormattedTime( time ) );
messageBuffer.append( "]" );
}
getLogger().info( messageBuffer.toString() );
}
private static String getFormattedTime( long time )
{
String pattern = "s.SSS's'";
if ( time / 60000L > 0 )
{
pattern = "m:s" + pattern;
if ( time / 3600000L > 0 )
{
pattern = "H:m" + pattern;
}
}
DateFormat fmt = new SimpleDateFormat( pattern );
fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
return fmt.format( new Date( time ) );
}
}

View File

@ -33,7 +33,7 @@ public final class MavenEmbedderConsoleLogger
{
if ( isDebugEnabled() )
{
System.out.print( "[ maven embedder DEBUG] " );
System.out.print( "[DEBUG] " );
System.out.println( message );
if ( null != throwable )
@ -48,7 +48,7 @@ public final class MavenEmbedderConsoleLogger
{
if ( isInfoEnabled() )
{
System.out.print( "[ maven embedder INFO] " );
System.out.print( "[INFO] " );
System.out.println( message );
if ( null != throwable )
@ -63,7 +63,7 @@ public final class MavenEmbedderConsoleLogger
{
if ( isWarnEnabled() )
{
System.out.print( "[ maven embedder WARNING] " );
System.out.print( "[WARNING] " );
System.out.println( message );
if ( null != throwable )
@ -78,7 +78,7 @@ public final class MavenEmbedderConsoleLogger
{
if ( isErrorEnabled() )
{
System.out.print( "[ maven embedder ERROR] " );
System.out.print( "[ERROR] " );
System.out.println( message );
if ( null != throwable )
@ -93,7 +93,7 @@ public final class MavenEmbedderConsoleLogger
{
if ( isFatalErrorEnabled() )
{
System.out.print( "[ maven embedder FATAL ERROR] " );
System.out.print( "[ERROR] " );
System.out.println( message );
if ( null != throwable )
@ -102,4 +102,8 @@ public final class MavenEmbedderConsoleLogger
}
}
}
public void close()
{
}
}

View File

@ -0,0 +1,137 @@
package org.apache.maven.embedder;
/*
* 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 java.io.File;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
/**
* @author Jason van Zyl
*/
public final class MavenEmbedderFileLogger
extends AbstractMavenEmbedderLogger
{
private PrintWriter log;
public MavenEmbedderFileLogger( File logFile )
{
try
{
this.log = new PrintWriter( logFile );
}
catch ( FileNotFoundException e )
{
// The client must make sure the file is valid.
}
}
public void debug( String message,
Throwable throwable )
{
if ( isDebugEnabled() )
{
print( "[DEBUG] " );
println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void info( String message,
Throwable throwable )
{
if ( isInfoEnabled() )
{
print( "[INFO] " );
println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void warn( String message,
Throwable throwable )
{
if ( isWarnEnabled() )
{
print( "[WARNING] " );
println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void error( String message,
Throwable throwable )
{
if ( isErrorEnabled() )
{
print( "[ERROR] " );
println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void fatalError( String message,
Throwable throwable )
{
if ( isFatalErrorEnabled() )
{
print( "[ERROR] " );
println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
protected void print( String message )
{
log.print( message );
}
protected void println( String message )
{
log.println( message );
}
public void close()
{
log.flush();
log.close();
}
}

View File

@ -75,4 +75,6 @@ public interface MavenEmbedderLogger
void setThreshold( int threshold );
int getThreshold();
void close();
}