diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java index f80cdf64d..f78f94c4b 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -1294,4 +1294,22 @@ public void testHelpfile() throws Exception { assertTrue(optionsContent.contains("-helpfile")); assertTrue(optionsContent.contains("'" + help.toFile().getAbsolutePath().replaceAll("\\\\", "/") + "'")); } + + /** It should include only single class in javadoc. */ + public void testSubpackagesExcludePackages() throws Exception { + Path testPom = unit.resolve("subpackages-exclude-packages-test/pom.xml"); + + JavadocReport mojo = lookupMojo(testPom); + + mojo.execute(); + + Path apidocs = new File(getBasedir(), "target/test/unit/subpackages-exclude-packages-test/target/site/apidocs").toPath(); + + // check if the classes in the specified subpackages were included + assertThat(apidocs.resolve("org/apache/project/IncludeClass.html")).exists(); + + // check the excluded packages + assertThat(apidocs.resolve("org/apache/internal")).doesNotExist(); + assertThat(apidocs.resolve("io")).doesNotExist(); + } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/stubs/SubpackagesExcludePackagesTestMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/javadoc/stubs/SubpackagesExcludePackagesTestMavenProjectStub.java new file mode 100644 index 000000000..6ac012777 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/javadoc/stubs/SubpackagesExcludePackagesTestMavenProjectStub.java @@ -0,0 +1,56 @@ +/* + * 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. + */ +package org.apache.maven.plugins.javadoc.stubs; + +import org.apache.maven.model.Build; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** */ +public class SubpackagesExcludePackagesTestMavenProjectStub extends MavenProjectStub { + public SubpackagesExcludePackagesTestMavenProjectStub() { + readModel(new File(getBasedir(), "pom.xml")); + + setGroupId(getModel().getGroupId()); + setArtifactId(getModel().getArtifactId()); + setVersion(getModel().getVersion()); + + setName(getModel().getName()); + setUrl(getModel().getUrl()); + setPackaging(getModel().getPackaging()); + + Build build = new Build(); + build.setFinalName(getName()); + build.setDirectory(super.getBasedir() + "/target/test/unit/subpackages-exclude-packages-test/target"); + setBuild(build); + + List compileSourceRoots = new ArrayList<>(); + compileSourceRoots.add(getBasedir() + "/src/main/java"); + setCompileSourceRoots(compileSourceRoots); + } + + /** {@inheritDoc} */ + @Override + public File getBasedir() { + return new File(super.getBasedir() + "/src/test/resources/unit/subpackages-exclude-packages-test"); + } +} diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/pom.xml b/src/test/resources/unit/subpackages-exclude-packages-test/pom.xml new file mode 100644 index 000000000..cfeff581f --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.apache.maven.plugins.maven-javadoc-plugin.unit + subpackages-exclude-packages-test + 1.0-SNAPSHOT + jar + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + ${basedir}/target/test/unit/subpackages-exclude-packages-test/target/site/apidocs + ${basedir}/target/test/unit/subpackages-exclude-packages-test/target/javadoc-bundle-options + + + org.apache + + + org.apache.internal + :org.apache.internal.* + + + true + + + + + + + + + + diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/io/ExcludeIoClass.java b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/io/ExcludeIoClass.java new file mode 100644 index 000000000..83f8c53fc --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/io/ExcludeIoClass.java @@ -0,0 +1,36 @@ +package io; + +/* + * 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. + */ + +/** + * Class to be excluded. + */ +public class ExcludeIoClass +{ + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + public void sampleMethod( String str ) + { + System.out.println( str ); + } +} \ No newline at end of file diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/ExcludeInternalClass.java b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/ExcludeInternalClass.java new file mode 100644 index 000000000..62ecf4e7a --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/ExcludeInternalClass.java @@ -0,0 +1,39 @@ +package org.apache.internal; + +/* + * 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.File; +import java.io.IOException; + +/** + * Class to be excluded. + */ +public class ExcludeInternalClass +{ + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + public void sampleMethod( String str ) + { + System.out.println( str ); + } +} \ No newline at end of file diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/ExcludeInternalSubClass.java b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/ExcludeInternalSubClass.java new file mode 100644 index 000000000..cf218ce6d --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/ExcludeInternalSubClass.java @@ -0,0 +1,36 @@ +package org.apache.internal.subpackage; + +/* + * 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. + */ + +/** + * Class to be excluded. + */ +public class ExcludeInternalSubClass +{ + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + public void sampleMethod( String str ) + { + System.out.println( str ); + } +} \ No newline at end of file diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/subsubpackage/ExcludeInternalSubSubClass.java b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/subsubpackage/ExcludeInternalSubSubClass.java new file mode 100644 index 000000000..53f7c25ce --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/internal/subpackage/subsubpackage/ExcludeInternalSubSubClass.java @@ -0,0 +1,36 @@ +package org.apache.internal.subpackage.subsubpackage; + +/* + * 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. + */ + +/** + * Class to be excluded. + */ +public class ExcludeInternalSubSubClass +{ + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + public void sampleMethod( String str ) + { + System.out.println( str ); + } +} \ No newline at end of file diff --git a/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/project/IncludeClass.java b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/project/IncludeClass.java new file mode 100644 index 000000000..6aadb6e85 --- /dev/null +++ b/src/test/resources/unit/subpackages-exclude-packages-test/src/main/java/org/apache/project/IncludeClass.java @@ -0,0 +1,36 @@ +package org.apache.project; + +/* + * 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. + */ + +/** + * Class to be included. + */ +public class IncludeClass +{ + /** + * Sample method that prints out the parameter string. + * + * @param str The string value to be printed. + */ + public void sampleMethod( String str ) + { + System.out.println( str ); + } +} \ No newline at end of file