From a5ef5f6338d0f1b80b81c6d5dbf7923b666aaaa0 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Mon, 11 Sep 2017 13:05:58 +0000
Subject: [PATCH] - Add loadModelFromFileWithUnknownFeatures(URI uri, boolean
 logError) that enables to not log errors to the console -
 loadModelFromFileWithUnknownFeatures(URI uri) kept for compatibility

---
 .../kernel/utils/EMFResourceUtils.java        | 29 +++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java
index 42137950d..711b208fc 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EMFResourceUtils.java
@@ -41,7 +41,7 @@ import org.fortiss.tooling.kernel.ToolingKernelActivator;
  * @author hoelzl
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating YELLOW Hash: 56BD3983999FF36819DDEDE7854E36EF
+ * @ConQAT.Rating YELLOW Hash: DF29CCFD1A2C94454FC9F8BFBD65E9CD
  */
 public final class EMFResourceUtils {
 	/**
@@ -82,8 +82,8 @@ public final class EMFResourceUtils {
 	}
 
 	/**
-	 * Loads the root model element from the given {@link URI}. Logs errors to the console and
-	 * returns <code>null</code>.
+	 * Loads the root model element from the given {@link URI}. Returns {@code null} in case of
+	 * errors, and logs errors to the console.
 	 * 
 	 * @param uri
 	 *            the resource {@link URI}.
@@ -91,6 +91,21 @@ public final class EMFResourceUtils {
 	 */
 	public static Pair<EObject, Map<EObject, AnyType>>
 			loadModelFromFileWithUnknownFeatures(URI uri) {
+		return loadModelFromFileWithUnknownFeatures(uri, true);
+	}
+
+	/**
+	 * Loads the root model element from the given {@link URI}. Returns {@code null} in case of
+	 * errors, and optionally logs errors to the console.
+	 * 
+	 * @param uri
+	 *            the resource {@link URI}.
+	 * @param logError
+	 *            Whether to log errors.
+	 * @return the root {@link EObject}.
+	 */
+	public static Pair<EObject, Map<EObject, AnyType>> loadModelFromFileWithUnknownFeatures(
+			URI uri, boolean logError) {
 		try {
 			ResourceSet rset = new ResourceSetImpl();
 			Resource r;
@@ -106,8 +121,12 @@ public final class EMFResourceUtils {
 						unknownFeatures);
 			}
 		} catch(IOException ex) {
-			error(ToolingKernelActivator.getDefault(),
-					"Failed to load model from " + uri.toString(), ex);
+			if(logError) {
+				error(ToolingKernelActivator.getDefault(),
+						"Failed to load model from " + uri.toString(), ex);
+			}
+		} catch(Throwable t) {
+			return null;
 		}
 		return null;
 	}
-- 
GitLab