bodewig 2003/04/03 07:49:48
Modified: docs/manual/OptionalTasks jdepend.html
src/main/org/apache/tools/ant/taskdefs/optional/jdepend
JDependTask.java
Log:
Apply some reflection to become JDepend version independent
Revision Changes Path
1.10 +1 -1 ant/docs/manual/OptionalTasks/jdepend.html
Index: jdepend.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/OptionalTasks/jdepend.html,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jdepend.html 2 Apr 2003 12:00:27 -0000 1.9
+++ jdepend.html 3 Apr 2003 15:49:47 -0000 1.10
@@ -93,7 +93,7 @@
the paths of compiled class code to analyze; the <sourcespath>
variable is still available in case you are using an earlier version
of JDepend. The <exclude> element can be used to set packages
-to ignore.</p>
+to ignore (requires JDepend 2.5 or above).</p>
<h3>Examples</h3>
1.19 +48 -17
ant/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
Index: JDependTask.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JDependTask.java 2 Apr 2003 12:00:27 -0000 1.18
+++ JDependTask.java 3 Apr 2003 15:49:48 -0000 1.19
@@ -58,6 +58,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.PathTokenizer;
@@ -104,19 +106,37 @@
private String format = "text";
private PatternSet defaultPatterns = new PatternSet();
- public JDependTask() {
+ private static Constructor packageFilterC;
+ private static Method setFilter;
+ static {
+ try {
+ Class packageFilter =
+ Class.forName("jdepend.framework.PackageFilter");
+ packageFilterC =
+ packageFilter.getConstructor(new Class[]
{java.util.Collection.class});
+ setFilter =
+ jdepend.textui.JDepend.class.getDeclaredMethod("setFilter",
+ new Class[]
{packageFilter});
+ } catch (Throwable t) {
+ if (setFilter == null) {
+ packageFilterC = null;
+ }
+ }
}
-/*
- public void setTimeout(Integer value) {
- _timeout = value;
+ public JDependTask() {
}
- public Integer getTimeout() {
- return _timeout;
- }
-*/
+ /*
+ public void setTimeout(Integer value) {
+ _timeout = value;
+ }
+
+ public Integer getTimeout() {
+ return _timeout;
+ }
+ */
/**
* The output file name.
@@ -305,9 +325,9 @@
if ("text".equals(format)) {
commandline.setClassname("jdepend.textui.JDepend");
} else
- if ("xml".equals(format)) {
- commandline.setClassname("jdepend.xmlui.JDepend");
- }
+ if ("xml".equals(format)) {
+ commandline.setClassname("jdepend.xmlui.JDepend");
+ }
if (_jvm != null) {
commandline.setVm(_jvm);
@@ -443,11 +463,22 @@
// This bit turns <exclude> child tags into patters to ignore
String[] patterns = defaultPatterns.getExcludePatterns(getProject());
if (patterns != null && patterns.length > 0) {
- Vector v = new Vector();
- for (int i = 0; i < patterns.length; i++) {
- v.addElement(patterns[i]);
+ if (setFilter != null) {
+ Vector v = new Vector();
+ for (int i = 0; i < patterns.length; i++) {
+ v.addElement(patterns[i]);
+ }
+ try {
+ Object o = packageFilterC.newInstance(new Object[] {v});
+ setFilter.invoke(jdepend, new Object[] {o});
+ } catch (Throwable e) {
+ log("excludes will be ignored as JDepend doesn't like
me: "
+ + e.getMessage(), Project.MSG_WARN);
+ }
+ } else {
+ log("Sorry, your version of JDepend doesn't support
excludes",
+ Project.MSG_WARN);
}
- jdepend.setFilter(new jdepend.framework.PackageFilter(v));
}
jdepend.analyze();
@@ -493,7 +524,7 @@
// not necessary as JDepend would fail, but why loose some time?
if (!f.exists() || !f.isDirectory()) {
throw new BuildException("\"" + f.getPath() + "\" does not "
- + "represent a valid directory. JDepend would fail.");
+ + "represent a valid directory.
JDepend would fail.");
}
commandline.createArgument().setValue(f.getPath());
}
@@ -505,7 +536,7 @@
// not necessary as JDepend would fail, but why loose some time?
if (!f.exists() || !f.isDirectory()) {
throw new BuildException("\"" + f.getPath() + "\" does not "
- + "represent a valid directory. JDepend would
fail.");
+ + "represent a valid directory.
JDepend would fail.");
}
commandline.createArgument().setValue(f.getPath());
}