diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java index e0f7e47db4..d6d0823d00 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -85,15 +85,17 @@ public class DoxiaMojo config.setModel( project.getModel() ); + config.setOutputDirectory( new File( generatedSiteDirectory ) ); + if ( project.getReports() != null ) { reportManager.addReports( project.getReports(), localRepository, remoteRepositories ); - for ( Iterator i = project.getReports().getPlugins().iterator(); i.hasNext(); ) + for ( Iterator i = reportManager.getReports().keySet().iterator(); i.hasNext(); ) { - org.apache.maven.model.Plugin plugin = (org.apache.maven.model.Plugin) i.next(); + String reportName = (String) i.next(); - reportManager.executeReport( plugin.getArtifactId(), config, outputDirectory ); + reportManager.executeReport( reportName, config ); } } diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java index 0d5817b900..153869ffef 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java @@ -26,16 +26,42 @@ import java.io.IOException; public abstract class AbstractMavenReport implements MavenReport { - public Sink getSink( File outputDirectory ) - throws IOException + private MavenReportConfiguration config; + + public MavenReportConfiguration getConfiguration() { - return getSink( outputDirectory, getOutputName() ); + return config; } - public Sink getSink( File outputDirectory, String outputName ) + public void setConfiguration( MavenReportConfiguration config ) + { + this.config = config; + } + + public void generate() + throws MavenReportException + { + if ( config == null ) + { + throw new MavenReportException( "You must specify a report configuration." ); + } + + execute(); + } + + protected abstract void execute() + throws MavenReportException; + + public Sink getSink() throws IOException { - FileWriter writer = new FileWriter( new File( outputDirectory, "xdoc/" + outputName + ".xml" ) ); + return getSink( getOutputName() ); + } + + public Sink getSink( String outputName ) + throws IOException + { + FileWriter writer = new FileWriter( new File( config.getOutputDirectory(), "xdoc/" + outputName + ".xml" ) ); return new XdocSink( writer ); } diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java index 7e5c088b47..1d799bd5a5 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java @@ -25,6 +25,7 @@ import org.codehaus.doxia.sink.Sink; * @todo Later it may be appropriate to create something like a VelocityMavenReportRenderer that could take a velocity template and pipe that through Doxia rather than coding them up like this. */ public abstract class AbstractMavenReportRenderer + implements MavenReportRenderer { protected Sink sink; @@ -180,7 +181,7 @@ public abstract class AbstractMavenReportRenderer sink.tableRow_(); } - protected abstract String getTitle(); + public abstract String getTitle(); protected abstract void renderBody(); diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java index 2c799155da..760d7e3259 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java @@ -32,14 +32,18 @@ public interface MavenReport { String ROLE = MavenReport.class.getName(); - void execute( MavenReportConfiguration config ) + MavenReportConfiguration getConfiguration(); + + void setConfiguration( MavenReportConfiguration config ); + + void generate() throws MavenReportException; String getOutputName(); - Sink getSink( File outputDirectory ) + Sink getSink() throws IOException; - Sink getSink( File outputDirectory, String outputName ) + Sink getSink( String outputName ) throws IOException; } diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java index 7250483d4f..356c5aaba9 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java @@ -19,6 +19,7 @@ package org.apache.maven.reporting; import org.apache.maven.model.Model; import org.apache.maven.model.Scm; +import java.io.File; import java.util.List; /** @@ -29,6 +30,18 @@ public class MavenReportConfiguration { private Model model; + private File outputDirectory; + + public File getOutputDirectory() + { + return outputDirectory; + } + + public void setOutputDirectory( File outputDirectory ) + { + this.outputDirectory = outputDirectory; + } + public Model getModel() { if ( model == null ) diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportRenderer.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportRenderer.java new file mode 100644 index 0000000000..7e50f1ec90 --- /dev/null +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportRenderer.java @@ -0,0 +1,32 @@ +package org.apache.maven.reporting; + +/* + * Copyright 2004-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.codehaus.doxia.sink.Sink; + +/** + * @author Jason van Zyl + * @author Emmanuel Venisse + * @version $Id: AbstractMavenReportRenderer.java 163373 2005-02-22 03:37:00Z brett $ + * @todo Later it may be appropriate to create something like a VelocityMavenReportRenderer that could take a velocity template and pipe that through Doxia rather than coding them up like this. + */ +public interface MavenReportRenderer +{ + String getTitle(); + + void render(); +} \ No newline at end of file diff --git a/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/DefaultMavenReportManager.java b/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/DefaultMavenReportManager.java index c973b1c576..85a9f01982 100644 --- a/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/DefaultMavenReportManager.java +++ b/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/DefaultMavenReportManager.java @@ -39,6 +39,7 @@ import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.StringUtils; import java.util.Iterator; import java.util.List; @@ -74,16 +75,19 @@ public class DefaultMavenReportManager String version = pluginReport.getVersion(); - if ( version == null ) - { - throw new ReportManagerException( "The version of " + groupId + ":" + artifactId + " can not be empty" ); + if ( pluginReport != null && StringUtils.isEmpty( version ) ) + { + // The model/project builder should have validated this already + String message = "The maven plugin with groupId: '" + groupId + "' and artifactId: '" + artifactId + + "' which was configured for use in this project does not have a version associated with it."; + throw new IllegalStateException( message ); } try { Artifact pluginArtifact = artifactFactory.createArtifact( pluginReport.getGroupId(), pluginReport.getArtifactId(), - pluginReport.getVersion(), + version, null, "maven-plugin", null ); addPlugin( pluginArtifact, localRepository, remoteRepositories ); @@ -159,17 +163,33 @@ public class DefaultMavenReportManager } } + public Map getReports() + { + try + { + mavenReports = container.lookupMap( MavenReport.ROLE ); + } + catch(ComponentLookupException e) + { + e.printStackTrace(); + } +System.out.println("nb reports=" + mavenReports.keySet().size() ); + return mavenReports; + } + /** * @todo we need some type of response */ - public void executeReport( String name, MavenReportConfiguration config, String outputDirectory ) + public void executeReport( String name, MavenReportConfiguration config ) throws MavenReportException { MavenReport report = (MavenReport) mavenReports.get( name ); if ( report != null ) { - report.execute( config ); + report.setConfiguration( config ); + + report.generate(); } else { diff --git a/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/MavenReportManager.java b/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/MavenReportManager.java index d17bb93dcb..1c2354df97 100644 --- a/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/MavenReportManager.java +++ b/maven-reporting/maven-reporting-manager/src/main/java/org/apache/maven/reporting/manager/MavenReportManager.java @@ -22,6 +22,7 @@ import org.apache.maven.reporting.MavenReportConfiguration; import org.apache.maven.reporting.MavenReportException; import java.util.List; +import java.util.Map; /** * Manage the set of available reports. @@ -34,9 +35,11 @@ public interface MavenReportManager { String ROLE = MavenReportManager.class.getName(); + Map getReports(); + void addReports( Reports reports, ArtifactRepository localRepository, List remoteRepositories ) throws ReportManagerException, ReportNotFoundException; - void executeReport( String name, MavenReportConfiguration config, String outputDirectory ) + void executeReport( String name, MavenReportConfiguration config ) throws MavenReportException; }