Browse Source

JDependTask did not close an output file

PR: 28557
Obtained from: Jeff Badorek


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276403 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
e160d8323d
2 changed files with 84 additions and 71 deletions
  1. +2
    -0
      WHATSNEW
  2. +82
    -71
      src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java

+ 2
- 0
WHATSNEW View File

@@ -126,6 +126,8 @@ Fixed bugs:
* I/O-intensive processes hung when executed via <exec spawn="true">.
Bugzilla reports 23893/26852.

* JDependTask did not close an output file. Bugzilla Report 28557.

Other changes:
--------------



+ 82
- 71
src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java View File

@@ -453,8 +453,8 @@ public class JDependTask extends Task {
jdepend = new jdepend.textui.JDepend();
}

FileWriter fw = null;
if (getOutputFile() != null) {
FileWriter fw;
try {
fw = new FileWriter(getOutputFile().getPath());
} catch (IOException e) {
@@ -467,87 +467,98 @@ public class JDependTask extends Task {
log("Output to be stored in " + getOutputFile().getPath());
}

if (getClassespath() != null) {
// This is the new, better way - use classespath instead
// of sourcespath. The code is currently the same - you
// need class files in a directory to use this - jar files
// coming soon....
String[] classesPath = getClassespath().list();
for (int i = 0; i < classesPath.length; i++) {
File f = new File(classesPath[i]);
// not necessary as JDepend would fail, but why loose
// some time?
if (!f.exists() || !f.isDirectory()) {
String msg = "\""
+ f.getPath()
+ "\" does not represent a valid"
+ " directory. JDepend would fail.";
log(msg);
throw new BuildException(msg);

try {
if (getClassespath() != null) {
// This is the new, better way - use classespath instead
// of sourcespath. The code is currently the same - you
// need class files in a directory to use this - jar files
// coming soon....
String[] classesPath = getClassespath().list();
for (int i = 0; i < classesPath.length; i++) {
File f = new File(classesPath[i]);
// not necessary as JDepend would fail, but why loose
// some time?
if (!f.exists() || !f.isDirectory()) {
String msg = "\""
+ f.getPath()
+ "\" does not represent a valid"
+ " directory. JDepend would fail.";
log(msg);
throw new BuildException(msg);
}
try {
jdepend.addDirectory(f.getPath());
} catch (IOException e) {
String msg =
"JDepend Failed when adding a class directory: "
+ e.getMessage();
log(msg);
throw new BuildException(msg);
}
}
try {
jdepend.addDirectory(f.getPath());
} catch (IOException e) {
String msg =
"JDepend Failed when adding a class directory: "
+ e.getMessage();
log(msg);
throw new BuildException(msg);

} else if (getSourcespath() != null) {

// This is the old way and is deprecated - classespath is
// the right way to do this and is above
String[] sourcesPath = getSourcespath().list();
for (int i = 0; i < sourcesPath.length; i++) {
File f = new File(sourcesPath[i]);

// not necessary as JDepend would fail, but why loose
// some time?
if (!f.exists() || !f.isDirectory()) {
String msg = "\""
+ f.getPath()
+ "\" does not represent a valid"
+ " directory. JDepend would fail.";
log(msg);
throw new BuildException(msg);
}
try {
jdepend.addDirectory(f.getPath());
} catch (IOException e) {
String msg =
"JDepend Failed when adding a source directory: "
+ e.getMessage();
log(msg);
throw new BuildException(msg);
}
}
}

} else if (getSourcespath() != null) {

// This is the old way and is deprecated - classespath is
// the right way to do this and is above
String[] sourcesPath = getSourcespath().list();
for (int i = 0; i < sourcesPath.length; i++) {
File f = new File(sourcesPath[i]);

// not necessary as JDepend would fail, but why loose
// some time?
if (!f.exists() || !f.isDirectory()) {
String msg = "\""
+ f.getPath()
+ "\" does not represent a valid"
+ " directory. JDepend would fail.";
log(msg);
throw new BuildException(msg);
}
try {
jdepend.addDirectory(f.getPath());
} catch (IOException e) {
String msg =
"JDepend Failed when adding a source directory: "
+ e.getMessage();
log(msg);
throw new BuildException(msg);
// This bit turns <exclude> child tags into patters to ignore
String[] patterns = defaultPatterns.getExcludePatterns(getProject());
if (patterns != null && patterns.length > 0) {
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);
}
}
}

// This bit turns <exclude> child tags into patters to ignore
String[] patterns = defaultPatterns.getExcludePatterns(getProject());
if (patterns != null && patterns.length > 0) {
if (setFilter != null) {
Vector v = new Vector();
for (int i = 0; i < patterns.length; i++) {
v.addElement(patterns[i]);
}
jdepend.analyze();
} finally {
if (fw != null) {
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);
fw.close();
} catch (Throwable t) {
// Ignore
}
} else {
log("Sorry, your version of JDepend doesn't support excludes",
Project.MSG_WARN);
}
}

jdepend.analyze();
return SUCCESS;
}



Loading…
Cancel
Save