Author: vsiveton
Date: Wed Sep 9 11:47:22 2009
New Revision: 812901
URL: http://svn.apache.org/viewvc?rev=812901&view=rev
Log:
o try to catch JVM init error
Modified:
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
Modified:
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java?rev=812901&r1=812900&r2=812901&view=diff
==============================================================================
---
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
(original)
+++
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
Wed Sep 9 11:47:22 2009
@@ -23,7 +23,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
@@ -53,6 +52,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.invoker.MavenInvocationException;
import org.codehaus.plexus.components.interactivity.InputHandler;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
@@ -374,7 +374,22 @@
}
// run clirr
- executeClirr();
+ try
+ {
+ executeClirr();
+ }
+ catch ( MavenInvocationException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "MavenInvocationException: " + e.getMessage(),
e );
+ }
+ else
+ {
+ getLog().error( "MavenInvocationException: " + e.getMessage()
);
+ }
+ getLog().info( "Clirr is ignored." );
+ }
// run qdox and process
try
@@ -485,7 +500,10 @@
}
else
{
- getLog().warn( "Unrecognized '" + s + "' for fixTags
parameter. Ignored it!" );
+ if ( getLog().isWarnEnabled() )
+ {
+ getLog().warn( "Unrecognized '" + s + "' for fixTags
parameter. Ignored it!" );
+ }
}
}
fixTags = StringUtils.join( filtered.iterator(), "," );
@@ -495,9 +513,12 @@
// encoding
if ( StringUtils.isEmpty( encoding ) )
{
- getLog().warn(
- "File encoding has not been set, using platform
encoding "
- + ReaderFactory.FILE_ENCODING + ", i.e. build
is platform dependent!" );
+ if ( getLog().isWarnEnabled() )
+ {
+ getLog().warn(
+ "File encoding has not been set, using platform
encoding "
+ + ReaderFactory.FILE_ENCODING + ", i.e.
build is platform dependent!" );
+ }
encoding = ReaderFactory.FILE_ENCODING;
}
@@ -505,7 +526,10 @@
if ( !( LEVEL_PUBLIC.equalsIgnoreCase( level.trim() ) ||
LEVEL_PROTECTED.equalsIgnoreCase( level.trim() )
|| LEVEL_PACKAGE.equalsIgnoreCase( level.trim() ) ||
LEVEL_PRIVATE.equalsIgnoreCase( level.trim() ) ) )
{
- getLog().warn( "Unrecognized '" + level + "' for level parameter,
using 'protected' level." );
+ if ( getLog().isWarnEnabled() )
+ {
+ getLog().warn( "Unrecognized '" + level + "' for level
parameter, using 'protected' level." );
+ }
level = "protected";
}
}
@@ -585,8 +609,11 @@
/**
* Invoke Maven to run clirr-maven-plugin to find API differences.
+ *
+ * @throws MavenInvocationException if any
*/
private void executeClirr()
+ throws MavenInvocationException
{
if ( ignoreClirr )
{
@@ -615,7 +642,7 @@
{
if ( invokerLogFile.exists() )
{
- String invokerLogContent = readFile( invokerLogFile, "UTF-8" );
+ String invokerLogContent = StringUtils.unifyLineSeparators(
FileUtils.fileRead( invokerLogFile, "UTF-8" ) );
// see
org.codehaus.mojo.clirr.AbstractClirrMojo#getComparisonArtifact()
final String artifactNotFoundMsg =
"Unable to find a previous version of the project in the
repository";
@@ -656,13 +683,19 @@
{
if ( !clirrTextOutputFile.exists() )
{
- getLog().info(
- "No Clirr output file '" +
clirrTextOutputFile.getAbsolutePath()
- + "' exists, Clirr is ignored." );
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info(
+ "No Clirr output file '" +
clirrTextOutputFile.getAbsolutePath()
+ + "' exists, Clirr is ignored." );
+ }
return;
}
- getLog().info( "Clirr output file was created: " +
clirrTextOutputFile.getAbsolutePath() );
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( "Clirr output file was created: " +
clirrTextOutputFile.getAbsolutePath() );
+ }
clirrNewClasses = new LinkedList();
clirrNewMethods = new LinkedHashMap();
@@ -674,7 +707,10 @@
String[] split = StringUtils.split( line, ":" );
if ( split.length != 4 )
{
- getLog().debug( "Unable to parse the clirr line: " + line );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Unable to parse the clirr line: " + line
);
+ }
continue;
}
@@ -685,7 +721,10 @@
}
catch ( NumberFormatException e )
{
- getLog().debug( "Unable to parse the clirr line: " + line );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Unable to parse the clirr line: " + line
);
+ }
continue;
}
@@ -794,7 +833,10 @@
}
else
{
- getLog().warn( f + " doesn't exist. Ignored it." );
+ if ( getLog().isWarnEnabled() )
+ {
+ getLog().warn( f + " doesn't exist. Ignored it." );
+ }
}
}
@@ -817,7 +859,10 @@
}
catch ( ParseException e )
{
- getLog().warn( "QDOX ParseException: " + e.getMessage() + ".
Can't fix it." );
+ if ( getLog().isWarnEnabled() )
+ {
+ getLog().warn( "QDOX ParseException: " + e.getMessage() +
". Can't fix it." );
+ }
}
}
@@ -881,9 +926,12 @@
File javaFile = new File( javaClass.getSource().getURL().getFile() );
// the original java content in memory
- final String originalContent = readFile( javaFile, encoding );
+ final String originalContent = StringUtils.unifyLineSeparators(
FileUtils.fileRead( javaFile, encoding ) );
- getLog().debug( "Fixing " + javaClass.getFullyQualifiedName() );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Fixing " + javaClass.getFullyQualifiedName() );
+ }
final StringWriter stringWriter = new StringWriter();
BufferedReader reader = null;
@@ -958,7 +1006,10 @@
IOUtil.close( reader );
}
- getLog().debug( "Saving " + javaClass.getFullyQualifiedName() );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Saving " + javaClass.getFullyQualifiedName() );
+ }
if ( outputDirectory != null
&& !outputDirectory.getAbsolutePath().equals(
getProjectSourceDirectory().getAbsolutePath() ) )
@@ -2822,27 +2873,6 @@
// ----------------------------------------------------------------------
/**
- * @param javaFile not null
- * @param encoding not null
- * @return the content with unified line separator of the given javaFile
using the given encoding.
- * @throws IOException if any
- */
- private static String readFile( final File javaFile, final String encoding
)
- throws IOException
- {
- Reader fileReader = null;
- try
- {
- fileReader = ReaderFactory.newReader( javaFile, encoding );
- return StringUtils.unifyLineSeparators( IOUtil.toString(
fileReader ) );
- }
- finally
- {
- IOUtil.close( fileReader );
- }
- }
-
- /**
* Write content into the given javaFile and using the given encoding.
* All line separators will be unified.
*
Modified:
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java?rev=812901&r1=812900&r2=812901&view=diff
==============================================================================
---
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
(original)
+++
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
Wed Sep 9 11:47:22 2009
@@ -78,6 +78,7 @@
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.apache.maven.wagon.PathUtils;
@@ -92,7 +93,6 @@
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.DefaultConsumer;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
@@ -1821,14 +1821,14 @@
continue;
}
- File argFile = new File( getJavadocDirectory(), arg.substring(
1 ) );
+ File argFile = new File( javadocOutputDirectory,
arg.substring( 1 ) );
if ( argFile.exists() )
{
argFile.deleteOnExit();
}
}
- File scriptFile = new File( getJavadocDirectory(),
DEBUG_JAVADOC_SCRIPT_NAME );
+ File scriptFile = new File( javadocOutputDirectory,
DEBUG_JAVADOC_SCRIPT_NAME );
if ( scriptFile.exists() )
{
scriptFile.deleteOnExit();
@@ -3170,11 +3170,13 @@
* in the project.
*
* @param arguments a list of arguments, not null
+ * @throws MavenReportException if any
* @see #offlineLinks
* @see #getModulesLinks()
* @see <a
href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#package-list">package-list
spec</a>
*/
private void addLinkofflineArguments( List arguments )
+ throws MavenReportException
{
List offlineLinksList =
( offlineLinks != null ? new ArrayList( Arrays.asList(
offlineLinks ) ) : new ArrayList() );
@@ -4226,9 +4228,12 @@
}
CommandLineUtils.StringStreamConsumer err = new
CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer out = new
CommandLineUtils.StringStreamConsumer();
try
{
- int exitCode = CommandLineUtils.executeCommandLine( cmd, new
DefaultConsumer(), err );
+ int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err
);
+
+ String output = ( StringUtils.isEmpty( out.getOutput() ) ? null :
'\n' + out.getOutput() );
if ( exitCode != 0 )
{
@@ -4239,13 +4244,46 @@
}
writeDebugJavadocScript( cmdLine, javadocOutputDirectory );
- StringBuffer msg = new StringBuffer( "Exit code: " + exitCode
+ " - " + err.getOutput() );
+ if ( StringUtils.isNotEmpty( output ) && isJavadocVMInitError(
output ) )
+ {
+ StringBuffer msg = new StringBuffer();
+ msg.append( output );
+ msg.append( '\n' ).append( '\n' );
+ msg.append( JavadocUtil.ERROR_INIT_VM ).append( '\n' );
+ msg.append( "Or, try to reduce the Java heap size for the
Javadoc goal using " );
+ msg.append( "-Dminmemory=<size> and -Dmaxmemory=<size>."
).append( '\n' ).append( '\n' );
+
+ msg.append( "Command line was: " ).append( cmdLine
).append( '\n' ).append( '\n' );
+ msg.append( "Refer to the generated Javadoc files in '"
).append( javadocOutputDirectory )
+ .append( "' dir.\n" );
+
+ throw new MavenReportException( msg.toString() );
+ }
+
+ if ( StringUtils.isNotEmpty( output ) )
+ {
+ getLog().info( output );
+ }
+
+ StringBuffer msg = new StringBuffer( "\nExit code: " );
+ msg.append( exitCode );
+ if ( StringUtils.isNotEmpty( err.getOutput() ) )
+ {
+ msg.append( " - " ).append( err.getOutput() );
+ }
msg.append( '\n' );
- msg.append( "Command line was: " + cmdLine ).append( '\n'
).append( '\n' );
- msg.append( "Refer to the generated Javadoc files in '" +
javadocOutputDirectory ).append( "' dir.\n" );
+ msg.append( "Command line was: " ).append( cmdLine ).append(
'\n' ).append( '\n' );
+
+ msg.append( "Refer to the generated Javadoc files in '"
).append( javadocOutputDirectory )
+ .append( "' dir.\n" );
throw new MavenReportException( msg.toString() );
}
+
+ if ( StringUtils.isNotEmpty( output ) )
+ {
+ getLog().info( output );
+ }
}
catch ( CommandLineException e )
{
@@ -4340,7 +4378,14 @@
}
catch ( Exception e )
{
- getLog().error( "Unable to retrieve the dependency: " +
dependency + ". Ignored." );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "Unable to retrieve the dependency: "
+ dependency + ". Ignored.", e );
+ }
+ else
+ {
+ getLog().error( "Unable to retrieve the dependency: "
+ dependency + ". Ignored." );
+ }
}
if ( artifact != null && artifact.getFile().exists() )
@@ -4360,7 +4405,14 @@
}
catch ( IOException e )
{
- getLog().error( "IOException: " + e.getMessage() );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "IOException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "IOException: " + e.getMessage() );
+ }
}
}
}
@@ -4460,11 +4512,13 @@
*
* @return the detected Javadoc links using the Maven conventions for all
modules defined in the current project
* or an empty list.
+ * @throws MavenReportException if any
* @see #detectOfflineLinks
* @see #reactorProjects
* @since 2.6
*/
private List getModulesLinks()
+ throws MavenReportException
{
if ( !( detectOfflineLinks && !isAggregator() && reactorProjects !=
null ) )
{
@@ -4503,8 +4557,28 @@
File invokerDir = new File(
project.getBuild().getDirectory(), "invoker" );
invokerDir.mkdirs();
File invokerLogFile = FileUtils.createTempFile(
"maven-javadoc-plugin", ".txt", invokerDir );
- JavadocUtil.invokeMaven( getLog(), new File(
localRepository.getBasedir() ), p.getFile(),
- Collections.singletonList(
javadocGoal ), null, invokerLogFile );
+ try
+ {
+ JavadocUtil.invokeMaven( getLog(), new File(
localRepository.getBasedir() ), p.getFile(),
+ Collections.singletonList(
javadocGoal ), null, invokerLogFile );
+ }
+ catch ( MavenInvocationException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "MavenInvocationException: " +
e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "MavenInvocationException: " +
e.getMessage() );
+ }
+
+ String invokerLogContent = JavadocUtil.readFile(
invokerLogFile, "UTF-8" );
+ if ( invokerLogContent != null &&
invokerLogContent.indexOf( JavadocUtil.ERROR_INIT_VM ) == -1 )
+ {
+ throw new MavenReportException( e.getMessage(), e
);
+ }
+ }
}
if ( location.exists() )
@@ -4515,7 +4589,10 @@
ol.setUrl( url );
ol.setLocation( location.getAbsolutePath() );
- getLog().debug( "Added Javadoc link: " + url + " for the
project: " + p.getId() );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Added Javadoc link: " + url + " for
the project: " + p.getId() );
+ }
modulesLinks.add( ol );
}
@@ -4558,24 +4635,27 @@
{
String url = getJavadocLink( artifactProject );
- getLog().debug(
- "Added Javadoc link: " + url + " for
the project: "
- + artifactProject.getId() );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug(
+ "Added Javadoc link: " + url + "
for the project: "
+ + artifactProject.getId() );
+ }
dependenciesLinks.add( url );
}
}
catch ( ProjectBuildingException e )
{
- getLog().debug(
- "Error when building the artifact: " +
artifact.toString()
- + ". Ignored to add Javadoc link." );
if ( getLog().isDebugEnabled() )
{
- getLog().debug( "ProjectBuildingException: " +
e.getMessage(), e );
+ getLog().debug(
+ "Error when building the artifact: " +
artifact.toString()
+ + ". Ignored to add Javadoc link."
);
+ getLog().error( "ProjectBuildingException: " +
e.getMessage(), e );
}
else
{
- getLog().debug( "ProjectBuildingException: " +
e.getMessage() );
+ getLog().error( "ProjectBuildingException: " +
e.getMessage() );
}
}
}
@@ -4613,18 +4693,24 @@
}
catch ( NumberFormatException e )
{
- getLog().debug(
- "NumberFormatException for the source
parameter in the maven-compiler-plugin. "
- + "Ignored it", e );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug(
+ "NumberFormatException for the source
parameter in the maven-compiler-plugin. "
+ + "Ignored it", e );
+ }
}
}
else
{
- getLog().debug(
- "No maven-compiler-plugin defined in
${build.plugins} or in "
- + "${project.build.pluginManagement} for the "
+ project.getId()
- + ". Added Javadoc API link according the
javadoc executable version i.e.: "
- + fJavadocVersion );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug(
+ "No maven-compiler-plugin defined in
${build.plugins} or in "
+ + "${project.build.pluginManagement} for
the " + project.getId()
+ + ". Added Javadoc API link according the
javadoc executable version i.e.: "
+ + fJavadocVersion );
+ }
}
String javaApiLink = null;
@@ -4647,11 +4733,17 @@
if ( StringUtils.isNotEmpty( javaApiLink ) )
{
- getLog().debug( "Found Java API link: " + javaApiLink );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Found Java API link: " + javaApiLink );
+ }
}
else
{
- getLog().debug( "No Java API link found." );
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "No Java API link found." );
+ }
}
return javaApiLink;
@@ -4728,7 +4820,7 @@
try
{
- FileUtils.fileWrite( commandLineFile.getAbsolutePath(), cmdLine );
+ FileUtils.fileWrite( commandLineFile.getAbsolutePath(), "UTF-8",
cmdLine );
if ( !SystemUtils.IS_OS_WINDOWS )
{
@@ -4748,6 +4840,28 @@
}
}
+ /**
+ * Check if the Javadoc JVM is correctly started or not.
+ *
+ * @param output the command line output, not null.
+ * @return <code>true</code> if Javadoc output command line contains
Javadoc word, <code>false</code> otherwise.
+ * @see #executeJavadocCommandLine(Commandline, File)
+ * @since 2.6.1
+ */
+ private boolean isJavadocVMInitError( String output )
+ {
+ /*
+ * see main.usage and main.Building_tree keys from
+ * com.sun.tools.javadoc.resources.javadoc bundle in tools.jar
+ */
+ if ( output.indexOf( "Javadoc" ) != -1 || output.indexOf( "javadoc" )
!= -1 )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
// ----------------------------------------------------------------------
// Static methods
// ----------------------------------------------------------------------
Modified:
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java?rev=812901&r1=812900&r2=812901&view=diff
==============================================================================
---
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
(original)
+++
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
Wed Sep 9 11:47:22 2009
@@ -29,7 +29,6 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
-import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Modifier;
import java.net.URL;
@@ -69,7 +68,6 @@
import org.apache.maven.shared.invoker.PrintStreamHandler;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -87,6 +85,11 @@
/** The default timeout used when fetching url, i.e. 2000. */
public static final int DEFAULT_TIMEOUT = 2000;
+ /** Error message when VM could not be started using invoker. */
+ protected static final String ERROR_INIT_VM =
+ "Error occurred during initialization of VM, try to reduce the Java
heap size for the MAVEN_OPTS " +
+ "environnement variable using -Xms:<size> and -Xmx:<size>.";
+
/**
* Method that removes the invalid directories in the specified
directories.
* <b>Note</b>: All elements in <code>dirs</code> could be an absolute or
relative against the project's base
@@ -966,10 +969,12 @@
* @param goals a not null goals list.
* @param properties the properties for the goals, could be null.
* @param invokerLog the log file where the invoker will be written, if
null using <code>System.out</code>.
+ * @throws MavenInvocationException if any
* @since 2.6
*/
protected static void invokeMaven( Log log, File localRepositoryDir, File
projectFile, List goals,
Properties properties, File invokerLog )
+ throws MavenInvocationException
{
if ( projectFile == null )
{
@@ -1032,89 +1037,68 @@
request.setJavaHome( javaHome );
}
- InvocationResult result;
- try
- {
- if ( log != null )
- {
- log.debug( "Invoking Maven for the goals: " + goals + " with
properties=" + properties );
- }
- result = invoke( log, invoker, request, invokerLog, goals,
properties, null );
- }
- catch ( MavenInvocationException e )
+ if ( log != null && log.isDebugEnabled() )
{
- if ( log != null )
- {
- if ( log.isDebugEnabled() )
- {
- log.error( "MavenInvocationException: " + e.getMessage(),
e );
- }
- else
- {
- log.error( "MavenInvocationException: " + e.getMessage() );
- }
- log.error( "Error when invoking Maven, consult the invoker
log." );
- }
- return;
+ log.debug( "Invoking Maven for the goals: " + goals + " with "
+ + ( properties == null ? "no properties" : "properties=" +
properties ) );
}
+ InvocationResult result = invoke( log, invoker, request, invokerLog,
goals, properties, null );
- String invokerLogContent = null;
- Reader reader = null;
- try
- {
- reader = ReaderFactory.newReader( invokerLog, "UTF-8" );
- invokerLogContent = IOUtil.toString( reader );
- }
- catch ( IOException e )
- {
- if ( log != null )
- {
- log.error( "IOException: " + e.getMessage() );
- }
- }
- finally
- {
- IOUtil.close( reader );
- }
-
- if ( invokerLogContent != null
- && invokerLogContent.indexOf( "Error occurred during
initialization of VM" ) != -1 )
+ if ( result.getExitCode() != 0 )
{
- if ( log != null )
- {
- log.info( "Error occurred during initialization of VM, try to
use an empty MAVEN_OPTS." );
+ String invokerLogContent = readFile( invokerLog, "UTF-8" );
- log.debug( "Reinvoking Maven for the goals: " + goals + " with
an empty MAVEN_OPTS" );
- }
- try
- {
- result = invoke( log, invoker, request, invokerLog, goals,
properties, "" );
- }
- catch ( MavenInvocationException e )
+ // see DefaultMaven
+ if ( invokerLogContent != null && ( invokerLogContent.indexOf(
"Scanning for projects..." ) == -1
+ || invokerLogContent.indexOf( OutOfMemoryError.class.getName()
) != -1 ) )
{
if ( log != null )
{
+ log.error( "Error occurred during initialization of VM,
trying to use an empty MAVEN_OPTS..." );
+
if ( log.isDebugEnabled() )
{
- log.error( "MavenInvocationException: " +
e.getMessage(), e );
+ log.debug( "Reinvoking Maven for the goals: " + goals
+ " with an empty MAVEN_OPTS..." );
}
- else
- {
- log.error( "MavenInvocationException: " +
e.getMessage() );
- }
- log.error( "Error when reinvoking Maven, consult the
invoker log." );
}
- return;
+ result = invoke( log, invoker, request, invokerLog, goals,
properties, "" );
}
}
if ( result.getExitCode() != 0 )
{
- if ( log != null )
+ String invokerLogContent = readFile( invokerLog, "UTF-8" );
+
+ // see DefaultMaven
+ if ( invokerLogContent != null && ( invokerLogContent.indexOf(
"Scanning for projects..." ) == -1
+ || invokerLogContent.indexOf( OutOfMemoryError.class.getName()
) != -1 ) )
{
- log.error( "Error when invoking Maven, consult the invoker log
file: "
- + invokerLog.getAbsolutePath() );
+ throw new MavenInvocationException( ERROR_INIT_VM );
}
+
+ throw new MavenInvocationException( "Error when invoking Maven,
consult the invoker log file: "
+ + invokerLog.getAbsolutePath() );
+ }
+ }
+
+ /**
+ * Read the given file and return the content or null if an IOException
occurs.
+ *
+ * @param javaFile not null
+ * @param encoding could be null
+ * @return the content with unified line separator of the given javaFile
using the given encoding.
+ * @see FileUtils#fileRead(File, String)
+ * @since 2.6.1
+ */
+ protected static String readFile( final File javaFile, final String
encoding )
+ {
+ try
+ {
+ return FileUtils.fileRead( javaFile, encoding );
+ }
+ catch (IOException e )
+ {
+ return null;
}
}
@@ -1188,7 +1172,10 @@
OutputStream os = null;
if ( invokerLog != null )
{
- log.debug( "Using " + invokerLog.getAbsolutePath() + " to log the
invoker" );
+ if ( log != null && log.isDebugEnabled() )
+ {
+ log.debug( "Using " + invokerLog.getAbsolutePath() + " to log
the invoker" );
+ }
try
{
@@ -1201,7 +1188,7 @@
}
catch ( FileNotFoundException e )
{
- if ( log != null )
+ if ( log != null && log.isErrorEnabled() )
{
log.error( "FileNotFoundException: " + e.getMessage() + ".
Using System.out to log the invoker." );
}
@@ -1209,7 +1196,7 @@
}
catch ( UnsupportedEncodingException e )
{
- if ( log != null )
+ if ( log != null && log.isErrorEnabled() )
{
log.error( "UnsupportedEncodingException: " +
e.getMessage()
+ ". Using System.out to log the invoker." );
@@ -1219,7 +1206,10 @@
}
else
{
- log.debug( "Using System.out to log the invoker." );
+ if ( log != null && log.isDebugEnabled() )
+ {
+ log.debug( "Using System.out to log the invoker." );
+ }
ps = System.out;
}
@@ -1232,7 +1222,8 @@
InvocationOutputHandler outputHandler = new PrintStreamHandler( ps,
false );
request.setOutputHandler( outputHandler );
- outputHandler.consumeLine( "Invoking Maven for the goals: " + goals +
" with properties=" + properties );
+ outputHandler.consumeLine( "Invoking Maven for the goals: " + goals +
" with "
+ + ( properties == null ? "no properties" : "properties=" +
properties ) );
outputHandler.consumeLine( "" );
outputHandler.consumeLine( "M2_HOME=" + getMavenHome( log ) );
outputHandler.consumeLine( "MAVEN_OPTS=" + getMavenOpts( log ) );
@@ -1268,7 +1259,7 @@
}
catch ( IOException e )
{
- if ( log != null )
+ if ( log != null && log.isDebugEnabled() )
{
log.debug( "IOException: " + e.getMessage() );
}
@@ -1278,7 +1269,7 @@
File m2Home = new File( mavenHome );
if ( !m2Home.exists() )
{
- if ( log != null )
+ if ( log != null && log.isErrorEnabled() )
{
log
.error( "Cannot find Maven application directory. Either
specify \'maven.home\' system property, or "
@@ -1303,7 +1294,7 @@
}
catch ( IOException e )
{
- if ( log != null )
+ if ( log != null && log.isDebugEnabled() )
{
log.debug( "IOException: " + e.getMessage() );
}
@@ -1339,7 +1330,7 @@
}
catch ( IOException e )
{
- if ( log != null )
+ if ( log != null && log.isDebugEnabled() )
{
log.debug( "IOException: " + e.getMessage() );
}
@@ -1348,7 +1339,7 @@
if ( javaHome == null || !javaHome.exists() )
{
- if ( log != null )
+ if ( log != null && log.isErrorEnabled() )
{
log.error( "Cannot find Java application directory. Either
specify \'java.home\' system property, or "
+ "JAVA_HOME environment variable." );
@@ -1372,7 +1363,7 @@
}
catch ( IOException e )
{
- if ( log != null )
+ if ( log != null && log.isDebugEnabled() )
{
log.debug( "IOException: " + e.getMessage() );
}
Modified:
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java?rev=812901&r1=812900&r2=812901&view=diff
==============================================================================
---
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
(original)
+++
maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
Wed Sep 9 11:47:22 2009
@@ -32,6 +32,7 @@
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.shared.invoker.MavenInvocationException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
@@ -613,8 +614,10 @@
*
* @param testPom not null
* @param log not null
+ * @throws MavenInvocationException if any
*/
private void invokeCompileGoal( File testPom, Log log )
+ throws MavenInvocationException
{
List goals = new ArrayList();
goals.add( "clean" );