[Commented] (JXR-68) ignores classes with same name in other packages

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Commented] (JXR-68) ignores classes with same name in other packages

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/JXR-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16574736#comment-16574736 ]

ASF GitHub Bot commented on JXR-68:
-----------------------------------

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

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-plugin/src/main/resources/jxr-report_el.properties b/maven-jxr-plugin/src/main/resources/jxr-report_el.properties
new file mode 100644
index 0000000..c971556
--- /dev/null
+++ b/maven-jxr-plugin/src/main/resources/jxr-report_el.properties
@@ -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.
+
+report.xref.main.name=\u03a0\u03b7\u03b3\u03b1\u03af\u03bf\u03c2 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2 Xref
+report.xref.main.description=\u0392\u03b1\u03c3\u03b9\u03c3\u03bc\u03ad\u03bd\u03b7 \u03c3\u03b5 HTML \u03ad\u03ba\u03b4\u03bf\u03c3\u03b7 \u03c0\u03b1\u03c1\u03b1\u03c0\u03bf\u03bc\u03c0\u03ae\u03c2 \u03c0\u03b7\u03b3\u03b1\u03af\u03bf\u03c5 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1 Java.
+report.xref.test.name=\u03a0\u03b7\u03b3\u03b1\u03af\u03bf\u03c2 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1\u03c2 Xref
+report.xref.test.description=\u0392\u03b1\u03c3\u03b9\u03c3\u03bc\u03ad\u03bd\u03b7 \u03c3\u03b5 HTML \u03ad\u03ba\u03b4\u03bf\u03c3\u03b7 \u03c0\u03b1\u03c1\u03b1\u03c0\u03bf\u03bc\u03c0\u03ae\u03c2 \u03c0\u03b7\u03b3\u03b1\u03af\u03bf\u03c5 \u03b4\u03bf\u03ba\u03b9\u03bc\u03b1\u03c3\u03c4\u03b9\u03ba\u03bf\u03cd \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1 Java.
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..96554d6 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
@@ -36,6 +36,8 @@
 import org.apache.maven.jxr.pacman.ClassType;
 import org.apache.maven.jxr.pacman.PackageManager;
 import org.apache.maven.jxr.pacman.PackageType;
+import org.apache.maven.jxr.util.ClassName;
+import org.apache.maven.jxr.util.ClassNameComparator;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
@@ -334,7 +336,7 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
     private Map<String, Object> getPackageInfo()
     {
         Map<String, Map<String, Object>> allPackages = new TreeMap<>();
-        Map<String, Map<String, String>> allClasses = new TreeMap<>();
+        Map<ClassName, Map<String, String>> allClasses = new TreeMap<>( new ClassNameComparator () );
 
         Enumeration<PackageType> packages = packageManager.getPackageTypes();
         while ( packages.hasMoreElements() )
@@ -360,6 +362,7 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
                 ClassType clazz = classes.nextElement();
 
                 String className = clazz.getName();
+                ClassName cn = new ClassName( pkgName, className );
                 Map<String, String> classInfo = new HashMap<>();
                 if ( clazz.getFilename() != null )
                 {
@@ -373,7 +376,7 @@ private void doVelocity( String templateName, String outDir, VelocityContext con
                 classInfo.put( "dir", pkgDir );
 
                 pkgClasses.put( className, classInfo );
-                allClasses.put( className, classInfo );
+                allClasses.put( cn, classInfo );
             }
 
             Map<String, Object> pkgInfo = new HashMap<>();
diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassName.java b/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassName.java
new file mode 100644
index 0000000..b881370
--- /dev/null
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassName.java
@@ -0,0 +1,92 @@
+package org.apache.maven.jxr.util;
+
+/*
+ * 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.
+ */
+
+/**
+ *
+ * A class in order to wrap the class name and provide a key.
+ * This will prevent TreeMap collection
+ * from replacing classes with the same name
+ */
+public class ClassName
+{
+    private static final int HASH_CONSTANT = 47;
+    
+    private String packageName;
+    private String className;
+
+    public ClassName()
+    {
+        //empty constructor
+    }
+
+    /**
+     *
+     * @param packageName
+     * @param className
+     */
+    public ClassName( String packageName, String className )
+    {
+        this.packageName = packageName;
+        this.className = className;
+    }
+
+    
+    public String getPackageName()
+    {
+        return packageName;
+    }
+
+    /**
+     *
+     * @param packageName
+     */
+    public void setPackageName( String packageName )
+    {
+        this.packageName = packageName;
+    }
+
+    public String getClassName()
+    {
+        return className;
+    }
+
+    /**
+     *
+     * @param className
+     */
+    public void setClassName( String className )
+    {
+        this.className = className;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "ClassName{" + "packageName=" + packageName + ", className=" + className + '}';
+    }
+
+    public String getKeyForComparison()
+    {
+        return this.className + this.packageName;
+    }
+    
+
+}
diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassNameComparator.java b/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassNameComparator.java
new file mode 100644
index 0000000..c91ec83
--- /dev/null
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/util/ClassNameComparator.java
@@ -0,0 +1,36 @@
+package org.apache.maven.jxr.util;
+
+/*
+ * 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.util.Comparator;
+
+/**
+ * A Comparator in order for the Treemap collection to know how it will compare
+ *
+ */
+public class ClassNameComparator implements Comparator<ClassName>
+{
+
+    @Override
+    public int compare( ClassName e1, ClassName e2 )
+    {
+        return e1.getKeyForComparison().compareTo( e2.getKeyForComparison() );
+    }
+}


 

----------------------------------------------------------------
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:
[hidden email]


> ignores classes with same name in other packages
> ------------------------------------------------
>
>                 Key: JXR-68
>                 URL: https://issues.apache.org/jira/browse/JXR-68
>             Project: Maven JXR
>          Issue Type: Bug
>          Components: maven2 jxr plugin
>    Affects Versions: 2.1
>            Reporter: Paul Sundling
>            Assignee: Karl Heinz Marbaise
>            Priority: Major
>             Fix For: 3.0.0
>
>
> say you the following classes
> package1/MyClass
> package2/MyClass
> While both will show up in javadocs plugin, only one will show up in JXR report.
> Let me know if you need a test case.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)