Browse Source

Optionally resolve the link attribute.

PR: 24364


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278003 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
8f927b8ff5
2 changed files with 51 additions and 4 deletions
  1. +12
    -1
      docs/manual/CoreTasks/javadoc.html
  2. +39
    -3
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java

+ 12
- 1
docs/manual/CoreTasks/javadoc.html View File

@@ -550,7 +550,9 @@ specify multiple occurrences of the arguments.</p>
</tr>
<tr>
<td valign="top">href</td>
<td valign="top">The URL for the external documentation you wish to link to</td>
<td valign="top">The URL for the external documentation you wish
to link to. This can be an absolute URL, or a relative file
name.</td>
<td align="center" valign="top">Yes</td>
</tr>
<tr>
@@ -565,6 +567,15 @@ specify multiple occurrences of the arguments.</p>
the external documentation</td>
<td align="center" valign="top">Only if the offline attribute is true</td>
</tr>
<tr>
<td valign="top">resolveLink</td>
<td valign="top">If the link attribute is a relative file name,
Ant will first try to locate the file relative to the current
project's basedir and if it finds a file there use an absolute URL
for the link attribute, otherwise it will pass the file name
verbatim to the javadoc command.</td>
<td align="center" valign="top">No, default is false.</td>
</tr>
</table>

<h4><a name="groupelement">group</a></h4>


+ 39
- 3
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -1200,6 +1200,7 @@ public class Javadoc extends Task {
private String href;
private boolean offline = false;
private File packagelistLoc;
private boolean resolveLink = false;

/** Constructor for LinkArguement */
public LinkArgument() {
@@ -1253,6 +1254,24 @@ public class Javadoc extends Task {
public boolean isLinkOffline() {
return offline;
}

/**
* Sets whether Ant should resolve the link attribute relative
* to the current basedir.
* @param resolve a <code>boolean</code> value
*/
public void setResolveLink(boolean resolve) {
this.resolveLink = resolve;
}

/**
* should Ant resolve the link attribute relative to the
* current basedir?
*/
public boolean shouldResolveLink() {
return resolveLink;
}

}

/**
@@ -1756,11 +1775,28 @@ public class Javadoc extends Task {
log("No href was given for the link - skipping",
Project.MSG_VERBOSE);
continue;
} else {
}
String link = null;
if (la.shouldResolveLink()) {
File hrefAsFile =
getProject().resolveFile(la.getHref());
if (hrefAsFile.exists()) {
try {
link = FILE_UTILS.getFileURL(hrefAsFile)
.toExternalForm();
} catch (MalformedURLException ex) {
// should be impossible
log("Warning: link location was invalid "
+ hrefAsFile, Project.MSG_WARN);
}
}
}
if (link == null) {
// is the href a valid URL
try {
URL base = new URL("file://.");
new URL(base, la.getHref());
link = la.getHref();
} catch (MalformedURLException mue) {
// ok - just skip
log("Link href \"" + la.getHref()
@@ -1790,7 +1826,7 @@ public class Javadoc extends Task {
toExecute.createArgument()
.setValue("-linkoffline");
toExecute.createArgument()
.setValue(la.getHref());
.setValue(link);
toExecute.createArgument()
.setValue(packageListURL);
} catch (MalformedURLException ex) {
@@ -1804,7 +1840,7 @@ public class Javadoc extends Task {
}
} else {
toExecute.createArgument().setValue("-link");
toExecute.createArgument().setValue(la.getHref());
toExecute.createArgument().setValue(link);
}
}
}


Loading…
Cancel
Save