Author: vsiveton Date: Thu Oct 28 12:00:04 2010 New Revision: 1028267 URL: http://svn.apache.org/viewvc?rev=1028267&view=rev Log: MPIR-204: License report should not try to include pdf content as plain text Submitted by: Grégory Joseph Reviewed by: Vincent Siveton
o patch applied with the modification that linkOnly parameter is always true if build is offline and license protocol is http or https Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml (with props) Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/LicenseReportTest.java Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java?rev=1028267&r1=1028266&r2=1028267&view=diff ============================================================================== --- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java (original) +++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/LicenseReport.java Thu Oct 28 12:00:04 2010 @@ -67,6 +67,16 @@ public class LicenseReport */ private boolean offline; + /** + * Whether the only render links to the license documents instead of inlining them. + * <br/> + * If the system is in {...@link #offline} mode, the linkOnly parameter will be always <code>true</code>. + * + * @parameter default-value="false" + * @since 2.3 + */ + private boolean linkOnly; + // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- @@ -74,7 +84,7 @@ public class LicenseReport /** {...@inheritdoc} */ public void executeReport( Locale locale ) { - LicenseRenderer r = new LicenseRenderer( getSink(), getProject(), i18n, locale, settings ); + LicenseRenderer r = new LicenseRenderer( getSink(), getProject(), i18n, locale, settings, linkOnly ); r.render(); } @@ -109,6 +119,13 @@ public class LicenseReport { return true; } + + if ( licenseUrl != null + && ( licenseUrl.getProtocol().equals( "http" ) || licenseUrl.getProtocol().equals( "https" ) ) ) + { + linkOnly = true; + return true; + } } return false; @@ -189,17 +206,21 @@ public class LicenseReport private static class LicenseRenderer extends AbstractProjectInfoRenderer { - private MavenProject project; + private final MavenProject project; + + private final Settings settings; - private Settings settings; + private final boolean linkOnly; - LicenseRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale, Settings settings ) + LicenseRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale, Settings settings, boolean linkOnly ) { super( sink, i18n, locale ); this.project = project; this.settings = settings; + + this.linkOnly = linkOnly; } protected String getI18Nsection() @@ -264,7 +285,7 @@ public class LicenseReport paragraph( e.getMessage() ); } - if ( licenseUrl != null ) + if ( licenseUrl != null && !linkOnly) { String licenseContent = null; try @@ -301,6 +322,11 @@ public class LicenseReport } } } + else if ( licenseUrl != null && linkOnly ) + { + link( licenseUrl.toExternalForm(), licenseUrl.toExternalForm() ); + } + } endSection(); Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/LicenseReportTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/LicenseReportTest.java?rev=1028267&r1=1028266&r2=1028267&view=diff ============================================================================== --- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/LicenseReportTest.java (original) +++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/LicenseReportTest.java Thu Oct 28 12:00:04 2010 @@ -24,6 +24,7 @@ import java.net.URL; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.TextBlock; import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; @@ -72,5 +73,46 @@ public class LicenseReportTest assertEquals( textBlocks[1].getText(), getString( "report.license.overview.intro" ) ); assertEquals( textBlocks[2].getText(), getString( "report.license.name" ) ); assertEquals( textBlocks[3].getText(), "The Apache Software License, Version 2.0" ); + + // only 1 link in default report + final WebLink[] links = response.getLinks(); + assertEquals(1, links.length); + assertEquals("http://maven.apache.org/", links[0].getURLString()); + } + + public void testReportLinksOnly() + throws Exception + { + generateReport( "license", "license-plugin-config-linkonly.xml" ); + assertTrue( "Test html generated", getGeneratedReport( "license.html" ).exists() ); + + URL reportURL = getGeneratedReport( "license.html" ).toURI().toURL(); + assertNotNull( reportURL ); + + // HTTPUnit + WebRequest request = new GetMethodWebRequest( reportURL.toString() ); + WebResponse response = WEB_CONVERSATION.getResponse( request ); + + // Basic HTML tests + assertTrue( response.isHTML() ); + assertTrue( response.getContentLength() > 0 ); + + // Test the Page title + assertEquals( getString( "report.license.name" ) + " - " + getString( "report.license.title" ), response + .getTitle() ); + + // Test the texts + TextBlock[] textBlocks = response.getTextBlocks(); + assertEquals( textBlocks[0].getText(), getString( "report.license.overview.title" ) ); + assertEquals( textBlocks[1].getText(), getString( "report.license.overview.intro" ) ); + assertEquals( textBlocks[2].getText(), getString( "report.license.name" ) ); + assertEquals( textBlocks[3].getText(), "The Apache Software License, Version 2.0" ); + + // here's our specific test + final WebLink[] links = response.getLinks(); + assertEquals(2, links.length); + assertEquals("http://maven.apache.org/", links[0].getURLString()); + assertEquals("http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getURLString()); + assertEquals("http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getText()); } } Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml?rev=1028267&view=auto ============================================================================== --- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml (added) +++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml Thu Oct 28 12:00:04 2010 @@ -0,0 +1,57 @@ +<!-- +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. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugin.projectinfo.tests</groupId> + <artifactId>license</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>license project info</name> + <licenses> + <license> + <name>The Apache Software License, Version 2.0</name> + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + <configuration> + <outputDirectory>target/test-harness/license</outputDirectory> + <localRepository>${localRepository}</localRepository> + <project implementation="org.apache.maven.report.projectinfo.stubs.LicenseStub"/> + <settings implementation="org.apache.maven.report.projectinfo.stubs.SettingsStub"/> + <offline>false</offline> + <linkOnly>true</linkOnly> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/license-plugin-config-linkonly.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain