aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2012-04-23 10:56:45 (EDT)
committerJohn Arthorne2012-04-24 16:26:55 (EDT)
commit76765dfdd00cd11b64e990cd1763909957d5b4ef (patch)
treef4b33f78f10624fcb5b1c24f03abb49a12925477
parent8e55c0a9b0932fee65c21ed9ba1ff0d74a024d82 (diff)
downloadeclipse.platform.releng-76765dfdd00cd11b64e990cd1763909957d5b4ef.zip
eclipse.platform.releng-76765dfdd00cd11b64e990cd1763909957d5b4ef.tar.gz
eclipse.platform.releng-76765dfdd00cd11b64e990cd1763909957d5b4ef.tar.bz2
bug 345669: Ensure Copyright Checker/Updater works with Git - tests
-rw-r--r--bundles/org.eclipse.releng.tests/.classpath2
-rw-r--r--bundles/org.eclipse.releng.tests/.settings/org.eclipse.jdt.core.prefs13
-rw-r--r--bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF9
-rw-r--r--bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/GitCopyrightAdapterTest.java151
4 files changed, 165 insertions, 10 deletions
diff --git a/bundles/org.eclipse.releng.tests/.classpath b/bundles/org.eclipse.releng.tests/.classpath
index b7464f3..472ee29 100644
--- a/bundles/org.eclipse.releng.tests/.classpath
+++ b/bundles/org.eclipse.releng.tests/.classpath
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.releng.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.releng.tests/.settings/org.eclipse.jdt.core.prefs
index b3ab182..1ed7988 100644
--- a/bundles/org.eclipse.releng.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.releng.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,3 @@
-#Fri Feb 11 09:19:22 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -8,16 +7,16 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=error
@@ -26,7 +25,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
@@ -87,6 +86,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF
index 19a5ddf..b9b2a46 100644
--- a/bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF
@@ -8,6 +8,11 @@ Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.pde.tools.versioning,
- org.junit
+ org.junit,
+ org.eclipse.jgit;bundle-version="1.3.0",
+ org.eclipse.core.resources,
+ org.eclipse.egit.core;bundle-version="1.3.0",
+ org.eclipse.jgit.junit;bundle-version="1.3.0",
+ org.eclipse.releng.tools;bundle-version="3.6.100"
Export-Package: org.eclipse.releng.tests
-Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/GitCopyrightAdapterTest.java b/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/GitCopyrightAdapterTest.java
new file mode 100644
index 0000000..ea85ef5
--- /dev/null
+++ b/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/GitCopyrightAdapterTest.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation 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:
+ * Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.releng.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+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.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.releng.tools.git.GitCopyrightAdapter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GitCopyrightAdapterTest extends LocalDiskRepositoryTestCase {
+
+ private static final IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
+
+ private static final String PROJECT_NAME = "Project";
+
+ private static final String FILE1_NAME = "Foo.java";
+
+ private static final String FILE2_NAME = "Bar.java";
+
+ private Repository db;
+
+ private File trash;
+
+ private File gitDir;
+
+ private IProject project;
+
+ private IFile file1;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ db = createWorkRepository();
+ trash = db.getWorkTree();
+ gitDir = new File(trash, Constants.DOT_GIT);
+ project = createProject(PROJECT_NAME);
+ file1 = project.getFile(FILE1_NAME);
+ connect();
+ }
+
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ if (project.exists())
+ project.delete(true, true, NULL_MONITOR);
+ if (gitDir.exists())
+ FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
+ super.tearDown();
+ }
+
+ @Test
+ public void testLastModifiedYear() throws Exception {
+ final Git git = new Git(db);
+ git.add().addFilepattern(PROJECT_NAME + "/" + FILE1_NAME).call();
+ final PersonIdent committer2011 = new PersonIdent(committer,
+ getDateForYear(2011));
+ git.commit().setMessage("old commit").setCommitter(committer2011)
+ .call();
+ git.add().addFilepattern(PROJECT_NAME + "/" + FILE2_NAME).call();
+ git.commit().setMessage("new commit").call();
+
+ final GitCopyrightAdapter adapter = new GitCopyrightAdapter(
+ new IResource[] { project });
+ adapter.initialize(NULL_MONITOR);
+ final int lastModifiedYear = adapter.getLastModifiedYear(file1,
+ NULL_MONITOR);
+
+ assertEquals(2011, lastModifiedYear);
+ }
+
+ @Test
+ public void testCopyrightUpdateComment() throws Exception {
+ final Git git = new Git(db);
+ git.add().addFilepattern(PROJECT_NAME + "/" + FILE1_NAME).call();
+ git.commit().setMessage("copyright update").call();
+
+ final GitCopyrightAdapter adapter = new GitCopyrightAdapter(
+ new IResource[] { project });
+ adapter.initialize(NULL_MONITOR);
+ final int lastModifiedYear = adapter.getLastModifiedYear(file1,
+ NULL_MONITOR);
+
+ assertEquals(0, lastModifiedYear);
+ }
+
+ private IProject createProject(String name) throws Exception {
+ final IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(name);
+ if (project.exists())
+ project.delete(true, null);
+ final IProjectDescription desc = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(name);
+ desc.setLocation(new Path(new File(db.getWorkTree(), name).getPath()));
+ project.create(desc, null);
+ project.open(null);
+
+ final IFile file1 = project.getFile(FILE1_NAME);
+ file1.create(
+ new ByteArrayInputStream("Hello, world".getBytes(project
+ .getDefaultCharset())), false, null);
+
+ final IFile file2 = project.getFile(FILE2_NAME);
+ file2.create(
+ new ByteArrayInputStream("Hi there".getBytes(project
+ .getDefaultCharset())), false, null);
+ return project;
+ }
+
+ private void connect() throws CoreException {
+ new ConnectProviderOperation(project, gitDir).execute(null);
+ }
+
+ private Date getDateForYear(int year) throws ParseException {
+ final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
+ return formatter.parse(Integer.toString(year) + "/6/30");
+ }
+
+} \ No newline at end of file