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/08 13:46:12 UTC
svn commit: r674775 - in
/maven/plugins/trunk/maven-project-info-reports-plugin/src:
main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java
Author: vsiveton
Date: Tue Jul 8 04:46:11 2008
New Revision: 674775
URL: http://svn.apache.org/viewvc?rev=674775&view=rev
Log:
MPIR-111: Make Classifier and Optional column in dependencies report "optional" in the renderer
o classifier and optional columns are now added if they differ
Modified:
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java?rev=674775&r1=674774&r2=674775&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java Tue Jul 8 04:46:11 2008
@@ -201,7 +201,13 @@
// Private methods
// ----------------------------------------------------------------------
- private String[] getDependencyTableHeader()
+ /**
+ * @param withClassifier <code>true</code> to include the classifier column, <code>false</code> otherwise.
+ * @param withOptional <code>true</code> to include the optional column, <code>false</code> otherwise.
+ * @return the dependency table header with/without classifier/optional column
+ * @see #getArtifactRow(Artifact, boolean, boolean)
+ */
+ private String[] getDependencyTableHeader( boolean withClassifier, boolean withOptional )
{
String groupId = getReportString( "report.dependencies.column.groupId" );
String artifactId = getReportString( "report.dependencies.column.artifactId" );
@@ -209,35 +215,52 @@
String classifier = getReportString( "report.dependencies.column.classifier" );
String type = getReportString( "report.dependencies.column.type" );
String optional = getReportString( "report.dependencies.column.optional" );
- return new String[]{groupId, artifactId, version, classifier, type, optional};
+
+ if ( withClassifier )
+ {
+ if ( withOptional )
+ {
+ return new String[] { groupId, artifactId, version, classifier, type, optional };
+ }
+
+ return new String[] { groupId, artifactId, version, classifier, type };
+ }
+
+ if ( withOptional )
+ {
+ return new String[] { groupId, artifactId, version, type, optional };
+ }
+
+ return new String[] { groupId, artifactId, version, type };
}
private void renderSectionProjectDependencies()
{
- String[] tableHeader = getDependencyTableHeader();
-
startSection( getTitle() );
// collect dependencies by scope
Map dependenciesByScope = dependencies.getDependenciesByScope( false );
- renderDependenciesForAllScopes( tableHeader, dependenciesByScope );
+ renderDependenciesForAllScopes( dependenciesByScope );
endSection();
}
- private void renderDependenciesForAllScopes( String[] tableHeader, Map dependenciesByScope )
- {
- renderDependenciesForScope( Artifact.SCOPE_COMPILE, (List) dependenciesByScope.get( Artifact.SCOPE_COMPILE ),
- tableHeader );
- renderDependenciesForScope( Artifact.SCOPE_RUNTIME, (List) dependenciesByScope.get( Artifact.SCOPE_RUNTIME ),
- tableHeader );
- renderDependenciesForScope( Artifact.SCOPE_TEST, (List) dependenciesByScope.get( Artifact.SCOPE_TEST ),
- tableHeader );
- renderDependenciesForScope( Artifact.SCOPE_PROVIDED, (List) dependenciesByScope.get( Artifact.SCOPE_PROVIDED ),
- tableHeader );
- renderDependenciesForScope( Artifact.SCOPE_SYSTEM, (List) dependenciesByScope.get( Artifact.SCOPE_SYSTEM ),
- tableHeader );
+ /**
+ * @param dependenciesByScope map with supported scopes as key and a list of <code>Artifact</code> as values.
+ * @see Artifact#SCOPE_COMPILE
+ * @see Artifact#SCOPE_PROVIDED
+ * @see Artifact#SCOPE_RUNTIME
+ * @see Artifact#SCOPE_SYSTEM
+ * @see Artifact#SCOPE_TEST
+ */
+ private void renderDependenciesForAllScopes( Map dependenciesByScope )
+ {
+ renderDependenciesForScope( Artifact.SCOPE_COMPILE, (List) dependenciesByScope.get( Artifact.SCOPE_COMPILE ) );
+ renderDependenciesForScope( Artifact.SCOPE_RUNTIME, (List) dependenciesByScope.get( Artifact.SCOPE_RUNTIME ) );
+ renderDependenciesForScope( Artifact.SCOPE_TEST, (List) dependenciesByScope.get( Artifact.SCOPE_TEST ) );
+ renderDependenciesForScope( Artifact.SCOPE_PROVIDED, (List) dependenciesByScope.get( Artifact.SCOPE_PROVIDED ) );
+ renderDependenciesForScope( Artifact.SCOPE_SYSTEM, (List) dependenciesByScope.get( Artifact.SCOPE_SYSTEM ) );
}
private void renderSectionProjectTransitiveDependencies()
@@ -252,11 +275,9 @@
}
else
{
- String[] tableHeader = getDependencyTableHeader();
-
paragraph( getReportString( "report.transitivedependencies.intro" ) );
- renderDependenciesForAllScopes( tableHeader, dependenciesByScope );
+ renderDependenciesForAllScopes( dependenciesByScope );
}
endSection();
@@ -615,23 +636,28 @@
endSection();
}
- private void renderDependenciesForScope( String scope, List artifacts, String[] tableHeader )
+ private void renderDependenciesForScope( String scope, List artifacts )
{
if ( artifacts != null )
{
+ boolean withClassifier = hasClassifier( artifacts );
+ boolean withOptional = hasOptional( artifacts );
+ String[] tableHeader = getDependencyTableHeader( withClassifier, withOptional );
+
// can't use straight artifact comparison because we want optional last
Collections.sort( artifacts, getArtifactComparator() );
startSection( scope );
paragraph( getReportString( "report.dependencies.intro." + scope ) );
+
startTable();
tableHeader( tableHeader );
-
for ( Iterator iterator = artifacts.iterator(); iterator.hasNext(); )
{
Artifact artifact = (Artifact) iterator.next();
- tableRow( getArtifactRow( artifact ) );
+
+ tableRow( getArtifactRow( artifact, withClassifier, withOptional ) );
}
endTable();
@@ -665,18 +691,54 @@
};
}
- private String[] getArtifactRow( Artifact artifact )
+ /**
+ * @param artifact not null
+ * @param withClassifier <code>true</code> to include the classifier column, <code>false</code> otherwise.
+ * @param withOptional <code>true</code> to include the optional column, <code>false</code> otherwise.
+ * @return the dependency row with/without classifier/optional column
+ * @see #getDependencyTableHeader(boolean, boolean)
+ */
+ private String[] getArtifactRow( Artifact artifact, boolean withClassifier, boolean withOptional )
{
String isOptional = artifact.isOptional() ? getReportString( "report.dependencies.column.isOptional" )
: getReportString( "report.dependencies.column.isNotOptional" );
+ if ( withClassifier )
+ {
+ if ( withOptional )
+ {
+ return new String[] {
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getClassifier(),
+ artifact.getType(),
+ isOptional };
+ }
+
+ return new String[] {
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getClassifier(),
+ artifact.getType() };
+ }
+
+ if ( withOptional )
+ {
+ return new String[] {
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getType(),
+ isOptional };
+ }
+
return new String[] {
artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
- artifact.getClassifier(),
- artifact.getType(),
- isOptional };
+ artifact.getType()};
}
private void printDependencyListing( DependencyNode node )
@@ -859,4 +921,43 @@
{
return i18n.getString( "project-info-report", locale, key );
}
+
+
+ /**
+ * @param artifacts not null
+ * @return <code>true</code> if one artifact in the list has a classifier, <code>false</code> otherwise.
+ */
+ private boolean hasClassifier( List artifacts )
+ {
+ for ( Iterator iterator = artifacts.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iterator.next();
+
+ if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param artifacts not null
+ * @return <code>true</code> if one artifact in the list is optional, <code>false</code> otherwise.
+ */
+ private boolean hasOptional( List artifacts )
+ {
+ for ( Iterator iterator = artifacts.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iterator.next();
+
+ if ( artifact.isOptional() )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java?rev=674775&r1=674774&r2=674775&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/DependenciesReportTest.java Tue Jul 8 04:46:11 2008
@@ -71,7 +71,7 @@
WebTable[] webTables = response.getTables();
assertEquals( webTables.length, 1 );
- assertEquals( webTables[0].getColumnCount(), 6 );
+ assertEquals( webTables[0].getColumnCount(), 4 );
assertEquals( webTables[0].getRowCount(), 1 + getTestMavenProject().getDependencies().size() );
// Test the texts