PR: MNG-469

remove MavenConfiguration class



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191301 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-18 16:52:44 +00:00
parent 1a63032af4
commit 7299bd7058
9 changed files with 55 additions and 199 deletions

View File

@ -28,7 +28,6 @@
import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportConfiguration;
import org.apache.maven.reporting.MavenReportException; import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.i18n.I18N;
@ -225,14 +224,8 @@ public void execute()
{ {
Locale locale = (Locale) i.next(); Locale locale = (Locale) i.next();
MavenReportConfiguration config = new MavenReportConfiguration();
config.setProject( project );
File localeOutputDirectory = getOuputDirectory( locale ); File localeOutputDirectory = getOuputDirectory( locale );
config.setReportOutputDirectory( localeOutputDirectory );
//Generate reports //Generate reports
if ( reports != null ) if ( reports != null )
{ {
@ -242,7 +235,7 @@ public void execute()
getLog().info( "Generate " + report.getName( locale ) + " report." ); getLog().info( "Generate " + report.getName( locale ) + " report." );
report.setConfiguration( config ); report.setReportOutputDirectory( localeOutputDirectory );
String outputFileName = report.getOutputName() + ".html"; String outputFileName = report.getOutputName() + ".html";

View File

@ -43,7 +43,9 @@ public abstract class AbstractMavenReport
extends AbstractMojo extends AbstractMojo
implements MavenReport implements MavenReport
{ {
/** @todo share, use default excludes from plexus utils. */ /**
* @todo share, use default excludes from plexus utils.
*/
protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*", "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
@ -62,47 +64,30 @@ public abstract class AbstractMavenReport
// Mac // Mac
"**/.DS_Store"}; "**/.DS_Store"};
private MavenReportConfiguration config;
private Sink sink; private Sink sink;
private Locale locale = Locale.ENGLISH; private Locale locale = Locale.ENGLISH;
public MavenReportConfiguration getConfiguration()
{
return config;
}
public void setConfiguration( MavenReportConfiguration config )
{
this.config = config;
}
protected abstract SiteRenderer getSiteRenderer(); protected abstract SiteRenderer getSiteRenderer();
protected abstract String getOutputDirectory(); protected abstract String getOutputDirectory();
protected abstract MavenProject getProject(); protected abstract MavenProject getProject();
private File reportOutputDirectory;
/** /**
* @see org.apache.maven.plugin.Mojo#execute() * @see org.apache.maven.plugin.Mojo#execute()
*/ */
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
config = new MavenReportConfiguration();
config.setProject( getProject() );
config.setReportOutputDirectory( new File( getOutputDirectory() ) );
try try
{ {
String outputDirectory = getOutputDirectory(); String outputDirectory = getOutputDirectory();
XhtmlSink sink = getSiteRenderer().createSink( new File( outputDirectory ), getOutputName() + ".html", XhtmlSink sink = getSiteRenderer().createSink( new File( outputDirectory ), getOutputName() + ".html",
outputDirectory, outputDirectory, getSiteDescriptor(), "maven" );
getSiteDescriptor(), "maven" );
generate( sink, Locale.ENGLISH ); generate( sink, Locale.ENGLISH );
@ -120,14 +105,9 @@ public void execute()
public void generate( Sink sink, Locale locale ) public void generate( Sink sink, Locale locale )
throws MavenReportException throws MavenReportException
{ {
if ( config == null )
{
throw new MavenReportException( "You must specify a report configuration." );
}
if ( sink == null ) if ( sink == null )
{ {
throw new MavenReportException( "You must specify a sink configuration." ); throw new MavenReportException( "You must specify a sink." );
} }
else else
{ {
@ -158,7 +138,6 @@ public String getCategoryName()
} }
private String getReportsMenu() private String getReportsMenu()
throws MojoExecutionException
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append( "<menu name=\"Project Documentation\">\n" ); buffer.append( "<menu name=\"Project Documentation\">\n" );
@ -212,4 +191,18 @@ private InputStream getSiteDescriptor()
return new StringInputStream( siteDescriptorContent ); return new StringInputStream( siteDescriptorContent );
} }
public File getReportOutputDirectory()
{
if ( reportOutputDirectory == null )
{
reportOutputDirectory = new File( getOutputDirectory() );
}
return reportOutputDirectory;
}
public void setReportOutputDirectory( File reportOutputDirectory )
{
this.reportOutputDirectory = reportOutputDirectory;
}
} }

View File

@ -19,6 +19,7 @@
import org.codehaus.doxia.sink.Sink; import org.codehaus.doxia.sink.Sink;
import java.io.IOException; import java.io.IOException;
import java.io.File;
import java.util.Locale; import java.util.Locale;
/** /**
@ -36,10 +37,6 @@ public interface MavenReport
String CATEGORY_PROJECT_REPORTS = "Project Reports"; String CATEGORY_PROJECT_REPORTS = "Project Reports";
MavenReportConfiguration getConfiguration();
void setConfiguration( MavenReportConfiguration config );
void generate( Sink sink, Locale locale ) void generate( Sink sink, Locale locale )
throws MavenReportException; throws MavenReportException;
@ -53,4 +50,9 @@ void generate( Sink sink, Locale locale )
Sink getSink() Sink getSink()
throws IOException; throws IOException;
// TODO: remove?
void setReportOutputDirectory( File outputDirectory );
File getReportOutputDirectory();
} }

View File

@ -1,133 +0,0 @@
package org.apache.maven.reporting;
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed 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 org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.List;
/**
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
*/
public class MavenReportConfiguration
{
private MavenProject project;
private File basedir;
private File outputDirectory;
public void setReportOutputDirectory( File outputDirectory )
{
this.outputDirectory = outputDirectory;
}
public File getReportOutputDirectory()
{
return outputDirectory;
}
public File getBasedir()
{
return basedir;
}
public void setBasedir( File basedir )
{
this.basedir = basedir;
}
public Model getModel()
{
return project.getModel();
}
public void setProject( MavenProject project )
{
this.project = project;
}
public MavenProject getProject()
{
return project;
}
public List getDependencies()
{
return getModel().getDependencies();
}
public List getMailingLists()
{
return getModel().getMailingLists();
}
public Scm getScm()
{
return getModel().getScm();
}
public void setScm( Scm scm )
{
getModel().setScm( scm );
}
public String getSourceDirectory()
{
return getModel().getBuild().getSourceDirectory();
}
public void setSourceDirectory( String sourceDirectory )
{
getModel().getBuild().setSourceDirectory( sourceDirectory );
}
public List getCompileSourceRoots()
{
return project.getCompileSourceRoots();
}
public String getScriptSourceDirectory()
{
return getModel().getBuild().getScriptSourceDirectory();
}
public void setScriptSourceDirectory( String scriptSourceDirectory )
{
getModel().getBuild().setScriptSourceDirectory( scriptSourceDirectory );
}
public String getTestSourceDirectory()
{
return getModel().getBuild().getTestSourceDirectory();
}
public void setTestSourceDirectory( String testSourceDirectory )
{
getModel().getBuild().setTestSourceDirectory( testSourceDirectory );
}
public List getTestCompileSourceRoots()
{
return project.getTestCompileSourceRoots();
}
}

View File

@ -141,7 +141,7 @@ public void executeReport( Locale locale )
{ {
FileOutputStream out; FileOutputStream out;
// TODO: I removed outputDirectory, and shouldn't have. Put it back here. // TODO: I removed outputDirectory, and shouldn't have. Put it back here.
File resultFile = new File( getConfiguration().getModel().getBuild().getDirectory() + "/site", resultFileName ); File resultFile = new File( getProject().getModel().getBuild().getDirectory() + "/site", resultFileName );
try try
{ {
File parentFile = resultFile.getParentFile(); File parentFile = resultFile.getParentFile();
@ -168,6 +168,7 @@ else if ( "plain".equals( extraFormatter ) )
} }
File[] files; File[] files;
String sourceDirectory = getProject().getBuild().getSourceDirectory();
try try
{ {
List filesList = getFilesToProcess( "**/*.java", null ); List filesList = getFilesToProcess( "**/*.java", null );
@ -180,7 +181,7 @@ else if ( "plain".equals( extraFormatter ) )
} }
catch( IOException e ) catch( IOException e )
{ {
throw new MavenReportException( "Can't parse " + getConfiguration().getSourceDirectory(), e ); throw new MavenReportException( "Can't parse " + sourceDirectory, e );
} }
Configuration config; Configuration config;
@ -220,7 +221,8 @@ else if ( "plain".equals( extraFormatter ) )
checker.configure( config ); checker.configure( config );
AuditListener sinkListener = new CheckstyleReportListener( getSink(), getConfiguration().getSourceDirectory() ); // TODO: use source roots
AuditListener sinkListener = new CheckstyleReportListener( getSink(), sourceDirectory );
if ( listener != null ) if ( listener != null )
{ {
@ -272,7 +274,7 @@ private List getFilesToProcess( String includes, String excludes )
excludesStr.append( DEFAULT_EXCLUDES[i] ); excludesStr.append( DEFAULT_EXCLUDES[i] );
} }
return FileUtils.getFiles( new File( getConfiguration().getSourceDirectory() ), includes, excludesStr.toString() ); return FileUtils.getFiles( new File( getProject().getBuild().getSourceDirectory() ), includes, excludesStr.toString() );
} }
private Properties createOverridingProperties() private Properties createOverridingProperties()
@ -280,7 +282,7 @@ private Properties createOverridingProperties()
Properties props = new Properties(); Properties props = new Properties();
props.setProperty( "checkstyle.header.file", "LICENSE.txt" ); props.setProperty( "checkstyle.header.file", "LICENSE.txt" );
// TODO: explicit output directory when it is back // TODO: explicit output directory when it is back
props.setProperty( "checkstyle.cache.file", getConfiguration().getModel().getBuild().getDirectory() + "/checkstyle-cachefile" ); props.setProperty( "checkstyle.cache.file", getProject().getModel().getBuild().getDirectory() + "/checkstyle-cachefile" );
return props; return props;
} }
} }

View File

@ -24,6 +24,7 @@
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException; import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.model.Model;
import org.codehaus.doxia.sink.Sink; import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer; import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
@ -106,11 +107,6 @@ protected SiteRenderer getSiteRenderer()
public void generate( Sink sink, Locale locale ) public void generate( Sink sink, Locale locale )
throws MavenReportException throws MavenReportException
{ {
if ( getConfiguration() == null )
{
throw new MavenReportException( "You must specify a report configuration." );
}
executeReport( locale); executeReport( locale);
} }
@ -122,23 +118,24 @@ protected void executeReport( Locale locale )
{ {
try try
{ {
File outputDir = new File( getConfiguration().getReportOutputDirectory().getAbsolutePath() + "/apidocs" ); File outputDir = new File( getReportOutputDirectory().getAbsolutePath() + "/apidocs" );
outputDir.mkdirs(); outputDir.mkdirs();
int actualYear = Calendar.getInstance().get( Calendar.YEAR ); int actualYear = Calendar.getInstance().get( Calendar.YEAR );
String year; String year;
if ( getConfiguration().getModel().getInceptionYear() != null Model model = getProject().getModel();
&& Integer.valueOf( getConfiguration().getModel().getInceptionYear() ).intValue() == actualYear ) if ( model.getInceptionYear() != null
&& Integer.valueOf( model.getInceptionYear() ).intValue() == actualYear )
{ {
year = getConfiguration().getModel().getInceptionYear(); year = model.getInceptionYear();
} }
else else
{ {
year = getConfiguration().getModel().getInceptionYear() + "-" + String.valueOf( actualYear ); year = model.getInceptionYear() + "-" + String.valueOf( actualYear );
} }
StringBuffer classpath = new StringBuffer(); StringBuffer classpath = new StringBuffer();
for ( Iterator i = getConfiguration().getProject().getCompileClasspathElements().iterator(); i.hasNext(); ) for ( Iterator i = getProject().getCompileClasspathElements().iterator(); i.hasNext(); )
{ {
classpath.append( (String) i.next() ); classpath.append( (String) i.next() );
if ( i.hasNext() ) if ( i.hasNext() )
@ -149,14 +146,14 @@ protected void executeReport( Locale locale )
StringBuffer sourcePath = new StringBuffer(); StringBuffer sourcePath = new StringBuffer();
String[] fileList = new String[1]; String[] fileList = new String[1];
for ( Iterator i = getConfiguration().getCompileSourceRoots().iterator(); i.hasNext(); ) for ( Iterator i = getProject().getCompileSourceRoots().iterator(); i.hasNext(); )
{ {
String sourceDirectory = (String) i.next(); String sourceDirectory = (String) i.next();
fileList = FileUtils.getFilesFromExtension( sourceDirectory, new String[] { "java" } ); fileList = FileUtils.getFilesFromExtension( sourceDirectory, new String[] { "java" } );
sourcePath.append( sourceDirectory ); sourcePath.append( sourceDirectory );
} }
File javadocDirectory = new File( getConfiguration().getProject().getBuild().getDirectory() + "/javadoc" ); File javadocDirectory = new File( getProject().getBuild().getDirectory() + "/javadoc" );
if ( fileList != null && fileList.length != 0 ) if ( fileList != null && fileList.length != 0 )
{ {
StringBuffer files = new StringBuffer(); StringBuffer files = new StringBuffer();
@ -181,11 +178,11 @@ protected void executeReport( Locale locale )
cl.createArgument().setValue( "-author" ); cl.createArgument().setValue( "-author" );
cl.createArgument().setValue( "-windowtitle" ); cl.createArgument().setValue( "-windowtitle" );
cl.createArgument().setValue( cl.createArgument().setValue(
getConfiguration().getModel().getName() + " " model.getName() + " "
+ getConfiguration().getModel().getVersion() ); + model.getVersion() );
cl.createArgument().setValue( "-bottom" ); cl.createArgument().setValue( "-bottom" );
cl.createArgument().setValue( "Copyright &copy; " + year + " " cl.createArgument().setValue( "Copyright &copy; " + year + " "
+ getConfiguration().getModel().getOrganization().getName() + model.getOrganization().getName()
+ ". All Rights Reserved." ); + ". All Rights Reserved." );
cl.createArgument().setValue( "-sourcePath" ); cl.createArgument().setValue( "-sourcePath" );
cl.createArgument().setValue( sourcePath.toString() ); cl.createArgument().setValue( sourcePath.toString() );

View File

@ -132,7 +132,9 @@ public void executeReport( Locale locale )
PMD pmd = new PMD(); PMD pmd = new PMD();
RuleContext ruleContext = new RuleContext(); RuleContext ruleContext = new RuleContext();
Report report = new Report(); Report report = new Report();
PmdReportListener reportSink = new PmdReportListener( sink, getConfiguration().getSourceDirectory() ); // TODO: use source roots instead
String sourceDirectory = getProject().getBuild().getSourceDirectory();
PmdReportListener reportSink = new PmdReportListener( sink, sourceDirectory );
report.addListener( reportSink ); report.addListener( reportSink );
ruleContext.setReport( report ); ruleContext.setReport( report );
@ -149,7 +151,7 @@ public void executeReport( Locale locale )
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MavenReportException( "Can't parse " + getConfiguration().getSourceDirectory(), e ); throw new MavenReportException( "Can't parse " + sourceDirectory, e );
} }
for ( Iterator i = files.iterator(); i.hasNext(); ) for ( Iterator i = files.iterator(); i.hasNext(); )
@ -209,7 +211,7 @@ public String getOutputName()
private List getFilesToProcess( String includes, String excludes ) private List getFilesToProcess( String includes, String excludes )
throws IOException throws IOException
{ {
File dir = new File( getConfiguration().getSourceDirectory() ); File dir = new File( getProject().getBuild().getSourceDirectory() );
if ( !dir.exists() ) if ( !dir.exists() )
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;

View File

@ -115,7 +115,7 @@ public void executeReport( Locale locale )
{ {
try try
{ {
DependenciesRenderer r = new DependenciesRenderer( getSink(), getConfiguration().getModel() ); DependenciesRenderer r = new DependenciesRenderer( getSink(), getProject().getModel() );
r.render(); r.render();
} }

View File

@ -116,7 +116,7 @@ public void executeReport( Locale locale )
{ {
try try
{ {
MailingListsRenderer r = new MailingListsRenderer( getSink(), getConfiguration().getModel() ); MailingListsRenderer r = new MailingListsRenderer( getSink(), getProject().getModel() );
r.render(); r.render();
} }