Author: vsiveton Date: Thu Oct 4 03:46:35 2007 New Revision: 581841 URL: http://svn.apache.org/viewvc?rev=581841&view=rev Log: MJAVADOC-149: Newline in ${project.organization.name} makes javadoc fail Submitted by: Benjamin Bentmann Reviewed by: Vincent Siveton
o Patch applied without the newlineFreeArgument() method: removed all newlines directly in quotedArgument() method o Patch adds also quotes for packagesheader parameter Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml (with props) maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java (with props) Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java?rev=581841&r1=581840&r2=581841&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java Thu Oct 4 03:46:35 2007 @@ -1262,8 +1262,7 @@ if ( StringUtils.isEmpty( doclet ) ) { addArgIf( arguments, author, "-author" ); - addArgIfNotEmpty( arguments, "-bottom", quotedArgument( getBottomText( project.getInceptionYear() ) ), - false, false ); + addArgIfNotEmpty( arguments, "-bottom", quotedArgument( getBottomText() ), false, false ); addArgIf( arguments, breakiterator, "-breakiterator", SINCE_JAVADOC_1_4 ); addArgIfNotEmpty( arguments, "-charset", quotedArgument( charset ) ); addArgIfNotEmpty( arguments, "-d", quotedPathArgument( javadocOutputDirectory.toString() ) ); @@ -1272,7 +1271,7 @@ addArgIfNotEmpty( arguments, "-doctitle", quotedArgument( getDoctitle() ), false, false ); addArgIfNotEmpty( arguments, "-excludedocfilessubdir", quotedPathArgument( excludedocfilessubdir ), SINCE_JAVADOC_1_4 ); - addArgIfNotEmpty( arguments, "-footer", quotedArgument( StringUtils.replace( footer, "\n", "" ) ), false, false ); + addArgIfNotEmpty( arguments, "-footer", quotedArgument( footer ), false, false ); if ( groups != null ) { for ( int i = 0; i < groups.length; i++ ) @@ -1290,7 +1289,7 @@ } } } - addArgIfNotEmpty( arguments, "-header", quotedArgument( StringUtils.replace( header, "\n", "" ) ), false, false ); + addArgIfNotEmpty( arguments, "-header", quotedArgument( header ), false, false ); addArgIfNotEmpty( arguments, "-helpfile", quotedPathArgument( helpfile ) ); addArgIf( arguments, keywords, "-keywords", SINCE_JAVADOC_1_4_2 ); @@ -1310,7 +1309,7 @@ addArgIf( arguments, nosince, "-nosince" ); addArgIf( arguments, notimestamp, "-notimestamp", SINCE_JAVADOC_1_5 ); addArgIf( arguments, notree, "-notree" ); - addArgIfNotEmpty( arguments, "-packagesheader", packagesheader, SINCE_JAVADOC_1_4_2 ); + addArgIfNotEmpty( arguments, "-packagesheader", quotedArgument( packagesheader ), SINCE_JAVADOC_1_4_2 ); if ( fJavadocVersion >= SINCE_JAVADOC_1_4 && fJavadocVersion < SINCE_JAVADOC_1_5 ) // Sun bug: 4714350 { addArgIf( arguments, quiet, "-quiet" ); @@ -1372,8 +1371,7 @@ } } - addArgIfNotEmpty( arguments, "-top", quotedArgument( StringUtils.replace( top, "\n", "" ) ), false, false, - SINCE_JAVADOC_1_6 ); + addArgIfNotEmpty( arguments, "-top", quotedArgument( top ), false, false, SINCE_JAVADOC_1_6 ); addArgIf( arguments, use, "-use" ); addArgIf( arguments, version, "-version" ); addArgIfNotEmpty( arguments, "-windowtitle", quotedArgument( getWindowtitle() ), false, false ); @@ -1745,14 +1743,15 @@ * Method that sets the bottom text that will be displayed on the bottom of the * javadocs. * - * @param inceptionYear the year when the project was started * @return a String that contains the text that will be displayed at the bottom of the javadoc */ - private String getBottomText( String inceptionYear ) + private String getBottomText() { int actualYear = Calendar.getInstance().get( Calendar.YEAR ); String year = String.valueOf( actualYear ); + String inceptionYear = project.getInceptionYear(); + String theBottom = StringUtils.replace( this.bottom, "{currentYear}", year ); if ( inceptionYear != null ) @@ -2784,7 +2783,10 @@ } /** - * Convenience method to wrap an argument value in quotes. Intended for values which may contain whitespaces. + * Convenience method to wrap an argument value in single quotes (i.e. <code>'</code>). Intended for values + * which may contain whitespaces. + * <br/> + * To prevent javadoc error, the line separator (i.e. <code>\n</code>) are skipped. * * @param value the argument value. * @return argument with quote @@ -2792,6 +2794,7 @@ private static String quotedArgument( String value ) { String arg = value; + if ( StringUtils.isNotEmpty( arg ) ) { if ( arg.indexOf( "'" ) != -1 ) @@ -2799,6 +2802,9 @@ arg = StringUtils.replace( arg, "'", "\\'" ); } arg = "'" + arg + "'"; + + // To prevent javadoc error + arg = StringUtils.replace( arg, "\n", " " ); } return arg; Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java?rev=581841&r1=581840&r2=581841&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java Thu Oct 4 03:46:35 2007 @@ -781,6 +781,28 @@ } /** + * Test newline in various string parameters + * + * @throws Exception if any + */ + public void testNewline() + throws Exception + { + File testPom = new File( getBasedir(), "src/test/resources/unit/newline-test/newline-test-plugin-config.xml" ); + JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + try + { + mojo.execute(); + } + catch ( MojoExecutionException e ) + { + fail( "Doesn't handle correctly newline for string parameters. See options and packages files." ); + } + + assertTrue( true ); + } + + /** * Method to test the jdk6 javadoc * * @throws Exception Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml?rev=581841&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml Thu Oct 4 03:46:35 2007 @@ -0,0 +1,88 @@ +<!-- +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> + <modelVersion>4.0.0</modelVersion> + <groupId>newline.test</groupId> + <artifactId>newline-test</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2007</inceptionYear> + <name>Maven Javadoc Plugin newline Test</name> + <url>http://maven.apache.org</url> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.javadoc.stubs.NewlineTestMavenProjectStub"/> + <localRepository>${localRepository}</localRepository> + <outputDirectory>${basedir}/target/test/unit/newline-test/target/site/apidocs</outputDirectory> + <packagesheader> + Maven Javadoc Plugin + newline 1.0-SNAPSHOT API + </packagesheader> + <doctitle> + Maven Javadoc Plugin + newline 1.0-SNAPSHOT API + </doctitle> + <windowtitle> + Maven Javadoc Plugin + newline 1.0-SNAPSHOT API + </windowtitle> + <header> + <![CDATA[ +<table border="0" cellpadding="0"> +<tr> + <td><img src="[EMAIL PROTECTED]/icon.gif" width="32" /></td> + <td>Copyright © All rights reserved.</td> +</tr> +</table> + ]]> + </header> + <footer> + <![CDATA[ +<table border="0" cellpadding="0"> +<tr> + <td><img src="[EMAIL PROTECTED]/icon.gif" width="32" /></td> + <td>Copyright © All rights reserved.</td> +</tr> +</table> + ]]> + </footer> + <top> + <![CDATA[ +Copyright 2005, +<a href="http://www.mycompany.com">MyCompany, Inc.<a> + ]]> + </top> + <bottom> + <![CDATA[ +Copyright 2005, +<a href="http://www.mycompany.com">MyCompany, Inc.<a> + ]]> + </bottom> + <quiet>true</quiet> + <debug>true</debug> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/newline-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java?rev=581841&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java Thu Oct 4 03:46:35 2007 @@ -0,0 +1,48 @@ +package test; + +/* + * 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. + */ + +/** + * Sample class inside the package to be included in the javadoc + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + */ +public class App +{ + /** + * The main method + * + * @param args an array of strings that contains the arguments + */ + public static void main( String[] args ) + { + System.out.println( "Sample Application." ); + } + + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + protected void sampleMethod( String str ) + { + System.out.println( str ); + } +} Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/newline-test/src/main/java/test/App.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"