Bug 398844 - Missing include/exclude file should cause task to fail
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/search/tests/SearchTest.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/search/tests/SearchTest.java
index 04cec48..cf839ac 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/search/tests/SearchTest.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/search/tests/SearchTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -137,7 +137,7 @@
 	 * @param filename
 	 * @return the listing of excluded items
 	 */
-	protected HashSet<String> getExcludeSet(IApiBaseline baseline, String filename) {
+	protected HashSet<String> getExcludeSet(IApiBaseline baseline, String filename) throws CoreException {
 		if(filename == null) {
 			return null;
 		}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/UtilTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/UtilTests.java
index 216ec622..72b2d46 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/UtilTests.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/UtilTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -50,6 +50,7 @@
 public class UtilTests extends TestCase {
 
 	private static final IPath SRC_LOC = TestSuiteHelper.getPluginDirectoryPath().append("test_source");
+	static final IPath SRC_LOC_SEARCH = TestSuiteHelper.getPluginDirectoryPath().append("test-search");
 	
 	/**
 	 * Tests that passing in <code>null</code> to the getAllFiles(..) method
@@ -664,4 +665,20 @@
 			assertTrue("Should not happen", false);
 		}
 	}
+	
+	/**
+	 * Tests that the utility method for reading in include/exclude regex tests throws an exception
+	 * when the file doesn't exist.
+	 * 
+	 * The regex parsing is tested more extensively in {@link org.eclipse.pde.api.tools.search.tests.SearchEngineTests}
+	 */
+	public void testInitializeRegexFilterList(){
+		File bogus = new File(SRC_LOC.toFile(), "DOES_NOT_EXIST");
+		try {
+			Util.initializeRegexFilterList(bogus.getAbsolutePath(), null, false);
+			fail("Util.initializeRegexFilterList should throw Core Exception for missing file");
+		} catch (CoreException e){
+			// Must hit here
+		}
+	}
 }
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
index a77df21..f1eed17 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2012 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -102,7 +102,7 @@
 import org.eclipse.jdt.launching.environments.ExecutionEnvironmentDescription;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.osgi.util.NLS;
-import org.eclipse.pde.api.tools.internal.ApiFilterStore;
+import org.eclipse.pde.api.tools.internal.FilterStore;
 import org.eclipse.pde.api.tools.internal.IApiCoreConstants;
 import org.eclipse.pde.api.tools.internal.builder.BuildState;
 import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
@@ -2110,6 +2110,8 @@
 					default:
 						return arguments[0];
 				}
+			default:
+				break;
 		}
 		return EMPTY_STRING;
 	}
@@ -2148,7 +2150,7 @@
 		return MANIFEST_PROJECT_RELATIVE_PATH.equals(path);
 	}
 	public static void touchCorrespondingResource(IProject project, IResource resource, String typeName) {
-		if (typeName != null && typeName != ApiFilterStore.GLOBAL) {
+		if (typeName != null && typeName != FilterStore.GLOBAL) {
 			if (Util.isManifest(resource.getProjectRelativePath())) {
 				try {
 					IJavaProject javaProject = JavaCore.create(project);
@@ -2262,52 +2264,53 @@
 	 * @param location
 	 * @param baseline
 	 * @return the list of bundles to be excluded
+	 * @throws CoreException if the location does not describe a includes file or an IOException occurs
 	 */
-	public static FilteredElements initializeRegexFilterList(String location, IApiBaseline baseline, boolean debug) {
+	public static FilteredElements initializeRegexFilterList(String location, IApiBaseline baseline, boolean debug) throws CoreException {
 		FilteredElements excludedElements = new FilteredElements();
 		if (location != null) {
 			File file = new File(location);
-			if (file.exists()) {
-				InputStream stream = null;
-				char[] contents = null;
-				try {
-					stream = new BufferedInputStream(new FileInputStream(file));
-					contents = getInputStreamAsCharArray(stream, -1, ISO_8859_1);
-				} 
-				catch (FileNotFoundException e) {} 
-				catch (IOException e) {} 
-				finally {
-					if (stream != null) {
-						try {
-							stream.close();
-						} catch (IOException e) {}
-					}
-				}
-				if (contents != null) {
-					LineNumberReader reader = new LineNumberReader(new StringReader(new String(contents)));
-					String line = null;
+			InputStream stream = null;
+			char[] contents = null;
+			try {
+				stream = new BufferedInputStream(new FileInputStream(file));
+				contents = getInputStreamAsCharArray(stream, -1, ISO_8859_1);
+			} catch (FileNotFoundException e) {
+				abort(NLS.bind(UtilMessages.Util_couldNotFindFilterFile,location), e);
+			} catch (IOException e) {
+				abort(NLS.bind(UtilMessages.Util_problemWithFilterFile,location), e);
+			} 
+			finally {
+				if (stream != null) {
 					try {
-						while ((line = reader.readLine()) != null) {
-							line = line.trim();
-							if (line.startsWith("#") || line.length() == 0) { //$NON-NLS-1$
-								continue; 
-							}
-							if(line.startsWith(REGULAR_EXPRESSION_START)) {
-								if(baseline != null) {
-									Util.collectRegexIds(line, excludedElements, baseline.getApiComponents(), debug);
-								}
-							} else {
-								excludedElements.addExactMatch(line);
-							}
+						stream.close();
+					} catch (IOException e) {}
+				}
+			}
+			if (contents != null) {
+				LineNumberReader reader = new LineNumberReader(new StringReader(new String(contents)));
+				String line = null;
+				try {
+					while ((line = reader.readLine()) != null) {
+						line = line.trim();
+						if (line.startsWith("#") || line.length() == 0) { //$NON-NLS-1$
+							continue; 
 						}
-					} 
-					catch (IOException e) {} 
-					catch (Exception e) {} 
-					finally {
-						try {
-							reader.close();
-						} catch (IOException e) {}
+						if(line.startsWith(REGULAR_EXPRESSION_START)) {
+							if(baseline != null) {
+								Util.collectRegexIds(line, excludedElements, baseline.getApiComponents(), debug);
+							}
+						} else {
+							excludedElements.addExactMatch(line);
+						}
 					}
+				} catch (IOException e) {
+					abort(NLS.bind(UtilMessages.Util_problemWithFilterFile,location), e);
+				} 
+				finally {
+					try {
+						reader.close();
+					} catch (IOException e) {}
 				}
 			}
 		}
@@ -2320,7 +2323,7 @@
 	 * @param list
 	 * @param components
 	 */
-	public static void collectRegexIds(String line, FilteredElements excludedElements, IApiComponent[] components, boolean debug) throws Exception {
+	public static void collectRegexIds(String line, FilteredElements excludedElements, IApiComponent[] components, boolean debug) throws CoreException {
 		if (line.startsWith(REGULAR_EXPRESSION_START)) {
 			String componentname = line;
 			// regular expression
@@ -2347,9 +2350,9 @@
 					}
 				}
 			} catch (PatternSyntaxException e) {
-				throw new Exception(NLS.bind(
+				abort(NLS.bind(
 						UtilMessages.comparison_invalidRegularExpression,
-						componentname));
+						componentname),e);
 			}
 		}
 	}
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/UtilMessages.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/UtilMessages.java
index 3cce669..529f49d 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/UtilMessages.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/UtilMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -19,6 +19,8 @@
 	public static String Util_5;
 	public static String Util_6;
 	public static String Util_builder_errorMessage;
+	public static String Util_couldNotFindFilterFile;
+	public static String Util_problemWithFilterFile;
 	public static String comparison_invalidRegularExpression;
 
 	static {
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/utilmessages.properties b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/utilmessages.properties
index 1a49fb3..a9dc674 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/utilmessages.properties
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/utilmessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2008, 2010 IBM Corporation and others.
+# Copyright (c) 2008, 2013 IBM Corporation and others.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
 # which accompanies this distribution, and is available at
@@ -13,4 +13,6 @@
 Util_5=Building project {0}
 Util_6=Could not locate method {0}{1}
 Util_builder_errorMessage=An error occurred while running the API tools builder.
+Util_couldNotFindFilterFile=Could not find filter file at: {0}
+Util_problemWithFilterFile=Problem with filter file at: {0}
 comparison_invalidRegularExpression=Invalid regular expression pattern : {0}
diff --git a/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java b/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
index 846abdc..5003803 100644
--- a/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
+++ b/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CommonUtilsTask.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -160,8 +160,12 @@
 	 * @param excludeListLocation
 	 * @return the set of project names to be excluded
 	 */
-	protected static FilteredElements initializeFilteredElements(String filterListLocation, IApiBaseline baseline, boolean debug) {
-		return Util.initializeRegexFilterList(filterListLocation, baseline, debug);
+	protected static FilteredElements initializeFilteredElements(String filterListLocation, IApiBaseline baseline, boolean debug) throws BuildException {
+		try {
+			return Util.initializeRegexFilterList(filterListLocation, baseline, debug);
+		} catch (CoreException e) {
+			throw new BuildException(e);
+		}
 	}
 
 	/**