View | Details | Raw Unified | Return to bug 378047 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.releng.tests/META-INF/MANIFEST.MF (-2 / +5 lines)
Lines 8-14 Bundle-ClassPath: relengtests.jar Link Here
8
Bundle-Vendor: %Plugin.providerName
8
Bundle-Vendor: %Plugin.providerName
9
Bundle-Localization: plugin
9
Bundle-Localization: plugin
10
Require-Bundle: org.eclipse.core.runtime,
10
Require-Bundle: org.eclipse.core.runtime,
11
 org.eclipse.pde.tools.versioning,
11
 org.junit,
12
 org.junit
12
 org.eclipse.jgit;bundle-version="1.3.0";resolution:=optional,
13
 org.eclipse.core.resources,
14
 org.eclipse.egit.core;bundle-version="1.3.0";resolution:=optional,
15
 org.eclipse.releng.tools;bundle-version="3.6.100"
13
Export-Package: org.eclipse.releng.tests
16
Export-Package: org.eclipse.releng.tests
14
Bundle-RequiredExecutionEnvironment: J2SE-1.4
17
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/AllRelengTests.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Tomasz Zarna and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tomasz Zarna <tzarna@gmail.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tests;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
public class AllRelengTests extends TestSuite {
17
	public static Test suite() {
18
		return new AllRelengTests();
19
	}
20
21
	public AllRelengTests() {
22
		addTestSuite(BuildTests.class);
23
		if (isJGitAvailable()) {
24
			addTestSuite(GitCopyrightAdapterTest.class);
25
		}
26
	}
27
28
	private boolean isJGitAvailable() {
29
		try {
30
			Class.forName("org.eclipse.jgit.api.Git");
31
		} catch (ClassNotFoundException e) {
32
			return false;
33
		}
34
		return true;
35
	}
36
}
(-)a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/GitCopyrightAdapterTest.java (+140 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Tomasz Zarna and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tomasz Zarna <tzarna@gmail.com> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.releng.tests;
12
13
import java.io.ByteArrayInputStream;
14
import java.io.File;
15
import java.text.ParseException;
16
import java.text.SimpleDateFormat;
17
import java.util.Date;
18
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProjectDescription;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.NullProgressMonitor;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.egit.core.op.ConnectProviderOperation;
29
import org.eclipse.jgit.api.Git;
30
import org.eclipse.jgit.lib.Constants;
31
import org.eclipse.jgit.lib.PersonIdent;
32
import org.eclipse.jgit.lib.Repository;
33
import org.eclipse.jgit.util.FileUtils;
34
import org.eclipse.releng.tools.git.GitCopyrightAdapter;
35
import org.junit.Assert;
36
37
public class GitCopyrightAdapterTest extends LocalDiskRepositoryTest {
38
39
	private static final IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
40
41
	private static final String PROJECT_NAME = "Project";
42
43
	private static final String FILE1_NAME = "Foo.java";
44
45
	private static final String FILE2_NAME = "Bar.java";
46
47
	private Repository db;
48
49
	private File trash;
50
51
	private File gitDir;
52
53
	private IProject project;
54
55
	private IFile file1;
56
57
	public void setUp() throws Exception {
58
		super.setUp();
59
		db = createWorkRepository();
60
		trash = db.getWorkTree();
61
		gitDir = new File(trash, Constants.DOT_GIT);
62
		project = createProject(PROJECT_NAME);
63
		file1 = project.getFile(FILE1_NAME);
64
		connect();
65
	}
66
67
	public void tearDown() throws Exception {
68
		if (project.exists())
69
			project.delete(true, true, NULL_MONITOR);
70
		if (gitDir.exists())
71
			FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
72
		super.tearDown();
73
	}
74
75
	public void testLastModifiedYear() throws Exception {
76
		final Git git = new Git(db);
77
		git.add().addFilepattern(PROJECT_NAME + "/" + FILE1_NAME).call();
78
		final PersonIdent committer2011 = new PersonIdent(committer,
79
				getDateForYear(2011));
80
		git.commit().setMessage("old commit").setCommitter(committer2011)
81
				.call();
82
		git.add().addFilepattern(PROJECT_NAME + "/" + FILE2_NAME).call();
83
		git.commit().setMessage("new commit").call();
84
85
		final GitCopyrightAdapter adapter = new GitCopyrightAdapter(
86
				new IResource[] { project });
87
		adapter.initialize(NULL_MONITOR);
88
		final int lastModifiedYear = adapter.getLastModifiedYear(file1,
89
				NULL_MONITOR);
90
91
		Assert.assertEquals(2011, lastModifiedYear);
92
	}
93
94
	public void testCopyrightUpdateComment() throws Exception {
95
		final Git git = new Git(db);
96
		git.add().addFilepattern(PROJECT_NAME + "/" + FILE1_NAME).call();
97
		git.commit().setMessage("copyright update").call();
98
99
		final GitCopyrightAdapter adapter = new GitCopyrightAdapter(
100
				new IResource[] { project });
101
		adapter.initialize(NULL_MONITOR);
102
		final int lastModifiedYear = adapter.getLastModifiedYear(file1,
103
				NULL_MONITOR);
104
105
		Assert.assertEquals(0, lastModifiedYear);
106
	}
107
108
	private IProject createProject(String name) throws Exception {
109
		final IProject project = ResourcesPlugin.getWorkspace().getRoot()
110
				.getProject(name);
111
		if (project.exists())
112
			project.delete(true, null);
113
		final IProjectDescription desc = ResourcesPlugin.getWorkspace()
114
				.newProjectDescription(name);
115
		desc.setLocation(new Path(new File(db.getWorkTree(), name).getPath()));
116
		project.create(desc, null);
117
		project.open(null);
118
119
		final IFile file1 = project.getFile(FILE1_NAME);
120
		file1.create(
121
				new ByteArrayInputStream("Hello, world".getBytes(project
122
						.getDefaultCharset())), false, null);
123
124
		final IFile file2 = project.getFile(FILE2_NAME);
125
		file2.create(
126
				new ByteArrayInputStream("Hi there".getBytes(project
127
						.getDefaultCharset())), false, null);
128
		return project;
129
	}
130
131
	private void connect() throws CoreException {
132
		new ConnectProviderOperation(project, gitDir).execute(null);
133
	}
134
135
	private Date getDateForYear(int year) throws ParseException {
136
		final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
137
		return formatter.parse(Integer.toString(year) + "/6/30");
138
	}
139
140
}
(-)a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/LocalDiskRepositoryTest.java (+140 lines)
Added Link Here
1
/*
2
 * Copyright (C) 2009-2010, Google Inc.
3
 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
4
 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
5
 * and other copyright owners as documented in the project's IP log.
6
 *
7
 * This class was originally copied from
8
 * org.eclipse.jgit.junit.LocalDiskRepositoryTest
9
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=378047
10
 *
11
 * This program and the accompanying materials are made available
12
 * under the terms of the Eclipse Distribution License v1.0 which
13
 * accompanies this distribution, is reproduced below, and is
14
 * available at http://www.eclipse.org/org/documents/edl-v10.php
15
 *
16
 * All rights reserved.
17
 *
18
 * Redistribution and use in source and binary forms, with or
19
 * without modification, are permitted provided that the following
20
 * conditions are met:
21
 *
22
 * - Redistributions of source code must retain the above copyright
23
 *   notice, this list of conditions and the following disclaimer.
24
 *
25
 * - Redistributions in binary form must reproduce the above
26
 *   copyright notice, this list of conditions and the following
27
 *   disclaimer in the documentation and/or other materials provided
28
 *   with the distribution.
29
 *
30
 * - Neither the name of the Eclipse Foundation, Inc. nor the
31
 *   names of its contributors may be used to endorse or promote
32
 *   products derived from this software without specific prior
33
 *   written permission.
34
 *
35
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
36
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
37
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
40
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
44
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
 */
49
package org.eclipse.releng.tests;
50
51
import java.io.File;
52
import java.io.IOException;
53
import java.util.ArrayList;
54
import java.util.Iterator;
55
import java.util.List;
56
57
import junit.framework.TestCase;
58
59
import org.eclipse.jgit.lib.Constants;
60
import org.eclipse.jgit.lib.PersonIdent;
61
import org.eclipse.jgit.lib.Repository;
62
import org.eclipse.jgit.lib.RepositoryCache;
63
import org.eclipse.jgit.storage.file.FileRepository;
64
import org.junit.Assert;
65
66
/**
67
 * This class is a modified version of org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
68
 *
69
 */
70
public class LocalDiskRepositoryTest extends TestCase {
71
	private static int testCount;
72
	protected PersonIdent committer;
73
	private final File trash = new File(new File("target"), "trash");
74
	private final List toClose = new ArrayList();
75
76
	protected void setUp() throws Exception {
77
		committer = new PersonIdent("J. Committer", "jcommitter@example.com");
78
	}
79
80
	protected void tearDown() throws Exception {
81
		RepositoryCache.clear();
82
		for (Iterator it = toClose.iterator(); it.hasNext();) {
83
			Repository r = (Repository) it.next();
84
			r.close();
85
		}
86
		toClose.clear();
87
	}
88
89
	/**
90
	 * Creates a new empty repository within a new empty working directory.
91
	 *
92
	 * @return the newly created repository, opened for access
93
	 * @throws IOException
94
	 *             the repository could not be created in the temporary area
95
	 */
96
	protected FileRepository createWorkRepository() throws IOException {
97
		return createRepository(false /* not bare */);
98
	}
99
100
	/**
101
	 * Creates a new empty repository.
102
	 *
103
	 * @param bare
104
	 *            true to create a bare repository; false to make a repository
105
	 *            within its working directory
106
	 * @return the newly created repository, opened for access
107
	 * @throws IOException
108
	 *             the repository could not be created in the temporary area
109
	 */
110
	private FileRepository createRepository(boolean bare) throws IOException {
111
		File gitdir = createUniqueTestGitDir(bare);
112
		FileRepository db = new FileRepository(gitdir);
113
		Assert.assertFalse(gitdir.exists());
114
		db.create();
115
		toClose.add(db);
116
		return db;
117
	}
118
119
	/**
120
	 * Creates a new unique directory for a test repository
121
	 *
122
	 * @param bare
123
	 *            true for a bare repository; false for a repository with a
124
	 *            working directory
125
	 * @return a unique directory for a test repository
126
	 * @throws IOException
127
	 */
128
	protected File createUniqueTestGitDir(boolean bare) throws IOException {
129
		String gitdirName = createUniqueTestFolderPrefix();
130
		if (!bare)
131
			gitdirName += "/";
132
		gitdirName += Constants.DOT_GIT;
133
		File gitdir = new File(trash, gitdirName);
134
		return gitdir.getCanonicalFile();
135
	}
136
137
	private String createUniqueTestFolderPrefix() {
138
		return "test" + (System.currentTimeMillis() + "_" + (testCount++));
139
	}
140
}

Return to bug 378047