summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJonathan Nieder2013-05-24 19:57:10 (EDT)
committer Jonathan Nieder2013-05-24 19:57:10 (EDT)
commita544ff72dbf62671d2530f4cfca0e8f9dd693d78 (patch)
treea1e218715829d52bf90fe5823b6a0905fb268173
parentcfc15dd9dce2252baad9dc8ce0828203a205c2cf (diff)
downloadjgit-a544ff72dbf62671d2530f4cfca0e8f9dd693d78.zip
jgit-a544ff72dbf62671d2530f4cfca0e8f9dd693d78.tar.gz
jgit-a544ff72dbf62671d2530f4cfca0e8f9dd693d78.tar.bz2
Remove dependency by ArchiveCommand on archive formatsrefs/changes/63/12563/4
Provide static registerFormat and unregisterFormat methods to allow formats to register themselves without the ArchiveCommand code being aware of them. Register the basic "zip" and "tar" support at bundle activation time (and deregister them when unloading the bundle). For anyone using this code as an OSGi plugin it should continue to just work. The jgit program does not load org.eclipse.jgit.pgm as an OSGi bundle, so let the Archive command register the formats it uses explicitly with registerFormat. Change-Id: Id39c03ea6923d0aed8316ed7b6bd04d5ced570a7
-rw-r--r--org.eclipse.jgit.pgm/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.jgit.pgm/pom.xml5
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java7
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java40
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/FormatActivator.java58
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java2
-rw-r--r--pom.xml7
10 files changed, 123 insertions, 6 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
index a6e5e21..a26e4b4 100644
--- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
@@ -34,8 +34,10 @@ Import-Package: org.apache.commons.compress.archivers;version="[1.3,2.0)",
org.eclipse.jgit.util;version="[3.0.0,3.1.0)",
org.eclipse.jgit.util.io;version="[3.0.0,3.1.0)",
org.kohsuke.args4j;version="[2.0.12,2.1.0)",
- org.kohsuke.args4j.spi;version="[2.0.12,2.1.0)"
+ org.kohsuke.args4j.spi;version="[2.0.12,2.1.0)",
+ org.osgi.framework;version="[4.0,5.0)"
Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.jgit.pgm.archive.FormatActivator
Export-Package: org.eclipse.jgit.pgm;version="3.0.0";
uses:="org.eclipse.jgit.lib,
org.eclipse.jgit.nls,
diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml
index b51019c..fe1c3b2 100644
--- a/org.eclipse.jgit.pgm/pom.xml
+++ b/org.eclipse.jgit.pgm/pom.xml
@@ -87,6 +87,11 @@
<artifactId>org.eclipse.jgit.ui</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
</dependencies>
<profiles>
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
index 3fa167e..4a15481 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
@@ -7,6 +7,8 @@ N=N
alreadyOnBranch=Already on ''{0}''
alreadyUpToDate=Already up-to-date.
+archiveFormatAlreadyRegistered=Archive format already registered: {0}
+archiveFormatAlreadyAbsent=Archive format already absent: {0}
authorInfo=Author: {0} <{1}>
averageMSPerRead=average {0} ms/read
branchAlreadyExists=A branch named ''{0}'' already exists.
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
index 6d4f5aa..06f6f40 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
@@ -47,12 +47,19 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.pgm.TextBuiltin;
import org.eclipse.jgit.pgm.archive.ArchiveCommand;
+import org.eclipse.jgit.pgm.archive.TarFormat;
+import org.eclipse.jgit.pgm.archive.ZipFormat;
import org.eclipse.jgit.pgm.internal.CLIText;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_archive")
class Archive extends TextBuiltin {
+ static {
+ ArchiveCommand.registerFormat("tar", new TarFormat());
+ ArchiveCommand.registerFormat("zip", new ZipFormat());
+ }
+
@Argument(index = 0, metaVar = "metaVar_treeish")
private ObjectId tree;
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
index 437c613..5e57237 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
@@ -71,24 +71,28 @@ import org.eclipse.jgit.treewalk.TreeWalk;
* Create a tarball from HEAD:
*
* <pre>
+ * ArchiveCommand.registerFormat("tar", new TarFormat());
* cmd = new ArchiveCommand(git.getRepository());
* try {
* cmd.setTree(db.resolve(&quot;HEAD&quot;))
* .setOutputStream(out).call();
* } finally {
* cmd.release();
+ * ArchiveCommand.unregisterFormat("tar");
* }
* </pre>
* <p>
* Create a ZIP file from master:
*
* <pre>
+ * ArchiveCommand.registerFormat("zip", new ZipFormat());
* try {
* cmd.setTree(db.resolve(&quot;master&quot;))
* .setFormat("zip")
* .setOutputStream(out).call();
* } finally {
* cmd.release();
+ * ArchiveCommand.unregisterFormat("zip");
* }
* </pre>
*
@@ -150,9 +154,39 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
private static final ConcurrentMap<String, Format<?>> formats =
new ConcurrentHashMap<String, Format<?>>();
- static {
- formats.put("zip", new ZipFormat());
- formats.put("tar", new TarFormat());
+ /**
+ * Adds support for an additional archival format. To avoid
+ * unnecessary dependencies, ArchiveCommand does not have support
+ * for any formats built in; use this function to add them.
+ *
+ * OSGi plugins providing formats should call this function at
+ * bundle activation time.
+ *
+ * @param name name of a format (e.g., "tar" or "zip").
+ * @param fmt archiver for that format
+ * @throws JGitInternalException
+ * An archival format with that name was already registered.
+ */
+ public static void registerFormat(String name, Format<?> fmt) {
+ if (formats.putIfAbsent(name, fmt) != null)
+ throw new JGitInternalException(MessageFormat.format(
+ CLIText.get().archiveFormatAlreadyRegistered,
+ name));
+ }
+
+ /**
+ * Removes support for an archival format so its Format can be
+ * garbage collected.
+ *
+ * @param name name of format (e.g., "tar" or "zip").
+ * @throws JGitInternalException
+ * No such archival format was registered.
+ */
+ public static void unregisterFormat(String name) {
+ if (formats.remove(name) == null)
+ throw new JGitInternalException(MessageFormat.format(
+ CLIText.get().archiveFormatAlreadyAbsent,
+ name));
}
private static Format<?> lookupFormat(String formatName) throws UnsupportedFormatException {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/FormatActivator.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/FormatActivator.java
new file mode 100644
index 0000000..4889faf
--- /dev/null
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/FormatActivator.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013 Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.pgm.archive;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class FormatActivator implements BundleActivator {
+ public void start(BundleContext context) throws Exception {
+ ArchiveCommand.registerFormat("tar", new TarFormat());
+ ArchiveCommand.registerFormat("zip", new ZipFormat());
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ ArchiveCommand.unregisterFormat("zip");
+ ArchiveCommand.unregisterFormat("tar");
+ }
+}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
index 5225259..55f6ca9 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
@@ -52,7 +52,7 @@ import org.apache.commons.compress.archivers.tar.TarConstants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
-class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+public class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
return new TarArchiveOutputStream(s);
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
index d264161..a23cc9f 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
@@ -51,7 +51,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
-class ZipFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
+public class ZipFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
return new ZipArchiveOutputStream(s);
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
index 937707b..b5580bf 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
@@ -76,6 +76,8 @@ public class CLIText extends TranslationBundle {
// @formatter:off
/***/ public String alreadyOnBranch;
/***/ public String alreadyUpToDate;
+ /***/ public String archiveFormatAlreadyRegistered;
+ /***/ public String archiveFormatAlreadyAbsent;
/***/ public String authorInfo;
/***/ public String averageMSPerRead;
/***/ public String branchAlreadyExists;
diff --git a/pom.xml b/pom.xml
index ee1e45f..76ba5c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,6 +182,7 @@
<!-- TODO: update Maven dependency for args4j to 2.0.21 as soon as available on Maven Central -->
<args4j-version>2.0.12</args4j-version>
<commons-compress-version>1.4.1</commons-compress-version>
+ <osgi-core-version>4.3.1</osgi-core-version>
<servlet-api-version>2.5</servlet-api-version>
<jetty-version>7.6.0.v20120127</jetty-version>
<clirr-version>2.4</clirr-version>
@@ -441,6 +442,12 @@
<artifactId>jetty-servlet</artifactId>
<version>${jetty-version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi-core-version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>