You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2018/07/29 17:20:01 UTC

[GitHub] khmarbaise closed pull request #7: [JXR-68] ignores classes with same name in other packages

khmarbaise closed pull request #7: [JXR-68] ignores classes with same name in other packages
URL: https://github.com/apache/maven-jxr/pull/7
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 String getBottom()
     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 void process( Log log )
         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 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
      * 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 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
                 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 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
             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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services