From 2df5874fc82ef6bbf8db66dafb3aec1e0caae19a Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Wed, 4 Sep 2002 14:33:07 +0000 Subject: [PATCH] Improved the error handling --- .../tools/checkstyle/CheckStyleTask.java | 28 ++++++++++++++----- .../tools/checkstyle/Configuration.java | 4 +++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java index 869f37ae4..9dd27c26d 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java @@ -27,6 +27,7 @@ import org.apache.tools.ant.taskdefs.LogOutputStream; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; +import org.apache.regexp.RESyntaxException; import java.io.File; import java.io.FileInputStream; @@ -153,20 +154,33 @@ public class CheckStyleTask */ public void setProperties(File aProps) { - Properties mProperties = new Properties(); + final Properties mProperties = new Properties(); try { mProperties.load(new FileInputStream(aProps)); - mConfig = new Configuration(mProperties, System.out); } catch (FileNotFoundException e) { throw new BuildException( - "Could not find Properties file '" + aProps + "'", - e, getLocation()); + "Could not find Properties file '" + aProps + "'", + e, getLocation()); } - catch (Exception e) { + catch (IOException e) { throw new BuildException( - "Error loading Properties file '" + aProps + "'", - e, getLocation()); + "Error loading Properties file '" + aProps + "'", + e, getLocation()); + } + + try { + mConfig = new Configuration(mProperties, System.out); + } + catch (RESyntaxException e) { + throw new BuildException( + "An regular expression error exists in '" + aProps + "'", + e, getLocation()); + } + catch (IOException e) { + throw new BuildException( + "An error loading the file '" + e.getMessage() + "'", + e, getLocation()); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java index c21f057d4..16ff1f5f8 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java @@ -726,6 +726,10 @@ public class Configuration private void setHeaderFile(String aFileName) throws FileNotFoundException, IOException { + // TODO: Need to fix bug that relative paths are not handled. Need to + // be given an absolute path to add to paths. This is needed for + // all properties that specified paths (headerFile, baseDir). + // Handle a missing property, or an empty one if ((aFileName == null) || (aFileName.trim().length() == 0)) { return;