Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2013-06-19 05:25:49 -0400
committerGerrit Code Review @ Eclipse.org2013-06-20 11:01:07 -0400
commit8d8cc5fad706d4e44d0e5528832655bb83a00837 (patch)
tree8eb3a55957270d4504e8df83ab4977dc8f28146d
parent81c1c4e3f7b24d283c7cfe2fe5a27dfcaf282269 (diff)
downloadorg.eclipse.emf.compare-8d8cc5fad706d4e44d0e5528832655bb83a00837.tar.gz
org.eclipse.emf.compare-8d8cc5fad706d4e44d0e5528832655bb83a00837.tar.xz
org.eclipse.emf.compare-8d8cc5fad706d4e44d0e5528832655bb83a00837.zip
Unit tests for the scope expanding
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java239
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/StorageTypedElement.java79
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/CompareGitTestCase.java72
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/GitTestRepository.java98
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/TestProject.java79
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java207
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/GitLogicalModelTest.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/LogicalModelTest.java)173
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/workspace/TestProject.java153
10 files changed, 728 insertions, 380 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.ide.ui.tests/META-INF/MANIFEST.MF
index dba3dc8b1..49c8c2118 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/META-INF/MANIFEST.MF
@@ -16,5 +16,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.compare.ide.ui;bundle-version="3.0.0",
org.eclipse.emf.compare;bundle-version="3.0.0",
org.eclipse.compare,
- org.eclipse.swt
+ org.eclipse.swt,
+ org.eclipse.emf.compare.ide;bundle-version="3.0.0"
Bundle-Activator: org.eclipse.emf.compare.ide.ui.tests.Activator
+Import-Package: com.google.common.collect;version="[11.0.0,15.0.0)"
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java
new file mode 100644
index 000000000..160c5c159
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (C) 2013 Obeo 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
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests;
+
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterators.filter;
+import static org.eclipse.emf.ecore.util.EcoreUtil.getAllProperContents;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.compare.ide.ui.tests.workspace.TestProject;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.junit.After;
+import org.junit.Before;
+
+@SuppressWarnings("nls")
+public class CompareTestCase {
+ protected static final String PACKAGE_NAME_PREFIX = "package";
+
+ protected static final String CLASS1_NAME_PREFIX = "Class_A";
+
+ protected static final String CLASS2_NAME_PREFIX = "Class_B";
+
+ protected static final String CLASS3_NAME_PREFIX = "Class_C";
+
+ protected static final String CLASS4_NAME_PREFIX = "Class_D";
+
+ protected TestProject project;
+
+ @Before
+ public void setUp() throws Exception {
+ project = new TestProject();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ project.dispose();
+ }
+
+ /**
+ * The base model for both our files will be one package containing two classes. There are no references
+ * and no attributes set, save for the name of these objects.
+ *
+ * @param nameSuffix
+ * Suffix that will be appended to all names for this model.
+ * @return A basic model to be used by these tests.
+ */
+ protected EPackage createBasicModel(String nameSuffix) {
+ EPackage root = createPackage(null, PACKAGE_NAME_PREFIX + nameSuffix);
+ createClass(root, CLASS1_NAME_PREFIX + nameSuffix);
+ createClass(root, CLASS2_NAME_PREFIX + nameSuffix);
+ return root;
+ }
+
+ protected EPackage createPackage(EPackage parent, String name) {
+ final EPackage newPackage = EcoreFactory.eINSTANCE.createEPackage();
+ newPackage.setName(name);
+ if (parent != null) {
+ parent.getESubpackages().add(newPackage);
+ }
+ return newPackage;
+ }
+
+ protected EClass createClass(EPackage parent, String name) {
+ final EClass newClass = EcoreFactory.eINSTANCE.createEClass();
+ newClass.setName(name);
+ if (parent != null) {
+ parent.getEClassifiers().add(newClass);
+ }
+ return newClass;
+ }
+
+ protected EObject findObject(Resource resource, String namePrefix) {
+ Iterator<EObject> children = EcoreUtil.getAllProperContents(resource, false);
+ while (children.hasNext()) {
+ final EObject child = children.next();
+ if (child instanceof ENamedElement && ((ENamedElement)child).getName().startsWith(namePrefix)) {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Connects an EMF resource to the given File within the given project. The resource will be created with
+ * a workspace-relative "{@code platform:/resource}" URI.
+ *
+ * @param file
+ * The file we're attaching an EMF Resource on.
+ * @param resourceSet
+ * The resource set in which the new Resource will be created.
+ * @return The created EMF Resource.
+ */
+ protected Resource connectResource(IFile file, ResourceSet resourceSet) throws CoreException {
+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
+
+ return createResource(uri, resourceSet);
+ }
+
+ private static Resource createResource(URI modelURI, ResourceSet resourceSet) {
+ final Resource resource = new XMIResourceImpl(modelURI) {
+ @Override
+ protected boolean useUUIDs() {
+ return true;
+ }
+ };
+ resourceSet.getResources().add(resource);
+ return resource;
+ }
+
+ /**
+ * This will seek for a random EClass in both given resources, then use the "eSuperTypes" reference of the
+ * source one to create a reference towards the target.
+ *
+ * @param source
+ * Resource within which we'll search for our source EClass (the class which will have a
+ * superType).
+ * @param target
+ * Resource within which we'll search for our target EClass (the superType).
+ */
+ protected void makeCrossReference(Resource source, Resource target) {
+ final Iterator<EClass> sourceChildren = filter(getAllProperContents(source, false), EClass.class);
+ final Iterator<EClass> targetChildren = filter(getAllProperContents(target, false), EClass.class);
+ assertTrue(sourceChildren.hasNext());
+ assertTrue(targetChildren.hasNext());
+ final EClass sourceClass = sourceChildren.next();
+ final EClass targetClass = targetChildren.next();
+
+ sourceClass.getESuperTypes().add(targetClass);
+ }
+
+ /**
+ * This will seek and break all cross-references from <code>source</code> to <code>target</code>.
+ *
+ * @param source
+ * Resource within which we'll search for our cross-references.
+ * @param target
+ * Target of the cross-references to break.
+ */
+ protected void breakCrossReferences(Resource source, Resource target) {
+ final Iterator<EObject> sourceChildren = getAllProperContents(source, false);
+
+ while (sourceChildren.hasNext()) {
+ final EObject child = sourceChildren.next();
+ breakCrossReferences(child, target);
+ }
+ }
+
+ private void breakCrossReferences(EObject source, Resource target) {
+ for (EReference ref : source.eClass().getEAllReferences()) {
+ final Object value = source.eGet(ref);
+ if (!ref.isMany()) {
+ if (value instanceof EObject && ((EObject)value).eResource() == target && !ref.isDerived()) {
+ source.eSet(ref, null);
+ }
+ } else if (value instanceof Collection<?>) {
+ final Collection<?> valueList = (Collection<?>)value;
+ final Iterable<EObject> copy = filter(new ArrayList<Object>(valueList), EObject.class);
+ for (EObject targetEObject : copy) {
+ if (targetEObject.eResource() == target) {
+ valueList.remove(targetEObject);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create a cross-resource reference through the "superType" reference of a given EClass.
+ * <p>
+ * The source EClass will be searched within the {@code source} Resource and its name should have a set
+ * prefix. Similarly, the target EClass will be searched withi the {@code target} Resource.
+ * </p>
+ *
+ * @param source
+ * Resource within which we'll search for our source EClass (the class which will have a
+ * superType).
+ * @param target
+ * Resource within which we'll search for our target EClass (the superType).
+ * @param sourceNamePrefix
+ * Prefix (or exact name) of the source EClass.
+ * @param targetNamePrefix
+ * Prefix (or exact name) of the target EClass.
+ */
+ protected void makeCrossReference(Resource source, Resource target, String sourceNamePrefix,
+ String targetNamePrefix) {
+ final EObject sourceObject = findObject(source, sourceNamePrefix);
+ final EObject targetObject = findObject(target, targetNamePrefix);
+
+ assertTrue(sourceObject instanceof EClass);
+ assertTrue(targetObject instanceof EClass);
+
+ ((EClass)sourceObject).getESuperTypes().add((EClass)targetObject);
+ }
+
+ protected void reload(Resource... resources) throws IOException {
+ for (Resource resource : resources) {
+ resource.getContents().clear();
+ resource.unload();
+ }
+ // separate loop to reload so that we are sure everything has been unloaded
+ for (Resource resource : resources) {
+ resource.load(Collections.emptyMap());
+ }
+ // And a third loop to re-resolve every cross-references between the reloaded resources
+ for (Resource resource : resources) {
+ EcoreUtil.resolveAll(resource);
+ }
+ }
+
+ protected void save(Resource... resources) throws IOException {
+ for (Resource resource : resources) {
+ resource.save(Collections.emptyMap());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/StorageTypedElement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/StorageTypedElement.java
new file mode 100644
index 000000000..bcbf8f227
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/StorageTypedElement.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests;
+
+import java.io.InputStream;
+
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.IEncodedStreamContentAccessor;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.swt.graphics.Image;
+
+/** Mostly copied from org.eclipse.team.internal.ui.StorageTypedElement. */
+public class StorageTypedElement implements ITypedElement, IEncodedStreamContentAccessor, IAdaptable {
+ private final IStorage storage;
+
+ private final String fullPath;
+
+ public StorageTypedElement(IStorage storage, String fullPath) {
+ this.storage = storage;
+ this.fullPath = fullPath;
+ }
+
+ public StorageTypedElement(IFile file) {
+ this(file, file.getFullPath().toString());
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ if (adapter == IStorage.class) {
+ return storage;
+ }
+ return storage.getAdapter(adapter);
+ }
+
+ public String getCharset() throws CoreException {
+ if (storage instanceof IEncodedStreamContentAccessor) {
+ return ((IEncodedStreamContentAccessor)storage).getCharset();
+ }
+ return null;
+ }
+
+ public InputStream getContents() throws CoreException {
+ return storage.getContents();
+ }
+
+ public Image getImage() {
+ return CompareUI.getImage(getType());
+ }
+
+ public String getName() {
+ return fullPath;
+ }
+
+ public String getType() {
+ String name = getName();
+ if (name != null) {
+ int index = name.lastIndexOf('.');
+ if (index == -1) {
+ return ""; //$NON-NLS-1$
+ }
+ if (index == (name.length() - 1)) {
+ return ""; //$NON-NLS-1$
+ }
+ return name.substring(index + 1);
+ }
+ return ITypedElement.FOLDER_TYPE;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/CompareGitTestCase.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/CompareGitTestCase.java
index 8eb77de06..995fc7ca5 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/CompareGitTestCase.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/CompareGitTestCase.java
@@ -9,25 +9,15 @@
package org.eclipse.emf.compare.ide.ui.tests.egit;
import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Iterator;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.GitCorePreferences;
+import org.eclipse.emf.compare.ide.ui.tests.CompareTestCase;
import org.eclipse.emf.compare.ide.ui.tests.egit.fixture.GitTestRepository;
import org.eclipse.emf.compare.ide.ui.tests.egit.fixture.MockSystemReader;
-import org.eclipse.emf.compare.ide.ui.tests.egit.fixture.TestProject;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.ENamedElement;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
@@ -38,9 +28,7 @@ import org.junit.BeforeClass;
/**
* The set up and tear down of this class were mostly copied from org.eclipse.egit.core.test.GitTestCase.
*/
-public class CompareGitTestCase {
- protected TestProject project;
-
+public class CompareGitTestCase extends CompareTestCase {
protected GitTestRepository repository;
// The ".git" folder of the test repository
@@ -54,8 +42,10 @@ public class CompareGitTestCase {
eGitPreferences.putBoolean(GitCorePreferences.core_autoShareProjects, false);
}
+ @Override
@Before
public void setUp() throws Exception {
+ super.setUp();
// ensure there are no shared Repository instances left
// when starting a new test
Activator.getDefault().getRepositoryCache().clear();
@@ -63,70 +53,20 @@ public class CompareGitTestCase {
SystemReader.setInstance(mockSystemReader);
mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace()
.getRoot().getLocation().toFile().getAbsoluteFile().toString());
- project = new TestProject();
gitDir = new File(project.getProject().getWorkspace().getRoot().getRawLocation().toFile(),
Constants.DOT_GIT);
repository = new GitTestRepository(gitDir);
repository.connect(project.getProject());
}
+ @Override
@After
public void tearDown() throws Exception {
+ super.tearDown();
repository.dispose();
- project.dispose();
Activator.getDefault().getRepositoryCache().clear();
if (gitDir.exists()) {
FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
}
-
- protected EPackage createPackage(EPackage parent, String name) {
- final EPackage newPackage = EcoreFactory.eINSTANCE.createEPackage();
- newPackage.setName(name);
- if (parent != null) {
- parent.getESubpackages().add(newPackage);
- }
- return newPackage;
- }
-
- protected EClass createClass(EPackage parent, String name) {
- final EClass newClass = EcoreFactory.eINSTANCE.createEClass();
- newClass.setName(name);
- if (parent != null) {
- parent.getEClassifiers().add(newClass);
- }
- return newClass;
- }
-
- protected EObject findObject(Resource resource, String namePrefix) {
- Iterator<EObject> children = EcoreUtil.getAllProperContents(resource, false);
- while (children.hasNext()) {
- final EObject child = children.next();
- if (child instanceof ENamedElement && ((ENamedElement)child).getName().startsWith(namePrefix)) {
- return child;
- }
- }
- return null;
- }
-
- protected void reload(Resource... resources) throws IOException {
- for (Resource resource : resources) {
- resource.getContents().clear();
- resource.unload();
- }
- // separate loop to reload so that we are sure everything has been unloaded
- for (Resource resource : resources) {
- resource.load(Collections.emptyMap());
- }
- // And a third loop to re-resolve every cross-references between the reloaded resources
- for (Resource resource : resources) {
- EcoreUtil.resolveAll(resource);
- }
- }
-
- protected void save(Resource... resources) throws IOException {
- for (Resource resource : resources) {
- resource.save(Collections.emptyMap());
- }
- }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/GitTestRepository.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/GitTestRepository.java
index f5360f9ca..acb32f05d 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/GitTestRepository.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/GitTestRepository.java
@@ -12,7 +12,6 @@ import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
-import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -33,10 +32,7 @@ import org.eclipse.egit.core.synchronize.GitSubscriberMergeContext;
import org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.compare.ide.ui.tests.workspace.TestProject;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -46,7 +42,6 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.util.FileUtils;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
@@ -86,7 +81,7 @@ public class GitTestRepository {
/**
* Track, add to index and finally commit the given files.
*
- * @param project
+ * @param testProject
* The project within which this file is located.
* @param commitMessage
* Message with which to commit this file.
@@ -94,9 +89,10 @@ public class GitTestRepository {
* The files to add and commit.
* @return The RevCommit corresponding to this operation.
*/
- public RevCommit addAndCommit(IProject project, String commitMessage, File... files) throws Exception {
+ public RevCommit addAndCommit(TestProject testProject, String commitMessage, File... files)
+ throws Exception {
track(files);
- addToIndex(project, files);
+ addToIndex(testProject, files);
return commit(commitMessage);
}
@@ -116,14 +112,14 @@ public class GitTestRepository {
/**
* Adds the given files to the index.
*
- * @param project
+ * @param testProject
* Project that contains these files.
* @param files
* Files to add to the index.
*/
- public void addToIndex(IProject project, File... files) throws Exception {
+ public void addToIndex(TestProject testProject, File... files) throws Exception {
for (File file : files) {
- addToIndex(getIFile(project, file));
+ addToIndex(testProject.getIFile(testProject.getProject(), file));
}
}
@@ -241,73 +237,6 @@ public class GitTestRepository {
return context.getSubscriber();
}
- /**
- * Create or get a file for the given path.
- *
- * @param project
- * Instance of project inside which a file will be created.
- * @param path
- * Project-relative path for the new file.
- * @return Newly created file
- */
- public File getOrCreateFile(IProject project, String path) throws IOException {
- String fullPath = project.getLocation().append(path).toOSString();
- int lastSeparator = fullPath.lastIndexOf(File.separator);
- FileUtils.mkdirs(new File(fullPath.substring(0, lastSeparator)), true);
-
- File file = new File(fullPath);
- if (!file.exists()) {
- FileUtils.createNewFile(file);
- }
-
- return file;
- }
-
- /**
- * Find an IFile corresponding to the given java.io.File within the given project.
- *
- * @param project
- * The project within which we're searching for a file.
- * @param file
- * java.io.File for which we're searching a corresponding eclipse IFile.
- * @return The IFile we found for the given file.
- */
- public IFile getIFile(IProject project, File file) throws CoreException {
- String relativePath = getRepoRelativePath(file.getAbsolutePath());
-
- String quotedProjectName = Pattern.quote(project.getName());
- relativePath = relativePath.replaceFirst(quotedProjectName, "");
-
- IFile iFile = project.getFile(relativePath);
- iFile.refreshLocal(0, new NullProgressMonitor());
-
- return iFile;
- }
-
- /**
- * Connects an EMF resource to the given File within the given project. The resource will be created with
- * a workspace-relative "{@code platform:/resource}" URI.
- *
- * @param project
- * The project within which the given file is located.
- * @param file
- * The file we're attaching an EMF Resource on.
- * @param resourceSet
- * The resource set in which the new Resource will be created.
- * @return The created EMF Resource.
- */
- public Resource connectResource(IProject project, File file, ResourceSet resourceSet)
- throws CoreException {
- String relativePath = getRepoRelativePath(file.getAbsolutePath());
-
- String quotedProjectName = Pattern.quote(project.getName());
- relativePath = relativePath.replaceFirst(".*(" + quotedProjectName + ")", "$1");
-
- URI uri = URI.createPlatformResourceURI(relativePath, true);
-
- return createResource(uri, resourceSet);
- }
-
private String getRepoRelativePath(String path) {
final int pfxLen = workdirPrefix.length();
final int pLen = path.length();
@@ -319,17 +248,6 @@ public class GitTestRepository {
return null;
}
- private static Resource createResource(URI modelURI, ResourceSet resourceSet) {
- final Resource resource = new XMIResourceImpl(modelURI) {
- @Override
- protected boolean useUUIDs() {
- return true;
- }
- };
- resourceSet.getResources().add(resource);
- return resource;
- }
-
/**
* This will query all model providers for those that are enabled on the given file and list all mappings
* available for that file.
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/TestProject.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/TestProject.java
deleted file mode 100644
index 15aa996ed..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/egit/fixture/TestProject.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Obeo 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
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.egit.fixture;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-
-@SuppressWarnings("nls")
-public class TestProject {
- /** The underlying eclipse project. */
- private IProject project;
-
- /**
- * Creates a new project in the workspace with a default name. An existing test project with that name
- * will be deleted and re-created.
- */
- public TestProject() throws CoreException {
- this("Project-1");
- }
-
- /**
- * This will create a new project with the given name inside the workspace. If this project already
- * existed, it will be deleted and re-created.
- *
- * @param name
- * Name of our project.
- */
- public TestProject(String name) throws CoreException {
- final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name);
- project = root.getProject(description.getName());
- if (project.exists()) {
- project.delete(true, true, new NullProgressMonitor());
- }
- project.create(description, new NullProgressMonitor());
- project.open(new NullProgressMonitor());
- }
-
- public IProject getProject() {
- return project;
- }
-
- public IFile createFile(String name, byte[] content) throws Exception {
- IFile file = project.getFile(name);
- InputStream inputStream = new ByteArrayInputStream(content);
- file.create(inputStream, true, new NullProgressMonitor());
-
- return file;
- }
-
- public IFolder createFolder(String name) throws Exception {
- IFolder folder = project.getFolder(name);
- folder.create(true, true, new NullProgressMonitor());
-
- return folder;
- }
-
- public void dispose() throws CoreException, IOException {
- if (project.exists()) {
- project.delete(true, true, new NullProgressMonitor());
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
index 13787a3fa..7fefd68e1 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/AllTests.java
@@ -14,13 +14,13 @@ import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.textui.TestRunner;
-import org.eclipse.emf.compare.ide.ui.tests.unit.LogicalModelTest;
+import org.eclipse.emf.compare.ide.ui.tests.unit.GitLogicalModelTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({LogicalModelTest.class, })
+@SuiteClasses({GitLogicalModelTest.class, })
public class AllTests {
/**
* Launches the test with the given arguments.
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java
new file mode 100644
index 000000000..dee17f54b
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.compare.ide.ui.internal.logical.ProjectModelResolver;
+import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
+import org.eclipse.emf.compare.ide.ui.tests.CompareTestCase;
+import org.eclipse.emf.compare.ide.utils.StorageTraversal;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public class DependenciesTest extends CompareTestCase {
+ private static final String FILE1_SUFFIX = "_file1";
+
+ private static final String FILE2_SUFFIX = "_file2";
+
+ private static final String FILE3_SUFFIX = "_file3";
+
+ private IFile iFile1;
+
+ private IFile iFile2;
+
+ private IFile iFile3;
+
+ private Resource resource1;
+
+ private Resource resource2;
+
+ private Resource resource3;
+
+ private IModelResolver resolver;
+
+ private IProgressMonitor monitor;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ resolver = new ProjectModelResolver();
+ resolver.initialize();
+ monitor = new NullProgressMonitor();
+
+ final IProject iProject = project.getProject();
+ final ResourceSet resourceSet = new ResourceSetImpl();
+
+ final File file1 = project.getOrCreateFile(iProject, "file1.ecore");
+ final File file2 = project.getOrCreateFile(iProject, "file2.ecore");
+ final File file3 = project.getOrCreateFile(iProject, "file3.ecore");
+
+ iFile1 = project.getIFile(iProject, file1);
+ iFile2 = project.getIFile(iProject, file2);
+ iFile3 = project.getIFile(iProject, file3);
+
+ resource1 = connectResource(iFile1, resourceSet);
+ resource2 = connectResource(iFile2, resourceSet);
+ resource3 = connectResource(iFile3, resourceSet);
+
+ resource1.getContents().add(createBasicModel(FILE1_SUFFIX));
+ resource2.getContents().add(createBasicModel(FILE2_SUFFIX));
+ resource3.getContents().add(createBasicModel(FILE3_SUFFIX));
+
+ save(resource1, resource2, resource3);
+ }
+
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ resolver.dispose();
+ super.tearDown();
+ }
+
+ @Test
+ public void testScopeNoDependencies() {
+ StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile1));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile2));
+
+ traversal = resolver.resolveLocalModel(iFile3, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile3));
+ }
+
+ @Test
+ public void testScopeAddedDependency() throws Exception {
+ makeCrossReference(resource2, resource1);
+ save(resource2);
+
+ StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 2);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 2);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+ }
+
+ @Test
+ public void testScopeRemovedDependency() throws Exception {
+ makeCrossReference(resource2, resource1);
+ save(resource2);
+
+ breakCrossReferences(resource2, resource1);
+ save(resource2);
+
+ StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile1));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile2));
+ }
+
+ @Test
+ public void testScopeDepth() throws Exception {
+ makeCrossReference(resource2, resource1);
+ makeCrossReference(resource3, resource2);
+ save(resource2, resource3);
+
+ StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 3);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+ assertTrue(traversal.getStorages().contains(iFile3));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 3);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+ assertTrue(traversal.getStorages().contains(iFile3));
+
+ traversal = resolver.resolveLocalModel(iFile3, monitor);
+ assertEquals(traversal.getStorages().size(), 3);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+ assertTrue(traversal.getStorages().contains(iFile3));
+ }
+
+ @Test
+ public void testScopeUpdate() throws Exception {
+ makeCrossReference(resource2, resource1);
+ makeCrossReference(resource3, resource2);
+ save(resource2, resource3);
+
+ StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 3);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile2));
+ assertTrue(traversal.getStorages().contains(iFile3));
+
+ breakCrossReferences(resource2, resource1);
+ save(resource2);
+
+ traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile1));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 2);
+ assertTrue(traversal.getStorages().contains(iFile2));
+ assertTrue(traversal.getStorages().contains(iFile3));
+
+ breakCrossReferences(resource3, resource2);
+ makeCrossReference(resource3, resource1);
+ save(resource3);
+
+ traversal = resolver.resolveLocalModel(iFile1, monitor);
+ assertEquals(traversal.getStorages().size(), 2);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile3));
+
+ traversal = resolver.resolveLocalModel(iFile2, monitor);
+ assertEquals(traversal.getStorages().size(), 1);
+ assertTrue(traversal.getStorages().contains(iFile2));
+
+ traversal = resolver.resolveLocalModel(iFile3, monitor);
+ assertEquals(traversal.getStorages().size(), 2);
+ assertTrue(traversal.getStorages().contains(iFile1));
+ assertTrue(traversal.getStorages().contains(iFile3));
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/LogicalModelTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/GitLogicalModelTest.java
index f98e99ed2..748a2136a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/LogicalModelTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/GitLogicalModelTest.java
@@ -10,36 +10,29 @@ package org.eclipse.emf.compare.ide.ui.tests.unit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.InputStream;
import java.util.List;
-import org.eclipse.compare.CompareUI;
-import org.eclipse.compare.IEncodedStreamContentAccessor;
-import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
-import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
-import org.eclipse.emf.compare.ide.ui.internal.logical.LogicalModelResolver;
+import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
+import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
+import org.eclipse.emf.compare.ide.ui.internal.logical.LogicalModelResolver;
import org.eclipse.emf.compare.ide.ui.internal.logical.SubscriberStorageAccessor;
-import org.eclipse.emf.compare.ide.ui.logical.IStorageProvider;
-import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
+import org.eclipse.emf.compare.ide.ui.logical.IStorageProvider;
+import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
+import org.eclipse.emf.compare.ide.ui.tests.StorageTypedElement;
import org.eclipse.emf.compare.ide.ui.tests.egit.CompareGitTestCase;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
@@ -47,33 +40,24 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.team.core.subscribers.Subscriber;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("nls")
-public class LogicalModelTest extends CompareGitTestCase {
+public class GitLogicalModelTest extends CompareGitTestCase {
private static final String MASTER = Constants.R_HEADS + Constants.MASTER;
private static final String BRANCH = Constants.R_HEADS + "branch";
- private static final String PACKAGE_NAME_PREFIX = "package";
-
- private static final String CLASS1_NAME_PREFIX = "Class_A";
-
- private static final String CLASS2_NAME_PREFIX = "Class_B";
-
- private static final String CLASS3_NAME_PREFIX = "Class_C";
-
- private static final String CLASS4_NAME_PREFIX = "Class_D";
-
private static final String FILE1_SUFFIX = "_file1";
private static final String FILE2_SUFFIX = "_file2";
private IFile iFile1;
+ private IFile iFile2;
+
private Resource resource1;
private Resource resource2;
@@ -115,12 +99,13 @@ public class LogicalModelTest extends CompareGitTestCase {
final IProject iProject = project.getProject();
final ResourceSet resourceSet = new ResourceSetImpl();
- final File file1 = repository.getOrCreateFile(iProject, "file1.ecore");
- final File file2 = repository.getOrCreateFile(iProject, "file2.ecore");
- iFile1 = repository.getIFile(iProject, file1);
+ final File file1 = project.getOrCreateFile(iProject, "file1.ecore");
+ final File file2 = project.getOrCreateFile(iProject, "file2.ecore");
+ iFile1 = project.getIFile(iProject, file1);
+ iFile2 = project.getIFile(iProject, file2);
- resource1 = repository.connectResource(iProject, file1, resourceSet);
- resource2 = repository.connectResource(iProject, file2, resourceSet);
+ resource1 = connectResource(iFile1, resourceSet);
+ resource2 = connectResource(iFile2, resourceSet);
resource1.getContents().add(createBasicModel(FILE1_SUFFIX));
resource2.getContents().add(createBasicModel(FILE2_SUFFIX));
@@ -129,18 +114,18 @@ public class LogicalModelTest extends CompareGitTestCase {
makeCrossReference(resource2, resource1, CLASS2_NAME_PREFIX, CLASS2_NAME_PREFIX);
save(resource1, resource2);
- commits[0] = repository.addAndCommit(iProject, "master-commit-1", file1, file2);
+ commits[0] = repository.addAndCommit(project, "master-commit-1", file1, file2);
// Second commit: add class in second resource
EPackage packFile2 = (EPackage)findObject(resource2, PACKAGE_NAME_PREFIX);
final EClass newClassFile2 = createClass(packFile2, CLASS3_NAME_PREFIX + FILE2_SUFFIX);
save(resource2);
- commits[1] = repository.addAndCommit(iProject, "master-commit-2", file2);
+ commits[1] = repository.addAndCommit(project, "master-commit-2", file2);
// Third: rename that new class
newClassFile2.setName(CLASS4_NAME_PREFIX + FILE2_SUFFIX);
save(resource2);
- commits[2] = repository.addAndCommit(iProject, "master-commit-3", file2);
+ commits[2] = repository.addAndCommit(project, "master-commit-3", file2);
// Branching point, though stay on master for now
repository.createBranch(MASTER, BRANCH);
@@ -148,7 +133,7 @@ public class LogicalModelTest extends CompareGitTestCase {
// fourth commit: remove the new class
packFile2.getEClassifiers().remove(newClassFile2);
save(resource2);
- commits[3] = repository.addAndCommit(iProject, "master-commit-4", file2);
+ commits[3] = repository.addAndCommit(project, "master-commit-4", file2);
// fifth and last commit on master: rename second class in both files
final EClass classBFile1 = (EClass)findObject(resource1, CLASS2_NAME_PREFIX);
@@ -156,7 +141,7 @@ public class LogicalModelTest extends CompareGitTestCase {
classBFile1.setName(CLASS3_NAME_PREFIX + FILE1_SUFFIX);
classBFile2.setName(CLASS3_NAME_PREFIX + FILE2_SUFFIX);
save(resource1, resource2);
- commits[4] = repository.addAndCommit(iProject, "master-commit-5", file1, file2);
+ commits[4] = repository.addAndCommit(project, "master-commit-5", file1, file2);
// checkout the branch now
repository.checkoutBranch(BRANCH);
@@ -169,13 +154,13 @@ public class LogicalModelTest extends CompareGitTestCase {
classAFile1.setName(CLASS3_NAME_PREFIX + FILE1_SUFFIX);
classAFile2.setName(CLASS3_NAME_PREFIX + FILE2_SUFFIX);
save(resource1, resource2);
- commits[5] = repository.addAndCommit(iProject, "branch-commit-1", file1, file2);
+ commits[5] = repository.addAndCommit(project, "branch-commit-1", file1, file2);
// second commit of the branch : delete the new (third) class
// We've reloaded the resource, our reference to the class must be reinitialized
EcoreUtil.remove(findObject(resource2, CLASS4_NAME_PREFIX));
save(resource2);
- commits[6] = repository.addAndCommit(iProject, "branch-commit-2", file2);
+ commits[6] = repository.addAndCommit(project, "branch-commit-2", file2);
masterTipSynonyms = new String[] {MASTER, commits[4].getName(), };
branchTipSynonyms = new String[] {BRANCH, commits[6].getName(), Constants.HEAD, };
@@ -283,7 +268,7 @@ public class LogicalModelTest extends CompareGitTestCase {
}
private Comparison compare(String sourceRev, String targetRev, IFile file) throws Exception {
- final String fullPath = file.getFullPath().toString();
+ final String fullPath = file.getFullPath().toString();
final Subscriber subscriber = repository.createSubscriberForComparison(sourceRev, targetRev, file);
final IStorageProviderAccessor accessor = new SubscriberStorageAccessor(subscriber);
final IStorageProvider sourceProvider = accessor.getStorageProvider(iFile1,
@@ -297,13 +282,13 @@ public class LogicalModelTest extends CompareGitTestCase {
assertNotNull(ancestorProvider);
final IProgressMonitor monitor = new NullProgressMonitor();
- final IStorageProviderAccessor storageAccessor = new SubscriberStorageAccessor(subscriber);
- final ITypedElement left = new StorageTypedElement(sourceProvider.getStorage(monitor), fullPath);
- final ITypedElement right = new StorageTypedElement(remoteProvider.getStorage(monitor), fullPath);
- final ITypedElement origin = new StorageTypedElement(ancestorProvider.getStorage(monitor), fullPath);
- final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(new LogicalModelResolver(),
- new IdenticalResourceMinimizer(), storageAccessor);
- final IComparisonScope scope = scopeBuilder.build(left, right, origin, monitor);
+ final IStorageProviderAccessor storageAccessor = new SubscriberStorageAccessor(subscriber);
+ final ITypedElement left = new StorageTypedElement(sourceProvider.getStorage(monitor), fullPath);
+ final ITypedElement right = new StorageTypedElement(remoteProvider.getStorage(monitor), fullPath);
+ final ITypedElement origin = new StorageTypedElement(ancestorProvider.getStorage(monitor), fullPath);
+ final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(new LogicalModelResolver(),
+ new IdenticalResourceMinimizer(), storageAccessor);
+ final IComparisonScope scope = scopeBuilder.build(left, right, origin, monitor);
final ResourceSet leftResourceSet = (ResourceSet)scope.getLeft();
final ResourceSet rightResourceSet = (ResourceSet)scope.getRight();
@@ -315,100 +300,4 @@ public class LogicalModelTest extends CompareGitTestCase {
return EMFCompare.builder().build().compare(scope, new BasicMonitor());
}
-
- /**
- * The base model for both our files will be one package containing two classes. There are no references
- * and no attributes set, save for the name of these objects.
- *
- * @param nameSuffix
- * Suffix that will be appended to all names for this model.
- * @return A basic model to be used by these tests.
- */
- private EPackage createBasicModel(String nameSuffix) {
- EPackage root = createPackage(null, PACKAGE_NAME_PREFIX + nameSuffix);
- createClass(root, CLASS1_NAME_PREFIX + nameSuffix);
- createClass(root, CLASS2_NAME_PREFIX + nameSuffix);
- return root;
- }
-
- /**
- * Create a cross-resource reference through the "superType" reference of a given EClass.
- * <p>
- * The source EClass will be searched within the {@code source} Resource and its name should have a set
- * prefix. Similarly, the target EClass will be searched withi the {@code target} Resource.
- * </p>
- *
- * @param source
- * Resource within which we'll search for our source EClass (the class which will have a
- * superType).
- * @param target
- * Resource within which we'll search for our target EClass (the superType).
- * @param sourceNamePrefix
- * Prefix (or exact name) of the source EClass.
- * @param targetNamePrefix
- * Prefix (or exact name) of the target EClass.
- */
- private void makeCrossReference(Resource source, Resource target, String sourceNamePrefix,
- String targetNamePrefix) {
- final EObject sourceObject = findObject(source, sourceNamePrefix);
- final EObject targetObject = findObject(target, targetNamePrefix);
-
- assertTrue(sourceObject instanceof EClass);
- assertTrue(targetObject instanceof EClass);
-
- ((EClass)sourceObject).getESuperTypes().add((EClass)targetObject);
- }
-
- /** Mostly copied from org.eclipse.team.internal.ui.StorageTypedElement. */
- private class StorageTypedElement implements ITypedElement, IEncodedStreamContentAccessor, IAdaptable {
- private final IStorage storage;
-
- private final String fullPath;
-
- public StorageTypedElement(IStorage storage, String fullPath) {
- this.storage = storage;
- this.fullPath = fullPath;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- if (adapter == IStorage.class) {
- return storage;
- }
- return storage.getAdapter(adapter);
- }
-
- public String getCharset() throws CoreException {
- if (storage instanceof IEncodedStreamContentAccessor) {
- return ((IEncodedStreamContentAccessor)storage).getCharset();
- }
- return null;
- }
-
- public InputStream getContents() throws CoreException {
- return storage.getContents();
- }
-
- public Image getImage() {
- return CompareUI.getImage(getType());
- }
-
- public String getName() {
- return fullPath;
- }
-
- public String getType() {
- String name = getName();
- if (name != null) {
- int index = name.lastIndexOf('.');
- if (index == -1) {
- return ""; //$NON-NLS-1$
- }
- if (index == (name.length() - 1)) {
- return ""; //$NON-NLS-1$
- }
- return name.substring(index + 1);
- }
- return ITypedElement.FOLDER_TYPE;
- }
- }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/workspace/TestProject.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/workspace/TestProject.java
new file mode 100644
index 000000000..8e4aa2cf4
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/workspace/TestProject.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (C) 2013 Obeo 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
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.workspace;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+@SuppressWarnings("nls")
+public class TestProject {
+ /** The underlying eclipse project. */
+ private IProject project;
+
+ /**
+ * Creates a new project in the workspace with a default name. An existing test project with that name
+ * will be deleted and re-created.
+ */
+ public TestProject() throws CoreException {
+ this("Project-1");
+ }
+
+ /**
+ * This will create a new project with the given name inside the workspace. If this project already
+ * existed, it will be deleted and re-created.
+ *
+ * @param name
+ * Name of our project.
+ */
+ public TestProject(String name) throws CoreException {
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name);
+ project = root.getProject(description.getName());
+ if (project.exists()) {
+ project.delete(true, true, new NullProgressMonitor());
+ }
+ project.create(description, new NullProgressMonitor());
+ project.open(new NullProgressMonitor());
+ }
+
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * Create or get a file for the given path.
+ *
+ * @param project
+ * Instance of project inside which a file will be created.
+ * @param path
+ * Project-relative path for the new file.
+ * @return Newly created file
+ */
+ public File getOrCreateFile(IProject aProject, String path) throws IOException {
+ String fullPath = aProject.getLocation().append(path).toOSString();
+ int lastSeparator = fullPath.lastIndexOf(File.separator);
+ mkdirs(new File(fullPath.substring(0, lastSeparator)), true);
+
+ File file = new File(fullPath);
+ if (!file.exists()) {
+ createNewFile(file);
+ }
+
+ return file;
+ }
+
+ /**
+ * Find an IFile corresponding to the given java.io.File within the given project.
+ *
+ * @param aProject
+ * The project within which we're searching for a file.
+ * @param file
+ * java.io.File for which we're searching a corresponding eclipse IFile.
+ * @return The IFile we found for the given file.
+ */
+ public IFile getIFile(IProject aProject, File file) throws CoreException {
+ IPath filePath = new Path(file.getAbsolutePath());
+ String relativePath = filePath.makeRelativeTo(aProject.getLocation()).toString();
+
+ String quotedProjectName = Pattern.quote(aProject.getName());
+ relativePath = relativePath.replaceFirst(quotedProjectName, "");
+
+ IFile iFile = aProject.getFile(relativePath);
+ iFile.refreshLocal(0, new NullProgressMonitor());
+
+ return iFile;
+ }
+
+ /**
+ * Creates the directory named by this abstract pathname, including any necessary but nonexistent parent
+ * directories. Note that if this operation fails it may have succeeded in creating some of the necessary
+ * parent directories.
+ *
+ * @param d
+ * directory to be created
+ * @param skipExisting
+ * if {@code true} skip creation of the given directory if it already exists in the file system
+ * @throws IOException
+ * if creation of {@code d} fails. This may occur if {@code d} did exist when the method was
+ * called. This can therefore cause IOExceptions during race conditions when multiple
+ * concurrent threads all try to create the same directory.
+ */
+ private static void mkdirs(final File d, boolean skipExisting) throws IOException {
+ if (!d.mkdirs()) {
+ if (skipExisting && d.isDirectory()) {
+ return;
+ }
+ }
+ }
+
+ private static void createNewFile(File f) throws IOException {
+ f.createNewFile();
+ }
+
+ public IFile createFile(String name, byte[] content) throws Exception {
+ IFile file = project.getFile(name);
+ InputStream inputStream = new ByteArrayInputStream(content);
+ file.create(inputStream, true, new NullProgressMonitor());
+
+ return file;
+ }
+
+ public IFolder createFolder(String name) throws Exception {
+ IFolder folder = project.getFolder(name);
+ folder.create(true, true, new NullProgressMonitor());
+
+ return folder;
+ }
+
+ public void dispose() throws CoreException, IOException {
+ if (project.exists()) {
+ project.delete(true, true, new NullProgressMonitor());
+ }
+ }
+}

Back to the top