You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/10/29 18:48:02 UTC

[jira] [Commented] (JXR-141) Invalid HTML generation when having multiple occurences of the same class on one line

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

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

rfscholte closed pull request #12: [JXR-141] Invalid HTML generation
URL: https://github.com/apache/maven-jxr/pull/12
 
 
   

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/JavaCodeTransform.java b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
index 2140623..8102e6f 100644
--- a/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
@@ -56,6 +56,7 @@
 import java.io.Writer;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
@@ -604,6 +605,12 @@ private String xrLine( String line, String packageName, ClassType classType )
         String replace = link;
         List<StringEntry> tokens = SimpleWordTokenizer.tokenize( buff.toString(), find );
 
+        // JXR-141: If there are more than 1 tokens to be replaced,
+        // then the start+end values are out of order during the
+        // buff.replace.
+        // Reversing the list solves it
+        Collections.reverse( tokens );
+
         for ( StringEntry token : tokens )
         {
             int start = token.getIndex();
diff --git a/maven-jxr/src/test/java/org/apache/maven/jxr/JXR141Test.java b/maven-jxr/src/test/java/org/apache/maven/jxr/JXR141Test.java
new file mode 100644
index 0000000..a73ecea
--- /dev/null
+++ b/maven-jxr/src/test/java/org/apache/maven/jxr/JXR141Test.java
@@ -0,0 +1,69 @@
+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.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * Simple unit-testtest that illustrates a line with more
+ * than one "token" to replace
+ */
+public class JXR141Test {
+
+    @Test
+    public void processPath() throws Exception
+    {
+        JXR jxr = new JXR();
+        jxr.setDest( Paths.get("target/jxr-141" ) );
+        jxr.setLog( new DummyLog() );
+        jxr.setOutputEncoding( "UTF-8" );
+        jxr.xref( Collections.singletonList( "src/test/resources/jxr141" ),"templates/jdk4",
+                "title", "title", "copyright" );
+
+        List<String> lines = Files.readAllLines( Paths.get( "target/jxr-141/Test141.html" ),
+                StandardCharsets.UTF_8 );
+
+        // Find line #27...
+        String line27 = null;
+        for ( String line : lines )
+        {
+            if ( line.contains( "#L27" ) )
+            {
+                line27 = line;
+                break;
+            }
+        }
+        
+        assertNotNull( "Line #27 not found - has source of Test141.java changed?", line27 );
+        assertEquals( "<a class=\"jxr_linenumber\" name=\"L27\" href=\"#L27\">27</a>      " +
+                "<strong class=\"jxr_keyword\">public</strong> <strong class=\"jxr_keyword\">static</strong> " +
+                "<strong class=\"jxr_keyword\">final</strong> <a name=\"Test141\" href=\"..//Test141.html#Test141\">" +
+                "Test141</a> instance = <strong class=\"jxr_keyword\">new</strong> " +
+                "<a name=\"Test141\" href=\"..//Test141.html#Test141\">Test141</a>();" , line27 );
+    }
+}
\ No newline at end of file
diff --git a/maven-jxr/src/test/resources/jxr141/Test141.java b/maven-jxr/src/test/resources/jxr141/Test141.java
new file mode 100644
index 0000000..b12917f
--- /dev/null
+++ b/maven-jxr/src/test/resources/jxr141/Test141.java
@@ -0,0 +1,28 @@
+
+/*
+ * 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.
+ */
+
+/**
+ * Simple test JAVA source that illustrates a line with more
+ * than one "token" to replace
+ */
+public class Test141
+{
+    public static final Test141 instance = new Test141();
+}
\ 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


> Invalid HTML generation when having multiple occurences of the same class on one line
> -------------------------------------------------------------------------------------
>
>                 Key: JXR-141
>                 URL: https://issues.apache.org/jira/browse/JXR-141
>             Project: Maven JXR
>          Issue Type: Bug
>          Components: jxr
>    Affects Versions: 3.0.0
>         Environment: Windows 7, Java 8 Update 60, Maven 3.3.9
>            Reporter: Anthony Whitford
>            Priority: Major
>
> I am getting invalid HTML generated, like:
> {code:xml}
> <a class="jxr_linenumber" name="L51" href="#L51">51</a>      <strong class="jxr_keyword">public</strong> <a name="TreeNode" href="../../../../com/westernasset/resteasy/extjs/TreeNode.html#TreeNode">TreeNode</a> (<strong class="jxr_keyword">final</strong> String text, <stron<a name="TreeNode" href="../../../../com/westernasset/resteasy/extjs/TreeNode.html#TreeNode">TreeNode</a>"jxr_keyword">final</strong> Boolean checked, <strong class="jxr_keyword">final</strong> <a name="TreeNode" href="../../../../com/westernasset/resteasy/extjs/TreeNode.html#TreeNode">TreeNode</a>[] children) {
> {code}
> Specifically, look at:
> {code:xml}
> <stron<a name="TreeNode" href="../../../../com/westernasset/resteasy/extjs/TreeNode.html#TreeNode">TreeNode</a>"jxr_keyword">final</strong> Boolean checked
> {code}
> The original Java code is:
> {code}
>     public TreeNode (final String text, final Boolean checked, final TreeNode[] children) {
> {code}



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