aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2012-04-23 10:53:41 (EDT)
committerJohn Arthorne2012-04-24 16:26:34 (EDT)
commit8e55c0a9b0932fee65c21ed9ba1ff0d74a024d82 (patch)
treee5b9c67f8fe55d2297cc271cd041849331a6a62b
parent025e6c3821d1b2f2ff31335ace33ff2792d8c512 (diff)
downloadeclipse.platform.releng-8e55c0a9b0932fee65c21ed9ba1ff0d74a024d82.zip
eclipse.platform.releng-8e55c0a9b0932fee65c21ed9ba1ff0d74a024d82.tar.gz
eclipse.platform.releng-8e55c0a9b0932fee65c21ed9ba1ff0d74a024d82.tar.bz2
bug 345669: Ensure Copyright Checker/Updater works with Gitv20120424-2026
-rw-r--r--bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF5
-rw-r--r--bundles/org.eclipse.releng.tools/plugin.xml7
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapter.java100
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapterFactory.java48
4 files changed, 159 insertions, 1 deletions
diff --git a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
index 951ee8e..43facd8 100644
--- a/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.releng.tools/META-INF/MANIFEST.MF
@@ -21,8 +21,11 @@ Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
org.eclipse.team.core,
org.eclipse.team.ui,
org.eclipse.compare,
- org.eclipse.ui.console
+ org.eclipse.ui.console,
+ org.eclipse.jgit;bundle-version="1.3.0";resolution:=optional,
+ org.eclipse.egit.core;bundle-version="1.3.0";resolution:=optional
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Export-Package: org.eclipse.releng.tools,
+ org.eclipse.releng.tools.git;x-friends:="org.eclipse.releng.tests",
org.eclipse.releng.tools.preferences
diff --git a/bundles/org.eclipse.releng.tools/plugin.xml b/bundles/org.eclipse.releng.tools/plugin.xml
index 0454c6c..66fd312 100644
--- a/bundles/org.eclipse.releng.tools/plugin.xml
+++ b/bundles/org.eclipse.releng.tools/plugin.xml
@@ -145,6 +145,13 @@
type="org.eclipse.releng.tools.IRepositoryProviderCopyrightAdapterFactory">
</adapter>
</factory>
+ <factory
+ adaptableType="org.eclipse.egit.core.internal.GitRepositoryProviderType"
+ class="org.eclipse.releng.tools.git.GitCopyrightAdapterFactory">
+ <adapter
+ type="org.eclipse.releng.tools.IRepositoryProviderCopyrightAdapterFactory">
+ </adapter>
+ </factory>
</extension>
</plugin>
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapter.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapter.java
new file mode 100644
index 0000000..6c0c40d
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapter.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2010 AGETO Service GmbH 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:
+ * IBM Corporation - initial API and implementation of CVS adapter
+ * Gunnar Wagenknecht - initial API and implementation of Git adapter
+ * IBM Corporation - ongoing maintenance
+ *******************************************************************************/
+package org.eclipse.releng.tools.git;
+
+import java.io.IOException;
+import java.util.Calendar;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.releng.tools.RelEngPlugin;
+import org.eclipse.releng.tools.RepositoryProviderCopyrightAdapter;
+
+public class GitCopyrightAdapter extends RepositoryProviderCopyrightAdapter {
+
+ private static String filterString = "copyright"; // lowercase //$NON-NLS-1$
+
+ public GitCopyrightAdapter(IResource[] resources) {
+ super(resources);
+ }
+
+ public int getLastModifiedYear(IFile file, IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ monitor.beginTask("Fetching logs from Git", 100); //$NON-NLS-1$
+ final RepositoryMapping mapping = RepositoryMapping
+ .getMapping(file);
+ if (mapping != null) {
+ final Repository repo = mapping.getRepository();
+ if (repo != null) {
+ RevWalk walk = null;
+ try {
+ final ObjectId start = repo.resolve(Constants.HEAD);
+ walk = new RevWalk(repo);
+ walk.setTreeFilter(AndTreeFilter.create(PathFilter
+ .create(mapping.getRepoRelativePath(file)),
+ TreeFilter.ANY_DIFF));
+ walk.markStart(walk.lookupCommit(start));
+ final RevCommit commit = walk.next();
+ if (commit != null) {
+ if (filterString != null
+ && commit.getFullMessage().toLowerCase()
+ .indexOf(filterString) != -1) {
+ // the last update was a copyright checkin -
+ // ignore
+ return 0;
+ }
+ final Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(0);
+ calendar.add(Calendar.SECOND,
+ commit.getCommitTime());
+ return calendar.get(Calendar.YEAR);
+ }
+ } catch (final IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ RelEngPlugin.ID, 0, NLS.bind(
+ "An error occured when processing {0}",
+ file.getName()), e));
+ } finally {
+ if (walk != null)
+ walk.release();
+ }
+ }
+ }
+ } finally {
+ monitor.done();
+ }
+ return -1;
+ }
+
+ public void initialize(IProgressMonitor monitor) throws CoreException {
+ // TODO We should perform a bulk "log" command to get the last modified
+ // year
+ }
+
+}
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapterFactory.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapterFactory.java
new file mode 100644
index 0000000..1a3b034
--- /dev/null
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/git/GitCopyrightAdapterFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2010 AGETO Service GmbH 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:
+ * Gunnar Wagenknecht - initial API and implementation
+ * IBM Corporation - ongoing maintenance
+ *******************************************************************************/
+package org.eclipse.releng.tools.git;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.releng.tools.IRepositoryProviderCopyrightAdapterFactory;
+import org.eclipse.releng.tools.RepositoryProviderCopyrightAdapter;
+import org.eclipse.team.core.RepositoryProviderType;
+
+public class GitCopyrightAdapterFactory implements IAdapterFactory,
+ IRepositoryProviderCopyrightAdapterFactory {
+
+ private static final Class[] ADAPTER_LIST = new Class[] { IRepositoryProviderCopyrightAdapterFactory.class };
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (IRepositoryProviderCopyrightAdapterFactory.class
+ .equals(adapterType)) {
+ return getGitCopyrightAdapter(adaptableObject);
+ }
+ return null;
+ }
+
+ private Object getGitCopyrightAdapter(Object adaptableObject) {
+ if (!(adaptableObject instanceof RepositoryProviderType))
+ return null;
+ return this;
+ }
+
+ public Class[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public RepositoryProviderCopyrightAdapter createAdapater(
+ IResource[] resources) {
+ return new GitCopyrightAdapter(resources);
+ }
+}