diff options
author | Mathieu Cartaud | 2016-07-01 14:59:57 +0000 |
---|---|---|
committer | Mathieu Cartaud | 2016-09-13 09:14:48 +0000 |
commit | 763123a51d6610d979bce46993b2c6e559c15308 (patch) | |
tree | 54eb05aa2c98fc87f4a9a92df75261c067b8b572 | |
parent | d27ccfd2eeab02689be473aa36bd507238f5e6cd (diff) | |
download | org.eclipse.emf.compare-763123a51d6610d979bce46993b2c6e559c15308.tar.gz org.eclipse.emf.compare-763123a51d6610d979bce46993b2c6e559c15308.tar.xz org.eclipse.emf.compare-763123a51d6610d979bce46993b2c6e559c15308.zip |
Activate checkstyle for Git test framework
Change-Id: I88b0dabfa99c2edb95fad0adb4cc6ca7b6eb9745
Signed-off-by: Mathieu Cartaud <mathieu.cartaud@obeo.fr>
20 files changed, 489 insertions, 44 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java index fed080673..005ba218c 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java @@ -130,20 +130,20 @@ public abstract class AbstractCompareStatement extends Statement { * The test method * @param resolutionStrategy * The resolution strategy used for this test - * @param selectedEngines - * EMFComapre configurations for this test + * @param configuration + * EMFCompare configurations for this test */ public AbstractCompareStatement(Object testObject, FrameworkMethod test, - ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration selectedEngines) { + ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration) { this.testObject = testObject; this.test = test; this.resolutionStrategy = resolutionStrategy; - this.disabledMatchEngines = selectedEngines.getDisabledMatchEngines(); - this.diffEngine = selectedEngines.getDiffEngine(); - this.eqEngine = selectedEngines.getEqEngine(); - this.reqEngine = selectedEngines.getReqEngine(); - this.conflictDetector = selectedEngines.getConflictDetector(); - this.disabledPostProcessors = selectedEngines.getDisabledPostProcessors(); + this.disabledMatchEngines = configuration.getDisabledMatchEngines(); + this.diffEngine = configuration.getDiffEngine(); + this.eqEngine = configuration.getEqEngine(); + this.reqEngine = configuration.getReqEngine(); + this.conflictDetector = configuration.getConflictDetector(); + this.disabledPostProcessors = configuration.getDisabledPostProcessors(); } /** diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/.project b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/.project index 7fdad9a71..17387ca5a 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/.project +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/.project @@ -20,9 +20,15 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> + <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> </natures> </projectDescription> diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/Activator.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/Activator.java index ed9cffe3e..224329c21 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/Activator.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/Activator.java @@ -10,11 +10,17 @@ *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.tests.git.framework; -import org.osgi.framework.BundleActivator; +import org.eclipse.core.runtime.Plugin; import org.osgi.framework.BundleContext; -public class Activator implements BundleActivator { +/** + * Activator for the EMFCompare Git Test Framework plugin. + * + * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a> + */ +public class Activator extends Plugin { + /** The bundle context. */ private static BundleContext context; static BundleContext getContext() { @@ -25,6 +31,7 @@ public class Activator implements BundleActivator { * (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ + @Override public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; } @@ -33,6 +40,7 @@ public class Activator implements BundleActivator { * (non-Javadoc) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ + @Override public void stop(BundleContext bundleContext) throws Exception { Activator.context = null; } diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.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 d9f9663cd..f6c79b5ab 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/GitMergeStrategyID.java @@ -17,15 +17,25 @@ package org.eclipse.emf.compare.ide.ui.tests.git.framework; */ public enum GitMergeStrategyID { + /** The default merge strategy used by JGit. */ JGIT_DEFAULT("jgit-default-mergeStrategy"), //$NON-NLS-1$ + /** The default merge strategy for EMFCompare. */ MODEL_RECURSIVE("model recursive"), //$NON-NLS-1$ + /** The merge strategy used for additif merge in EMFCompare. */ MODEL_ADDITIVE("model additive"); //$NON-NLS-1$ + /** The value of the enum to return. */ private String value; - private GitMergeStrategyID(String value) { + /** + * Constructor. + * + * @param value + * The text value associated with the enum value + */ + 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 b26e10dce..295addee3 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 @@ -33,6 +33,7 @@ public class GitTestRunner extends AbstractCompareTestRunner { * @param testClass * The class to test * @throws InitializationError + * If the test cannot be created */ public GitTestRunner(Class<?> testClass) throws InitializationError { super(testClass); diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/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 dfaa75a09..56da62b26 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/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 @@ -82,18 +82,32 @@ import org.eclipse.team.core.subscribers.SubscriberScopeManager; @SuppressWarnings({"restriction" }) public class GitTestSupport extends InternalGitTestSupport { - public final static String COMPARE_NO_PROJECT_SELECTED = "noProject"; //$NON-NLS-1$ + /** + * Used to specify that there is only one project in the repository. The tester does not have to specify + * it. + */ + public static final String COMPARE_NO_PROJECT_SELECTED = "noProject"; //$NON-NLS-1$ + /** The result of the merge operation. */ private MergeResult mergeResult; + /** The result of the rebase operation. */ private RebaseResult rebaseResult; + /** The result of the cherry-pick operation. */ private CherryPickResult cherryPickResult; public Repository getRepository() { return repository; } + /** + * Get the list of projects in the workspace. All projects are refreshed before being returned. + * + * @return the list of all projects + * @throws CoreException + * Thrown if the refresh operation went wrong + */ public List<IProject> getProjects() throws CoreException { for (IProject project : projects) { project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); @@ -101,6 +115,13 @@ public class GitTestSupport extends InternalGitTestSupport { return Lists.newArrayList(projects); } + /** + * Get The JGit Status Object from the repository. + * + * @return the status Object of the Git repository + * @throws Exception + * If the status cannot be retrieved + */ public Status getStatus() throws Exception { Git git = new Git(repository); try { @@ -132,8 +153,11 @@ public class GitTestSupport extends InternalGitTestSupport { * The branch to merge with (for example "master" or "refs/for/master", both syntaxes are * accepted) * @throws CoreException + * Thrown if the merge operation or the refresh of projects went wrong * @throws IOException + * Thrown if the checkout operation went wrong * @throws InterruptedException + * Thrown if the checkout operation went wrong */ public void merge(String local, String remote) throws CoreException, IOException, InterruptedException { checkoutBranch(normalizeBranch(local)); @@ -155,8 +179,11 @@ public class GitTestSupport extends InternalGitTestSupport { * The branch where the commit will be cherry-picked (for example "master" or * "refs/for/master", both syntaxes are accepted) * @throws CoreException + * Thrown if the cherry-pick operation or the refresh of projects went wrong * @throws IOException + * Thrown if the checkout operation went wrong * @throws InterruptedException + * Thrown if the checkout operation went wrong */ public void cherryPick(String local, String remote) throws CoreException, IOException, InterruptedException { @@ -185,8 +212,11 @@ public class GitTestSupport extends InternalGitTestSupport { * The branch to rebase on (for example "master" or "refs/for/master", both syntaxes are * accepted) * @throws CoreException + * Thrown if the rebase operation or the refresh of projects went wrong * @throws IOException + * Thrown if the checkout operation went wrong * @throws InterruptedException + * Thrown if the checkout operation went wrong */ public void rebase(String local, String remote) throws CoreException, IOException, InterruptedException { checkoutBranch(normalizeBranch(local)); @@ -217,7 +247,9 @@ public class GitTestSupport extends InternalGitTestSupport { * The file to compare (the relative path to the file from the project) * @return the comparison * @throws IOException + * Thrown if the checkout operation went wrong * @throws CoreException + * Thrown if the checkout operation went wrong */ public Comparison compare(String from, String to, String fileName) throws IOException, CoreException { return compare(from, to, fileName, COMPARE_NO_PROJECT_SELECTED); @@ -246,7 +278,9 @@ public class GitTestSupport extends InternalGitTestSupport { * file will be used (use this when their is only one project) * @return the comparison * @throws IOException + * Thrown if the checkout operation went wrong * @throws CoreException + * Thrown if the checkout operation went wrong */ public Comparison compare(String from, String to, String fileName, String containerProject) throws IOException, CoreException { @@ -348,6 +382,15 @@ public class GitTestSupport extends InternalGitTestSupport { return comparisonBuilder.build().compare(scope, new BasicMonitor()); } + /** + * Get the resources associated with the given mappings. + * + * @param mappings + * An array of resourceMappings + * @param context + * The context of resourceMappings + * @return a list of resources + */ private Set<IResource> collectResources(ResourceMapping[] mappings, ResourceMappingContext context) { final Set<IResource> resources = new HashSet<IResource>(); for (ResourceMapping mapping : mappings) { @@ -370,6 +413,9 @@ public class GitTestSupport extends InternalGitTestSupport { * The branch to checkout (for example "master" or "refs/heads/master", both syntaxes are * accepted) * @throws CoreException + * Thrown if the merge operation or the refresh of projects went wrong + * @throws IOException + * Thrown if the cannot retrieve the current branch */ public void checkoutBranch(String refName) throws CoreException, IOException { ResetOperation reset = new ResetOperation(repository, repository.getBranch(), ResetType.HARD); @@ -390,7 +436,7 @@ public class GitTestSupport extends InternalGitTestSupport { * * @return <code>true</code> if the repository is in a conflict state, <code>false</code> otherwise. * @throws Exception - * if the status of the repository could not be created queried. + * If the status of the repository could not be created queried. */ public boolean noConflict() throws Exception { return getStatus().getConflicting().isEmpty(); 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 index b7eb81567..37b1f104c 100644 --- 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 @@ -53,10 +53,30 @@ import org.eclipse.jgit.lib.Repository; @Target(ElementType.METHOD) public @interface GitCherryPick { - /** The name of the local branch. */ + /** + * The name of the local branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return the local branch + */ String local(); - /** The name of the remote branch. */ + /** + * The name of the remote branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return 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 7307c7dd6..2ad9fa81f 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 @@ -37,20 +37,44 @@ import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport; @Target(ElementType.METHOD) public @interface GitCompare { - /** The name of the local branch. */ + /** + * The name of the local branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return the local branch + */ String local(); - /** The name of the remote branch. */ + /** + * The name of the remote branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return the remote branch + */ String remote(); /** * The path of the file to compare. The path must be project relative + * + * @return the path to the file to compare */ String file(); /** * This value is optional. If not used, the runner will assume that only one project is contained in the * repository. If used, the value will be used to get the project containing the file to compare. + * + * @return the project containing the file to compare or the default value */ String containerProject() default GitTestSupport.COMPARE_NO_PROJECT_SELECTED; 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 9401bdf3e..a9670377c 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 @@ -54,10 +54,30 @@ import org.eclipse.jgit.lib.Repository; @Target(ElementType.METHOD) public @interface GitMerge { - /** The name of the local branch. */ + /** + * The name of the local branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return the local branch + */ String local(); - /** The name of the remote branch. */ + /** + * The name of the remote branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return 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/GitMergeStrategy.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 292341d22..ef3e915a8 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMergeStrategy.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 @@ -28,8 +28,10 @@ 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. + * will be returned (which is set to "model recursive"). If the annotation is not used the merge strategy + * defined in the class EMFCompareGitTestRunner will be used. + * + * @return the merge strategy or its default value ("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 index 8ca4b3e72..c097cea0d 100644 --- 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 @@ -53,10 +53,30 @@ import org.eclipse.jgit.lib.Repository; @Target(ElementType.METHOD) public @interface GitRebase { - /** The name of the local branch. */ + /** + * The name of the local branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return the local branch + */ String local(); - /** The name of the remote branch. */ + /** + * The name of the remote branch. User can specified qualified name or simple name (i.e. + * refs/heads/myBranch or myBranch). + * + * <pre> + * The qualified name of the branch used for the test will always be on the format refs/heads/... which + * means it is not possible to make a comparison on a Gerrit like branch (refs/for/...) + * </pre> + * + * @return 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/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 5bb49294f..98c3858af 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 @@ -30,17 +30,35 @@ import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.Gi 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.BlockJUnit4ClassRunner; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; /** + * EMFCompare specific {@link BlockJUnit4ClassRunner} used for Git comparisons. + * * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a> */ public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock { + /** The merge strategy to use for the test. */ private GitMergeStrategyID mergeStrategy; + /** + * Constructor for the classic (no Git) comparison statement. + * + * @param klass + * The test class + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configurations for this test + * @param mergeStrategy + * The merge strategy to use for this test. + * @throws InitializationError + * If something went wrong during test initialization + */ public GitTestCaseJUnitBlock(Class<?> klass, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy) throws InitializationError { @@ -74,7 +92,9 @@ public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock { Object testObject = null; try { testObject = createTest(); + // CHECKSTYLE:OFF JUnit createTest() method throws an Exception } catch (Exception e) { + // CHECKSTYLE:ON Assert.fail(e.getMessage()); } 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/AbstractGitOperationStatement.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 b655f395e..c22f82de4 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.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 @@ -29,14 +29,34 @@ import org.junit.runners.model.FrameworkMethod; @SuppressWarnings("restriction") public abstract class AbstractGitOperationStatement extends AbstractGitStatement { + /** The path of the archive containing the repository. */ + protected final String path; + + /** The merge strategy used for the test. */ private final GitMergeStrategyID mergeStrategy; + /** The EGit preferences. */ private final IEclipsePreferences eGitPreferences; - protected final String path; - + /** The default merge strategy to use if none is provided by user. */ private String defaultMergeStrategy = GitMergeStrategyID.MODEL_RECURSIVE.getValue(); + /** + * Constructor for Git comparison statements. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param mergeStrategy + * The merge strategy used for the test + * @param path + * The path of the archive containing the repository + */ public AbstractGitOperationStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy, String path) { @@ -65,12 +85,37 @@ public abstract class AbstractGitOperationStatement extends AbstractGitStatement } } + /** + * Get the branch that will be used as local branch for the test. This method have to be sub-classed by + * clients to properly get the branch. + * + * @return the local branch + */ protected abstract String getCheckoutedBranch(); + /** + * Get the branch that will be used as remote branch for the test. This method have to be sub-classed by + * clients to properly get the branch.. + * + * @return the remote branch + */ protected abstract String getOtherBranch(); + /** + * Call the Git operation used in for the test. This method have to be sub-classed by clients to call the + * correct operation. + * + * @param gitTestsSupport + * The support class that allow to perform Git operations + * @param from + * The local branch + * @param to + * The remote branch + * @throws Exception + * Thrown if a Git operation have an issue during execution + */ protected abstract void callGitOperation(GitTestSupport gitTestsSupport, String from, String to) - throws Throwable; + throws Exception; @Override protected void setEMFComparePreferences() { @@ -84,6 +129,9 @@ public abstract class AbstractGitOperationStatement extends AbstractGitStatement eGitPreferences.put(GitCorePreferences.core_preferredMergeStrategy, defaultMergeStrategy); } + /** + * Set the merge strategy preference to run the test in the correct conditions. + */ private void setMergeStrategyPreference() { defaultMergeStrategy = eGitPreferences.get(GitCorePreferences.core_preferredMergeStrategy, defaultMergeStrategy); 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/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 5504c6637..3c3be398c 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/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 @@ -32,14 +32,43 @@ import org.eclipse.jgit.api.Status; import org.eclipse.jgit.lib.Repository; import org.junit.runners.model.FrameworkMethod; +/** + * EMFCompare specific Git statements must extends this class. + * + * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a> + */ public abstract class AbstractGitStatement extends AbstractCompareStatement { + /** + * Constructor for the classic (no Git) comparison statement. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + */ public AbstractGitStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration) { super(testObject, test, resolutionStrategy, configuration); } - protected Object[] createParameters(Method method, GitTestSupport gitTestsSupport) throws Throwable { + /** + * Compute the list of parameters to give to the test method. The parameters are returned in the correct + * order. + * + * @param method + * The test method + * @param gitTestsSupport + * The support class used for Git operations + * @return the list of parameters for the method + * @throws Exception + * If the method use an incorrect parameter + */ + protected Object[] createParameters(Method method, GitTestSupport gitTestsSupport) throws Exception { final Builder<Object> builder = ImmutableList.builder(); Class<?>[] paramTypes = method.getParameterTypes(); for (Class<?> paramType : paramTypes) { @@ -67,6 +96,13 @@ public abstract class AbstractGitStatement extends AbstractCompareStatement { return builder.build().toArray(); } + /** + * Test if the given type is some kind of Collection. + * + * @param paramType + * The Class to test + * @return <code>true</code> if the given parameter is a Collection + */ private boolean isCollectionCompatible(Class<?> paramType) { return paramType.equals(Collection.class) || paramType.equals(List.class) || paramType.equals(Iterable.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 index 051a61742..cc130b1d4 100644 --- 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 @@ -24,6 +24,22 @@ import org.junit.runners.model.FrameworkMethod; */ public class GitCherryPickStatement extends AbstractGitOperationStatement { + /** + * Constructor for Git cherry-pick statements. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param mergeStrategy + * The merge strategy used for the test + * @param path + * The path of the archive containing the repository + */ public GitCherryPickStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy, String path) { @@ -32,7 +48,7 @@ public class GitCherryPickStatement extends AbstractGitOperationStatement { @Override protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch) - throws Throwable { + throws Exception { gitTestsSupport.cherryPick(localBranch, remoteBranch); } 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/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 ddd08bac6..a44a5692a 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/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 @@ -25,8 +25,23 @@ import org.junit.runners.model.FrameworkMethod; */ public class GitCompareStatement extends AbstractGitStatement { + /** The path of the archive containing the repository. */ private final String path; + /** + * Constructor for the Git comparison statement. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param path + * The path of the archive containing the repository + */ public GitCompareStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, String path) { super(testObject, test, 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/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 index 78de6c9dc..657d411ce 100644 --- 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 @@ -24,6 +24,22 @@ import org.junit.runners.model.FrameworkMethod; */ public class GitMergeStatement extends AbstractGitOperationStatement { + /** + * Constructor for Git merge statements. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param mergeStrategy + * The merge strategy used for the test + * @param path + * The path of the archive containing the repository + */ public GitMergeStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy, String path) { super(testObject, test, resolutionStrategy, configuration, mergeStrategy, path); @@ -31,7 +47,7 @@ public class GitMergeStatement extends AbstractGitOperationStatement { @Override protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch) - throws Throwable { + throws Exception { gitTestsSupport.merge(localBranch, remoteBranch); } 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 index a7bc5124c..59c1ed3d1 100644 --- 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 @@ -24,6 +24,22 @@ import org.junit.runners.model.FrameworkMethod; */ public class GitRebaseStatement extends AbstractGitOperationStatement { + /** + * Constructor for Git rebase statements. + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param mergeStrategy + * The merge strategy used for the test + * @param path + * The path of the archive containing the repository + */ public GitRebaseStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy, String path) { @@ -32,7 +48,7 @@ public class GitRebaseStatement extends AbstractGitOperationStatement { @Override protected void callGitOperation(GitTestSupport gitTestsSupport, String localBranch, String remoteBranch) - throws Throwable { + throws Exception { gitTestsSupport.rebase(localBranch, remoteBranch); } 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/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 b73668be2..1263604b3 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/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 @@ -23,8 +23,24 @@ import org.junit.runners.model.FrameworkMethod; */ public class GitTestStatement extends AbstractGitStatement { + /** The path of the archive containing the repository. */ private final String path; + /** + * Constructor for the test where the user only wants to do a setup of the test (unzip archive, load + * projects). + * + * @param testObject + * The test class + * @param test + * The test method + * @param resolutionStrategy + * The resolution strategy used for this test + * @param configuration + * EMFCompare configuration for this test + * @param path + * The path of the archive containing the repository + */ public GitTestStatement(Object testObject, FrameworkMethod test, ResolutionStrategyID resolutionStrategy, EMFCompareTestConfiguration configuration, String path) { super(testObject, test, 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/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 index 4c0392178..6488d8908 100644 --- 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 @@ -47,25 +47,39 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; @SuppressWarnings({"restriction" }) public class InternalGitTestSupport { - private final static String GIT_BRANCH_PREFIX = "refs/heads/"; //$NON-NLS-1$ + /** The prefix of Git branches. */ + private static final String GIT_BRANCH_PREFIX = "refs/heads/"; //$NON-NLS-1$ - /** - * Size of the buffer to read/write data - */ + /** Name of the Eclipse metadata folder. */ + private static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$ + + /** Size of the buffer to read/write data. */ private static final int BUFFER_SIZE = 4096; - protected Repository repository = null; + /** The JGit repository. */ + protected Repository repository; - protected IProject[] projects = null; + /** The list of projects in the repository. */ + protected IProject[] projects; - protected ArrayList<Runnable> disposers = null; + /** The list of JGit disposers. */ + protected ArrayList<Runnable> disposers; + /** Query used to specify if the projects import must override existing projects. */ private IOverwriteQuery overwriteQuery = new IOverwriteQuery() { public String queryOverwrite(String file) { return ALL; } }; + /** + * Adapt the given <code>branch</code> name to be in a correct format for Git or return it directly if it + * is already the case. + * + * @param branch + * The branch name we want to normalize + * @return the branch in Git format + */ protected static String normalizeBranch(String branch) { if (branch.startsWith(GIT_BRANCH_PREFIX)) { return branch; @@ -74,8 +88,18 @@ public class InternalGitTestSupport { } } - protected void createRepositoryFromPath(Class<?> clazz, String path) - throws IOException, InvocationTargetException, InterruptedException, CoreException { + /** + * Perform all loading actions (unzip the archive, connect the git repository to JGit, import the + * contained projects in the workspace and connect them through JGit). + * + * @param clazz + * The test class + * @param path + * The path of the archive containing the Git repository + * @throws Exception + * If something goes wrong during unzip or import steps + */ + protected void createRepositoryFromPath(Class<?> clazz, String path) throws Exception { final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // Delete all projects that can remain in the workspace : prevent errors dues to wrong cleanup of // other tests @@ -91,22 +115,41 @@ public class InternalGitTestSupport { } /** - * Connect a project to this repository. + * Connect a project to the Git repository. * * @param project * The project to connect + * @throws CoreException + * Thrown if the project cannot be connected to the workspace + * @throws InterruptedException + * Thrown if the operation is interrupted */ private void connect(IProject project) throws CoreException, InterruptedException { ConnectProviderOperation op = new ConnectProviderOperation(project, repository.getDirectory()); op.execute(null); } + /** + * Connect the Git repository to JGit. + * + * @param file + * The path to the root of the repository + * @throws IOException + * If their is a problem during the connection to JGit + */ private void connectRepository(File file) throws IOException { File gitDir = findGitDir(file); this.repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir); this.disposers = new ArrayList<Runnable>(); } + /** + * Find the ".git" folder in the repository. + * + * @param file + * The path of the root of the unziped files + * @return The path to the .git folder + */ private File findGitDir(File file) { for (File child : file.listFiles()) { if (child.isDirectory() && child.getName().equals(".git")) { //$NON-NLS-1$ @@ -121,10 +164,22 @@ public class InternalGitTestSupport { return null; } + /** + * Import the Eclipse projects contained in the given file. + * + * @param file + * The folder to look inside + * @throws InvocationTargetException + * Thrown if an error happen during the import of the project + * @throws InterruptedException + * Thrown if the import operation is interrupted + * @throws CoreException + * Thrown if the project cannot be created in the workspace + */ private void importProjects(File file) throws InvocationTargetException, InterruptedException, CoreException { for (File child : file.listFiles()) { - if (child.isDirectory() && !child.getName().equals(".metadata") //$NON-NLS-1$ + if (child.isDirectory() && !child.getName().equals(METADATA_FOLDER) && !child.getName().equals(".git")) { //$NON-NLS-1$ importProjects(child); } else if (child.getName().equals(".project")) { //$NON-NLS-1$ @@ -133,6 +188,18 @@ public class InternalGitTestSupport { } } + /** + * Import the project located in the given path into the test workspace. + * + * @param file + * The path to the .project file + * @throws InvocationTargetException + * Thrown if an error happen during the import of the project + * @throws InterruptedException + * Thrown if the import operation is interrupted + * @throws CoreException + * Thrown if the project cannot be created in the workspace + */ private void importProject(File file) throws InvocationTargetException, InterruptedException, CoreException { IProjectDescription description = ResourcesPlugin.getWorkspace() @@ -147,6 +214,18 @@ public class InternalGitTestSupport { importOperation.run(new NullProgressMonitor()); } + /** + * Extract the zip file into the given workspace. + * + * @param clazz + * The test class + * @param path + * The path to the archive (relative to the test class) + * @param root + * The root of the test workspace + * @throws IOException + * Thrown if the zip extraction goes wrong + */ private void extractArchive(Class<?> clazz, String path, IWorkspaceRoot root) throws IOException { InputStream resourceAsStream = clazz.getResourceAsStream(path); ZipInputStream zipIn = new ZipInputStream(resourceAsStream); @@ -164,6 +243,16 @@ public class InternalGitTestSupport { zipIn.close(); } + /** + * Extract the given input stream to the given location. + * + * @param zipIn + * The zip input stream + * @param filePath + * The destination path for the extraction + * @throws IOException + * Thrown if something happen during the extraction + */ private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] bytesIn = new byte[BUFFER_SIZE]; @@ -174,6 +263,14 @@ public class InternalGitTestSupport { bos.close(); } + /** + * Clean all possibly remaining elements to start the test in a clean state. + * + * @throws CoreException + * Thrown if a project cannot be deleted + * @throws IOException + * Thrown if a file cannot be deleted + */ protected void setup() throws CoreException, IOException { final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject[] unknownProjects = workspaceRoot.getProjects(); @@ -186,12 +283,20 @@ public class InternalGitTestSupport { File file = new File(workspaceRoot.getLocation().toOSString()); for (File child : file.listFiles()) { - if (!child.getName().equals(".metadata")) { //$NON-NLS-1$ + if (!child.getName().equals(METADATA_FOLDER)) { FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY); } } } + /** + * Clear workspace and repository for next tests. + * + * @throws CoreException + * Thrown if a project cannot be deleted + * @throws IOException + * Thrown if a file cannot be deleted + */ protected void tearDown() throws CoreException, IOException { if (repository != null) { repository.close(); @@ -215,7 +320,7 @@ public class InternalGitTestSupport { File file = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); for (File child : file.listFiles()) { - if (!child.getName().equals(".metadata")) { //$NON-NLS-1$ + if (!child.getName().equals(METADATA_FOLDER)) { FileUtils.delete(child, FileUtils.RECURSIVE | FileUtils.RETRY); } } |