Author: vsiveton Date: Mon Sep 14 10:12:19 2009 New Revision: 814556 URL: http://svn.apache.org/viewvc?rev=814556&view=rev Log: o validate locale and charset options o added more unit tests
Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml (with props) maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml (with props) maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml (with props) maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml (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 maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml 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=814556&r1=814555&r2=814556&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 Mon Sep 14 10:12:19 2009 @@ -3708,7 +3708,78 @@ // encoding if ( StringUtils.isNotEmpty( getEncoding() ) && !JavadocUtil.validateEncoding( getEncoding() ) ) { - throw new MavenReportException( "Encoding not supported: " + getEncoding() ); + throw new MavenReportException( "Unsupported option <encoding/> '" + getEncoding() + "'" ); + } + + // locale + if ( StringUtils.isNotEmpty( this.locale ) ) + { + StringTokenizer tokenizer = new StringTokenizer( this.locale, "_" ); + final int maxTokens = 3; + if ( tokenizer.countTokens() > maxTokens ) + { + throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + + "', should be language_country_variant." ); + } + + Locale localeObject = null; + if ( tokenizer.hasMoreTokens() ) + { + String language = tokenizer.nextToken().toLowerCase( Locale.ENGLISH ); + if ( !Arrays.asList( Locale.getISOLanguages() ).contains( language ) ) + { + throw new MavenReportException( "Unsupported language '" + language + + "' in option <locale/> '" + this.locale + "'" ); + } + localeObject = new Locale( language ); + + if ( tokenizer.hasMoreTokens() ) + { + String country = tokenizer.nextToken().toUpperCase( Locale.ENGLISH ); + if ( !Arrays.asList( Locale.getISOCountries() ).contains( country ) ) + { + throw new MavenReportException( "Unsupported country '" + country + + "' in option <locale/> '" + this.locale + "'" ); + } + localeObject = new Locale( language, country ); + + if ( tokenizer.hasMoreTokens() ) + { + String variant = tokenizer.nextToken(); + localeObject = new Locale( language, country, variant ); + } + } + } + + if ( localeObject == null ) + { + throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + + "', should be language_country_variant." ); + } + + this.locale = localeObject.toString(); + final List availableLocalesList = Arrays.asList( Locale.getAvailableLocales() ); + if ( StringUtils.isNotEmpty( localeObject.getVariant() ) + && !availableLocalesList.contains( localeObject ) ) + { + StringBuffer sb = new StringBuffer(); + sb.append( "Unsupported option <locale/> with variant '" ).append( this.locale ); + sb.append( "'" ); + + localeObject = new Locale( localeObject.getLanguage(), localeObject.getCountry() ); + this.locale = localeObject.toString(); + + sb.append( ", trying to use <locale/> without variant, i.e. '" ).append( this.locale ).append( "'" ); + if ( getLog().isWarnEnabled() ) + { + getLog().warn( sb.toString() ); + } + } + + if ( !availableLocalesList.contains( localeObject ) ) + { + throw new MavenReportException( "Unsupported option <locale/> '" + this.locale + "'" ); + } } } @@ -3725,7 +3796,13 @@ // docencoding if ( StringUtils.isNotEmpty( getDocencoding() ) && !JavadocUtil.validateEncoding( getDocencoding() ) ) { - throw new MavenReportException( "Encoding not supported: " + getDocencoding() ); + throw new MavenReportException( "Unsupported option <docencoding/> '" + getDocencoding() + "'" ); + } + + // charset + if ( StringUtils.isNotEmpty( getCharset() ) && !JavadocUtil.validateEncoding( getCharset() ) ) + { + throw new MavenReportException( "Unsupported option <charset/> '" + getCharset() + "'" ); } // helpfile @@ -4286,7 +4363,8 @@ } writeDebugJavadocScript( cmdLine, javadocOutputDirectory ); - if ( StringUtils.isNotEmpty( output ) && isJavadocVMInitError( output ) ) + if ( StringUtils.isNotEmpty( output ) && StringUtils.isEmpty( err.getOutput() ) + && isJavadocVMInitError( output ) ) { StringBuffer msg = new StringBuffer(); msg.append( output ); 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=814556&r1=814555&r2=814556&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 Mon Sep 14 10:12:19 2009 @@ -1043,8 +1043,10 @@ public void testValidateOptions() throws Exception { - File testPom = new File( getBasedir(), - "src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml" ); + // encoding + File testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml" ); JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); try { @@ -1053,11 +1055,62 @@ } catch ( MojoExecutionException e ) { - assertTrue( "Not wrong encoding catch", e.getMessage().indexOf( "Encoding not supported" ) != -1 ); + assertTrue( "Not wrong encoding catch", + e.getMessage().indexOf( "Unsupported option <encoding/>" ) != -1 ); + } + testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml" ); + mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + try + { + mojo.execute(); + assertTrue( "Not wrong docencoding catch", false ); + } + catch ( MojoExecutionException e ) + { + assertTrue( "Not wrong docencoding catch", e.getMessage() + .indexOf( "Unsupported option <docencoding/>" ) != -1 ); + } + testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml" ); + mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + try + { + mojo.execute(); + assertTrue( "Not wrong charset catch", false ); + } + catch ( MojoExecutionException e ) + { + assertTrue( "Not wrong charset catch", e.getMessage().indexOf( "Unsupported option <charset/>" ) != -1 ); } - testPom = new File( getBasedir(), - "src/test/resources/unit/validate-options-test/conflict-options-test-plugin-config.xml" ); + // locale + testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml" ); + mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + try + { + mojo.execute(); + assertTrue( "Not wrong locale catch", false ); + } + catch ( MojoExecutionException e ) + { + assertTrue( "Not wrong locale catch", e.getMessage().indexOf( "Unsupported option <locale/>" ) != -1 ); + } + testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" ); + mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); + mojo.execute(); + assertTrue( "Not wrong locale catch", true ); + + // conflict options + testPom = + new File( getBasedir(), + "src/test/resources/unit/validate-options-test/conflict-options-test-plugin-config.xml" ); mojo = (JavadocReport) lookupMojo( "javadoc", testPom ); try { @@ -1066,7 +1119,8 @@ } catch ( MojoExecutionException e ) { - assertTrue( "Not conflict catch", e.getMessage().indexOf( "Option <nohelp/> conflicts with <helpfile/>" ) != -1 ); + assertTrue( "Not conflict catch", e.getMessage() + .indexOf( "Option <nohelp/> conflicts with <helpfile/>" ) != -1 ); } } Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml?rev=814556&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml Mon Sep 14 10:12:19 2009 @@ -0,0 +1,51 @@ +<!-- +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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId> + <artifactId>wrong-charset-options-test</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2007</inceptionYear> + <name>Maven Javadoc Plugin wrong charset 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.WrongEncodingOptionsTestMavenProjectStub"/> + <localRepository>${localRepository}</localRepository> + <outputDirectory>${basedir}/target/test/unit/validate-options-test/target/site/apidocs</outputDirectory> + <show>protected</show> + <groups/> + <tags/> + <quiet>true</quiet> + <debug>true</debug> + <charset>wrong</charset> + <stylesheet>java</stylesheet> + <failOnError>true</failOnError> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml?rev=814556&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml Mon Sep 14 10:12:19 2009 @@ -0,0 +1,51 @@ +<!-- +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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId> + <artifactId>wrong-docencoding-options-test</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2007</inceptionYear> + <name>Maven Javadoc Plugin wrong docencoding 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.WrongEncodingOptionsTestMavenProjectStub"/> + <localRepository>${localRepository}</localRepository> + <outputDirectory>${basedir}/target/test/unit/validate-options-test/target/site/apidocs</outputDirectory> + <show>protected</show> + <groups/> + <tags/> + <quiet>true</quiet> + <debug>true</debug> + <docencoding>wrong</docencoding> + <stylesheet>java</stylesheet> + <failOnError>true</failOnError> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml?rev=814556&r1=814555&r2=814556&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml Mon Sep 14 10:12:19 2009 @@ -37,13 +37,11 @@ <localRepository>${localRepository}</localRepository> <outputDirectory>${basedir}/target/test/unit/validate-options-test/target/site/apidocs</outputDirectory> <show>protected</show> - <encoding>ISO-8859-1</encoding> <groups/> <tags/> <quiet>true</quiet> <debug>true</debug> <encoding>wrong</encoding> - <docencoding>wrong</docencoding> <stylesheet>java</stylesheet> <failOnError>true</failOnError> </configuration> Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml?rev=814556&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml Mon Sep 14 10:12:19 2009 @@ -0,0 +1,51 @@ +<!-- +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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId> + <artifactId>wrong-locale-options-test</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2007</inceptionYear> + <name>Maven Javadoc Plugin wrong locale 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.WrongEncodingOptionsTestMavenProjectStub"/> + <localRepository>${localRepository}</localRepository> + <outputDirectory>${basedir}/target/test/unit/validate-options-test/target/site/apidocs</outputDirectory> + <show>protected</show> + <groups/> + <tags/> + <quiet>true</quiet> + <debug>true</debug> + <locale>wrong_wrong_wrong_wrong</locale> + <stylesheet>java</stylesheet> + <failOnError>true</failOnError> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml?rev=814556&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml Mon Sep 14 10:12:19 2009 @@ -0,0 +1,51 @@ +<!-- +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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId> + <artifactId>wrong-locale-options-test</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2007</inceptionYear> + <name>Maven Javadoc Plugin wrong locale 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.WrongEncodingOptionsTestMavenProjectStub"/> + <localRepository>${localRepository}</localRepository> + <outputDirectory>${basedir}/target/test/unit/validate-options-test/target/site/apidocs</outputDirectory> + <show>protected</show> + <groups/> + <tags/> + <quiet>true</quiet> + <debug>true</debug> + <locale>fr_CA_wrong</locale> + <stylesheet>java</stylesheet> + <failOnError>true</failOnError> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision