PR: MNG-530

don't attempt to configure non-report mojos during reporting



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@220042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-21 12:18:35 +00:00
parent 1af333b028
commit ed7ccf707a
5 changed files with 253 additions and 266 deletions

View File

@ -19,7 +19,6 @@
<groupId>org.apache.maven.reporting</groupId> <groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId> <artifactId>maven-reporting-api</artifactId>
<version>2.0-beta-1-SNAPSHOT</version> <version>2.0-beta-1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -122,7 +121,7 @@
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-clover-plugin</artifactId>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -52,6 +52,7 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.MavenMetadataSource; import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.PlexusContainerException;
@ -286,7 +287,7 @@ public class DefaultPluginManager
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() ); dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
} }
plugin = getConfiguredMojo( mojoDescriptor, session, dom, project ); plugin = getConfiguredMojo( mojoDescriptor, session, dom, project, false );
} }
catch ( PluginConfigurationException e ) catch ( PluginConfigurationException e )
{ {
@ -375,7 +376,11 @@ public class DefaultPluginManager
Xpp3Dom dom = project.getReportConfiguration( reportPlugin.getGroupId(), Xpp3Dom dom = project.getReportConfiguration( reportPlugin.getGroupId(),
reportPlugin.getArtifactId(), executionId ); reportPlugin.getArtifactId(), executionId );
reports.add( getConfiguredMojo( mojoDescriptor, session, dom, project ) ); Mojo reportMojo = getConfiguredMojo( mojoDescriptor, session, dom, project, true );
if ( reportMojo != null )
{
reports.add( reportMojo );
}
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
@ -401,19 +406,24 @@ public class DefaultPluginManager
} }
private Mojo getConfiguredMojo( MojoDescriptor mojoDescriptor, MavenSession session, Xpp3Dom dom, private Mojo getConfiguredMojo( MojoDescriptor mojoDescriptor, MavenSession session, Xpp3Dom dom,
MavenProject project ) MavenProject project, boolean report )
throws ComponentLookupException, PluginConfigurationException, PluginManagerException throws ComponentLookupException, PluginConfigurationException, PluginManagerException
{ {
PlexusContainer pluginContainer = getPluginContainer( mojoDescriptor.getPluginDescriptor() );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
// if this is the first time this plugin has been used, the plugin's container will only // if this is the first time this plugin has been used, the plugin's container will only
// contain the plugin's artifact in isolation; we need to finish resolving the plugin's // contain the plugin's artifact in isolation; we need to finish resolving the plugin's
// dependencies, and add them to the container. // dependencies, and add them to the container.
ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session ); ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session );
Mojo plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() ); Mojo plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( report && !( plugin instanceof MavenReport ) )
{
// TODO: the mojoDescriptor should actually capture this information so we don't get this far
return null;
}
plugin.setLog( mojoLogger ); plugin.setLog( mojoLogger );

View File

@ -41,8 +41,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven.reporting</groupId> <groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId> <artifactId>maven-reporting-impl</artifactId>
<version>2.0-alpha-3</version> <version>2.0-beta-1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>clover</groupId> <groupId>clover</groupId>

View File

@ -1,234 +1,234 @@
package org.apache.maven.plugin.pmd; package org.apache.maven.plugin.pmd;
/* /*
* Copyright 2005 The Apache Software Foundation. * Copyright 2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.PMDException; import net.sourceforge.pmd.PMDException;
import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory; import net.sourceforge.pmd.RuleSetFactory;
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.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;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
/** /**
* Implement the PMD report. * Implement the PMD report.
* *
* @goal pmd * @goal pmd
* *
* @todo needs to support the multiple source roots * @todo needs to support the multiple source roots
* @author Brett Porter * @author Brett Porter
* @version $Id: PmdReport.java,v 1.3 2005/02/23 00:08:53 brett Exp $ * @version $Id: PmdReport.java,v 1.3 2005/02/23 00:08:53 brett Exp $
*/ */
public class PmdReport public class PmdReport
extends AbstractMavenReport extends AbstractMavenReport
{ {
/** /**
* @parameter expression="${project.build.directory}/site" * @parameter expression="${project.build.directory}/site"
* @required * @required
*/ */
private String outputDirectory; private String outputDirectory;
/** /**
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}" * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
* @required * @required
* @readonly * @readonly
*/ */
private SiteRenderer siteRenderer; private SiteRenderer siteRenderer;
/** /**
* @parameter expression="${project}" * @parameter expression="${project}"
* @required * @required
* @readonly * @readonly
*/ */
private MavenProject project; private MavenProject project;
/** /**
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/ */
public String getName( Locale locale ) public String getName( Locale locale )
{ {
return getBundle( locale ).getString( "report.pmd.name" ); return getBundle( locale ).getString( "report.pmd.name" );
} }
/** /**
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/ */
public String getDescription( Locale locale ) public String getDescription( Locale locale )
{ {
return getBundle( locale ).getString( "report.pmd.description" ); return getBundle( locale ).getString( "report.pmd.description" );
} }
/** /**
* @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory()
*/ */
protected String getOutputDirectory() protected String getOutputDirectory()
{ {
return outputDirectory; return outputDirectory;
} }
/** /**
* @see org.apache.maven.reporting.AbstractMavenReport#getProject() * @see org.apache.maven.reporting.AbstractMavenReport#getProject()
*/ */
protected MavenProject getProject() protected MavenProject getProject()
{ {
return project; return project;
} }
/** /**
* @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer()
*/ */
protected SiteRenderer getSiteRenderer() protected SiteRenderer getSiteRenderer()
{ {
return siteRenderer; return siteRenderer;
} }
/** /**
* @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale) * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
*/ */
public void executeReport( Locale locale ) public void executeReport( Locale locale )
throws MavenReportException throws MavenReportException
{ {
Sink sink = getSink(); Sink sink = getSink();
PMD pmd = new PMD(); PMD pmd = new PMD();
RuleContext ruleContext = new RuleContext(); RuleContext ruleContext = new RuleContext();
Report report = new Report(); Report report = new Report();
// TODO: use source roots instead // TODO: use source roots instead
String sourceDirectory = getProject().getBuild().getSourceDirectory(); String sourceDirectory = getProject().getBuild().getSourceDirectory();
PmdReportListener reportSink = new PmdReportListener( sink, sourceDirectory, getBundle( locale ) ); PmdReportListener reportSink = new PmdReportListener( sink, sourceDirectory, getBundle( locale ) );
report.addListener( reportSink ); report.addListener( reportSink );
ruleContext.setReport( report ); ruleContext.setReport( report );
RuleSetFactory ruleSetFactory = new RuleSetFactory(); RuleSetFactory ruleSetFactory = new RuleSetFactory();
InputStream rulesInput = pmd.getClass().getResourceAsStream( "/rulesets/controversial.xml" ); InputStream rulesInput = pmd.getClass().getResourceAsStream( "/rulesets/controversial.xml" );
RuleSet ruleSet = ruleSetFactory.createRuleSet( rulesInput ); RuleSet ruleSet = ruleSetFactory.createRuleSet( rulesInput );
reportSink.beginDocument(); reportSink.beginDocument();
List files; List files;
try try
{ {
files = getFilesToProcess( "**/*.java", null ); files = getFilesToProcess( "**/*.java", null );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MavenReportException( "Can't parse " + sourceDirectory, e ); throw new MavenReportException( "Can't parse " + sourceDirectory, e );
} }
for ( Iterator i = files.iterator(); i.hasNext(); ) for ( Iterator i = files.iterator(); i.hasNext(); )
{ {
File file = (File) i.next(); File file = (File) i.next();
FileReader fileReader; FileReader fileReader;
try try
{ {
fileReader = new FileReader( file ); fileReader = new FileReader( file );
} }
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
{ {
throw new MavenReportException( "Error opening source file: " + file, e ); throw new MavenReportException( "Error opening source file: " + file, e );
} }
try try
{ {
// TODO: lazily call beginFile in case there are no rules // TODO: lazily call beginFile in case there are no rules
reportSink.beginFile( file ); reportSink.beginFile( file );
ruleContext.setSourceCodeFilename( file.getAbsolutePath() ); ruleContext.setSourceCodeFilename( file.getAbsolutePath() );
pmd.processFile( fileReader, ruleSet, ruleContext ); pmd.processFile( fileReader, ruleSet, ruleContext );
reportSink.endFile( file ); reportSink.endFile( file );
} }
catch ( PMDException e ) catch ( PMDException e )
{ {
Exception ex = e; Exception ex = e;
if ( e.getReason() != null ) if ( e.getReason() != null )
{ {
ex = e.getReason(); ex = e.getReason();
} }
throw new MavenReportException( "Failure executing PMD for: " + file, ex ); throw new MavenReportException( "Failure executing PMD for: " + file, ex );
} }
finally finally
{ {
try try
{ {
fileReader.close(); fileReader.close();
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MavenReportException( "Error closing source file: " + file, e ); throw new MavenReportException( "Error closing source file: " + file, e );
} }
} }
} }
reportSink.endDocument(); reportSink.endDocument();
} }
/** /**
* @see org.apache.maven.reporting.MavenReport#getOutputName() * @see org.apache.maven.reporting.MavenReport#getOutputName()
*/ */
public String getOutputName() public String getOutputName()
{ {
return "pmd"; return "pmd";
} }
private List getFilesToProcess( String includes, String excludes ) private List getFilesToProcess( String includes, String excludes )
throws IOException throws IOException
{ {
File dir = new File( getProject().getBuild().getSourceDirectory() ); File dir = new File( getProject().getBuild().getSourceDirectory() );
if ( !dir.exists() ) if ( !dir.exists() )
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
StringBuffer excludesStr = new StringBuffer(); StringBuffer excludesStr = new StringBuffer();
if ( StringUtils.isNotEmpty( excludes ) ) if ( StringUtils.isNotEmpty( excludes ) )
{ {
excludesStr.append( excludes ); excludesStr.append( excludes );
} }
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ ) for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
{ {
if ( excludesStr.length() > 0 ) if ( excludesStr.length() > 0 )
{ {
excludesStr.append( "," ); excludesStr.append( "," );
} }
excludesStr.append( DEFAULT_EXCLUDES[i] ); excludesStr.append( DEFAULT_EXCLUDES[i] );
} }
return FileUtils.getFiles( dir, includes, excludesStr.toString() ); return FileUtils.getFiles( dir, includes, excludesStr.toString() );
} }
private static ResourceBundle getBundle( Locale locale ) private static ResourceBundle getBundle( Locale locale )
{ {
return ResourceBundle.getBundle("pmd-report", locale, PmdReport.class.getClassLoader() ); return ResourceBundle.getBundle("pmd-report", locale, PmdReport.class.getClassLoader() );
} }
} }

View File

@ -908,19 +908,6 @@ public class DoxiaMojo
{ {
ReportPlugin reportPlugin = (ReportPlugin) it.next(); ReportPlugin reportPlugin = (ReportPlugin) it.next();
// try
// {
// pluginManager.verifyPlugin( reportPlugin, project, settings, localRepository );
// }
// catch ( PluginVersionResolutionException e )
// {
// throw new MojoExecutionException( "Cannot resolve version for report plugin", e );
// }
// catch ( PluginManagerException e )
// {
// throw new MojoExecutionException( "Cannot find report plugin", e );
// }
try try
{ {
List reportSets = reportPlugin.getReportSets(); List reportSets = reportPlugin.getReportSets();
@ -943,16 +930,7 @@ public class DoxiaMojo
} }
} }
for ( Iterator i = reportsList.iterator(); i.hasNext(); ) reports.addAll( reportsList );
{
Object obj = i.next();
//TODO: Remove this test when getReports will return only reports object
if ( obj instanceof MavenReport )
{
reports.add( obj );
}
}
} }
catch ( PluginManagerException e ) catch ( PluginManagerException e )
{ {