mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
This commit is contained in:
parent
a64e195ca9
commit
81ef12b24a
7 changed files with 123 additions and 82 deletions
|
@ -148,43 +148,28 @@ public class HtmlDocletWriter extends HtmlDocWriter {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
int previndex = 0;
|
int previndex = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (configuration.docrootparent.length() > 0) {
|
final String docroot = "{@docroot}";
|
||||||
final String docroot_parent = "{@docroot}/..";
|
// Search for lowercase version of {@docRoot}
|
||||||
// Search for lowercase version of {@docRoot}/..
|
index = lowerHtml.indexOf(docroot, previndex);
|
||||||
index = lowerHtml.indexOf(docroot_parent, previndex);
|
// If next {@docRoot} tag not found, append rest of htmlstr and exit loop
|
||||||
// If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
|
if (index < 0) {
|
||||||
if (index < 0) {
|
buf.append(htmlstr.substring(previndex));
|
||||||
buf.append(htmlstr.substring(previndex));
|
break;
|
||||||
break;
|
}
|
||||||
}
|
// If next {@docroot} tag found, append htmlstr up to start of tag
|
||||||
// If next {@docroot}/.. pattern found, append htmlstr up to start of tag
|
buf.append(htmlstr.substring(previndex, index));
|
||||||
buf.append(htmlstr.substring(previndex, index));
|
previndex = index + docroot.length();
|
||||||
previndex = index + docroot_parent.length();
|
if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) {
|
||||||
// Insert docrootparent absolute path where {@docRoot}/.. was located
|
// Insert the absolute link if {@docRoot} is followed by "/..".
|
||||||
|
|
||||||
buf.append(configuration.docrootparent);
|
buf.append(configuration.docrootparent);
|
||||||
// Append slash if next character is not a slash
|
previndex += 3;
|
||||||
if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
|
|
||||||
buf.append('/');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
final String docroot = "{@docroot}";
|
|
||||||
// Search for lowercase version of {@docRoot}
|
|
||||||
index = lowerHtml.indexOf(docroot, previndex);
|
|
||||||
// If next {@docRoot} tag not found, append rest of htmlstr and exit loop
|
|
||||||
if (index < 0) {
|
|
||||||
buf.append(htmlstr.substring(previndex));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If next {@docroot} tag found, append htmlstr up to start of tag
|
|
||||||
buf.append(htmlstr.substring(previndex, index));
|
|
||||||
previndex = index + docroot.length();
|
|
||||||
// Insert relative path where {@docRoot} was located
|
// Insert relative path where {@docRoot} was located
|
||||||
buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
|
buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
|
||||||
// Append slash if next character is not a slash
|
}
|
||||||
if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
|
// Append slash if next character is not a slash
|
||||||
buf.append('/');
|
if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
|
||||||
}
|
buf.append('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
@ -1604,26 +1589,30 @@ public class HtmlDocletWriter extends HtmlDocWriter {
|
||||||
result.addContent(seeTagToContent((SeeTag) tagelem));
|
result.addContent(seeTagToContent((SeeTag) tagelem));
|
||||||
} else if (! tagName.equals("Text")) {
|
} else if (! tagName.equals("Text")) {
|
||||||
boolean wasEmpty = result.isEmpty();
|
boolean wasEmpty = result.isEmpty();
|
||||||
Content output = TagletWriter.getInlineTagOuput(
|
Content output;
|
||||||
configuration.tagletManager, holderTag,
|
if (configuration.docrootparent.length() > 0
|
||||||
tagelem, getTagletWriterInstance(isFirstSentence));
|
&& tagelem.name().equals("@docRoot")
|
||||||
|
&& ((tags[i + 1]).text()).startsWith("/..")) {
|
||||||
|
// If Xdocrootparent switch ON, set the flag to remove the /.. occurrence after
|
||||||
|
// {@docRoot} tag in the very next Text tag.
|
||||||
|
textTagChange = true;
|
||||||
|
// Replace the occurrence of {@docRoot}/.. with the absolute link.
|
||||||
|
output = new StringContent(configuration.docrootparent);
|
||||||
|
} else {
|
||||||
|
output = TagletWriter.getInlineTagOuput(
|
||||||
|
configuration.tagletManager, holderTag,
|
||||||
|
tagelem, getTagletWriterInstance(isFirstSentence));
|
||||||
|
}
|
||||||
if (output != null)
|
if (output != null)
|
||||||
result.addContent(output);
|
result.addContent(output);
|
||||||
if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
|
if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
} else if (configuration.docrootparent.length() > 0 &&
|
|
||||||
tagelem.name().equals("@docRoot") &&
|
|
||||||
((tags[i + 1]).text()).startsWith("/..")) {
|
|
||||||
//If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
|
|
||||||
//{@docRoot} tag in the very next Text tag.
|
|
||||||
textTagChange = true;
|
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String text = tagelem.text();
|
String text = tagelem.text();
|
||||||
//If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
|
//If Xdocrootparent switch ON, remove the /.. occurrence after {@docRoot} tag.
|
||||||
if (textTagChange) {
|
if (textTagChange) {
|
||||||
text = text.replaceFirst("/..", "");
|
text = text.replaceFirst("/..", "");
|
||||||
textTagChange = false;
|
textTagChange = false;
|
||||||
|
|
|
@ -80,9 +80,7 @@ public class TagletWriterImpl extends TagletWriter {
|
||||||
*/
|
*/
|
||||||
public Content getDocRootOutput() {
|
public Content getDocRootOutput() {
|
||||||
String path;
|
String path;
|
||||||
if (configuration.docrootparent.length() > 0)
|
if (htmlWriter.pathToRoot.isEmpty())
|
||||||
path = configuration.docrootparent;
|
|
||||||
else if (htmlWriter.pathToRoot.isEmpty())
|
|
||||||
path = ".";
|
path = ".";
|
||||||
else
|
else
|
||||||
path = htmlWriter.pathToRoot.getPath();
|
path = htmlWriter.pathToRoot.getPath();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6553182
|
* @bug 6553182 8025416
|
||||||
* @summary This test verifies the -Xdocrootparent option.
|
* @summary This test verifies the -Xdocrootparent option.
|
||||||
* @author Bhavesh Patel
|
* @author Bhavesh Patel
|
||||||
* @library ../lib/
|
* @library ../lib/
|
||||||
|
@ -35,43 +35,87 @@ public class TestDocRootLink extends JavadocTester {
|
||||||
private static final String BUG_ID = "6553182";
|
private static final String BUG_ID = "6553182";
|
||||||
private static final String[][] TEST1 = {
|
private static final String[][] TEST1 = {
|
||||||
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
||||||
"<a href=\"../../technotes/guides/index.html\">"
|
"Refer <a href=\"../../technotes/guides/index.html\">Here</a>"
|
||||||
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
||||||
|
"This <a href=\"../pkg2/C2.html\">Here</a> should not be replaced" + NL +
|
||||||
|
" with an absolute link."
|
||||||
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
||||||
|
"Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
|
||||||
|
" <a href=\"../pkg2/C2.html\">Link 2</a>."
|
||||||
},
|
},
|
||||||
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
||||||
"<a href=\"../../technotes/guides/index.html\">"
|
"<a href=\"../../technotes/guides/index.html\">" + NL +
|
||||||
|
" Test document 1</a>"
|
||||||
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
||||||
|
"<a href=\"../pkg2/C2.html\">" + NL +
|
||||||
|
" Another Test document 1</a>"
|
||||||
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
||||||
|
"<a href=\"../technotes/guides/index.html\">" + NL +
|
||||||
|
" Another Test document 2.</a>"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final String[][] NEGATED_TEST1 = {
|
private static final String[][] NEGATED_TEST1 = {
|
||||||
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
||||||
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
||||||
},
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "C1.html",
|
||||||
|
"<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
|
||||||
|
},
|
||||||
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
||||||
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
||||||
|
},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "package-summary.html",
|
||||||
|
"<a href=\"http://download.oracle.com/javase/7/docs/pkg2/C2.html\">"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final String[][] TEST2 = {
|
private static final String[][] TEST2 = {
|
||||||
{BUG_ID + FS + "pkg2" + FS + "C2.html",
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
|
||||||
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
"Refer <a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">Here</a>"
|
||||||
},
|
},
|
||||||
{BUG_ID + FS + "pkg2" + FS + "package-summary.html",
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
|
||||||
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">"
|
"This <a href=\"../pkg1/C1.html\">Here</a> should not be replaced" + NL +
|
||||||
|
" with an absolute link."
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
|
||||||
|
"Testing <a href=\"../technotes/guides/index.html\">Link 1</a> and" + NL +
|
||||||
|
" <a href=\"../pkg1/C1.html\">Link 2</a>."
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
|
||||||
|
"<a href=\"http://download.oracle.com/javase/7/docs/technotes/guides/index.html\">" + NL +
|
||||||
|
" Test document 1</a>"
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
|
||||||
|
"<a href=\"../pkg1/C1.html\">" + NL + " Another Test document 1</a>"
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
|
||||||
|
"<a href=\"../technotes/guides/index.html\">" + NL + " Another Test document 2.</a>"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final String[][] NEGATED_TEST2 = {
|
private static final String[][] NEGATED_TEST2 = {
|
||||||
{BUG_ID + FS + "pkg2" + FS + "C2.html",
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
|
||||||
"<a href=\"../../technotes/guides/index.html\">"
|
"<a href=\"../../technotes/guides/index.html\">"
|
||||||
},
|
},
|
||||||
{BUG_ID + FS + "pkg2" + FS + "package-summary.html",
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "C2.html",
|
||||||
|
"<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
|
||||||
"<a href=\"../../technotes/guides/index.html\">"
|
"<a href=\"../../technotes/guides/index.html\">"
|
||||||
|
},
|
||||||
|
{BUG_ID + "-1" + FS + "pkg2" + FS + "package-summary.html",
|
||||||
|
"<a href=\"http://download.oracle.com/javase/7/docs/pkg1/C1.html\">"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final String[] ARGS1 =
|
private static final String[] ARGS1 =
|
||||||
new String[]{
|
new String[]{
|
||||||
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"
|
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1", "pkg2"
|
||||||
};
|
};
|
||||||
private static final String[] ARGS2 =
|
private static final String[] ARGS2 =
|
||||||
new String[]{
|
new String[]{
|
||||||
"-d", BUG_ID, "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg2"
|
"-d", BUG_ID + "-1", "-Xdocrootparent", "http://download.oracle.com/javase/7/docs", "-sourcepath", SRC_DIR, "pkg1", "pkg2"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,12 @@ package pkg1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class 1. This is a test.
|
* Class 1. This is a test.
|
||||||
* Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
|
* Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. This link should
|
||||||
* or not.
|
* not be replaced with an absolute link.
|
||||||
|
* This <a href="{@docRoot}/pkg2/C2.html">Here</a> should not be replaced
|
||||||
|
* with an absolute link.
|
||||||
|
* Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
|
||||||
|
* <a href="{@docRoot}/pkg2/C2.html">Link 2</a>. 2 back-to-back links using
|
||||||
|
* docroot. These should not be replaced with an absolute link.
|
||||||
*/
|
*/
|
||||||
public class C1 {}
|
public class C1 {}
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
<title>javax.management package</title>
|
<title>javax.management package</title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
This is a test.
|
This is a test.
|
||||||
<p id="spec">
|
<p id="spec">
|
||||||
@see <a href="{@docRoot}/../technotes/guides/index.html">
|
@see <a href="{@docRoot}/../technotes/guides/index.html">
|
||||||
Test document 1</a>
|
Test document 1</a> should not be replaced with an absolute link.
|
||||||
in particular the
|
@see <a href="{@docRoot}/pkg2/C2.html">
|
||||||
<a href="{@docRoot}/../technotes/guides/index.html">
|
Another Test document 1</a> which should not be replaced with an absolute link.
|
||||||
|
<a href="{@docRoot}/technotes/guides/index.html">
|
||||||
|
Another Test document 2.</a> which should not be replaced with an absolute link.
|
||||||
|
|
||||||
Test document 2.</a>
|
@since 1.5
|
||||||
|
|
||||||
@since 1.5
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -24,8 +24,13 @@
|
||||||
package pkg2;
|
package pkg2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class 1. This is a test.
|
* Class 2. This is a test.
|
||||||
* Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a>. Lets see if this works
|
* Refer <a href="{@docRoot}/../technotes/guides/index.html">Here</a> should be
|
||||||
* or not.
|
* replaced with an absolute link.
|
||||||
|
* This <a href="{@docRoot}/pkg1/C1.html">Here</a> should not be replaced
|
||||||
|
* with an absolute link.
|
||||||
|
* Testing <a href="{@docRoot}/technotes/guides/index.html">Link 1</a> and
|
||||||
|
* <a href="{@docRoot}/pkg1/C1.html">Link 2</a>. Both should not be replaced with
|
||||||
|
* an absolute link.
|
||||||
*/
|
*/
|
||||||
public class C2 {}
|
public class C2 {}
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
<title>javax.management package</title>
|
<title>javax.management package</title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
This is a test.
|
This is a test.
|
||||||
<p id="spec">
|
<p id="spec">
|
||||||
@see <a href="{@docRoot}/../technotes/guides/index.html">
|
@see <a href="{@docRoot}/../technotes/guides/index.html">
|
||||||
Test document 1</a>
|
Test document 1</a> should be replaced with an absolute link.
|
||||||
in particular the
|
@see <a href="{@docRoot}/pkg1/C1.html">
|
||||||
<a href="{@docRoot}/../technotes/guides/index.html">
|
Another Test document 1</a> which should not be replaced with an absolute link.
|
||||||
|
<a href="{@docRoot}/technotes/guides/index.html">
|
||||||
|
Another Test document 2.</a> which should not be replaced with an absolute link.
|
||||||
|
|
||||||
Test document 2.</a>
|
@since 1.5
|
||||||
|
|
||||||
@since 1.5
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue