You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/07/14 15:16:08 UTC
svn commit: r676578 - in
/maven/plugins/trunk/maven-project-info-reports-plugin/src/main:
java/org/apache/maven/report/projectinfo/PluginsReport.java
resources/project-info-report.properties
resources/project-info-report_fr.properties
Author: vsiveton
Date: Mon Jul 14 06:16:07 2008
New Revision: 676578
URL: http://svn.apache.org/viewvc?rev=676578&view=rev
Log:
MPIR-125: Create a plugin report
o first implementation
o added some keys
Added:
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java (with props)
Modified:
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties
Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java?rev=676578&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java Mon Jul 14 06:16:07 2008
@@ -0,0 +1,307 @@
+package org.apache.maven.report.projectinfo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.report.projectinfo.dependencies.ArtifactUtils;
+import org.apache.maven.reporting.AbstractMavenReportRenderer;
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Generates the Project Plugins report.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 2.1
+ * @goal plugins
+ * @requiresDependencyResolution test
+ */
+public class PluginsReport
+ extends AbstractProjectInfoReport
+{
+ // ----------------------------------------------------------------------
+ // Mojo components
+ // ----------------------------------------------------------------------
+
+ /**
+ * Maven Project Builder component.
+ *
+ * @component
+ */
+ private MavenProjectBuilder mavenProjectBuilder;
+
+ /**
+ * Maven Artifact Factory component.
+ *
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ // ----------------------------------------------------------------------
+ // Public methods
+ // ----------------------------------------------------------------------
+
+ /** {@inheritDoc} */
+ public String getName( Locale locale )
+ {
+ return i18n.getString( "project-info-report", locale, "report.plugins.name" );
+ }
+
+ /** {@inheritDoc} */
+ public String getDescription( Locale locale )
+ {
+ return i18n.getString( "project-info-report", locale, "report.plugins.description" );
+ }
+
+ /** {@inheritDoc} */
+ public void executeReport( Locale locale )
+ {
+ PluginsRenderer r = new PluginsRenderer( getLog(), getSink(), locale, i18n, project.getPluginArtifacts(),
+ project.getReportArtifacts(), project, mavenProjectBuilder,
+ artifactFactory, localRepository );
+ r.render();
+ }
+
+ /** {@inheritDoc} */
+ public String getOutputName()
+ {
+ return "plugins";
+ }
+
+ /** {@inheritDoc} */
+ public boolean canGenerateReport()
+ {
+ return ( project.getPluginArtifacts() != null && !project.getPluginArtifacts().isEmpty() )
+ || ( project.getReportArtifacts() != null && !project.getReportArtifacts().isEmpty() );
+ }
+
+ // ----------------------------------------------------------------------
+ // Private
+ // ----------------------------------------------------------------------
+
+ /**
+ * Internal renderer class
+ */
+ protected static class PluginsRenderer
+ extends AbstractMavenReportRenderer
+ {
+ private final Log log;
+
+ private final List plugins;
+
+ private final List reports;
+
+ private final Locale locale;
+
+ private final I18N i18n;
+
+ private final MavenProject project;
+
+ private final MavenProjectBuilder mavenProjectBuilder;
+
+ private final ArtifactFactory artifactFactory;
+
+ private final ArtifactRepository localRepository;
+
+ /**
+ * @param log
+ * @param sink
+ * @param locale
+ * @param i18n
+ * @param plugins
+ * @param reports
+ * @param project
+ * @param mavenProjectBuilder
+ * @param artifactFactory
+ * @param localRepository
+ */
+ public PluginsRenderer( Log log, Sink sink, Locale locale, I18N i18n, Set plugins, Set reports, MavenProject project,
+ MavenProjectBuilder mavenProjectBuilder, ArtifactFactory artifactFactory,
+ ArtifactRepository localRepository )
+ {
+ super( sink );
+
+ this.log = log;
+
+ this.locale = locale;
+
+ this.plugins = new ArrayList( plugins );
+
+ this.reports = new ArrayList( reports );
+
+ this.i18n = i18n;
+
+ this.project = project;
+
+ this.mavenProjectBuilder = mavenProjectBuilder;
+
+ this.artifactFactory = artifactFactory;
+
+ this.localRepository = localRepository;
+ }
+
+ /** {@inheritDoc} */
+ public String getTitle()
+ {
+ return getReportString( "report.plugins.title" );
+ }
+
+ /** {@inheritDoc} */
+ public void renderBody()
+ {
+ // === Section: Project Plugins.
+ renderSectionPlugins( true );
+
+ // === Section: Project Reports.
+ renderSectionPlugins( false );
+ }
+
+ /**
+ * @param isPlugins <code>true</code> to use <code>plugins</code> variable, <code>false</code> to use
+ * <code>reports</code> variable.
+ */
+ private void renderSectionPlugins( boolean isPlugins )
+ {
+ List list = ( isPlugins ? plugins : reports );
+ String[] tableHeader = getPluginTableHeader();
+
+ startSection( ( isPlugins ? getReportString( "report.plugins.title" )
+ : getReportString( "report.plugins.report.title" ) ) );
+
+ if ( list == null || list.isEmpty() )
+ {
+
+ paragraph( ( isPlugins ? getReportString( "report.plugins.nolist" )
+ : getReportString( "report.plugins.report.nolist" ) ) );
+
+ endSection();
+
+ return;
+ }
+
+ Collections.sort( list, getArtifactComparator() );
+
+ startTable();
+ tableHeader( tableHeader );
+
+ for ( Iterator iterator = list.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iterator.next();
+
+ VersionRange versionRange;
+ if ( StringUtils.isEmpty( artifact.getVersion() ) )
+ {
+ versionRange = VersionRange.createFromVersion( Artifact.RELEASE_VERSION );
+ }
+ else
+ {
+ versionRange = VersionRange.createFromVersion( artifact.getVersion() );
+ }
+
+ Artifact pluginArtifact = artifactFactory.createParentArtifact( artifact.getGroupId(), artifact
+ .getArtifactId(), versionRange.toString() );
+ List artifactRepositories = project.getPluginArtifactRepositories();
+ if ( artifactRepositories == null )
+ {
+ artifactRepositories = new ArrayList();
+ }
+ try
+ {
+ MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( pluginArtifact,
+ artifactRepositories,
+ localRepository );
+ tableRow( getPluginRow( pluginProject.getGroupId(), pluginProject.getArtifactId(), pluginProject
+ .getVersion(), pluginProject.getUrl() ) );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ log.info( "Could not build project for: " + artifact.getArtifactId() + ":" + e.getMessage(), e );
+ tableRow( getPluginRow( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+ null ) );
+ }
+
+ }
+ endTable();
+
+ endSection();
+ }
+
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
+ private String[] getPluginTableHeader()
+ {
+ // reused key...
+ String groupId = getReportString( "report.dependencyManagement.column.groupId" );
+ String artifactId = getReportString( "report.dependencyManagement.column.artifactId" );
+ String version = getReportString( "report.dependencyManagement.column.version" );
+ return new String[] { groupId, artifactId, version };
+ }
+
+ private String[] getPluginRow( String groupId, String artifactId, String version, String link )
+ {
+ artifactId = ArtifactUtils.getArtifactIdCell( artifactId, link );
+ return new String[] { groupId, artifactId, version };
+ }
+
+ private Comparator getArtifactComparator()
+ {
+ return new Comparator()
+ {
+ /** {@inheritDoc} */
+ public int compare( Object o1, Object o2 )
+ {
+ Artifact a1 = (Artifact) o1;
+ Artifact a2 = (Artifact) o2;
+
+ int result = a1.getGroupId().compareTo( a2.getGroupId() );
+ if ( result == 0 )
+ {
+ result = a1.getArtifactId().compareTo( a2.getArtifactId() );
+ }
+ return result;
+ }
+ };
+ }
+
+ private String getReportString( String key )
+ {
+ return i18n.getString( "project-info-report", locale, key );
+ }
+ }
+}
Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/PluginsReport.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties?rev=676578&r1=676577&r2=676578&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties Mon Jul 14 06:16:07 2008
@@ -235,3 +235,9 @@
report.pluginManagement.name = Plugin Management
report.pluginManagement.description = This document lists the plugins that are defined through pluginManagement.
report.pluginManagement.title = Project Plugin Management
+report.plugins.name = Project Plugins
+report.plugins.description = This document lists the build plugins and the report plugins used by this project.
+report.plugins.title = Project Build Plugins
+report.plugins.report.title = Project Report Plugins
+report.plugins.nolist = There are no plugins defined in the Build part of this project.
+report.plugins.report.nolist = There are no plugins reports defined in the Reporting part of this project.
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties?rev=676578&r1=676577&r2=676578&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties Mon Jul 14 06:16:07 2008
@@ -235,3 +235,9 @@
report.pluginManagement.name = Gestion des plugins
report.pluginManagement.description = Ce document liste les plugins d\u00e9finis \u00e0 travers plugins.
report.pluginManagement.title = Gestion des plugins du project
+report.plugins.name = Plugins du projets
+report.plugins.description = Ce document liste les plugins de type build et rapport utilis\u00e9s par ce projet.
+report.plugins.title = Plugins du projet de type build
+report.plugins.report.title = Plugins du projet de type rapport
+report.plugins.nolist = Il n\u0092y a aucun plugin de type build d\u00e9fini dans la partie Build du projet.
+report.plugins.report.nolist = Il n\u0092y a aucun plugin de type rapport d\u00e9fini dans la partie Reporting du projet.
\ No newline at end of file