clean up MavenReportException uses

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@314937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-12 14:58:24 +00:00
parent 0ad22e0a67
commit ec7316abed
10 changed files with 281 additions and 268 deletions

View File

@ -38,15 +38,16 @@ import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Map;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@ -240,7 +241,8 @@ public class CheckstyleReport
{
if ( !canGenerateReport() )
{
throw new MavenReportException( "No source directory to process for style" );
// TODO: failure if not a report
throw new MavenReportException( "No source directory to process for checkstyle" );
}
Map files = executeCheckstyle();
@ -253,22 +255,30 @@ public class CheckstyleReport
private Map executeCheckstyle()
throws MavenReportException
{
File[] files = getFilesToProcess( includes, excludes );
File[] files = new File[0];
try
{
files = getFilesToProcess( includes, excludes );
}
catch ( IOException e )
{
throw new MavenReportException( "Error getting files to process", e );
}
String configFile = getConfigFile();
Properties overridingProperties = getOverridingProperties();
ModuleFactory moduleFactory = getModuleFactory();
FilterSet filterSet = getSuppressions();
Checker checker;
try
{
Configuration config = ConfigurationLoader.loadConfiguration( configFile, new PropertiesExpander(
overridingProperties ) );
ModuleFactory moduleFactory = getModuleFactory();
FilterSet filterSet = getSuppressions();
Configuration config =
ConfigurationLoader.loadConfiguration( configFile, new PropertiesExpander( overridingProperties ) );
checker = new Checker();
@ -313,6 +323,8 @@ public class CheckstyleReport
if ( failsOnError && nbErrors > 0 )
{
// TODO: should be a failure, not an error. Report is not meant to throw an exception here (so site would
// work regardless of config), but should record this information
throw new MavenReportException( "There are " + nbErrors + " formatting errors." );
}
@ -348,6 +360,7 @@ public class CheckstyleReport
}
else
{
// TODO: failure if not a report
throw new MavenReportException(
"Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'." );
}
@ -358,8 +371,6 @@ public class CheckstyleReport
private OutputStream getOutputStream( File file )
throws MavenReportException
{
try
{
File parentFile = file.getAbsoluteFile().getParentFile();
@ -368,16 +379,20 @@ public class CheckstyleReport
parentFile.mkdirs();
}
return new FileOutputStream( file );
}
catch ( IOException ioe )
FileOutputStream fileOutputStream = null;
try
{
throw new MavenReportException( "Can't open file for output: " + file.getAbsolutePath(), ioe );
fileOutputStream = new FileOutputStream( file );
}
catch ( FileNotFoundException e )
{
throw new MavenReportException( "Unable to create output stream: " + file, e );
}
return fileOutputStream;
}
private File[] getFilesToProcess( String includes, String excludes )
throws MavenReportException
throws MavenReportException, IOException
{
StringBuffer excludesStr = new StringBuffer();
@ -397,16 +412,7 @@ public class CheckstyleReport
excludesStr.append( defaultExcludes[i] );
}
List files;
try
{
files = FileUtils.getFiles( sourceDirectory, includes, excludesStr.toString() );
}
catch ( IOException ioe )
{
throw new MavenReportException( "Failed to get source files", ioe );
}
List files = FileUtils.getFiles( sourceDirectory, includes, excludesStr.toString() );
return (File[]) files.toArray( EMPTY_FILE_ARRAY );
}
@ -419,9 +425,16 @@ public class CheckstyleReport
try
{
if ( propertiesFile != null )
{
if ( propertiesFile.exists() )
{
p.load( new FileInputStream( propertiesFile ) );
}
else
{
getLog().warn( "File '" + propertiesFile + "' not found - skipping" );
}
}
else if ( propertiesURL != null )
{
p.load( propertiesURL.openStream() );
@ -465,6 +478,7 @@ public class CheckstyleReport
}
else
{
// TODO: failure if not a report
throw new MavenReportException( "Invalid configuration file format: " + format );
}
@ -472,22 +486,15 @@ public class CheckstyleReport
}
private ModuleFactory getModuleFactory()
throws MavenReportException
throws CheckstyleException
{
if ( StringUtils.isEmpty( packageNamesFile ) )
{
return null;
}
try
{
return PackageNamesLoader.loadModuleFactory( packageNamesFile );
}
catch ( CheckstyleException ce )
{
throw new MavenReportException( "failed to load package names XML: " + packageNamesFile, ce );
}
}
private FilterSet getSuppressions()
throws MavenReportException

View File

@ -19,6 +19,7 @@ package org.apache.maven.plugin.javadoc;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
@ -28,6 +29,7 @@ import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
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;
@ -578,8 +580,6 @@ public class JavadocReport
*/
protected void executeReport( Locale locale )
throws MavenReportException
{
try
{
int actualYear = Calendar.getInstance().get( Calendar.YEAR );
String year = String.valueOf( actualYear );
@ -602,6 +602,8 @@ public class JavadocReport
StringBuffer options = new StringBuffer();
StringBuffer classpath = new StringBuffer();
try
{
for ( Iterator i = getProject().getCompileClasspathElements().iterator(); i.hasNext(); )
{
classpath.append( (String) i.next() );
@ -611,6 +613,11 @@ public class JavadocReport
classpath.append( PATH_SEPARATOR );
}
}
}
catch ( DependencyResolutionRequiredException e )
{
throw new MavenReportException( "Error in plugin descriptor - compile dependencies were not resolved", e );
}
if ( classpath.length() > 0 )
{
@ -659,10 +666,24 @@ public class JavadocReport
File file = new File( javadocDirectory, "files" );
file.deleteOnExit();
try
{
FileUtils.fileWrite( file.getAbsolutePath(), files.toString() );
}
catch ( IOException e )
{
throw new MavenReportException( "Unable to write temporary file for command execution", e );
}
try
{
// Copy default style sheet
copyDefaultStylesheet( javadocDirectory );
}
catch ( IOException e )
{
throw new MavenReportException( "Unable to copy default stylesheet", e );
}
Commandline cmd = new Commandline();
@ -698,8 +719,7 @@ public class JavadocReport
}
else
{
getLog().error(
"The maxmemory '" + maxmemory + "' is not a valid number. Ignore this option." );
getLog().error( "The maxmemory '" + maxmemory + "' is not a valid number. Ignore this option." );
}
}
}
@ -720,8 +740,7 @@ public class JavadocReport
}
else
{
getLog().error(
"The minmemory '" + minmemory + "' is not a valid number. Ignore this option." );
getLog().error( "The minmemory '" + minmemory + "' is not a valid number. Ignore this option." );
}
}
}
@ -774,8 +793,7 @@ public class JavadocReport
addArgIf( arguments, docfilessubdirs, "-docfilessubdirs", 1.4f );
addArgIfNotEmpty( arguments, "-docencoding", quotedArgument( docencoding ) );
addArgIfNotEmpty( arguments, "-doctitle", quotedArgument( doctitle ) );
addArgIfNotEmpty( arguments, "-excludedocfilessubdir", quotedPathArgument( excludedocfilessubdir ),
1.4f );
addArgIfNotEmpty( arguments, "-excludedocfilessubdir", quotedPathArgument( excludedocfilessubdir ), 1.4f );
addArgIfNotEmpty( arguments, "-footer", quotedArgument( footer ) );
addArgIfNotEmpty( arguments, "-group", quotedArgument( group ), true );
addArgIfNotEmpty( arguments, "-header", quotedArgument( header ) );
@ -811,7 +829,14 @@ public class JavadocReport
options.append( " " );
options.append( (String) it.next() );
}
try
{
FileUtils.fileWrite( optionsFile.getAbsolutePath(), options.toString() );
}
catch ( IOException e )
{
throw new MavenReportException( "Unable to write temporary file for command execution", e );
}
cmd.createArgument().setValue( "@options" );
optionsFile.deleteOnExit();
}
@ -820,17 +845,19 @@ public class JavadocReport
getLog().info( Commandline.toString( cmd.getCommandline() ) );
int exitCode = CommandLineUtils.executeCommandLine( cmd, new DefaultConsumer(), new DefaultConsumer() );
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
try
{
int exitCode = CommandLineUtils.executeCommandLine( cmd, new DefaultConsumer(), err );
if ( exitCode != 0 )
{
throw new MavenReportException( "Exit code: " + exitCode );
throw new MavenReportException( "Exit code: " + exitCode + " - " + err.getOutput() );
}
}
catch ( Exception e )
catch ( CommandLineException e )
{
getLog().debug( e );
throw new MavenReportException( "An error has occurred in javadoc report generation.", e );
throw new MavenReportException( "Unable to execute javadoc command", e );
}
}
@ -1034,10 +1061,8 @@ public class JavadocReport
* @param resource the resource
* @return InputStream An input stream for reading the resource, or <tt>null</tt>
* if the resource could not be found
* @throws Exception if any
*/
private static InputStream getStream( String resource )
throws Exception
{
return JavadocReport.class.getClassLoader().getResourceAsStream( resource );
}
@ -1047,14 +1072,14 @@ public class JavadocReport
* loader to the output directory.
*
* @param outputDirectory the output directory
* @throws Exception if any
* @throws IOException if any
* @see #DEFAULT_CSS_NAME
*/
private void copyDefaultStylesheet( File outputDirectory )
throws Exception
throws IOException
{
if ( ( outputDirectory == null ) || ( !outputDirectory.exists() ) )
if ( outputDirectory == null || !outputDirectory.exists() )
{
throw new IOException( "The outputDirectory " + outputDirectory + " doesn't exists." );
}
@ -1084,6 +1109,6 @@ public class JavadocReport
public boolean isExternalReport()
{
return true;
return true && super.isExternalReport();
}
}

View File

@ -22,7 +22,6 @@ import org.apache.maven.model.Notifier;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.StringUtils;
@ -107,7 +106,6 @@ public class CimReport
}
public void executeReport( Locale locale )
throws MavenReportException
{
CimRenderer r = new CimRenderer( getSink(), getProject().getModel(), locale );

View File

@ -24,7 +24,6 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
@ -151,7 +150,6 @@ public class DependenciesReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
DependenciesRenderer r = new DependenciesRenderer( getSink(), getProject(), locale, mavenProjectBuilder,
artifactFactory, localRepository );

View File

@ -21,7 +21,6 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.StringUtils;
@ -117,7 +116,6 @@ public class IssueTrackingReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
IssueTrackingRenderer r = new IssueTrackingRenderer( getSink(), getProject().getModel(), locale );

View File

@ -21,7 +21,6 @@ import org.apache.maven.model.License;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.IOUtil;
@ -128,7 +127,6 @@ public class LicenseReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
LicenseRenderer r = new LicenseRenderer( getSink(), getProject(), locale );

View File

@ -21,7 +21,6 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.StringUtils;
@ -119,7 +118,6 @@ public class MailingListsReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
MailingListsRenderer r = new MailingListsRenderer( getSink(), getProject().getModel(), locale );

View File

@ -21,7 +21,6 @@ import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.scm.manager.NoSuchScmProviderException;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository;
@ -135,7 +134,6 @@ public class ScmReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
ScmRenderer r = new ScmRenderer( scmManager, getSink(), getProject().getModel(), locale );

View File

@ -22,7 +22,6 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.StringUtils;
@ -121,7 +120,6 @@ public class TeamListReport
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/
public void executeReport( Locale locale )
throws MavenReportException
{
TeamListRenderer r = new TeamListRenderer( getSink(), getProject().getModel(), locale );

View File

@ -18,6 +18,7 @@ package org.apache.maven.plugins.site;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportException;
@ -44,6 +45,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -51,7 +53,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Comparator;
/**
* Generates the project site.
@ -178,7 +179,7 @@ public class SiteMojo
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
throws MojoExecutionException
throws MojoExecutionException, MojoFailureException
{
if ( templateDirectory == null )
{
@ -289,11 +290,7 @@ public class SiteMojo
}
// Exception if a file is duplicate
String msg = createDuplicateExceptionMsg( duplicate, locale );
if ( msg != null )
{
throw new MavenReportException( msg );
}
checkDuplicates( duplicate, locale );
String siteDescriptor = getSiteDescriptor( reports, locale, projectInfos, projectReports );
@ -1132,13 +1129,13 @@ public class SiteMojo
}
/**
* Create an <code>Exception</code> message if a file is duplicate.
* Throw an exception if a file is duplicate.
*
* @param duplicate a map of duplicate files
* @param locale the current locale
* @return the Message to throw
*/
private String createDuplicateExceptionMsg( Map duplicate, Locale locale )
private void checkDuplicates( Map duplicate, Locale locale )
throws MojoFailureException
{
if ( duplicate.size() > 0 )
{
@ -1182,11 +1179,9 @@ public class SiteMojo
if ( sb != null )
{
return sb.toString();
throw new MojoFailureException( sb.toString() );
}
}
return null;
}
/**