Case insensitive model file extensions

I modified the file extension handling in the
AbstractResourceScopeProvider#hasApplicableFileExtension(IFile), to
ignore the case of the file extensions of IFiles, and also ignore the
case of the file extensions of the registered Content Types (e.g. .txt,
.TXT, .TxT are both accepted now as a .txt Content Type). Its usage
should be through the
ResourceScopeProviderRegistry#hasApplicableFileExtension(IFile)

Change-Id: Ieb6a664e94f6cf90f0f82300a361bdec2433b23f
Signed-off-by: Andras Janko <andras.janko@incquerylabs.com>
Signed-off-by: Balazs Varnai <balazs_varnai@mentor.com>
diff --git a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/scoping/AbstractResourceScopeProvider.java b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/scoping/AbstractResourceScopeProvider.java
index 81d8de3..7b635c9 100644
--- a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/scoping/AbstractResourceScopeProvider.java
+++ b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/scoping/AbstractResourceScopeProvider.java
@@ -1,16 +1,16 @@
 /**

  * <copyright>

- * 

+ *

  * Copyright (c) 2008-2012 See4sys 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

  * http://www.eclipse.org/legal/epl-v10.html

- * 

- * Contributors: 

+ *

+ * Contributors:

  *     See4sys - Initial API and implementation

  *     BMW Car IT - [373481] Performance optimizations for model loading

- * 

+ *

  * </copyright>

  */

 package org.eclipse.sphinx.emf.scoping;

@@ -57,16 +57,18 @@
 			return false;

 		}

 

+		extension = extension.toLowerCase();

+

 		// Check if the given file's extension matches one of the extensions associated with one of the content types

 		// that are supported by one of the metamodel descriptors which this resource scope provider is used for

 		for (IMetaModelDescriptor mmDescriptor : ResourceScopeProviderRegistry.INSTANCE.getMetaModelDescriptorsFor(this)) {

 			for (String contentTypeId : mmDescriptor.getContentTypeIds()) {

-				if (ExtendedPlatform.getContentTypeFileExtensions(contentTypeId).contains(extension)) {

+				if (isContentTypeContainsFileExtension(contentTypeId, extension)) {

 					return true;

 				}

 			}

 			for (String compatibleContentTypeId : mmDescriptor.getCompatibleContentTypeIds()) {

-				if (ExtendedPlatform.getContentTypeFileExtensions(compatibleContentTypeId).contains(extension)) {

+				if (isContentTypeContainsFileExtension(compatibleContentTypeId, extension)) {

 					return true;

 				}

 			}

@@ -104,7 +106,7 @@
 

 	/**

 	 * Creates a new {@link IResourceScope resource scope} for given workspace resource.

-	 * 

+	 *

 	 * @param resource

 	 *            The {@link IResource workspace resource} to create the {@link IResourceScope resource scope} for.

 	 * @return The newly created {@link IResourceScope resource scope}.

@@ -130,4 +132,13 @@
 	public Diagnostic validate(IFile file) {

 		return Diagnostic.OK_INSTANCE;

 	}

+

+	private boolean isContentTypeContainsFileExtension(String contentTypeID, String fileExtension) {

+		for (String contentTypeFileExtension : ExtendedPlatform.getContentTypeFileExtensions(contentTypeID)) {

+			if (contentTypeFileExtension != null && fileExtension.equals(contentTypeFileExtension.toLowerCase())) {

+				return true;

+			}

+		}

+		return false;

+	}

 }

diff --git a/tests/org.eclipse.sphinx.tests.emf.integration/src/org/eclipse/sphinx/tests/emf/integration/scoping/ResourceScopeProviderRegistryTest.java b/tests/org.eclipse.sphinx.tests.emf.integration/src/org/eclipse/sphinx/tests/emf/integration/scoping/ResourceScopeProviderRegistryTest.java
new file mode 100644
index 0000000..9c90d08
--- /dev/null
+++ b/tests/org.eclipse.sphinx.tests.emf.integration/src/org/eclipse/sphinx/tests/emf/integration/scoping/ResourceScopeProviderRegistryTest.java
@@ -0,0 +1,50 @@
+package org.eclipse.sphinx.tests.emf.integration.scoping;

+

+import java.util.Set;

+

+import org.eclipse.core.resources.IFile;

+import org.eclipse.sphinx.emf.scoping.ResourceScopeProviderRegistry;

+import org.eclipse.sphinx.testutils.integration.referenceworkspace.DefaultIntegrationTestCase;

+import org.eclipse.sphinx.testutils.integration.referenceworkspace.DefaultTestReferenceWorkspace;

+

+public class ResourceScopeProviderRegistryTest extends DefaultIntegrationTestCase {

+

+	public ResourceScopeProviderRegistryTest() {

+		setRecycleReferenceWorkspaceOfPreviousTestRun(false);

+

+		// Set subset of projects to load

+		Set<String> projectsToLoad = getProjectSubsetToLoad();

+		projectsToLoad.add(DefaultTestReferenceWorkspace.HB_PROJECT_NAME_20_F);

+	}

+

+	public void testResourceScopeProviderRegistry_UpperCaseFileExtension() {

+		IFile file20F_1 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_1);

+		assertNotNull(file20F_1);

+		assertEquals("INSTANCEMODEL", file20F_1.getFileExtension()); //$NON-NLS-1$

+		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_1));

+

+		IFile file20F_2 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_2);

+		assertNotNull(file20F_2);

+		assertEquals("TYPEMODEL", file20F_2.getFileExtension()); //$NON-NLS-1$

+		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_2));

+	}

+

+	public void testResourceScopeProviderRegistry_MixedCaseFileExtension() {

+		IFile file20F_3 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_3);

+		assertNotNull(file20F_3);

+		assertEquals("InStAnCeMoDeL", file20F_3.getFileExtension()); //$NON-NLS-1$

+		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_3));

+

+		IFile file20F_4 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_4);

+		assertNotNull(file20F_4);

+		assertEquals("Typemodel", file20F_4.getFileExtension()); //$NON-NLS-1$

+		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_4));

+	}

+

+	public void testResourceScopeProviderRegistry_LowerCaseFileExtension() {

+		IFile file21F_4 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_21_20F_4);

+		assertNotNull(file21F_4);

+		assertEquals("instancemodel", file21F_4.getFileExtension()); //$NON-NLS-1$

+		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file21F_4));

+	}

+}

diff --git a/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/resources/input/referenceWorkspace.zip b/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/resources/input/referenceWorkspace.zip
index e164b6a..c084895 100644
--- a/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/resources/input/referenceWorkspace.zip
+++ b/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/resources/input/referenceWorkspace.zip
Binary files differ
diff --git a/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/src/org/eclipse/sphinx/testutils/integration/referenceworkspace/DefaultTestReferenceWorkspace.java b/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/src/org/eclipse/sphinx/testutils/integration/referenceworkspace/DefaultTestReferenceWorkspace.java
index 8aa9f81..71a4d2d 100644
--- a/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/src/org/eclipse/sphinx/testutils/integration/referenceworkspace/DefaultTestReferenceWorkspace.java
+++ b/tests/org.eclipse.sphinx.testutils.integration.referenceworkspace/src/org/eclipse/sphinx/testutils/integration/referenceworkspace/DefaultTestReferenceWorkspace.java
@@ -139,6 +139,15 @@
 	public static final String UML2_FILE_NAME_20E_2 = "uml2File_20E_2.uml";
 	public static final String UML2_FILE_NAME_20E_3 = "uml2File_20E_3.uml";
 
+	/* ----- HUMMINGBIRD 20 Project A ----- */
+	public static final String HB_PROJECT_NAME_20_F = "hbProject20_F";
+
+	public static final String HB_FILE_NAME_20_20F_1 = "hbFile20_20F_1.INSTANCEMODEL";
+	public static final String HB_FILE_NAME_20_20F_2 = "hbFile20_20F_2.TYPEMODEL";
+	public static final String HB_FILE_NAME_20_20F_3 = "hbFile20_20F_3.InStAnCeMoDeL";
+	public static final String HB_FILE_NAME_20_20F_4 = "hbFile20_20F_4.Typemodel";
+	public static final String HB_FILE_NAME_21_20F_4 = "hbFile21_20F_4.instancemodel";
+
 	/* ----- HUMMINGBIRD 20 Workflows ----- */
 	public static final String HB_PROJECT_NAME_20_WORKFLOWS = "hbProject20.workflows";
 
@@ -154,6 +163,7 @@
 	public IProject hbProject20_C;
 	public IProject hbProject20_D;
 	public IProject hbProject20_E;
+	public IProject hbProject20_F;
 	public IProject hbProject20_Workflows;
 
 	/* ----- EditingDomains ----- */
@@ -193,6 +203,7 @@
 		hbProject20_C = getReferenceProject(HB_PROJECT_NAME_20_C);
 		hbProject20_D = getReferenceProject(HB_PROJECT_NAME_20_D);
 		hbProject20_E = getReferenceProject(HB_PROJECT_NAME_20_E);
+		hbProject20_F = getReferenceProject(HB_PROJECT_NAME_20_F);
 		hbProject20_Workflows = getReferenceProject(HB_PROJECT_NAME_20_WORKFLOWS);
 	}
 
@@ -205,8 +216,8 @@
 	@Override
 	protected void initReferenceFileDescriptors() {
 
-		addFileDescriptors(HB_PROJECT_NAME_10_A, new String[] { HB_FILE_NAME_10_10A_1, HB_FILE_NAME_10_10A_2, HB_FILE_NAME_10_10A_3,
-				HB_FILE_NAME_10_10A_4, HB_FILE_NAME_10_10A_5 }, Hummingbird10MMDescriptor.INSTANCE);
+		addFileDescriptors(HB_PROJECT_NAME_10_A, new String[] { HB_FILE_NAME_10_10A_1, HB_FILE_NAME_10_10A_2, HB_FILE_NAME_10_10A_3, HB_FILE_NAME_10_10A_4, HB_FILE_NAME_10_10A_5 },
+				Hummingbird10MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_10_B, new String[] { HB_FILE_NAME_10_10B_1, HB_FILE_NAME_10_10B_2, HB_FILE_NAME_10_10B_3 },
 				Hummingbird10MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_10_C, new String[] { HB_FILE_NAME_10_10C_1, HB_FILE_NAME_10_10C_2, HB_FILE_NAME_10_10C_3 },
@@ -217,11 +228,13 @@
 				Hummingbird10MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_10_E, new String[] { HB_FILE_NAME_10_10E_1, HB_FILE_NAME_10_10E_2, HB_FILE_NAME_10_10E_3 },
 				Hummingbird10MMDescriptor.INSTANCE);
-		addFileDescriptors(HB_PROJECT_NAME_10_F, new String[] { HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_1,
-				HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_2, HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_3 },
+		addFileDescriptors(
+				HB_PROJECT_NAME_10_F, new String[] { HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_1,
+						HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_2, HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_3 },
 				Hummingbird10MMDescriptor.INSTANCE);
-		addFileDescriptors(HB_PROJECT_NAME_20_A, new String[] { HB_FILE_NAME_20_20A_1, HB_FILE_NAME_20_20A_2, HB_FILE_NAME_20_20A_3,
-				HB_FILE_NAME_20_20A_4, HB_FILE_NAME_21_20A_4 }, Hummingbird20MMDescriptor.INSTANCE);
+		addFileDescriptors(HB_PROJECT_NAME_20_A,
+				new String[] { HB_FILE_NAME_20_20A_1, HB_FILE_NAME_20_20A_2, HB_FILE_NAME_20_20A_3, HB_FILE_NAME_20_20A_4, HB_FILE_NAME_21_20A_4 },
+				Hummingbird20MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_20_B, new String[] { HB_FILE_NAME_20_20B_1, HB_FILE_NAME_20_20B_2, HB_FILE_NAME_20_20B_3 },
 				Hummingbird20MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_20_B, new String[] { UML2_FILE_NAME_20B_1, UML2_FILE_NAME_20B_2, UML2_FILE_NAME_20B_3 },
@@ -238,12 +251,15 @@
 				Hummingbird20MMDescriptor.INSTANCE);
 		addFileDescriptors(HB_PROJECT_NAME_20_E, new String[] { UML2_FILE_NAME_20E_1, UML2_FILE_NAME_20E_2, UML2_FILE_NAME_20E_3 },
 				UML2MMDescriptor.INSTANCE);
+		addFileDescriptors(HB_PROJECT_NAME_20_F,
+				new String[] { HB_FILE_NAME_20_20F_1, HB_FILE_NAME_20_20F_2, HB_FILE_NAME_20_20F_3, HB_FILE_NAME_20_20F_4, HB_FILE_NAME_21_20F_4 },
+				Hummingbird20MMDescriptor.INSTANCE);
 	}
 
 	@Override
 	protected String[] getReferenceProjectsNames() {
 		return new String[] { HB_PROJECT_NAME_10_A, HB_PROJECT_NAME_10_B, HB_PROJECT_NAME_10_C, HB_PROJECT_NAME_10_D, HB_PROJECT_NAME_10_E,
 				HB_PROJECT_NAME_10_F, HB_PROJECT_NAME_20_A, HB_PROJECT_NAME_20_B, HB_PROJECT_NAME_20_C, HB_PROJECT_NAME_20_D, HB_PROJECT_NAME_20_E,
-				HB_PROJECT_NAME_20_WORKFLOWS };
+				HB_PROJECT_NAME_20_F, HB_PROJECT_NAME_20_WORKFLOWS };
 	}
 }
\ No newline at end of file