git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 2/3] Build jgit.jar and jgit_src.zip alongside jgit CLI wrapper

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 2, 2008, 16:28 UTC
Message-ID
<1220372892-15423-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1220372892-15423-1-git-send-email-spearce@spearce.org>

When we build jgit the CLI executable we have the classes already compiled so we can easily construct a jgit.jar and jgit_src.zip at the same time. This makes it easier for folks who need the library and not the command line interface package.

We do not include JSch in jgit.jar as we assume the downstream user can supply us the package. In an IDE scenario it is quite likely the IDE already has a copy of JSch available for use, so we really don't want to supply our own and potentially put two different versions on the classpath.

The version we embed within our JAR manifest is now more like the dotted format used by C Git or git-gui. In particular we embed the "-dirty" suffix if the tree contains modifications.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .gitignore   |    2 ++
 make_jgit.sh |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0763732..baf2766 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 /jgit
+/jgit.jar
+/jgit_src.zip
diff --git a/make_jgit.sh b/make_jgit.sh
index c119202..a15f73f 100755
--- a/make_jgit.sh
+++ b/make_jgit.sh
@@ -1,6 +1,9 @@
 #!/bin/sh
 
-O=jgit
+O_CLI=jgit
+O_JAR=jgit.jar
+O_SRC=jgit_src.zip
+
 PLUGINS="
 	org.spearce.jgit
 	org.spearce.jgit.pgm
@@ -11,7 +14,7 @@ JARS="
 "
 
 PSEP=":"
-T=".temp$$.$O"
+T=".temp$$.$O_CLI"
 T_MF="$T.MF"
 R=`pwd`
 if [ "$OSTYPE" = "cygwin" ]
@@ -30,7 +33,7 @@ then
 fi
 
 cleanup_bin() {
-	rm -f $T $O+ $T_MF
+	rm -f $T $O_CLI+ $O_JAR+ $O_SRC+ $T_MF
 	for p in $PLUGINS
 	do
 		rm -rf $p/bin2
@@ -39,13 +42,21 @@ cleanup_bin() {
 
 die() {
 	cleanup_bin
-	rm -f $O
+	rm -f $O_CLI $O_JAR $O_SRC
 	echo >&2 "$@"
 	exit 1
 }
 
 cleanup_bin
-rm -f $O
+rm -f $O_CLI $O_JAR $O_SRC
+
+VN=`git describe --abbrev=4 HEAD 2>/dev/null`
+git update-index -q --refresh
+if [ -n "`git diff-index --name-only HEAD --`" ]
+then
+	VN="$VN-dirty"
+fi
+VN=`echo "$VN" | sed -e s/-/./g`
 
 CLASSPATH=
 for j in $JARS
@@ -73,20 +84,39 @@ do
 		-d ../bin2) || die "Building $p failed."
 	CLASSPATH="${CLASSPATH}${PSEP}$R/$p/bin2"
 done
+echo
 
+echo "Version $VN" &&
 echo Manifest-Version: 1.0 >$T_MF &&
 echo Implementation-Title: jgit >>$T_MF &&
-echo Implementation-Version: `git describe HEAD` >>$T_MF &&
+echo Implementation-Version: $VN >>$T_MF &&
+
+java org.spearce.jgit.pgm.build.JarLinkUtil \
+	-include org.spearce.jgit/bin2 \
+	-file META-INF/MANIFEST.MF=$T_MF \
+	>$O_JAR+ &&
+chmod 555 $O_JAR+ &&
+mv $O_JAR+ $O_JAR &&
+echo "Created $O_JAR." &&
+
+java org.spearce.jgit.pgm.build.JarLinkUtil \
+	-include org.spearce.jgit/src \
+	-file META-INF/MANIFEST.MF=$T_MF \
+	>$O_SRC+ &&
+chmod 555 $O_SRC+ &&
+mv $O_SRC+ $O_SRC &&
+echo "Created $O_SRC." &&
 
-sed s/@@use_self@@/1/ jgit.sh >$O+ &&
+M_TB=META-INF/services/org.spearce.jgit.pgm.TextBuiltin &&
+sed s/@@use_self@@/1/ jgit.sh >$O_CLI+ &&
 java org.spearce.jgit.pgm.build.JarLinkUtil \
 	`for p in $JARS   ; do printf %s " -include $p"     ;done` \
 	`for p in $PLUGINS; do printf %s " -include $p/bin2";done` \
-	-file META-INF/services/org.spearce.jgit.pgm.TextBuiltin=org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin \
+	-file $M_TB=org.spearce.jgit.pgm/src/$M_TB \
 	-file META-INF/MANIFEST.MF=$T_MF \
-	>>$O+ &&
-chmod 555 $O+ &&
-mv $O+ $O &&
-echo "Created $O." || die "Creating $O failed."
+	>>$O_CLI+ &&
+chmod 555 $O_CLI+ &&
+mv $O_CLI+ $O_CLI &&
+echo "Created $O_CLI." || die "Build failed."
 
 cleanup_bin
-- 
1.6.0.1.207.g020e5
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 3 in “Make all files in our JAR have the same timestamp”
  1. 1/3 Make all files in our JAR have the same timestampShawn O. Pearce, Sep 2, 2008
  2. 2/3 Build jgit.jar and jgit_src.zip alongside jgit CLI wrapperShawn O. Pearce, Sep 2, 2008
  3. 3/3 Add a tiny "jgit version" programShawn O. Pearce, Sep 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.