Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Cartaud2016-06-13 16:07:41 +0000
committerMathieu Cartaud2016-07-01 14:16:29 +0000
commit889b193baf3276837ca1865930ad28586f3ffa96 (patch)
treeafacdc46db11519891aad0e4a9b84359c85c1aa3
parenta69e93cc3f989615c512a12e5a4e62ec5ff95bc8 (diff)
downloadorg.eclipse.emf.compare-889b193baf3276837ca1865930ad28586f3ffa96.tar.gz
org.eclipse.emf.compare-889b193baf3276837ca1865930ad28586f3ffa96.tar.xz
org.eclipse.emf.compare-889b193baf3276837ca1865930ad28586f3ffa96.zip
Add rebase and cherry-pick operations in test framework
Change-Id: Id7a471eb74d1a0f774953e663e542901002f29cb Signed-off-by: Mathieu Cartaud <mathieu.cartaud@obeo.fr>
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/.settings/org.eclipse.jdt.ui.prefs2
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/conflicts/MoveOfDiagramConflictDetectionTest.java4
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/egit/IgnoreDiFileChangesInGitMergeTest.java4
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/ResourceAttachmentChangeMoveNoConflictTests.java327
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/data/resourceAttachmentChangeMoveNoConflict.zipbin0 -> 19618 bytes
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/annotations/Compare.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/MergeStrategyID.java)4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestRunner.java8
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestSupport.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestSupport.java)279
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCherryPick.java62
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCompare.java10
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java8
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMergeStrategy.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/MergeStrategy.java)6
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitRebase.java62
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitTest.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestCaseJUnitBlock.java23
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/MergeStatement.java)40
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitStatement.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/AbstractGitStatement.java)23
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCherryPickStatement.java51
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCompareStatement.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitCompareStatement.java)11
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java50
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitRebaseStatement.java51
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitTestStatement.java (renamed from plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestStatement.java)8
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/InternalGitTestSupport.java224
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/DirCacheResourceVariantTreeProviderTest.java6
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/RenamedControlledResourceTests.java14
27 files changed, 775 insertions, 509 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/.settings/org.eclipse.jdt.ui.prefs
index 76077fa2a..de1c79644 100644
--- a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/.settings/org.eclipse.jdt.ui.prefs
@@ -18,7 +18,7 @@ sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
-sp_cleanup.format_source_code=false
+sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
diff --git a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/conflicts/MoveOfDiagramConflictDetectionTest.java b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/conflicts/MoveOfDiagramConflictDetectionTest.java
index 584ef6101..1f2e26523 100644
--- a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/conflicts/MoveOfDiagramConflictDetectionTest.java
+++ b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/conflicts/MoveOfDiagramConflictDetectionTest.java
@@ -37,7 +37,7 @@ import org.junit.runner.RunWith;
@ResolutionStrategies(ResolutionStrategyID.WORKSPACE)
public class MoveOfDiagramConflictDetectionTest {
- @GitCompare(localBranch = "branch1", remoteBranch = "branch2", fileToCompare = "model.uml")
+ @GitCompare(local = "branch1", remote = "branch2", file = "model.uml")
@GitInput("/data/case001.zip")
public void pseudoConflictsOnResourceRootTest(Comparison comparison) throws Exception {
assertEquals(16, comparison.getDifferences().size());
@@ -48,7 +48,7 @@ public class MoveOfDiagramConflictDetectionTest {
}
}
- @GitCompare(localBranch = "branch1", remoteBranch = "branch2", fileToCompare = "model.uml")
+ @GitCompare(local = "branch1", remote = "branch2", file = "model.uml")
@GitInput("/data/case002.zip")
public void conflictsOnResourceRootTest(Comparison comparison) throws Exception {
assertEquals(4, comparison.getDifferences().size());
diff --git a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/egit/IgnoreDiFileChangesInGitMergeTest.java b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/egit/IgnoreDiFileChangesInGitMergeTest.java
index 4a625bb32..d31efc376 100644
--- a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/egit/IgnoreDiFileChangesInGitMergeTest.java
+++ b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/egit/IgnoreDiFileChangesInGitMergeTest.java
@@ -16,9 +16,9 @@ import static org.junit.Assert.assertTrue;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ResolutionStrategies;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestRunner;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitInput;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSupport;
import org.junit.runner.RunWith;
/**
@@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
@ResolutionStrategies(ResolutionStrategyID.WORKSPACE)
public class IgnoreDiFileChangesInGitMergeTest {
- @GitMerge(localBranch = "branch1", remoteBranch = "branch2")
+ @GitMerge(local = "branch1", remote = "branch2")
@GitInput("data/ignore-di-file-changes.zip")
public void testIgnoredDiFileChangesAfterGitMerge(GitTestSupport testSupport) throws Exception {
assertTrue(testSupport.noConflict());
diff --git a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/ResourceAttachmentChangeMoveNoConflictTests.java b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/ResourceAttachmentChangeMoveNoConflictTests.java
index beb8061a3..180b92c21 100644
--- a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/ResourceAttachmentChangeMoveNoConflictTests.java
+++ b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/ResourceAttachmentChangeMoveNoConflictTests.java
@@ -14,218 +14,109 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.size;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.util.List;
-import org.eclipse.compare.ITypedElement;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.mapping.ModelProvider;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-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.common.util.BasicMonitor;
+import org.eclipse.core.resources.IResource;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.EMFCompare.Builder;
import org.eclipse.emf.compare.ResourceAttachmentChange;
-import org.eclipse.emf.compare.diagram.internal.extensions.DiagramChange;
-import org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository;
-import org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.MockSystemReader;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
-import org.eclipse.emf.compare.ide.ui.internal.logical.EMFModelProvider;
-import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
-import org.eclipse.emf.compare.ide.ui.internal.logical.StorageTypedElement;
-import org.eclipse.emf.compare.ide.ui.internal.logical.SubscriberStorageAccessor;
-import org.eclipse.emf.compare.ide.ui.internal.logical.resolver.CrossReferenceResolutionScope;
-import org.eclipse.emf.compare.ide.ui.internal.logical.resolver.ThreadedModelResolver;
-import org.eclipse.emf.compare.ide.ui.internal.preferences.EMFCompareUIPreferences;
-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.CompareTestCase;
-import org.eclipse.emf.compare.ide.ui.tests.workspace.TestProject;
-import org.eclipse.emf.compare.rcp.internal.extension.impl.EMFCompareBuilderConfigurator;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.compare.utils.EMFComparePredicates;
-import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ResolutionStrategies;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestRunner;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCherryPick;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCompare;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitInput;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitRebase;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Shape;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jgit.api.ResetCommand.ResetType;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.util.FileUtils;
-import org.eclipse.jgit.util.SystemReader;
-import org.eclipse.team.core.subscribers.Subscriber;
-import org.eclipse.uml2.uml.Class;
+import org.eclipse.jgit.api.Status;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageableElement;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
+import org.junit.runner.RunWith;
/**
* Tests for ResourceAttachmentChange with MOVE kind.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
*/
-@SuppressWarnings({"restriction", "nls", "unused" })
-public class ResourceAttachmentChangeMoveNoConflictTests extends AbstractResourceAttachmentChangeMoveTests {
-
- /**
- * Path to the test data.
- */
- private static String TEST_DATA_PATH = "src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/data/";
-
- private ResourceSetImpl resourceSet;
-
- private IProject iProject;
-
- private TestProject testProject1;
-
- private IFile modelDi;
-
- private IFile modelNotation;
-
- private IFile modelUml;
-
- private IFile fragmentDi;
-
- private IFile fragmentNotation;
-
- private IFile fragmentUml;
+@SuppressWarnings({"nls", })
+@RunWith(GitTestRunner.class)
+@ResolutionStrategies(ResolutionStrategyID.WORKSPACE)
+public class ResourceAttachmentChangeMoveNoConflictTests {
/**
* BRANCH_3 checkouted. Comparison with BRANCH_2 (the move). Comparison: No conflicts. Some differences,
* with just 1 {@link ResourceAttachmentChange} of kind MOVE.
*/
- @Test
- public void testComparisonMoveRemote() throws Exception {
- setUpRepositoryCase001();
- // Check comparison model : no conflicts and 1 RAC Move
- repository.checkoutBranch(BRANCH_3);
- Comparison comparison = compare(BRANCH_3, BRANCH_2, modelNotation);
+ @GitCompare(local = "branch3", remote = "branch2", file = "model.notation")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testComparisonMoveRemote(Comparison comparison) throws Exception {
assertTrue(comparison.getConflicts().isEmpty());
assertEquals(1, size(filter(comparison.getDifferences(),
and(instanceOf(ResourceAttachmentChange.class), ofKind(DifferenceKind.MOVE)))));
- testProject1.dispose();
}
/**
* BRANCH_2 checkouted (the move). Comparison with BRANCH_3. Comparison: No conflicts. Some differences,
* with just 1 {@link ResourceAttachmentChange} of kind MOVE.
*/
- @Test
- public void testComparisonMoveLocal() throws Exception {
- setUpRepositoryCase001();
- // Check comparison model : no conflicts and 1 RAC Move
- repository.checkoutBranch(BRANCH_2);
- Comparison comparison = compare(BRANCH_2, BRANCH_3, modelNotation);
+ @GitCompare(local = "branch2", remote = "branch3", file = "model.notation")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testComparisonMoveLocal(Comparison comparison) throws Exception {
assertTrue(comparison.getConflicts().isEmpty());
assertEquals(1, size(filter(comparison.getDifferences(),
and(instanceOf(ResourceAttachmentChange.class), ofKind(DifferenceKind.MOVE)))));
- testProject1.dispose();
}
/**
* BRANCH_3 checkouted. Merge with BRANCH_2 (the move). Merge: No conflicts. The fragmented model and new
* diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be there.
*/
- @Test
- public void testMergeMoveRemote() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_3, ResetType.HARD);
-
- repository.mergeLogicalWithNewCommit(BRANCH_2);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitMerge(local = "branch3", remote = "branch2")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testMergeMoveRemote(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
/**
* BRANCH_2 checkouted (the move). Merge with BRANCH_3. Merge: No conflicts. The fragmented model and new
* diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be there.
*/
- @Test
- public void testMergeMoveLocal() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_2, ResetType.HARD);
-
- repository.mergeLogicalWithNewCommit(BRANCH_3);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitMerge(local = "branch2", remote = "branch3")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testMergeMoveLocal(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
/**
* BRANCH_3 checkouted. Merge with BRANCH_2 (the move). Rebase: No conflicts. The fragmented model and new
* diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be there.
*/
- @Test
- public void testRebaseMoveRemote() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_3, ResetType.HARD);
-
- repository.rebaseLogical(BRANCH_2);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitRebase(local = "branch3", remote = "branch2")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testRebaseMoveRemote(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
/**
* BRANCH_2 checkouted (the move). Merge with BRANCH_3. Rebase: No conflicts. The fragmented model and new
* diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be there.
*/
- @Test
- public void testRebaseMoveLocal() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_2, ResetType.HARD);
-
- repository.rebaseLogical(BRANCH_3);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitRebase(local = "branch2", remote = "branch3")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testRebaseMoveLocal(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
/**
@@ -233,17 +124,10 @@ public class ResourceAttachmentChangeMoveNoConflictTests extends AbstractResourc
* new diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be
* there.
*/
- @Test
- public void testCherryPickMoveRemote() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_3, ResetType.HARD);
-
- repository.cherryPickLogical(BRANCH_2);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitCherryPick(local = "branch3", remote = "branch2")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testCherryPickMoveRemote(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
/**
@@ -251,98 +135,55 @@ public class ResourceAttachmentChangeMoveNoConflictTests extends AbstractResourc
* new diagram from 2nd commit have to be in the repository. The changes from the 3rd commit have to be
* there.
*/
- @Test
- public void testCherryPickMoveLocal() throws Exception {
- setUpRepositoryCase001();
- repository.checkoutBranch(MASTER);
- repository.reset(BRANCH_2, ResetType.HARD);
-
- repository.cherryPickLogical(BRANCH_3);
-
- checkContentsCase001();
-
- testProject1.dispose();
+ @GitCherryPick(local = "branch2", remote = "branch3")
+ @GitInput("data/resourceAttachmentChangeMoveNoConflict.zip")
+ public void testCherryPickMoveLocal(Status status, List<IProject> projects) throws Exception {
+ checkContentsCase001(status, projects);
}
- /**
- * Case 001. 3 commits. 1st commit: a model with 2 packages. 1 class diagram associated to the model, and
- * 1 class diagram associated to the 2nd package. 2nd commit: the 2nd package is fragmented. The class
- * diagram associated is moved in a new resource (notation model). 3rd commit: reset to the 1st commit.
- * Add a class under the 2nd package. Also add in the diagram.
- */
- private void setUpRepositoryCase001() throws Exception {
- resourceSet = new ResourceSetImpl();
- File workingDirectory = repository.getRepository().getWorkTree();
- testProject1 = new TestProject("Project1", workingDirectory.getAbsolutePath());
- iProject = testProject1.getProject();
- repository.connect(iProject);
-
- // 1st commit: a model with 2 packages.
- // 1 class diagram associated to the model, and 1 class diagram associated to the 2nd package.
- modelDi = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit1/model.di", "");
- modelNotation = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit1/model.notation",
- "");
- modelUml = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit1/model.uml", "");
-
- repository.addAllAndCommit("1st-commit");
- repository.createBranch(MASTER, BRANCH_1);
-
- // 2nd commit: the 2nd package is fragmented.
- // The class diagram associated is moved in a new resource (notation model).
- modelDi = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit2/model.di", "");
- modelNotation = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit2/model.notation",
- "");
- modelUml = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit2/model.uml", "");
- fragmentDi = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit2/fragment.di", "");
- fragmentNotation = addToProject(TEST_DATA_PATH, testProject1, iProject,
- "case001/commit2/fragment.notation", "");
- fragmentUml = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit2/fragment.uml",
- "");
- repository.addAllAndCommit("2nd-commit");
- repository.createBranch(MASTER, BRANCH_2);
-
- // Back to 1st commit
- repository.reset(BRANCH_1, ResetType.HARD);
-
- // 3rd commit: reset to the 1st commit.
- // Add a class under the 2nd package. Also add in the diagram.
- modelDi = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit3/model.di", "");
- modelNotation = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit3/model.notation",
- "");
- modelUml = addToProject(TEST_DATA_PATH, testProject1, iProject, "case001/commit3/model.uml", "");
- repository.addAllAndCommit("3rd-commit");
- repository.createBranch(MASTER, BRANCH_3);
-
- repository.checkoutBranch(MASTER);
- }
-
- private void checkContentsCase001() throws Exception {
+ private void checkContentsCase001(Status status, List<IProject> projects) throws Exception {
// No conflicts
- assertTrue(repository.status().getConflicting().isEmpty());
+ assertTrue(status.getConflicting().isEmpty());
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Resource resourceModelDi = null;
+ Resource resourceModelUml = null;
+ Resource resourceModelNotation = null;
+ Resource resourceFragmentDi = null;
+ Resource resourceFragmentUml = null;
+ Resource resourceFragmentNotation = null;
// The project1 is accessible.
+ IProject iProject = projects.get(0);
assertTrue(iProject.isAccessible());
// After the merge, the repository should contain the new files from 2nd commit.
- assertTrue(modelDi.exists());
- assertTrue(modelNotation.exists());
- assertTrue(modelUml.exists());
- assertTrue(fragmentDi.exists());
- assertTrue(fragmentNotation.exists());
- assertTrue(fragmentUml.exists());
-
- // Check resources contents
- Resource resourceFragmentUml = resourceSet
- .getResource(URI.createPlatformResourceURI(fragmentUml.getFullPath().toString(), true), true);
- Resource resourceFragmentNotation = resourceSet.getResource(
- URI.createPlatformResourceURI(fragmentNotation.getFullPath().toString(), true), true);
- Resource resourceFragmentDi = resourceSet
- .getResource(URI.createPlatformResourceURI(fragmentDi.getFullPath().toString(), true), true);
- Resource resourceModelUml = resourceSet
- .getResource(URI.createPlatformResourceURI(modelUml.getFullPath().toString(), true), true);
- Resource resourceModelNotation = resourceSet.getResource(
- URI.createPlatformResourceURI(modelNotation.getFullPath().toString(), true), true);
- Resource resourceModelDi = resourceSet
- .getResource(URI.createPlatformResourceURI(modelDi.getFullPath().toString(), true), true);
+ for (IResource res : iProject.members()) {
+ if (res.getName().equals("model.di")) {
+ resourceModelDi = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ } else if (res.getName().equals("model.uml")) {
+ resourceModelUml = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ } else if (res.getName().equals("model.notation")) {
+ resourceModelNotation = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ } else if (res.getName().equals("fragment.di")) {
+ resourceFragmentDi = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ } else if (res.getName().equals("fragment.uml")) {
+ resourceFragmentUml = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ } else if (res.getName().equals("fragment.notation")) {
+ resourceFragmentNotation = resourceSet
+ .getResource(URI.createPlatformResourceURI(res.getFullPath().toString(), true), true);
+ }
+ }
+ assertNotNull(resourceModelDi);
+ assertNotNull(resourceModelUml);
+ assertNotNull(resourceModelNotation);
+ assertNotNull(resourceFragmentDi);
+ assertNotNull(resourceFragmentUml);
+ assertNotNull(resourceFragmentNotation);
// ClassDiagramP2 should be in fragment.notation
assertEquals(1, resourceFragmentNotation.getContents().size());
diff --git a/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/data/resourceAttachmentChangeMoveNoConflict.zip b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/data/resourceAttachmentChangeMoveNoConflict.zip
new file mode 100644
index 000000000..2b798482a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.diagram.papyrus.tests.git/src/org/eclipse/emf/compare/diagram/papyrus/tests/resourceattachmentchange/move/data/resourceAttachmentChangeMoveNoConflict.zip
Binary files differ
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/annotations/Compare.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/annotations/Compare.java
index 6eec9d369..99ed26189 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/annotations/Compare.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/annotations/Compare.java
@@ -52,6 +52,8 @@ public @interface Compare {
/**
* Classes of resource set hooks to consider during resource loading.
+ *
+ * @return the value or an empty Array if not used
*/
Class<?>[] resourceSetHooks() default {};
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/META-INF/MANIFEST.MF
index 738173e09..92a597cab 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/META-INF/MANIFEST.MF
@@ -26,5 +26,6 @@ Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Export-Package: org.eclipse.emf.compare.ide.ui.tests.git.framework,
org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations,
- org.eclipse.emf.compare.ide.ui.tests.git.framework.internal
+ org.eclipse.emf.compare.ide.ui.tests.git.framework.internal,
+ org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements
Import-Package: com.google.common.collect;version="[11.0.0,16.0.0)"
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/MergeStrategyID.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.java
index 830fc3016..fd9193351 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/MergeStrategyID.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.java
@@ -15,7 +15,7 @@ package org.eclipse.emf.compare.ide.ui.tests.git.framework;
*
* @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
*/
-public enum MergeStrategyID {
+public enum GitMergeStrategyID {
JGIT_DEFAULT("jgit-default-mergeStrategy"), //$NON-NLS-1$
@@ -25,7 +25,7 @@ public enum MergeStrategyID {
private String value;
- private MergeStrategyID(String value) {
+ private GitMergeStrategyID(String value) {
this.value = value;
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestRunner.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestRunner.java
index 7d1b88969..b26e10dce 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestRunner.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestRunner.java
@@ -13,7 +13,7 @@ package org.eclipse.emf.compare.ide.ui.tests.git.framework;
import org.eclipse.emf.compare.ide.ui.tests.framework.AbstractCompareTestRunner;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.MergeStrategy;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMergeStrategy;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestCaseJUnitBlock;
import org.junit.runners.model.InitializationError;
@@ -25,7 +25,7 @@ import org.junit.runners.model.InitializationError;
public class GitTestRunner extends AbstractCompareTestRunner {
/** Default merge strategy if the @MergeStrategy annotation is not used. */
- private static MergeStrategyID defaultMergeStrategy = MergeStrategyID.MODEL_RECURSIVE;
+ private static GitMergeStrategyID defaultMergeStrategy = GitMergeStrategyID.MODEL_RECURSIVE;
/**
* Constructor.
@@ -41,8 +41,8 @@ public class GitTestRunner extends AbstractCompareTestRunner {
@Override
public void createRunner(Class<?> testClass, ResolutionStrategyID resolutionStrategy,
EMFCompareTestConfiguration configuration) throws InitializationError {
- MergeStrategy mStrategy = getTestClass().getAnnotation(MergeStrategy.class);
- final MergeStrategyID mergeStrategy;
+ GitMergeStrategy mStrategy = getTestClass().getAnnotation(GitMergeStrategy.class);
+ final GitMergeStrategyID mergeStrategy;
if (mStrategy == null) {
mergeStrategy = defaultMergeStrategy;
} else {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestSupport.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestSupport.java
index 052943327..2fd84e47f 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestSupport.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitTestSupport.java
@@ -9,49 +9,37 @@
* Obeo - initial API and implementation
* Philip Langer - add convenience methods
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;
+package org.eclipse.emf.compare.ide.ui.tests.git.framework;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import com.google.common.collect.Lists;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.internal.util.ResourceUtil;
import org.eclipse.egit.core.op.BranchOperation;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
-import org.eclipse.egit.core.op.DisconnectProviderOperation;
+import org.eclipse.egit.core.op.CherryPickOperation;
import org.eclipse.egit.core.op.MergeOperation;
+import org.eclipse.egit.core.op.RebaseOperation;
import org.eclipse.egit.core.op.ResetOperation;
import org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber;
import org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext;
@@ -69,198 +57,38 @@ import org.eclipse.emf.compare.ide.ui.internal.logical.SubscriberStorageAccessor
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
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.git.framework.internal.statements.InternalGitTestSupport;
import org.eclipse.emf.compare.rcp.internal.extension.impl.EMFCompareBuilderConfigurator;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jgit.api.CheckoutResult;
+import org.eclipse.jgit.api.CherryPickResult;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.api.RebaseResult;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
-import org.eclipse.ui.dialogs.IOverwriteQuery;
-import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
-import org.eclipse.ui.wizards.datatransfer.ImportOperation;
/**
- * This class contains methods to compare a file between two branchs in an existing git repository.
+ * This class contains methods to perform git operations in the context of an EMFCompare test. This class may
+ * be injected in client.
*
* @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
*/
@SuppressWarnings({"restriction" })
-public class GitTestSupport {
-
- /**
- * Size of the buffer to read/write data
- */
- private static final int BUFFER_SIZE = 4096;
-
- private final static String GIT_BRANCH_PREFIX = "refs/heads/"; //$NON-NLS-1$
+public class GitTestSupport extends InternalGitTestSupport {
public final static String COMPARE_NO_PROJECT_SELECTED = "noProject"; //$NON-NLS-1$
- private Repository repository = null;
-
- private IProject[] projects = null;
-
- private ArrayList<Runnable> disposers = null;
-
private MergeResult mergeResult;
- private IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
- public String queryOverwrite(String file) {
- return ALL;
- }
- };
-
- protected void createRepositoryFromPath(Class<?> clazz, String path)
- throws IOException, InvocationTargetException, InterruptedException, CoreException {
- final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- // Delete all projects that can remain in the workspace : prevent errors dues to wrong cleanup of
- // other tests
- root.delete(true, new NullProgressMonitor());
- IPath location = root.getLocation();
- extractArchive(clazz, path, root);
- importProjects(new File(location.toString()));
- connectRepository(new File(location.toString()));
- projects = root.getProjects();
- for (IProject project : projects) {
- connect(project);
- }
- }
-
- private void connectRepository(File file) throws IOException {
- File gitDir = findGitDir(file);
- this.repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir);
- this.disposers = new ArrayList<Runnable>();
- }
-
- /**
- * Connect a project to this repository.
- *
- * @param project
- * The project to connect
- */
- private void connect(IProject project) throws CoreException, InterruptedException {
- ConnectProviderOperation op = new ConnectProviderOperation(project, repository.getDirectory());
- op.execute(null);
- }
+ private RebaseResult rebaseResult;
- private File findGitDir(File file) {
- for (File child : file.listFiles()) {
- if (child.isDirectory() && child.getName().equals(".git")) { //$NON-NLS-1$
- return child;
- } else if (child.isDirectory()) {
- File findGitDir = findGitDir(child);
- if (findGitDir != null) {
- return findGitDir;
- }
- }
- }
- return null;
- }
-
- private void importProjects(File file)
- throws InvocationTargetException, InterruptedException, CoreException {
- for (File child : file.listFiles()) {
- if (child.isDirectory() && !child.getName().equals(".metadata") //$NON-NLS-1$
- && !child.getName().equals(".git")) { //$NON-NLS-1$
- importProjects(child);
- } else if (child.getName().equals(".project")) { //$NON-NLS-1$
- importProject(child);
- }
- }
- }
-
- private void importProject(File file)
- throws InvocationTargetException, InterruptedException, CoreException {
- IProjectDescription description = ResourcesPlugin.getWorkspace()
- .loadProjectDescription(new Path(file.getAbsolutePath()));
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
- project.create(description, new NullProgressMonitor());
- project.open(new NullProgressMonitor());
-
- ImportOperation importOperation = new ImportOperation(project.getFullPath(), file.getParentFile(),
- FileSystemStructureProvider.INSTANCE, overwriteQuery);
- importOperation.setCreateContainerStructure(false);
- importOperation.run(new NullProgressMonitor());
- }
-
- private void extractArchive(Class<?> clazz, String path, IWorkspaceRoot root) throws IOException {
- InputStream resourceAsStream = clazz.getResourceAsStream(path);
- ZipInputStream zipIn = new ZipInputStream(resourceAsStream);
- ZipEntry entry = null;
- while ((entry = zipIn.getNextEntry()) != null) {
- String filePath = root.getLocation() + File.separator + entry.getName();
- if (!entry.isDirectory()) {
- extractFile(zipIn, filePath);
- } else {
- File dir = new File(filePath);
- dir.mkdir();
- }
- zipIn.closeEntry();
- }
- zipIn.close();
- }
-
- private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
- byte[] bytesIn = new byte[BUFFER_SIZE];
- int read = 0;
- while ((read = zipIn.read(bytesIn)) != -1) {
- bos.write(bytesIn, 0, read);
- }
- bos.close();
- }
-
- protected void setup() throws CoreException, IOException {
- final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- IProject[] unknownProjects = workspaceRoot.getProjects();
- if (unknownProjects != null && unknownProjects.length > 0) {
- for (IProject iProject : unknownProjects) {
- iProject.delete(true, new NullProgressMonitor());
- }
- }
- Activator.getDefault().getRepositoryCache().clear();
-
- File file = new File(workspaceRoot.getLocation().toOSString());
- for (File child : file.listFiles()) {
- if (!child.getName().equals(".metadata")) { //$NON-NLS-1$
- FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY);
- }
- }
- }
-
- protected void tearDown() throws CoreException, IOException {
- if (repository != null) {
- repository.close();
- repository = null;
- }
- if (disposers != null) {
- for (Runnable disposer : disposers) {
- disposer.run();
- }
- disposers.clear();
- }
-
- Activator.getDefault().getRepositoryCache().clear();
-
- if (projects != null) {
- new DisconnectProviderOperation(Arrays.asList(projects)).execute(null);
- for (IProject iProject : projects) {
- iProject.delete(true, new NullProgressMonitor());
- }
- }
-
- File file = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
- for (File child : file.listFiles()) {
- if (!child.getName().equals(".metadata")) { //$NON-NLS-1$
- FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY);
- }
- }
- }
+ private CherryPickResult cherryPickResult;
public Repository getRepository() {
return repository;
@@ -286,20 +114,30 @@ public class GitTestSupport {
return mergeResult;
}
+ public RebaseResult getRebaseResult() {
+ return rebaseResult;
+ }
+
+ public CherryPickResult getCherryPickResult() {
+ return cherryPickResult;
+ }
+
/**
* Merge two branches with the given merge strategy.
*
- * @param from
+ * @param local
* The checkouted branch (for example "master" or "refs/for/master", both syntaxes are
* accepted)
- * @param to
+ * @param remote
* The branch to merge with (for example "master" or "refs/for/master", both syntaxes are
* accepted)
* @throws CoreException
+ * @throws IOException
+ * @throws InterruptedException
*/
- public void merge(String from, String to) throws CoreException, IOException, InterruptedException {
- checkoutBranch(normalizeBranch(from));
- MergeOperation op = new MergeOperation(repository, normalizeBranch(to));
+ public void merge(String local, String remote) throws CoreException, IOException, InterruptedException {
+ checkoutBranch(normalizeBranch(local));
+ MergeOperation op = new MergeOperation(repository, normalizeBranch(remote));
op.execute(new NullProgressMonitor());
mergeResult = op.getResult();
for (IProject iProject : projects) {
@@ -308,6 +146,59 @@ public class GitTestSupport {
}
/**
+ * Cherry-pick the commit located on the given "from" branch to the given "to" branch.
+ *
+ * @param local
+ * The branch on with the commit will be cherry-picked (for example "master" or
+ * "refs/for/master", both syntaxes are accepted)
+ * @param remote
+ * The branch where the commit will be cherry-picked (for example "master" or
+ * "refs/for/master", both syntaxes are accepted)
+ * @throws CoreException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public void cherryPick(String local, String remote)
+ throws CoreException, IOException, InterruptedException {
+ checkoutBranch(normalizeBranch(local));
+ RevWalk revWalk = new RevWalk(repository);
+ try {
+ RevCommit commitId = revWalk.parseCommit(repository.findRef(remote).getObjectId());
+ CherryPickOperation op = new CherryPickOperation(repository, commitId);
+ op.execute(new NullProgressMonitor());
+ cherryPickResult = op.getResult();
+ for (IProject iProject : projects) {
+ iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ } finally {
+ revWalk.close();
+ }
+ }
+
+ /**
+ * Rebase the given from branch on the to branch.
+ *
+ * @param local
+ * The checkouted branch (for example "master" or "refs/for/master", both syntaxes are
+ * accepted)
+ * @param remote
+ * The branch to rebase on (for example "master" or "refs/for/master", both syntaxes are
+ * accepted)
+ * @throws CoreException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public void rebase(String local, String remote) throws CoreException, IOException, InterruptedException {
+ checkoutBranch(normalizeBranch(local));
+ RebaseOperation op = new RebaseOperation(repository, repository.findRef(remote));
+ op.execute(new NullProgressMonitor());
+ rebaseResult = op.getResult();
+ for (IProject iProject : projects) {
+ iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ }
+
+ /**
* <pre>
* Compare the file on the given path between the two given branches. This method is attended to be used
* when their is only one project in the repository.
@@ -492,14 +383,6 @@ public class GitTestSupport {
}
}
- protected static String normalizeBranch(String branch) {
- if (branch.startsWith(GIT_BRANCH_PREFIX)) {
- return branch;
- } else {
- return GIT_BRANCH_PREFIX + branch;
- }
- }
-
/**
* Specifies whether the repository is in conflict state or not.
* <p>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCherryPick.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCherryPick.java
new file mode 100644
index 000000000..b7eb81567
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCherryPick.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.jgit.api.CherryPickResult;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.lib.Repository;
+
+/**
+ * Annotation used to test the cherry-pick of models.
+ * <p>
+ * The test method may take the following arguments in an arbitrary order. Note that you also may only accept
+ * a subset of these in the signature of the test method:
+ * </p>
+ * <ul>
+ * <li>{@link Status}</li>
+ * <li>{@link Repository}</li>
+ * <li>List<{@link IProject}></li>
+ * <li>{@link CherryPickResult}</li>
+ * <li>{@link GitTestSupport}</li>
+ * </ul>
+ *
+ * <pre>
+ * For instance, the signature of the test method may be:
+ * public void doTest({@link Status} status, {@link Repository} repository,
+ * List<{@link IProject}> projects) {}
+ *
+ * If you want to be able to perform extra manipulation on the repository in your
+ * test case (merge, checkout, comparison), you can take the {@link GitTestSupport}
+ * as a parameter:
+ * public void doTest({@link Status} status, {@link Repository} repository,
+ * List<{@link IProject}> projects, {@link GitTestSupport} support) {}
+ * </pre>
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface GitCherryPick {
+
+ /** The name of the local branch. */
+ String local();
+
+ /** The name of the remote branch. */
+ String remote();
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCompare.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCompare.java
index b8dc29213..7307c7dd6 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCompare.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitCompare.java
@@ -16,7 +16,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
/**
* Annotation used to launch a comparison on a git repository.
@@ -37,14 +37,16 @@ import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSuppor
@Target(ElementType.METHOD)
public @interface GitCompare {
- String localBranch();
+ /** The name of the local branch. */
+ String local();
- String remoteBranch();
+ /** The name of the remote branch. */
+ String remote();
/**
* The path of the file to compare. The path must be project relative
*/
- String fileToCompare();
+ String file();
/**
* This value is optional. If not used, the runner will assume that only one project is contained in the
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java
index 7c8a7926c..9401bdf3e 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java
@@ -17,7 +17,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
@@ -54,8 +54,10 @@ import org.eclipse.jgit.lib.Repository;
@Target(ElementType.METHOD)
public @interface GitMerge {
- String localBranch();
+ /** The name of the local branch. */
+ String local();
- String remoteBranch();
+ /** The name of the remote branch. */
+ String remote();
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/MergeStrategy.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMergeStrategy.java
index 6320bb9e1..292341d22 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/MergeStrategy.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMergeStrategy.java
@@ -15,7 +15,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.MergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
/**
* Annotation used to select the merge strategy used for the test class.
@@ -24,13 +24,13 @@ import org.eclipse.emf.compare.ide.ui.tests.git.framework.MergeStrategyID;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface MergeStrategy {
+public @interface GitMergeStrategy {
/**
* The merge strategy used for all tests in the class. If the annotation is used empty, the default value
* will be returned. If the annotation is not used the merge strategy defined in the class
* EMFCompareGitTestRunner will be used.
*/
- MergeStrategyID value() default MergeStrategyID.MODEL_RECURSIVE;
+ GitMergeStrategyID value() default GitMergeStrategyID.MODEL_RECURSIVE;
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitRebase.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitRebase.java
new file mode 100644
index 000000000..8ca4b3e72
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitRebase.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.jgit.api.RebaseResult;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.lib.Repository;
+
+/**
+ * Annotation used to test the rebase of models.
+ * <p>
+ * The test method may take the following arguments in an arbitrary order. Note that you also may only accept
+ * a subset of these in the signature of the test method:
+ * </p>
+ * <ul>
+ * <li>{@link Status}</li>
+ * <li>{@link Repository}</li>
+ * <li>List<{@link IProject}></li>
+ * <li>{@link RebaseResult}</li>
+ * <li>{@link GitTestSupport}</li>
+ * </ul>
+ *
+ * <pre>
+ * For instance, the signature of the test method may be:
+ * public void doTest({@link Status} status, {@link Repository} repository,
+ * List<{@link IProject}> projects) {}
+ *
+ * If you want to be able to perform extra manipulation on the repository in your
+ * test case (merge, checkout, comparison), you can take the {@link GitTestSupport}
+ * as a parameter:
+ * public void doTest({@link Status} status, {@link Repository} repository,
+ * List<{@link IProject}> projects, {@link GitTestSupport} support) {}
+ * </pre>
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface GitRebase {
+
+ /** The name of the local branch. */
+ String local();
+
+ /** The name of the remote branch. */
+ String remote();
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitTest.java
index 75311cec7..7f860bb48 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitTest.java
@@ -16,7 +16,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestCaseJUnitBlock.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestCaseJUnitBlock.java
index a0543e80d..5bb49294f 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestCaseJUnitBlock.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestCaseJUnitBlock.java
@@ -17,11 +17,18 @@ import java.util.List;
import org.eclipse.emf.compare.ide.ui.tests.framework.AbstractCompareTestCaseJUnitBlock;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.MergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCherryPick;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCompare;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitInput;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitRebase;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitTest;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitCherryPickStatement;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitCompareStatement;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitMergeStatement;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitRebaseStatement;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitTestStatement;
import org.junit.Assert;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
@@ -32,10 +39,10 @@ import org.junit.runners.model.Statement;
*/
public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock {
- private MergeStrategyID mergeStrategy;
+ private GitMergeStrategyID mergeStrategy;
public GitTestCaseJUnitBlock(Class<?> klass, ResolutionStrategyID resolutionStrategy,
- EMFCompareTestConfiguration configuration, MergeStrategyID mergeStrategy)
+ EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy)
throws InitializationError {
super(klass, resolutionStrategy, configuration);
this.mergeStrategy = mergeStrategy;
@@ -51,6 +58,8 @@ public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock {
final List<FrameworkMethod> allMethods = Lists
.newArrayList(getTestClass().getAnnotatedMethods(GitCompare.class));
allMethods.addAll(getTestClass().getAnnotatedMethods(GitMerge.class));
+ allMethods.addAll(getTestClass().getAnnotatedMethods(GitCherryPick.class));
+ allMethods.addAll(getTestClass().getAnnotatedMethods(GitRebase.class));
allMethods.addAll(getTestClass().getAnnotatedMethods(GitTest.class));
return allMethods;
}
@@ -77,7 +86,13 @@ public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock {
result = new GitCompareStatement(testObject, method, resolutionStrategy, configuration,
input.value());
} else if (method.getAnnotation(GitMerge.class) != null) {
- result = new MergeStatement(testObject, method, resolutionStrategy, configuration,
+ result = new GitMergeStatement(testObject, method, resolutionStrategy, configuration,
+ mergeStrategy, input.value());
+ } else if (method.getAnnotation(GitCherryPick.class) != null) {
+ result = new GitCherryPickStatement(testObject, method, resolutionStrategy, configuration,
+ mergeStrategy, input.value());
+ } else if (method.getAnnotation(GitRebase.class) != null) {
+ result = new GitRebaseStatement(testObject, method, resolutionStrategy, configuration,
mergeStrategy, input.value());
} else if (method.getAnnotation(GitTest.class) != null) {
result = new GitTestStatement(testObject, method, resolutionStrategy, configuration,
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/MergeStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java
index 77fa18570..b655f395e 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/MergeStatement.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java
@@ -9,36 +9,37 @@
* Obeo - initial API and implementation
* Philip Langer - support more flexible parameters of test methods
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
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.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.MergeStrategyID;
-import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.junit.runners.model.FrameworkMethod;
/**
- * This class handle all merge tests.
+ * This class handle all test related to git operations (merge, rebase, cherry-pick).
*
* @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
*/
@SuppressWarnings("restriction")
-public class MergeStatement extends AbstractGitStatement {
+public abstract class AbstractGitOperationStatement extends AbstractGitStatement {
- private final MergeStrategyID mergeStrategy;
+ private final GitMergeStrategyID mergeStrategy;
private final IEclipsePreferences eGitPreferences;
- private final String path;
+ protected final String path;
- private String defaultMergeStrategy = MergeStrategyID.MODEL_RECURSIVE.getValue();
+ private String defaultMergeStrategy = GitMergeStrategyID.MODEL_RECURSIVE.getValue();
- public MergeStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy,
- EMFCompareTestConfiguration configuration, MergeStrategyID mergeStrategy, String path) {
+ public AbstractGitOperationStatement(Object testObject, FrameworkMethod test,
+ ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration,
+ GitMergeStrategyID mergeStrategy, String path) {
super(testObject, test, resolutionStrategy, configuration);
this.mergeStrategy = mergeStrategy;
this.eGitPreferences = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
@@ -48,17 +49,15 @@ public class MergeStatement extends AbstractGitStatement {
@Override
public void evaluate() throws Throwable {
setEMFComparePreferences();
- GitMerge merge = test.getAnnotation(GitMerge.class);
- String localBranch = GitTestSupport.normalizeBranch(merge.localBranch());
- String remoteBranch = GitTestSupport.normalizeBranch(merge.remoteBranch());
+ String from = InternalGitTestSupport.normalizeBranch(getCheckoutedBranch());
+ String to = InternalGitTestSupport.normalizeBranch(getOtherBranch());
GitTestSupport gitTestsSupport = new GitTestSupport();
try {
gitTestsSupport.setup();
gitTestsSupport.createRepositoryFromPath(test.getMethod().getDeclaringClass(), path);
- gitTestsSupport.merge(localBranch, remoteBranch);
- Class<?>[] paramTypes = test.getMethod().getParameterTypes();
- Object[] parameters = createParameters(paramTypes, gitTestsSupport);
+ callGitOperation(gitTestsSupport, from, to);
+ Object[] parameters = createParameters(test.getMethod(), gitTestsSupport);
test.invokeExplosively(testObject, parameters);
} finally {
restoreEMFComparePreferences();
@@ -66,6 +65,13 @@ public class MergeStatement extends AbstractGitStatement {
}
}
+ protected abstract String getCheckoutedBranch();
+
+ protected abstract String getOtherBranch();
+
+ protected abstract void callGitOperation(GitTestSupport gitTestsSupport, String from, String to)
+ throws Throwable;
+
@Override
protected void setEMFComparePreferences() {
super.setEMFComparePreferences();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/AbstractGitStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitStatement.java
index 701aea1f2..5504c6637 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/AbstractGitStatement.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitStatement.java
@@ -9,18 +9,25 @@
* Obeo - initial API and implementation
* Philip Langer - support more flexible parameters of test methods
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.compare.ide.ui.tests.framework.AbstractCompareStatement;
-import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCherryPick;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitRebase;
+import org.eclipse.jgit.api.CherryPickResult;
import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.api.RebaseResult;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
import org.junit.runners.model.FrameworkMethod;
@@ -32,14 +39,20 @@ public abstract class AbstractGitStatement extends AbstractCompareStatement {
super(testObject, test, resolutionStrategy, configuration);
}
- protected Object[] createParameters(Class<?>[] paramTypes, GitTestSupport gitTestsSupport)
- throws Throwable {
+ protected Object[] createParameters(Method method, GitTestSupport gitTestsSupport) throws Throwable {
final Builder<Object> builder = ImmutableList.builder();
+ Class<?>[] paramTypes = method.getParameterTypes();
for (Class<?> paramType : paramTypes) {
if (paramType.equals(GitTestSupport.class)) {
builder.add(gitTestsSupport);
- } else if (paramType.equals(MergeResult.class)) {
+ } else if (paramType.equals(MergeResult.class) && method.getAnnotation(GitMerge.class) != null) {
builder.add(gitTestsSupport.getMergeResult());
+ } else if (paramType.equals(RebaseResult.class)
+ && method.getAnnotation(GitRebase.class) != null) {
+ builder.add(gitTestsSupport.getRebaseResult());
+ } else if (paramType.equals(CherryPickResult.class)
+ && method.getAnnotation(GitCherryPick.class) != null) {
+ builder.add(gitTestsSupport.getCherryPickResult());
} else if (isCollectionCompatible(paramType)) {
builder.add(gitTestsSupport.getProjects());
} else if (paramType.equals(Repository.class)) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCherryPickStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCherryPickStatement.java
new file mode 100644
index 000000000..051a61742
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCherryPickStatement.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
+
+import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCherryPick;
+import org.junit.runners.model.FrameworkMethod;
+
+/**
+ * This class handle all test related to cherry-pick operations.
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+public class GitCherryPickStatement extends AbstractGitOperationStatement {
+
+ public GitCherryPickStatement(Object testObject, FrameworkMethod test,
+ ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration,
+ GitMergeStrategyID mergeStrategy, String path) {
+ super(testObject, test, resolutionStrategy, configuration, mergeStrategy, path);
+ }
+
+ @Override
+ protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch)
+ throws Throwable {
+ gitTestsSupport.cherryPick(localBranch, remoteBranch);
+ }
+
+ @Override
+ protected String getCheckoutedBranch() {
+ GitCherryPick cherryPick = test.getAnnotation(GitCherryPick.class);
+ return cherryPick.local();
+ }
+
+ @Override
+ protected String getOtherBranch() {
+ GitCherryPick cherryPick = test.getAnnotation(GitCherryPick.class);
+ return cherryPick.remote();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitCompareStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCompareStatement.java
index 47ba05862..ddd08bac6 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitCompareStatement.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitCompareStatement.java
@@ -9,11 +9,12 @@
* Obeo - initial API and implementation
* Philip Langer - support more flexible parameters of test methods
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCompare;
import org.junit.runners.model.FrameworkMethod;
@@ -36,9 +37,9 @@ public class GitCompareStatement extends AbstractGitStatement {
public void evaluate() throws Throwable {
setEMFComparePreferences();
GitCompare compare = test.getAnnotation(GitCompare.class);
- String localBranch = GitTestSupport.normalizeBranch(compare.localBranch());
- String remoteBranch = GitTestSupport.normalizeBranch(compare.remoteBranch());
- String fileToCompare = normalizePath(compare.fileToCompare());
+ String localBranch = InternalGitTestSupport.normalizeBranch(compare.local());
+ String remoteBranch = InternalGitTestSupport.normalizeBranch(compare.remote());
+ String fileToCompare = normalizePath(compare.file());
String containerProject = compare.containerProject();
GitTestSupport gitTestsSupport = new GitTestSupport();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java
new file mode 100644
index 000000000..78de6c9dc
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
+
+import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
+import org.junit.runners.model.FrameworkMethod;
+
+/**
+ * This class handle all test related to merge operations.
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+public class GitMergeStatement extends AbstractGitOperationStatement {
+
+ public GitMergeStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy,
+ EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy, String path) {
+ super(testObject, test, resolutionStrategy, configuration, mergeStrategy, path);
+ }
+
+ @Override
+ protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch)
+ throws Throwable {
+ gitTestsSupport.merge(localBranch, remoteBranch);
+ }
+
+ @Override
+ protected String getCheckoutedBranch() {
+ GitMerge merge = test.getAnnotation(GitMerge.class);
+ return merge.local();
+ }
+
+ @Override
+ protected String getOtherBranch() {
+ GitMerge merge = test.getAnnotation(GitMerge.class);
+ return merge.remote();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitRebaseStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitRebaseStatement.java
new file mode 100644
index 000000000..a7bc5124c
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitRebaseStatement.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
+
+import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitRebase;
+import org.junit.runners.model.FrameworkMethod;
+
+/**
+ * This class handle all test related to rebase operations.
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+public class GitRebaseStatement extends AbstractGitOperationStatement {
+
+ public GitRebaseStatement(Object testObject, FrameworkMethod test,
+ ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration,
+ GitMergeStrategyID mergeStrategy, String path) {
+ super(testObject, test, resolutionStrategy, configuration, mergeStrategy, path);
+ }
+
+ @Override
+ protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch)
+ throws Throwable {
+ gitTestsSupport.rebase(localBranch, remoteBranch);
+ }
+
+ @Override
+ protected String getCheckoutedBranch() {
+ GitRebase rebase = test.getAnnotation(GitRebase.class);
+ return rebase.local();
+ }
+
+ @Override
+ protected String getOtherBranch() {
+ GitRebase rebase = test.getAnnotation(GitRebase.class);
+ return rebase.remote();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitTestStatement.java
index 198666e63..b73668be2 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/GitTestStatement.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitTestStatement.java
@@ -9,10 +9,11 @@
* Obeo - initial API and implementation
* Philip Langer - support more flexible parameters of test methods
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
-import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
+import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
+import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport;
import org.junit.runners.model.FrameworkMethod;
/**
@@ -38,8 +39,7 @@ public class GitTestStatement extends AbstractGitStatement {
try {
gitTestsSupport.setup();
gitTestsSupport.createRepositoryFromPath(test.getMethod().getDeclaringClass(), path);
- Class<?>[] paramTypes = test.getMethod().getParameterTypes();
- Object[] parameters = createParameters(paramTypes, gitTestsSupport);
+ Object[] parameters = createParameters(test.getMethod(), gitTestsSupport);
test.invokeExplosively(testObject, parameters);
} finally {
restoreEMFComparePreferences();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/InternalGitTestSupport.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/InternalGitTestSupport.java
new file mode 100644
index 000000000..4c0392178
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/InternalGitTestSupport.java
@@ -0,0 +1,224 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+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;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.core.op.DisconnectProviderOperation;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+
+/**
+ * This class contains utility methods to perform git tests. Those methods are internal and are not intended
+ * to be used by clients.
+ *
+ * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
+ */
+@SuppressWarnings({"restriction" })
+public class InternalGitTestSupport {
+
+ private final static String GIT_BRANCH_PREFIX = "refs/heads/"; //$NON-NLS-1$
+
+ /**
+ * Size of the buffer to read/write data
+ */
+ private static final int BUFFER_SIZE = 4096;
+
+ protected Repository repository = null;
+
+ protected IProject[] projects = null;
+
+ protected ArrayList<Runnable> disposers = null;
+
+ private IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
+ public String queryOverwrite(String file) {
+ return ALL;
+ }
+ };
+
+ protected static String normalizeBranch(String branch) {
+ if (branch.startsWith(GIT_BRANCH_PREFIX)) {
+ return branch;
+ } else {
+ return GIT_BRANCH_PREFIX + branch;
+ }
+ }
+
+ protected void createRepositoryFromPath(Class<?> clazz, String path)
+ throws IOException, InvocationTargetException, InterruptedException, CoreException {
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ // Delete all projects that can remain in the workspace : prevent errors dues to wrong cleanup of
+ // other tests
+ root.delete(true, new NullProgressMonitor());
+ IPath location = root.getLocation();
+ extractArchive(clazz, path, root);
+ importProjects(new File(location.toString()));
+ connectRepository(new File(location.toString()));
+ projects = root.getProjects();
+ for (IProject project : projects) {
+ connect(project);
+ }
+ }
+
+ /**
+ * Connect a project to this repository.
+ *
+ * @param project
+ * The project to connect
+ */
+ private void connect(IProject project) throws CoreException, InterruptedException {
+ ConnectProviderOperation op = new ConnectProviderOperation(project, repository.getDirectory());
+ op.execute(null);
+ }
+
+ private void connectRepository(File file) throws IOException {
+ File gitDir = findGitDir(file);
+ this.repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir);
+ this.disposers = new ArrayList<Runnable>();
+ }
+
+ private File findGitDir(File file) {
+ for (File child : file.listFiles()) {
+ if (child.isDirectory() && child.getName().equals(".git")) { //$NON-NLS-1$
+ return child;
+ } else if (child.isDirectory()) {
+ File findGitDir = findGitDir(child);
+ if (findGitDir != null) {
+ return findGitDir;
+ }
+ }
+ }
+ return null;
+ }
+
+ private void importProjects(File file)
+ throws InvocationTargetException, InterruptedException, CoreException {
+ for (File child : file.listFiles()) {
+ if (child.isDirectory() && !child.getName().equals(".metadata") //$NON-NLS-1$
+ && !child.getName().equals(".git")) { //$NON-NLS-1$
+ importProjects(child);
+ } else if (child.getName().equals(".project")) { //$NON-NLS-1$
+ importProject(child);
+ }
+ }
+ }
+
+ private void importProject(File file)
+ throws InvocationTargetException, InterruptedException, CoreException {
+ IProjectDescription description = ResourcesPlugin.getWorkspace()
+ .loadProjectDescription(new Path(file.getAbsolutePath()));
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
+ project.create(description, new NullProgressMonitor());
+ project.open(new NullProgressMonitor());
+
+ ImportOperation importOperation = new ImportOperation(project.getFullPath(), file.getParentFile(),
+ FileSystemStructureProvider.INSTANCE, overwriteQuery);
+ importOperation.setCreateContainerStructure(false);
+ importOperation.run(new NullProgressMonitor());
+ }
+
+ private void extractArchive(Class<?> clazz, String path, IWorkspaceRoot root) throws IOException {
+ InputStream resourceAsStream = clazz.getResourceAsStream(path);
+ ZipInputStream zipIn = new ZipInputStream(resourceAsStream);
+ ZipEntry entry = null;
+ while ((entry = zipIn.getNextEntry()) != null) {
+ String filePath = root.getLocation() + File.separator + entry.getName();
+ if (!entry.isDirectory()) {
+ extractFile(zipIn, filePath);
+ } else {
+ File dir = new File(filePath);
+ dir.mkdir();
+ }
+ zipIn.closeEntry();
+ }
+ zipIn.close();
+ }
+
+ private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
+ byte[] bytesIn = new byte[BUFFER_SIZE];
+ int read = 0;
+ while ((read = zipIn.read(bytesIn)) != -1) {
+ bos.write(bytesIn, 0, read);
+ }
+ bos.close();
+ }
+
+ protected void setup() throws CoreException, IOException {
+ final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject[] unknownProjects = workspaceRoot.getProjects();
+ if (unknownProjects != null && unknownProjects.length > 0) {
+ for (IProject iProject : unknownProjects) {
+ iProject.delete(true, new NullProgressMonitor());
+ }
+ }
+ Activator.getDefault().getRepositoryCache().clear();
+
+ File file = new File(workspaceRoot.getLocation().toOSString());
+ for (File child : file.listFiles()) {
+ if (!child.getName().equals(".metadata")) { //$NON-NLS-1$
+ FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ }
+ }
+
+ protected void tearDown() throws CoreException, IOException {
+ if (repository != null) {
+ repository.close();
+ repository = null;
+ }
+ if (disposers != null) {
+ for (Runnable disposer : disposers) {
+ disposer.run();
+ }
+ disposers.clear();
+ }
+
+ Activator.getDefault().getRepositoryCache().clear();
+
+ if (projects != null) {
+ new DisconnectProviderOperation(Arrays.asList(projects)).execute(null);
+ for (IProject iProject : projects) {
+ iProject.delete(true, new NullProgressMonitor());
+ }
+ }
+
+ File file = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
+ for (File child : file.listFiles()) {
+ if (!child.getName().equals(".metadata")) { //$NON-NLS-1$
+ FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/DirCacheResourceVariantTreeProviderTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/DirCacheResourceVariantTreeProviderTest.java
index 8a2bed4dd..452a4a240 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/DirCacheResourceVariantTreeProviderTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/DirCacheResourceVariantTreeProviderTest.java
@@ -60,7 +60,7 @@ public class DirCacheResourceVariantTreeProviderTest {
assertTrue(treeProvider.getRemoteTree().hasResourceVariant(iFile1));
}
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/dirCacheResourceVariantTreeProvider/dirCacheTreesNoConflict.zip")
public void testDirCacheTreesNoConflict(Status status, Repository repository, List<IProject> projects)
throws Exception {
@@ -83,7 +83,7 @@ public class DirCacheResourceVariantTreeProviderTest {
assertTrue(treeProvider.getRemoteTree().hasResourceVariant(iFile2));
}
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/dirCacheResourceVariantTreeProvider/dirCacheTreesConflictOnOne.zip")
public void testDirCacheTreesConflictOnOne(Status status, Repository repository, List<IProject> projects)
throws Exception {
@@ -108,7 +108,7 @@ public class DirCacheResourceVariantTreeProviderTest {
assertTrue(treeProvider.getRemoteTree().hasResourceVariant(iFile2));
}
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/dirCacheResourceVariantTreeProvider/dirCacheTreesConflict.zip")
public void testDirCacheTreesConflict(Status status, Repository repository, List<IProject> projects)
throws Exception {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/RenamedControlledResourceTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/RenamedControlledResourceTests.java
index b0b3694a2..ca373f841 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/RenamedControlledResourceTests.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/RenamedControlledResourceTests.java
@@ -50,7 +50,7 @@ import org.junit.runner.RunWith;
@RunWith(GitTestRunner.class)
public class RenamedControlledResourceTests {
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/renamedControlledResources/renameNoConflicts.zip")
public void testMergeNoConflictRemoteRename(Status status, Repository repository, List<IProject> projects)
throws Exception {
@@ -78,7 +78,7 @@ public class RenamedControlledResourceTests {
assertEquals("C1", testC1.getName());
}
- @GitMerge(localBranch = "branch", remoteBranch = "master")
+ @GitMerge(local = "branch", remote = "master")
@GitInput("data/renamedControlledResources/renameNoConflicts.zip")
public void testMergeNoConflictLocalRename(Status status, Repository repository, List<IProject> projects)
throws Exception {
@@ -106,7 +106,7 @@ public class RenamedControlledResourceTests {
assertEquals("C1", testC1.getName());
}
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/renamedControlledResources/renameNoConflictsLocalChanges.zip")
public void testMergeNoConflictRemoteRenameLocalChanges(Status status, Repository repository,
List<IProject> projects) throws Exception {
@@ -135,7 +135,7 @@ public class RenamedControlledResourceTests {
assertEquals("NewClassInRemotelyRenamedPackage", testNewClass.getName());
}
- @GitCompare(localBranch = "master", remoteBranch = "branch", fileToCompare = "file1.ecore")
+ @GitCompare(local = "master", remote = "branch", file = "file1.ecore")
@GitInput("data/renamedControlledResources/renameNoConflicts.zip")
public void testComparisonNoConflictRemoteRename(Comparison comparison) throws Exception {
assertTrue(comparison.getConflicts().isEmpty());
@@ -151,7 +151,7 @@ public class RenamedControlledResourceTests {
and(instanceOf(ResourceAttachmentChange.class), ofKind(DifferenceKind.MOVE)))));
}
- @GitCompare(localBranch = "branch", remoteBranch = "master", fileToCompare = "file1.ecore")
+ @GitCompare(local = "branch", remote = "master", file = "file1.ecore")
@GitInput("data/renamedControlledResources/renameNoConflicts.zip")
public void testComparisonNoConflictLocalRename(Comparison comparison) throws Exception {
assertTrue(comparison.getConflicts().isEmpty());
@@ -167,7 +167,7 @@ public class RenamedControlledResourceTests {
and(instanceOf(ResourceAttachmentChange.class), ofKind(DifferenceKind.MOVE)))));
}
- @GitMerge(localBranch = "master", remoteBranch = "branch")
+ @GitMerge(local = "master", remote = "branch")
@GitInput("data/renamedControlledResources/renameConflicts.zip")
public void testMergeConflict(Status status, Repository repository, List<IProject> projects)
throws Exception {
@@ -184,7 +184,7 @@ public class RenamedControlledResourceTests {
assertTrue(iProject.getFile("file2_other.ecore").exists());
}
- @GitCompare(localBranch = "master", remoteBranch = "branch", fileToCompare = "file1.ecore")
+ @GitCompare(local = "master", remote = "branch", file = "file1.ecore")
@GitInput("data/renamedControlledResources/renameConflicts.zip")
public void testComparisonConflict(Comparison comparison) throws Exception {
assertEquals(1, comparison.getConflicts().size());

Back to the top