git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>,
	Marek Zawirski <marek.zawirski@gmail.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 7/8] Pack jgit into a portable single file command line utility
Date: Mon, 30 Jun 2008 23:04:04 -0400	[thread overview]
Message-ID: <1214881445-3931-8-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1214881445-3931-7-git-send-email-spearce@spearce.org>

On UNIX (and even Cygwin) we can package the entire jgit library into
a single JAR file and prefix that JAR with a shell script to start the
JVM, passing in the script/JAR file as the only classpath.  This trick
works because the table of contents for the ZIP file is at the end of
the stream, and the JVM tends to only do random access through that
table when it looks up classes for loading.

A tiny shell script called make_jgit.sh compiles everything with the
command line javac and packages it into the portable jgit shell
script, making it possible to build and use jgit without touching
either Eclipse or Maven.

Currently this is quite easy to implement as we have only one support
library (JSch), but things may get more complicated if we add another
JAR to our classpath.

With this I can install JGit into my personal account and make use
of it on a daily basis from the command line:

	./make_jgit.sh
	mv jgit ~/bin
	jgit push ...

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .gitignore   |    1 +
 jgit         |   37 -------------------------------------
 jgit.sh      |   45 +++++++++++++++++++++++++++++++++++++++++++++
 make_jgit.sh |   26 ++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 37 deletions(-)
 create mode 100644 .gitignore
 delete mode 100755 jgit
 create mode 100755 jgit.sh
 create mode 100755 make_jgit.sh

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0763732
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/jgit
diff --git a/jgit b/jgit
deleted file mode 100755
index be7df7e..0000000
--- a/jgit
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-jgit_home=`dirname $0`
-cp="$jgit_home/org.spearce.jgit/bin"
-cp="$cp:$jgit_home/org.spearce.jgit/lib/jsch-0.1.37.jar"
-unset jgit_home
-java_args=
-
-# Cleanup paths for Cygwin.
-#
-case "`uname`" in
-CYGWIN*)
-	cp=`cygpath --windows --mixed --path "$cp"`
-	;;
-Darwin)
-	if test -e /System/Library/Frameworks/JavaVM.framework
-	then
-		java_args='
-			-Dcom.apple.mrj.application.apple.menu.about.name=JGit
-			-Dcom.apple.mrj.application.growbox.intrudes=false
-			-Dapple.laf.useScreenMenuBar=true
-			-Xdock:name=JGit
-		'
-	fi
-	;;
-esac
-
-CLASSPATH="$cp"
-export CLASSPATH
-
-java=java
-if test -n "$JAVA_HOME"
-then
-	java="$JAVA_HOME/bin/java"
-fi
-
-exec "$java" $java_args org.spearce.jgit.pgm.Main "$@"
diff --git a/jgit.sh b/jgit.sh
new file mode 100755
index 0000000..84927bc
--- /dev/null
+++ b/jgit.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+if [ "@@use_self@@" = "1" ]
+then
+	this_script=`which "$0" 2>/dev/null`
+	[ $? -gt 0 -a -f "$0" ] && this_script="$0"
+	cp=$this_script
+else
+	jgit_home=`dirname $0`
+	cp="$jgit_home/org.spearce.jgit/bin"
+	cp="$cp:$jgit_home/org.spearce.jgit/lib/jsch-0.1.37.jar"
+	unset jgit_home
+	java_args=
+fi
+
+# Cleanup paths for Cygwin.
+#
+case "`uname`" in
+CYGWIN*)
+	cp=`cygpath --windows --mixed --path "$cp"`
+	;;
+Darwin)
+	if test -e /System/Library/Frameworks/JavaVM.framework
+	then
+		java_args='
+			-Dcom.apple.mrj.application.apple.menu.about.name=JGit
+			-Dcom.apple.mrj.application.growbox.intrudes=false
+			-Dapple.laf.useScreenMenuBar=true
+			-Xdock:name=JGit
+		'
+	fi
+	;;
+esac
+
+CLASSPATH="$cp"
+export CLASSPATH
+
+java=java
+if test -n "$JAVA_HOME"
+then
+	java="$JAVA_HOME/bin/java"
+fi
+
+exec "$java" $java_args org.spearce.jgit.pgm.Main "$@"
+exit 1
diff --git a/make_jgit.sh b/make_jgit.sh
new file mode 100755
index 0000000..3889dca
--- /dev/null
+++ b/make_jgit.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+PATH=$JAVA_HOME/bin:$PATH
+O=jgit
+T=".temp$$.$O"
+
+rm -f $O
+rm -rf $T $O+ org.spearce.jgit/bin2
+cp org.spearce.jgit/lib/jsch-0.1.37.jar $T &&
+mkdir org.spearce.jgit/bin2 &&
+(cd org.spearce.jgit/src &&
+ find . -name \*.java -type f |
+ xargs javac \
+	-source 1.5 \
+	-target 1.5 \
+	-g \
+	-d ../bin2 \
+	-cp ../lib/jsch-0.1.37.jar) &&
+jar uf $T -C org.spearce.jgit/bin2 . &&
+jar uf $T -C org.spearce.jgit META-INF &&
+sed s/@@use_self@@/1/ jgit.sh >$O+ &&
+cat $T >>$O+ &&
+chmod 555 $O+ &&
+mv $O+ $O &&
+echo "Created $O." &&
+rm -rf $T $O+ org.spearce.jgit/bin2
-- 
1.5.6.74.g8a5e

  reply	other threads:[~2008-07-01  3:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01  3:03 [JGIT PATCH 0/8] Minor push fixups Shawn O. Pearce
2008-07-01  3:03 ` [JGIT PATCH 1/8] Correct thin pack completion in IndexPack to handle some bundles Shawn O. Pearce
2008-07-01  3:03   ` [JGIT PATCH 2/8] Delete reflog when deleting ref during dumb transport push Shawn O. Pearce
2008-07-01  3:04     ` [JGIT PATCH 3/8] Refuse to create or delete funny ref names over dumb transports Shawn O. Pearce
2008-07-01  3:04       ` [JGIT PATCH 4/8] Shorten progress message text from PackWriter Shawn O. Pearce
2008-07-01  3:04         ` [JGIT PATCH 5/8] Correctly name the stderr redirection thread for local transport Shawn O. Pearce
2008-07-01  3:04           ` [JGIT PATCH 6/8] Support 'git upload-pack' and 'git receive-pack' over SSH Shawn O. Pearce
2008-07-01  3:04             ` Shawn O. Pearce [this message]
2008-07-01  3:04               ` [JGIT PATCH 8/8] Don't try to pack 0{40} during push of delete and update Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1214881445-3931-8-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=marek.zawirski@gmail.com \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).