This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch JXR-68 in repository https://gitbox.apache.org/repos/asf/maven-jxr.git
commit 4e933b18322ce7612dad929da9ace3c59cbcf949 Author: Jesper Udby <[email protected]> AuthorDate: Sun Jul 29 16:37:34 2018 +0200 [JXR-68] ignores classes with same name in other packages --- .../org/apache/maven/jxr/DirectoryIndexer.java | 12 ++-- .../org/apache/maven/jxr/DirectoryIndexerTest.java | 77 ++++++++++++++++++++++ maven-jxr/src/test/resources/jxr68/CClass.java | 21 ++++++ maven-jxr/src/test/resources/jxr68/SomeClass.java | 21 ++++++ .../src/test/resources/jxr68/pkga/BClass.java | 22 +++++++ .../src/test/resources/jxr68/pkga/SomeClass.java | 22 +++++++ .../src/test/resources/jxr68/pkgb/AClass.java | 22 +++++++ .../src/test/resources/jxr68/pkgb/SomeClass.java | 22 +++++++ 8 files changed, 214 insertions(+), 5 deletions(-) diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/DirectoryIndexer.java b/maven-jxr/src/main/java/org/apache/maven/jxr/DirectoryIndexer.java index b15b058..a622f6c 100644 --- a/maven-jxr/src/main/java/org/apache/maven/jxr/DirectoryIndexer.java +++ b/maven-jxr/src/main/java/org/apache/maven/jxr/DirectoryIndexer.java @@ -215,7 +215,7 @@ public class DirectoryIndexer public void process( Log log ) throws JxrException { - Map<String, Object> info = getPackageInfo(); + Map<String, Map<String, ?>> info = getPackageInfo(); VelocityEngine engine = new VelocityEngine(); setProperties( engine, log ); @@ -240,7 +240,7 @@ public class DirectoryIndexer doVelocity( "allclasses-frame", root, context, engine ); doVelocity( "overview-summary", root, context, engine ); - Iterator iter = ( (Map) info.get( "allPackages" ) ).values().iterator(); + Iterator<Map<String, ?>> iter = ( (Map) info.get( "allPackages" ) ).values().iterator(); while ( iter.hasNext() ) { Map pkgInfo = (Map) iter.next(); @@ -331,7 +331,7 @@ public class DirectoryIndexer * allClasses collection of Maps with class info, format as above * */ - private Map<String, Object> getPackageInfo() + Map<String, Map<String, ?>> getPackageInfo() { Map<String, Map<String, Object>> allPackages = new TreeMap<>(); Map<String, Map<String, String>> allClasses = new TreeMap<>(); @@ -373,7 +373,9 @@ public class DirectoryIndexer classInfo.put( "dir", pkgDir ); pkgClasses.put( className, classInfo ); - allClasses.put( className, classInfo ); + // Adding package name to key in order to ensure classes with identical names in different packages are + // all included. + allClasses.put( className + "#" + pkgName, classInfo ); } Map<String, Object> pkgInfo = new HashMap<>(); @@ -384,7 +386,7 @@ public class DirectoryIndexer allPackages.put( pkgName, pkgInfo ); } - Map<String, Object> info = new HashMap<>(); + Map<String, Map<String, ?>> info = new HashMap<>(); info.put( "allPackages", allPackages ); info.put( "allClasses", allClasses ); diff --git a/maven-jxr/src/test/java/org/apache/maven/jxr/DirectoryIndexerTest.java b/maven-jxr/src/test/java/org/apache/maven/jxr/DirectoryIndexerTest.java new file mode 100644 index 0000000..aaf6c7d --- /dev/null +++ b/maven-jxr/src/test/java/org/apache/maven/jxr/DirectoryIndexerTest.java @@ -0,0 +1,77 @@ +package org.apache.maven.jxr; + +/* + * 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 org.apache.maven.jxr.pacman.FileManager; +import org.apache.maven.jxr.pacman.PackageManager; +import org.junit.Test; + +import java.nio.file.Paths; +import java.util.Iterator; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class DirectoryIndexerTest { + /** + * Parse the files in test/resources/jxr68 packages, ensure all are present in the allClasses Map, + * in the correct order. + * + * @throws Exception + */ + @Test + public void testJXR_68() throws Exception + { + FileManager fileManager = FileManager.getInstance(); + PackageManager packageManager = new PackageManager( new DummyLog(), fileManager ); + packageManager.process(Paths.get( "src/test/resources/jxr68" )); + DirectoryIndexer directoryIndexer = new DirectoryIndexer( packageManager, "" ); + + final Map<String, Map<String, ?>> packageInfo = directoryIndexer.getPackageInfo(); + final Map<String, ?> allPackages = packageInfo.get( "allPackages" ); + assertEquals(3, allPackages.size()); + assertTrue( allPackages.containsKey( "(default package)" ) ); + assertTrue( allPackages.containsKey( "pkga" ) ); + assertTrue( allPackages.containsKey( "pkgb" ) ); + final Map<String, Map<String, String>> allClasses = (Map<String, Map<String, String>>) packageInfo.get( "allClasses" ); + assertEquals( 6, allClasses.size() ); + final Iterator<Map<String, String>> iterator = allClasses.values().iterator(); + // #1: AClass + assertEquals( "AClass", iterator.next().get( "name" ) ); + // #2: BClass + assertEquals( "BClass", iterator.next().get( "name" ) ); + // #3: CClass + assertEquals( "CClass", iterator.next().get( "name" ) ); + // #4: SomeClass in default package + Map<String, String> classInfo = iterator.next(); + assertEquals( "SomeClass", classInfo.get( "name" ) ); + assertEquals( ".", classInfo.get( "dir" ) ); + // #5: SomeClass in "pkga" + classInfo = iterator.next(); + assertEquals( "SomeClass", classInfo.get( "name" ) ); + assertEquals( "pkga", classInfo.get( "dir" ) ); + // #6: SomeClass in "pkgb" + classInfo = iterator.next(); + assertEquals( "SomeClass", classInfo.get( "name" ) ); + assertEquals( "pkgb", classInfo.get( "dir" ) ); + } + +} \ No newline at end of file diff --git a/maven-jxr/src/test/resources/jxr68/CClass.java b/maven-jxr/src/test/resources/jxr68/CClass.java new file mode 100644 index 0000000..e417e4c --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/CClass.java @@ -0,0 +1,21 @@ + +/* + * 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 CClass {} diff --git a/maven-jxr/src/test/resources/jxr68/SomeClass.java b/maven-jxr/src/test/resources/jxr68/SomeClass.java new file mode 100644 index 0000000..bb17a6c --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/SomeClass.java @@ -0,0 +1,21 @@ + +/* + * 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 SomeClass {} diff --git a/maven-jxr/src/test/resources/jxr68/pkga/BClass.java b/maven-jxr/src/test/resources/jxr68/pkga/BClass.java new file mode 100644 index 0000000..072d052 --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/pkga/BClass.java @@ -0,0 +1,22 @@ +package pkga; + +/* + * 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 BClass {} diff --git a/maven-jxr/src/test/resources/jxr68/pkga/SomeClass.java b/maven-jxr/src/test/resources/jxr68/pkga/SomeClass.java new file mode 100644 index 0000000..daeaeef --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/pkga/SomeClass.java @@ -0,0 +1,22 @@ +package pkga; + +/* + * 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 SomeClass {} \ No newline at end of file diff --git a/maven-jxr/src/test/resources/jxr68/pkgb/AClass.java b/maven-jxr/src/test/resources/jxr68/pkgb/AClass.java new file mode 100644 index 0000000..0ccecb1 --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/pkgb/AClass.java @@ -0,0 +1,22 @@ +package pkgb; + +/* + * 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 AClass {} diff --git a/maven-jxr/src/test/resources/jxr68/pkgb/SomeClass.java b/maven-jxr/src/test/resources/jxr68/pkgb/SomeClass.java new file mode 100644 index 0000000..5bb53c7 --- /dev/null +++ b/maven-jxr/src/test/resources/jxr68/pkgb/SomeClass.java @@ -0,0 +1,22 @@ +package pkgb; + +/* + * 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 SomeClass {} \ No newline at end of file
