From e160d8323df859e424047fd929fa01a3da0340a3 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Fri, 23 Apr 2004 16:56:20 +0000 Subject: [PATCH] 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 --- WHATSNEW | 2 + .../optional/jdepend/JDependTask.java | 153 ++++++++++-------- 2 files changed, 84 insertions(+), 71 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 2eb0e54d9..c9ec28e97 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -126,6 +126,8 @@ Fixed bugs: * I/O-intensive processes hung when executed via . Bugzilla reports 23893/26852. +* JDependTask did not close an output file. Bugzilla Report 28557. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java index 1635a1a4b..a39b06f1a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java @@ -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 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 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; }