Author: vsiveton Date: Wed Mar 18 12:38:24 2009 New Revision: 755581 URL: http://svn.apache.org/viewvc?rev=755581&view=rev Log: o refactoring the class to remove duplicate code found by cpd, to improve reading and to fix some qdox issues. o added more test cases
Added: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java (with props) maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java (with props) maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java (with props) maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java (with props) Modified: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh (contents, props changed) maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java Added: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java?rev=755581&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java Wed Mar 18 12:38:24 2009 @@ -0,0 +1,54 @@ +package fix.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. + */ + +/** + * Some Javadoc. + */ +public class ClassWithJavadoc +{ + public static final String MY_STRING_CONSTANT = "value"; + + public static final int MY_INT_CONSTANT = 1; + + public static final String EOL = System.getProperty( "line.separator" ); + + private static final String MY_PRIVATE_CONSTANT = ""; + + public static void main( String[] args ) + { + System.out.println( "Sample Application." ); + } + + /** + * @param str + */ + public String methodWithMissingParameters( String str, boolean b, int i ) + { + return null; + } + + /** + * @param str + */ + public void methodWithWrongJavadocParameters( String aString ) + { + } +} Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithJavadoc.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java?rev=755581&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java Wed Mar 18 12:38:24 2009 @@ -0,0 +1,33 @@ +package fix.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. + */ + +public class ClassWithNoJavadoc +{ + public static void main( String[] args ) + { + System.out.println( "Sample Application." ); + } + + private void sampleMethod( String str ) + { + System.out.println( str ); + } +} Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/ClassWithNoJavadoc.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java?rev=755581&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java Wed Mar 18 12:38:24 2009 @@ -0,0 +1,34 @@ +package fix.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. + */ + +/** + * Some Javadoc. + */ +public interface InterfaceWithJavadoc +{ + /** comment */ + String MY_STRING_CONSTANT = "value"; + + /** + * My method + */ + public void method( String aString ); +} Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithJavadoc.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java?rev=755581&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java Wed Mar 18 12:38:24 2009 @@ -0,0 +1,27 @@ +package fix.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. + */ + +public interface InterfaceWithNoJavadoc +{ + String MY_STRING_CONSTANT = "value"; + + public void method( String aString ); +} Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/src/main/java/fix/test/InterfaceWithNoJavadoc.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh?rev=755581&r1=755580&r2=755581&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh Wed Mar 18 12:38:24 2009 @@ -1,48 +1,157 @@ -/* - * 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.io.*; -import org.codehaus.plexus.util.*; - -boolean result = true; -try -{ - String encoding = "UTF-8"; - File javaFile = new File( basedir, "/src/main/java/fix/test/App.java" ); - Reader fileReader = null; - String originalContent; - try - { - fileReader = ReaderFactory.newReader( javaFile, encoding ); - originalContent = IOUtil.toString( fileReader ); - } - finally - { - IOUtil.close( fileReader ); - } - result = ( originalContent.indexOf( "<p>sampleMethod</p>" ) != -1 ) - && ( originalContent.indexOf( "@param str a {...@link java.lang.String} object." ) != -1 ); -} -catch( IOException e ) -{ - e.printStackTrace(); - result = false; -} - -return result; +/* + * 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.io.*; +import org.codehaus.plexus.util.*; + +boolean result = true; +try +{ + String encoding = "UTF-8"; + + Reader fileReader = null; + + File buildLog = new File( basedir, "build.log" ); + String logContent; + try + { + fileReader = ReaderFactory.newReader( buildLog, encoding ); + logContent = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + File javaFile = new File( basedir, "/src/main/java/fix/test/App.java" ); + String content; + try + { + fileReader = ReaderFactory.newReader( javaFile, encoding ); + content = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + result = result && ( StringUtils.countMatches( content, " * App class" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @generatorClass toto" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @todo review it" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @version 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @author <a href=\"mailto:vincent.sive...@gmail.com\">Vincent Siveton</a>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @since 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * The main method" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param args an array of strings that contains the arguments" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * <p>sampleMethod</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param str a {...@link java.lang.String} object." ) == 1 ); + + javaFile = new File( basedir, "/src/main/java/fix/test/ClassWithNoJavadoc.java" ); + try + { + fileReader = ReaderFactory.newReader( javaFile, encoding ); + content = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + result = result && ( StringUtils.countMatches( content, " * <p>ClassWithNoJavadoc class.</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @version $Id: $" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @since 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * <p>main</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param args an array of {...@link java.lang.String} objects." ) == 1 ); + // private sampleMethod + result = result && ( StringUtils.countMatches( content, " * <p>sampleMethod</p>" ) == 0 ); + result = result && ( StringUtils.countMatches( content, " * @param str a {...@link java.lang.String} object." ) == 0 ); + + javaFile = new File( basedir, "/src/main/java/fix/test/ClassWithJavadoc.java" ); + try + { + fileReader = ReaderFactory.newReader( javaFile, encoding ); + content = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + result = result && ( StringUtils.countMatches( content, " * Some Javadoc." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @since 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " /** Constant <code>MY_STRING_CONSTANT=\"value\"</code> */" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " /** Constant <code>MY_INT_CONSTANT=1</code> */" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " /** Constant <code>EOL=\"System.getProperty( line.separator )\"</code> */" ) == 1 ); + // private constant + result = result && ( StringUtils.countMatches( content, " /** Constant <code>MY_PRIVATE_CONSTANT=\"\"</code> */" ) == 0 ); + result = result && ( StringUtils.countMatches( content, " * <p>main</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param args an array of {...@link java.lang.String} objects." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * <p>methodWithMissingParameters</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param str a {...@link java.lang.String} object." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param b a boolean." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param i a int." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @return a {...@link java.lang.String} object." ) == 1 ); + + // check unknown param + result = result && ( StringUtils.countMatches( logContent, "[WARNING] Fixed unknown param 'str' defined in fix.test.ClassWithJavadoc#methodWithWrongJavadocParameters(aString)" ) == 1 ); + + javaFile = new File( basedir, "/src/main/java/fix/test/InterfaceWithNoJavadoc.java" ); + try + { + fileReader = ReaderFactory.newReader( javaFile, encoding ); + content = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + result = result && ( StringUtils.countMatches( content, " * <p>InterfaceWithNoJavadoc interface.</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @version $Id: $" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @since 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " /** Constant <code>MY_STRING_CONSTANT=\"value\"</code> */" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * <p>method</p>" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param aString a {...@link java.lang.String} object." ) == 1 ); + + javaFile = new File( basedir, "/src/main/java/fix/test/InterfaceWithJavadoc.java" ); + try + { + fileReader = ReaderFactory.newReader( javaFile, encoding ); + content = IOUtil.toString( fileReader ); + } + finally + { + IOUtil.close( fileReader ); + } + + result = result && ( StringUtils.countMatches( content, " * Some Javadoc." ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @version $Id: $" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @since 1.0" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " /** comment */" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * My method" ) == 1 ); + result = result && ( StringUtils.countMatches( content, " * @param aString a {...@link java.lang.String} object." ) == 1 ); + +} +catch( Throwable e ) +{ + e.printStackTrace(); + result = false; +} + +return result; Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/it/MJAVADOC-226/verify.bsh ------------------------------------------------------------------------------ svn:eol-style = native