Skip to content

Commit 475db31

Browse files
committed
Add test for custom FixJavadocMojo#defaultVersion
1 parent d875e1b commit 475db31

File tree

6 files changed

+258
-0
lines changed

6 files changed

+258
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals=clean compile javadoc:fix
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.plugins.maven-javadoc-plugin.it</groupId>
24+
<artifactId>javadoc-fix-version</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
<packaging>jar</packaging>
27+
28+
<properties>
29+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30+
<maven.compiler.source>@maven.compiler.source@</maven.compiler.source>
31+
<maven.compiler.target>@maven.compiler.target@</maven.compiler.target>
32+
</properties>
33+
34+
<build>
35+
<defaultGoal>install</defaultGoal>
36+
<directory>target</directory>
37+
<sourceDirectory>src/main/java</sourceDirectory>
38+
<outputDirectory>target/classes</outputDirectory>
39+
<finalName>${artifactId}-${version}</finalName>
40+
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>@compilerPluginVersion@</version>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-javadoc-plugin</artifactId>
50+
<version>@project.version@</version>
51+
<configuration>
52+
<force>true</force>
53+
<ignoreClirr>true</ignoreClirr>
54+
<fixTags>version</fixTags>
55+
<defaultVersion>1.2.3</defaultVersion>
56+
</configuration>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fix.test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
/**
23+
* Some Javadoc.
24+
*/
25+
public class ClassWithJavadoc
26+
{
27+
/**
28+
* Nested
29+
*/
30+
public static class NestedClass
31+
{
32+
}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fix.test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
/**
23+
* Some Javadoc.
24+
*
25+
* @version 5.6.7
26+
*/
27+
public class ClassWithJavadocAndVersion
28+
{
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fix.test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
public class ClassWithNoJavadoc
23+
{
24+
public static class NestedClass
25+
{
26+
}
27+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
import java.util.*;
22+
import org.codehaus.plexus.util.*;
23+
24+
assertLines( String fileName, int start, String[] expectedLines )
25+
{
26+
File javaFile = new File( basedir, "/src/main/java/fix/test/" + fileName );
27+
String content = FileUtils.fileRead( javaFile, "UTF-8" );
28+
String[] lines = content.split( "\\R" );
29+
if ( start + expectedLines.length >= lines.length )
30+
{
31+
throw new IllegalArgumentException( "too few lines for " + fileName + ", expected: " + Arrays.toString( expectedLines ) );
32+
}
33+
34+
for ( int i = 0; i < expectedLines.length; i++ )
35+
{
36+
String line = lines[ start + i ];
37+
String expectedLine = expectedLines[ i ];
38+
if ( !line.equals( expectedLine ) )
39+
{
40+
throw new IllegalArgumentException( "unexpected line for " + fileName + ":\n expected: " + expectedLine + "\n actual: " + line );
41+
}
42+
}
43+
}
44+
45+
boolean result = true;
46+
try
47+
{
48+
assertLines( "ClassWithJavadoc.java", 21, new String[] {
49+
"/**",
50+
" * Some Javadoc.",
51+
" *",
52+
" * @version 1.2.3", // should have added version
53+
" */",
54+
} );
55+
// Should not have added `@version` to nested class
56+
assertLines( "ClassWithJavadoc.java", 28, new String[] {
57+
" /**",
58+
" * Nested",
59+
" */",
60+
} );
61+
62+
63+
assertLines( "ClassWithJavadocAndVersion.java", 21, new String[] {
64+
"/**",
65+
" * Some Javadoc.",
66+
" *",
67+
" * @version 5.6.7", // should have kept existing version
68+
" */",
69+
} );
70+
71+
72+
assertLines( "ClassWithNoJavadoc.java", 21, new String[] {
73+
"/**",
74+
" * <p>ClassWithNoJavadoc class.</p>",
75+
" *",
76+
" * @version 1.2.3", // should have added version
77+
" */",
78+
} );
79+
// Did not add Javadoc to nested class (TODO: missing javadoc:fix functionality?; but should not add `@version`)
80+
assertLines( "ClassWithNoJavadoc.java", 27, new String[] {
81+
"{",
82+
" public static class NestedClass",
83+
} );
84+
}
85+
catch( Throwable e )
86+
{
87+
e.printStackTrace();
88+
result = false;
89+
}
90+
91+
return result;

0 commit comments

Comments
 (0)