From 5b89088f877fdc52d6e5de23be47da940838e4df Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 31 Oct 2009 18:47:16 -0700 Subject: Switch pgm, test to proper plugin projects This way we depend upon the MANIFEST.MF to define our classpath and our build will act more like any other OSGI bundle build. Change-Id: I9e1f1f5a0bccb0ab0e39e49b75fb400fea446619 Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.pgm/.classpath | 4 +-- org.eclipse.jgit.pgm/.project | 11 ++++++++ .../.settings/org.eclipse.pde.core.prefs | 3 +++ org.eclipse.jgit.pgm/META-INF/MANIFEST.MF | 22 +++++++++++++++ .../services/org.eclipse.jgit.pgm.TextBuiltin | 31 ++++++++++++++++++++++ org.eclipse.jgit.pgm/build.properties | 5 ++++ org.eclipse.jgit.pgm/plugin.properties | 2 ++ .../services/org.eclipse.jgit.pgm.TextBuiltin | 31 ---------------------- org.eclipse.jgit.test/.classpath | 1 - org.eclipse.jgit.test/META-INF/MANIFEST.MF | 17 +++++++++++- 10 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 org.eclipse.jgit.pgm/.settings/org.eclipse.pde.core.prefs create mode 100644 org.eclipse.jgit.pgm/META-INF/MANIFEST.MF create mode 100644 org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin create mode 100644 org.eclipse.jgit.pgm/build.properties create mode 100644 org.eclipse.jgit.pgm/plugin.properties delete mode 100644 org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin diff --git a/org.eclipse.jgit.pgm/.classpath b/org.eclipse.jgit.pgm/.classpath index 058848cf20..304e86186a 100644 --- a/org.eclipse.jgit.pgm/.classpath +++ b/org.eclipse.jgit.pgm/.classpath @@ -2,8 +2,6 @@ - - - + diff --git a/org.eclipse.jgit.pgm/.project b/org.eclipse.jgit.pgm/.project index bbaafc2612..6fc89ae5e6 100644 --- a/org.eclipse.jgit.pgm/.project +++ b/org.eclipse.jgit.pgm/.project @@ -10,8 +10,19 @@ + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature diff --git a/org.eclipse.jgit.pgm/.settings/org.eclipse.pde.core.prefs b/org.eclipse.jgit.pgm/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..75c779a483 --- /dev/null +++ b/org.eclipse.jgit.pgm/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +#Sat Oct 31 18:40:07 PDT 2009 +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5100d140a5 --- /dev/null +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin_name +Bundle-SymbolicName: org.eclipse.jgit.pgm +Bundle-Version: 0.6.0.qualifier +Bundle-Vendor: %provider_name +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: org.eclipse.jgit.awtui, + org.eclipse.jgit.dircache, + org.eclipse.jgit.errors, + org.eclipse.jgit.lib, + org.eclipse.jgit.revplot, + org.eclipse.jgit.revwalk, + org.eclipse.jgit.revwalk.filter, + org.eclipse.jgit.transport, + org.eclipse.jgit.treewalk, + org.eclipse.jgit.treewalk.filter, + org.kohsuke.args4j, + org.kohsuke.args4j.spi +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.jgit.pgm diff --git a/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin new file mode 100644 index 0000000000..6c2a653066 --- /dev/null +++ b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin @@ -0,0 +1,31 @@ +org.eclipse.jgit.pgm.AmazonS3Client +org.eclipse.jgit.pgm.Branch +org.eclipse.jgit.pgm.Clone +org.eclipse.jgit.pgm.Daemon +org.eclipse.jgit.pgm.DiffTree +org.eclipse.jgit.pgm.Fetch +org.eclipse.jgit.pgm.Glog +org.eclipse.jgit.pgm.IndexPack +org.eclipse.jgit.pgm.Init +org.eclipse.jgit.pgm.Log +org.eclipse.jgit.pgm.LsRemote +org.eclipse.jgit.pgm.LsTree +org.eclipse.jgit.pgm.MergeBase +org.eclipse.jgit.pgm.Push +org.eclipse.jgit.pgm.ReceivePack +org.eclipse.jgit.pgm.RevList +org.eclipse.jgit.pgm.RevParse +org.eclipse.jgit.pgm.Rm +org.eclipse.jgit.pgm.ShowRev +org.eclipse.jgit.pgm.ShowRef +org.eclipse.jgit.pgm.Tag +org.eclipse.jgit.pgm.UploadPack +org.eclipse.jgit.pgm.Version + +org.eclipse.jgit.pgm.debug.MakeCacheTree +org.eclipse.jgit.pgm.debug.ReadDirCache +org.eclipse.jgit.pgm.debug.RebuildCommitGraph +org.eclipse.jgit.pgm.debug.ShowCacheTree +org.eclipse.jgit.pgm.debug.ShowCommands +org.eclipse.jgit.pgm.debug.ShowDirCache +org.eclipse.jgit.pgm.debug.WriteDirCache diff --git a/org.eclipse.jgit.pgm/build.properties b/org.eclipse.jgit.pgm/build.properties new file mode 100644 index 0000000000..aa1a008269 --- /dev/null +++ b/org.eclipse.jgit.pgm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.jgit.pgm/plugin.properties b/org.eclipse.jgit.pgm/plugin.properties new file mode 100644 index 0000000000..f8fbd725c1 --- /dev/null +++ b/org.eclipse.jgit.pgm/plugin.properties @@ -0,0 +1,2 @@ +plugin_name=Java Git Command Line Interface (Incubation) +provider_name=eclipse.org diff --git a/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin b/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin deleted file mode 100644 index 6c2a653066..0000000000 --- a/org.eclipse.jgit.pgm/src/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin +++ /dev/null @@ -1,31 +0,0 @@ -org.eclipse.jgit.pgm.AmazonS3Client -org.eclipse.jgit.pgm.Branch -org.eclipse.jgit.pgm.Clone -org.eclipse.jgit.pgm.Daemon -org.eclipse.jgit.pgm.DiffTree -org.eclipse.jgit.pgm.Fetch -org.eclipse.jgit.pgm.Glog -org.eclipse.jgit.pgm.IndexPack -org.eclipse.jgit.pgm.Init -org.eclipse.jgit.pgm.Log -org.eclipse.jgit.pgm.LsRemote -org.eclipse.jgit.pgm.LsTree -org.eclipse.jgit.pgm.MergeBase -org.eclipse.jgit.pgm.Push -org.eclipse.jgit.pgm.ReceivePack -org.eclipse.jgit.pgm.RevList -org.eclipse.jgit.pgm.RevParse -org.eclipse.jgit.pgm.Rm -org.eclipse.jgit.pgm.ShowRev -org.eclipse.jgit.pgm.ShowRef -org.eclipse.jgit.pgm.Tag -org.eclipse.jgit.pgm.UploadPack -org.eclipse.jgit.pgm.Version - -org.eclipse.jgit.pgm.debug.MakeCacheTree -org.eclipse.jgit.pgm.debug.ReadDirCache -org.eclipse.jgit.pgm.debug.RebuildCommitGraph -org.eclipse.jgit.pgm.debug.ShowCacheTree -org.eclipse.jgit.pgm.debug.ShowCommands -org.eclipse.jgit.pgm.debug.ShowDirCache -org.eclipse.jgit.pgm.debug.WriteDirCache diff --git a/org.eclipse.jgit.test/.classpath b/org.eclipse.jgit.test/.classpath index 3c42728dbf..ea41285773 100644 --- a/org.eclipse.jgit.test/.classpath +++ b/org.eclipse.jgit.test/.classpath @@ -4,7 +4,6 @@ - diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 8c89f045cf..225611ba9b 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -9,4 +9,19 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.jcraft.jsch, junit.framework, - junit.textui + junit.textui, + org.eclipse.jgit.diff, + org.eclipse.jgit.dircache, + org.eclipse.jgit.errors, + org.eclipse.jgit.fnmatch, + org.eclipse.jgit.lib, + org.eclipse.jgit.merge, + org.eclipse.jgit.patch, + org.eclipse.jgit.revplot, + org.eclipse.jgit.revwalk, + org.eclipse.jgit.revwalk.filter, + org.eclipse.jgit.transport, + org.eclipse.jgit.treewalk, + org.eclipse.jgit.treewalk.filter, + org.eclipse.jgit.util, + org.eclipse.jgit.util.io -- cgit v1.2.3 From dad52baae835f28c7fc4b8cc184f8f6703433ac4 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 31 Oct 2009 18:07:26 -0700 Subject: Refactor our Maven build to be modular Drop our simple and stupid jgit.sh and instead rely upon Maven for the command line based build. Maven is relatively simple to download and install, and doesn't require the entire Eclipse IDE. To avoid too much refactoring of the current code we reuse the existing src/ directory within each plugin, and treat each of the existing OSGI bundles as one Maven artifact. The command line wrapper jgit.sh no longer works in the uncompiled state, as we don't know where to obtain our JSch or args4j from. Developers will now need to compile it with `mvn package`, or run our Main class from within an IDE which has the proper classpath. Bug: 291265 Change-Id: I355e95fa92fa7502651091d2b651be6917a26805 Signed-off-by: Shawn O. Pearce --- .gitignore | 6 - jgit-maven/.gitignore | 1 - jgit-maven/jgit/pom.xml | 226 ----------------------------- jgit.sh | 94 ------------ make_jgit.sh | 181 ----------------------- org.eclipse.jgit.pgm/.gitignore | 1 + org.eclipse.jgit.pgm/META-INF/MANIFEST.MF | 2 + org.eclipse.jgit.pgm/jgit.sh | 83 +++++++++++ org.eclipse.jgit.pgm/pom.xml | 170 ++++++++++++++++++++++ org.eclipse.jgit.test/.gitignore | 6 +- org.eclipse.jgit.test/pom.xml | 95 ++++++++++++ org.eclipse.jgit.ui/.gitignore | 1 + org.eclipse.jgit.ui/plugin.properties | 2 +- org.eclipse.jgit.ui/pom.xml | 95 ++++++++++++ org.eclipse.jgit/.gitignore | 3 +- org.eclipse.jgit/pom.xml | 95 ++++++++++++ pom.xml | 234 ++++++++++++++++++++++++++++++ 17 files changed, 782 insertions(+), 513 deletions(-) delete mode 100644 .gitignore delete mode 100644 jgit-maven/.gitignore delete mode 100644 jgit-maven/jgit/pom.xml delete mode 100644 jgit.sh delete mode 100644 make_jgit.sh create mode 100644 org.eclipse.jgit.pgm/jgit.sh create mode 100644 org.eclipse.jgit.pgm/pom.xml create mode 100644 org.eclipse.jgit.test/pom.xml create mode 100644 org.eclipse.jgit.ui/pom.xml create mode 100644 org.eclipse.jgit/pom.xml create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d73c6106c0..0000000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/jgit -/jgit.jar -/jgit_src.zip -/jgit_docs.zip -/org.eclipse.jgit/lib/jsch-*.jar -/org.eclipse.jgit.pgm/lib/args4j-*.jar diff --git a/jgit-maven/.gitignore b/jgit-maven/.gitignore deleted file mode 100644 index eb5a316cbd..0000000000 --- a/jgit-maven/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/jgit-maven/jgit/pom.xml b/jgit-maven/jgit/pom.xml deleted file mode 100644 index 5f30afbfb4..0000000000 --- a/jgit-maven/jgit/pom.xml +++ /dev/null @@ -1,226 +0,0 @@ - - - - - 4.0.0 - org.eclipse - jgit - jar - 0.6.0-SNAPSHOT - jgit - http://repo.or.cz/w/jgit.git - - - GIT Mailing List - git@vger.kernel.org - http://marc.info/?l=git - - - Pure Java implementation of Git - - - Shawn O. Pearce - spearce@spearce.org - - Maintainer - - - - Robin Rosenberg - robin.rosenberg@dewire.com - - Maintainer - - - - Dave Watson - dwatson@mimvista.com - - Developer - - - - Roger C. Soares - rogersoares@intelinet.com.br - - Developer - - - - Marek Zawirski - marek.zawirski@gmail.com - - Developer - - - - Charles O'Farrell - charleso@charleso.org - - Contributor - - - - Imran M Yousuf - imyousuf@smartitengineering.com - Smart IT Engineering - - Contributor - - - - - - Eclipse Distribution License (New BSD License) - - 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. - - - - - ../../org.eclipse.jgit/src/ - - - ../../org.eclipse.jgit.test/tst-rsrc/ - - - ../../org.eclipse.jgit.test/tst/ - - - maven-compiler-plugin - 2.0.2 - - 1.5 - 1.5 - UTF-8 - - - - maven-surefire-plugin - 2.4.2 - - - **/*Test.java - **/*TestCase.java - **/T000*.java - - - - - maven-source-plugin - - - - jar - - - - - - maven-javadoc-plugin - - - - jar - - - - - - - - - junit - junit - 3.8.1 - test - - - com.jcraft - jsch - 0.1.41 - compile - - - - - jgit-maven-snapshot-repository - JGit Maven Snapshot Repository - dav:https://egit.googlecode.com/svn/maven/snapshot-repository/ - true - - - diff --git a/jgit.sh b/jgit.sh deleted file mode 100644 index 76b582919c..0000000000 --- a/jgit.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/sh -# Copyright (C) 2008-2009, Google Inc. -# Copyright (C) 2008, Shawn O. Pearce -# 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. - - -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.eclipse.jgit/bin" - cp="$cp:$jgit_home/org.eclipse.jgit/lib/jsch-0.1.37.jar" - cp="$cp:$jgit_home/org.eclipse.jgit.pgm/bin" - cp="$cp:$jgit_home/org.eclipse.jgit.pgm/lib/args4j-2.0.9.jar" - unset jgit_home - java_args= -fi - -if [ -n "$JGIT_CLASSPATH" ] -then - cp="$cp:$JGIT_CLASSPATH" -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.eclipse.jgit.pgm.Main "$@" -exit 1 diff --git a/make_jgit.sh b/make_jgit.sh deleted file mode 100644 index f7363f9f4b..0000000000 --- a/make_jgit.sh +++ /dev/null @@ -1,181 +0,0 @@ -#!/bin/sh -# Copyright (C) 2009, Christian Halstrick -# Copyright (C) 2008-2009, Google Inc. -# Copyright (C) 2009, Johannes Schindelin -# Copyright (C) 2008, Mike Ralphson -# Copyright (C) 2009, Mykola Nikishov -# Copyright (C) 2009, Nicholas Campbell -# Copyright (C) 2009, Robin Rosenberg -# Copyright (C) 2008, Shawn O. Pearce -# 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. - - -O_CLI=jgit -O_JAR=jgit.jar -O_SRC=jgit_src.zip -O_DOC=jgit_docs.zip - -PLUGINS=" - org.eclipse.jgit - org.eclipse.jgit.ui - org.eclipse.jgit.pgm -" -JARS=" - org.eclipse.jgit/lib/jsch-0.1.37.jar - org.eclipse.jgit.pgm/lib/args4j-2.0.9.jar -" - -PSEP=":" -T=".temp$$.$O_CLI" -T_MF="$T.MF" -R=`pwd` -if [ "$OSTYPE" = "cygwin" ] -then - R=`cygpath -m $R` - PSEP=";" -fi -if [ "$MSYSTEM" = "MINGW" -o "$MSYSTEM" = "MINGW32" ] -then - PSEP=";" - R=`pwd -W` -fi - -if [ -n "$JAVA_HOME" ] -then - PATH=${JAVA_HOME}/bin${PSEP}${PATH} -fi - -cleanup_bin() { - rm -f $T $O_CLI+ $O_JAR+ $O_SRC+ $T_MF - for p in $PLUGINS - do - rm -rf $p/bin2 - done - rm -rf docs -} - -die() { - cleanup_bin - rm -f $O_CLI $O_JAR $O_SRC - echo >&2 "$@" - exit 1 -} - -cleanup_bin -rm -f $O_CLI $O_JAR $O_SRC $O_DOC - -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=${VN:-untagged}`echo "$VN" | sed -e s/-/./g` - -CLASSPATH= -for j in $JARS -do - if [ -z "$CLASSPATH" ] - then - CLASSPATH="$R/$j" - else - CLASSPATH="${CLASSPATH}${PSEP}$R/$j" - fi -done -export CLASSPATH - -for p in $PLUGINS -do - echo "Entering $p ..." - (cd $p/src && - mkdir ../bin2 && - find . -name \*.java -type f | - xargs javac \ - -source 1.5 \ - -target 1.5 \ - -encoding UTF-8 \ - -g \ - -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: $VN >>$T_MF && - -java org.eclipse.jgit.pgm.build.JarLinkUtil \ - -include org.eclipse.jgit/bin2 \ - -file META-INF/MANIFEST.MF=$T_MF \ - >$O_JAR+ && -mv $O_JAR+ $O_JAR && -echo "Created $O_JAR." && - -java org.eclipse.jgit.pgm.build.JarLinkUtil \ - -include org.eclipse.jgit/src \ - -file META-INF/MANIFEST.MF=$T_MF \ - >$O_SRC+ && -mv $O_SRC+ $O_SRC && -echo "Created $O_SRC." && - -M_TB=META-INF/services/org.eclipse.jgit.pgm.TextBuiltin && -sed s/@@use_self@@/1/ jgit.sh >$O_CLI+ && -java org.eclipse.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 $M_TB=org.eclipse.jgit.pgm/src/$M_TB \ - -file META-INF/MANIFEST.MF=$T_MF \ - >>$O_CLI+ && -chmod 555 $O_CLI+ && -mv $O_CLI+ $O_CLI && -echo "Created $O_CLI." || die "Build failed." - -echo "Building Javadocs ..." -for p in $PLUGINS; do - javadoc -quiet -sourcepath "$p/src/" -d "docs/$p/" \ - `find "$p/src" -name "*.java"` -done - -(cd docs && jar cf "../$O_DOC" .) -echo "Created $O_DOC." - -cleanup_bin diff --git a/org.eclipse.jgit.pgm/.gitignore b/org.eclipse.jgit.pgm/.gitignore index 5e56e040ec..934e0e06ff 100644 --- a/org.eclipse.jgit.pgm/.gitignore +++ b/org.eclipse.jgit.pgm/.gitignore @@ -1 +1,2 @@ /bin +/target diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index 5100d140a5..4d0bacc664 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -20,3 +20,5 @@ Import-Package: org.eclipse.jgit.awtui, org.kohsuke.args4j.spi Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.jgit.pgm +Main-Class: org.eclipse.jgit.pgm.Main +Implementation-Title: JGit Command Line Interface diff --git a/org.eclipse.jgit.pgm/jgit.sh b/org.eclipse.jgit.pgm/jgit.sh new file mode 100644 index 0000000000..e6a2119ef1 --- /dev/null +++ b/org.eclipse.jgit.pgm/jgit.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# Copyright (C) 2008-2009, Google Inc. +# Copyright (C) 2008, Shawn O. Pearce +# 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. + + +this_script=`which "$0" 2>/dev/null` +[ $? -gt 0 -a -f "$0" ] && this_script="$0" +cp=$this_script + +if [ -n "$JGIT_CLASSPATH" ] +then + cp="$cp:$JGIT_CLASSPATH" +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.eclipse.jgit.pgm.Main "$@" +exit 1 diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml new file mode 100644 index 0000000000..8f2312b85e --- /dev/null +++ b/org.eclipse.jgit.pgm/pom.xml @@ -0,0 +1,170 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit.pgm + JGit - Command Line Interface + + + Command line client tools built on top of JGit. + + + + + args4j + args4j + + + + org.eclipse.jgit + org.eclipse.jgit + + + + org.eclipse.jgit + org.eclipse.jgit.ui + + + + + src/ + + + + . + + META-INF/services/org.eclipse.jgit.pgm.TextBuiltin + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 1.2 + + + package + + shade + + + jgit-cli + false + + + + + org.eclipse.jgit.pgm.Main + JGit Command Line Interface + ${project.version} + + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.3 + + + create_jgit + package + + + + + + + + + + + run + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.3 + + + attach_jgit + package + + attach-artifact + + + + + ${basedir}/target/jgit + sh + + + + + + + + + diff --git a/org.eclipse.jgit.test/.gitignore b/org.eclipse.jgit.test/.gitignore index 9d7d1382b7..b5bbb0ab81 100644 --- a/org.eclipse.jgit.test/.gitignore +++ b/org.eclipse.jgit.test/.gitignore @@ -1,3 +1,3 @@ -bin -tst/todopack -trash +/bin +/target +/trash diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml new file mode 100644 index 0000000000..2eb8f9aa78 --- /dev/null +++ b/org.eclipse.jgit.test/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit.test + JGit - Core Tests + + + JUnit tests for the core library. + + + + + org.eclipse.jgit + org.eclipse.jgit + + + + + tst/ + + + + tst-rsrc/ + + + + + + maven-surefire-plugin + 2.4.2 + + + **/*Test.java + **/*TestCase.java + **/T000*.java + + + + + + diff --git a/org.eclipse.jgit.ui/.gitignore b/org.eclipse.jgit.ui/.gitignore index 5e56e040ec..934e0e06ff 100644 --- a/org.eclipse.jgit.ui/.gitignore +++ b/org.eclipse.jgit.ui/.gitignore @@ -1 +1,2 @@ /bin +/target diff --git a/org.eclipse.jgit.ui/plugin.properties b/org.eclipse.jgit.ui/plugin.properties index e6c6c08650..b9acc51512 100644 --- a/org.eclipse.jgit.ui/plugin.properties +++ b/org.eclipse.jgit.ui/plugin.properties @@ -1,2 +1,2 @@ -plugin_name=Java Git UI (Incubation) +plugin_name=Java Git AWT User Interface (Incubation) provider_name=eclipse.org diff --git a/org.eclipse.jgit.ui/pom.xml b/org.eclipse.jgit.ui/pom.xml new file mode 100644 index 0000000000..f77a143cb3 --- /dev/null +++ b/org.eclipse.jgit.ui/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit.ui + JGit - AWT User Interface + + + AWT/Swing based UI + + + + + org.eclipse.jgit + org.eclipse.jgit + + + + + src/ + + + + . + + plugin.properties + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + + + + + + diff --git a/org.eclipse.jgit/.gitignore b/org.eclipse.jgit/.gitignore index ba077a4031..934e0e06ff 100644 --- a/org.eclipse.jgit/.gitignore +++ b/org.eclipse.jgit/.gitignore @@ -1 +1,2 @@ -bin +/bin +/target diff --git a/org.eclipse.jgit/pom.xml b/org.eclipse.jgit/pom.xml new file mode 100644 index 0000000000..e0359398b0 --- /dev/null +++ b/org.eclipse.jgit/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit + JGit - Core + + + Repository access and algorithms + + + + + com.jcraft + jsch + + + + + src/ + + + + . + + plugin.properties + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..910b587167 --- /dev/null +++ b/pom.xml @@ -0,0 +1,234 @@ + + + + + 4.0.0 + + org.eclipse.jgit + jgit-parent + pom + 0.6.0-SNAPSHOT + + JGit - Parent + http://www.eclipse.org/egit/ + + + Pure Java implementation of Git + + + + + egit-dev Mailing List + egit-dev@eclipse.org + https://dev.eclipse.org/mailman/listinfo/egit-dev + https://dev.eclipse.org/mailman/listinfo/egit-dev + http://dev.eclipse.org/mhonarc/lists/egit-dev + + + + GIT Mailing List + git@vger.kernel.org + http://marc.info/?l=git + + + + + https://bugs.eclipse.org/bugs/ + Bugzilla + + + + + Eclipse Distribution License (New BSD License) + + 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. + + + + + + UTF-8 + UTF-8 + + + + + + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + UTF-8 + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + ${project.build.sourceEncoding} + true + + http://java.sun.com/j2se/1.5.0/docs/api + + + + + attach-javadocs + + jar + + + + + + + + + + junit + junit + test + + + + + + + + com.jcraft + jsch + 0.1.41 + + + + + args4j + args4j + 2.0.12 + + + + junit + junit + 3.8.1 + + + + org.eclipse.jgit + org.eclipse.jgit + ${project.version} + + + + org.eclipse.jgit + org.eclipse.jgit.ui + ${project.version} + + + + + + + jgit-maven-snapshot + JGit Maven Repository + dav:https://egit.googlecode.com/svn/maven/ + true + + + + + org.eclipse.jgit + org.eclipse.jgit.ui + org.eclipse.jgit.pgm + org.eclipse.jgit.test + + -- cgit v1.2.3 From a95198580f1cea5655a65b72d0986350144aa01e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 17:12:37 -0700 Subject: Delete obsolete JarLinkUtil Since we are now using the maven-shade-plugin to flatten out our dependencies into a single stand-alone JAR we no longer need to use our own command line utility. Change-Id: I057c782cc66c44f11ed2ff2b4b4ca9cc82c7426a Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/pgm/build/JarLinkUtil.java | 212 --------------------- 1 file changed, 212 deletions(-) delete mode 100644 org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/build/JarLinkUtil.java diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/build/JarLinkUtil.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/build/JarLinkUtil.java deleted file mode 100644 index e63f39c01e..0000000000 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/build/JarLinkUtil.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (C) 2008, Shawn O. Pearce - * 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.build; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import java.util.zip.ZipOutputStream; - -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.Option; -import org.kohsuke.args4j.spi.MapOptionHandler; - -/** - * Combines multiple JAR and directory sources into a single JAR file. - *

- * This is a crude command line utility to combine multiple JAR files into a - * single JAR file, without first needing to unpack the individual JARs. - *

- * The output ZIP stream is sent to standard out and can be redirected onto the - * end of a shell script which starts the JRE. - */ -public class JarLinkUtil { - /** - * Combine multiple JARs. - * - * @param argv - * the command line arguments indicating the files to pack. - * @throws IOException - * a source file could not be read. - */ - public static void main(final String[] argv) throws IOException { - final JarLinkUtil util = new JarLinkUtil(); - final CmdLineParser clp = new CmdLineParser(util); - try { - clp.parseArgument(argv); - } catch (CmdLineException e) { - clp.printSingleLineUsage(System.err); - System.exit(1); - } - util.run(); - } - - @Option(name = "-include", required = true) - private List includes = new ArrayList(); - - @Option(name = "-file", handler = MapOptionHandler.class) - private Map files = new HashMap(); - - private final Map chosenSources = new HashMap(); - - private long creationTime; - - private ZipOutputStream zos; - - private JarLinkUtil() { - // Command line utility only. - } - - private void run() throws IOException { - for (final File src : includes) { - if (src.isFile()) - scanJar(src); - else - scanDirectory(src, src, ""); - } - for (final Map.Entry e : files.entrySet()) - chosenSources.put(e.getKey(), new File(e.getValue())); - - creationTime = System.currentTimeMillis(); - zos = new ZipOutputStream(System.out); - zos.setLevel(9); - - for (final File src : includes) { - if (src.isFile()) - appendJar(src); - else - appendDirectory(src, src, ""); - } - for (final String name : files.keySet()) - appendFile(chosenSources.get(name), name); - - zos.close(); - } - - private void scanJar(final File jarPath) throws IOException { - final ZipFile zf = new ZipFile(jarPath); - final Enumeration e = zf.entries(); - while (e.hasMoreElements()) - chosenSources.put(e.nextElement().getName(), jarPath); - zf.close(); - } - - private void scanDirectory(final File rootPath, final File dirPath, - final String pfx) throws IOException { - final File[] entries = dirPath.listFiles(); - if (entries == null) - return; - for (final File e : entries) { - if (e.getName().equals(".") || e.getName().equals("..")) - continue; - - if (e.isDirectory()) - scanDirectory(rootPath, e, pfx + e.getName() + "/"); - else - chosenSources.put(pfx + e.getName(), rootPath); - } - } - - private void appendJar(final File jarPath) throws IOException { - final ZipFile zf = new ZipFile(jarPath); - final Enumeration e = zf.entries(); - while (e.hasMoreElements()) { - final ZipEntry ze = e.nextElement(); - final String name = ze.getName(); - if (chosenSources.get(name) == jarPath) - appendEntry(name, ze.getSize(), ze.getTime(), zf - .getInputStream(ze)); - } - zf.close(); - } - - private void appendDirectory(final File rootDir, final File dirPath, - final String pfx) throws IOException { - final File[] entries = dirPath.listFiles(); - if (entries == null) - return; - for (final File e : entries) { - if (e.getName().equals(".") || e.getName().equals("..")) - continue; - - if (e.isDirectory()) - appendDirectory(rootDir, e, pfx + e.getName() + "/"); - else if (chosenSources.get(pfx + e.getName()) == rootDir) - appendFile(e, pfx + e.getName()); - } - } - - private void appendFile(final File path, final String name) - throws IOException { - final long len = path.length(); - final InputStream is = new FileInputStream(path); - appendEntry(name, len, creationTime, is); - } - - private void appendEntry(final String name, final long len, - final long time, final InputStream is) throws IOException { - final ZipEntry ze = new ZipEntry(name); - ze.setSize(len); - ze.setTime(time); - zos.putNextEntry(ze); - try { - final byte[] buf = new byte[4096]; - int n; - while ((n = is.read(buf)) >= 0) - zos.write(buf, 0, n); - } finally { - is.close(); - } - zos.closeEntry(); - } -} -- cgit v1.2.3 From 49aac32500985440c8c7599ccf953f011da8a763 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 18:08:56 -0700 Subject: Create JUnit test utilities for JGit derived sources The LocalDiskRepositoryTestCase class is derived from the current RepositoryTestCase code and is meant for application (or our own) tests to subclass and access temporary repositories on the local client disk. Change-Id: Idff096cea40a7b2b56a90fb5de179ba61ea3a0eb Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.junit/.classpath | 7 + org.eclipse.jgit.junit/.gitignore | 2 + org.eclipse.jgit.junit/.project | 28 ++ .../.settings/org.eclipse.core.resources.prefs | 6 + .../.settings/org.eclipse.core.runtime.prefs | 3 + .../.settings/org.eclipse.jdt.core.prefs | 320 ++++++++++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 62 ++++ org.eclipse.jgit.junit/META-INF/MANIFEST.MF | 27 ++ org.eclipse.jgit.junit/build.properties | 5 + org.eclipse.jgit.junit/plugin.properties | 2 + org.eclipse.jgit.junit/pom.xml | 101 ++++++ .../jgit/junit/LocalDiskRepositoryTestCase.java | 401 +++++++++++++++++++++ .../org/eclipse/jgit/junit/MockSystemReader.java | 110 ++++++ pom.xml | 7 + 14 files changed, 1081 insertions(+) create mode 100644 org.eclipse.jgit.junit/.classpath create mode 100644 org.eclipse.jgit.junit/.gitignore create mode 100644 org.eclipse.jgit.junit/.project create mode 100644 org.eclipse.jgit.junit/.settings/org.eclipse.core.resources.prefs create mode 100644 org.eclipse.jgit.junit/.settings/org.eclipse.core.runtime.prefs create mode 100644 org.eclipse.jgit.junit/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.jgit.junit/.settings/org.eclipse.jdt.ui.prefs create mode 100644 org.eclipse.jgit.junit/META-INF/MANIFEST.MF create mode 100644 org.eclipse.jgit.junit/build.properties create mode 100644 org.eclipse.jgit.junit/plugin.properties create mode 100644 org.eclipse.jgit.junit/pom.xml create mode 100644 org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java create mode 100644 org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java diff --git a/org.eclipse.jgit.junit/.classpath b/org.eclipse.jgit.junit/.classpath new file mode 100644 index 0000000000..64c5e31b7a --- /dev/null +++ b/org.eclipse.jgit.junit/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.jgit.junit/.gitignore b/org.eclipse.jgit.junit/.gitignore new file mode 100644 index 0000000000..934e0e06ff --- /dev/null +++ b/org.eclipse.jgit.junit/.gitignore @@ -0,0 +1,2 @@ +/bin +/target diff --git a/org.eclipse.jgit.junit/.project b/org.eclipse.jgit.junit/.project new file mode 100644 index 0000000000..90325d8fa2 --- /dev/null +++ b/org.eclipse.jgit.junit/.project @@ -0,0 +1,28 @@ + + + org.eclipse.jgit.junit + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.eclipse.jgit.junit/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.junit/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..6a9621db1d --- /dev/null +++ b/org.eclipse.jgit.junit/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +#Sat Dec 20 21:21:24 CET 2008 +eclipse.preferences.version=1 +encoding//tst-rsrc/org/eclipse/jgit/patch/testGetText_BothISO88591.patch=ISO-8859-1 +encoding//tst-rsrc/org/eclipse/jgit/patch/testGetText_Convert.patch=ISO-8859-1 +encoding//tst-rsrc/org/eclipse/jgit/patch/testGetText_DiffCc.patch=ISO-8859-1 +encoding/=UTF-8 diff --git a/org.eclipse.jgit.junit/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.jgit.junit/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..9f733eeea7 --- /dev/null +++ b/org.eclipse.jgit.junit/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Mon Mar 24 18:55:56 EDT 2008 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8bfa5f141a --- /dev/null +++ b/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,320 @@ +#Tue Feb 05 00:01:29 CET 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=error +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=error +org.eclipse.jdt.core.compiler.problem.unusedLocal=error +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error +org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false +org.eclipse.jdt.core.formatter.comment.format_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=80 +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=80 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false diff --git a/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..9adc9b1d31 --- /dev/null +++ b/org.eclipse.jgit.junit/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,62 @@ +#Sat Oct 31 14:53:06 PDT 2009 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_JGit +formatter_settings_version=10 +internal.default.compliance=default +org.eclipse.jdt.ui.ignorelowercasenames=true +org.eclipse.jdt.ui.importorder=java;javax;org;com; +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +org.eclipse.jdt.ui.text.custom_code_templates= +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..0ff1c0f96a --- /dev/null +++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin_name +Bundle-SymbolicName: org.eclipse.jgit.junit +Bundle-Version: 0.6.0.qualifier +Bundle-Localization: plugin +Bundle-Vendor: %provider_name +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: com.jcraft.jsch, + junit.framework, + org.eclipse.jgit.diff, + org.eclipse.jgit.dircache, + org.eclipse.jgit.errors, + org.eclipse.jgit.fnmatch, + org.eclipse.jgit.lib, + org.eclipse.jgit.merge, + org.eclipse.jgit.patch, + org.eclipse.jgit.revplot, + org.eclipse.jgit.revwalk, + org.eclipse.jgit.revwalk.filter, + org.eclipse.jgit.transport, + org.eclipse.jgit.treewalk, + org.eclipse.jgit.treewalk.filter, + org.eclipse.jgit.util, + org.eclipse.jgit.util.io +Export-Package: org.eclipse.jgit.junit;version="0.6.0" diff --git a/org.eclipse.jgit.junit/build.properties b/org.eclipse.jgit.junit/build.properties new file mode 100644 index 0000000000..aa1a008269 --- /dev/null +++ b/org.eclipse.jgit.junit/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.jgit.junit/plugin.properties b/org.eclipse.jgit.junit/plugin.properties new file mode 100644 index 0000000000..d137bd4980 --- /dev/null +++ b/org.eclipse.jgit.junit/plugin.properties @@ -0,0 +1,2 @@ +plugin_name=Java Git JUnit Utility Classes (Incubation) +provider_name=eclipse.org diff --git a/org.eclipse.jgit.junit/pom.xml b/org.eclipse.jgit.junit/pom.xml new file mode 100644 index 0000000000..d38764a1fe --- /dev/null +++ b/org.eclipse.jgit.junit/pom.xml @@ -0,0 +1,101 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit.junit + JGit - JUnit Utility Classes + + + Utility classes to support JUnit testing of JGit applications. + + + + + org.eclipse.jgit + org.eclipse.jgit + + + + junit + junit + provided + + + + + src/ + + + + . + + plugin.properties + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + + + + + + diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java new file mode 100644 index 0000000000..5c8935c490 --- /dev/null +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Robin Rosenberg + * Copyright (C) 2007, Shawn O. Pearce + * 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.junit; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.eclipse.jgit.lib.FileBasedConfig; +import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.RepositoryCache; +import org.eclipse.jgit.lib.WindowCache; +import org.eclipse.jgit.lib.WindowCacheConfig; +import org.eclipse.jgit.util.IO; +import org.eclipse.jgit.util.SystemReader; + +/** + * JUnit TestCase with specialized support for temporary local repository. + *

+ * A temporary directory is created for each test, allowing each test to use a + * fresh environment. The temporary directory is cleaned up after the test ends. + *

+ * Callers should not use {@link RepositoryCache} from within these tests as it + * may wedge file descriptors open past the end of the test. + *

+ * A system property {@code jgit.junit.usemmap} defines whether memory mapping + * is used. Memory mapping has an effect on the file system, in that memory + * mapped files in Java cannot be deleted as long as the mapped arrays have not + * been reclaimed by the garbage collector. The programmer cannot control this + * with precision, so temporary files may hang around longer than desired during + * a test, or tests may fail altogether if there is insufficient file + * descriptors or address space for the test process. + */ +public abstract class LocalDiskRepositoryTestCase extends TestCase { + private static Thread shutdownHook; + + private static int testCount; + + private static final boolean useMMAP = "true".equals(System + .getProperty("jgit.junit.usemmap")); + + /** A fake (but stable) identity for author fields in the test. */ + protected PersonIdent author; + + /** A fake (but stable) identity for committer fields in the test. */ + protected PersonIdent committer; + + private final File trash = new File(new File("target"), "trash"); + + private final List toClose = new ArrayList(); + + private MockSystemReader mockSystemReader; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + if (shutdownHook == null) { + shutdownHook = new Thread() { + @Override + public void run() { + System.gc(); + recursiveDelete("SHUTDOWN", trash, false, false); + } + }; + Runtime.getRuntime().addShutdownHook(shutdownHook); + } + + recursiveDelete(testName(), trash, true, false); + + mockSystemReader = new MockSystemReader(); + mockSystemReader.userGitConfig = new FileBasedConfig(new File(trash, + "usergitconfig")); + SystemReader.setInstance(mockSystemReader); + + final long now = mockSystemReader.getCurrentTime(); + final int tz = mockSystemReader.getTimezone(now); + author = new PersonIdent("J. Author", "jauthor@example.com"); + author = new PersonIdent(author, now, tz); + + committer = new PersonIdent("J. Committer", "jcommitter@example.com"); + committer = new PersonIdent(committer, now, tz); + + final WindowCacheConfig c = new WindowCacheConfig(); + c.setPackedGitLimit(128 * WindowCacheConfig.KB); + c.setPackedGitWindowSize(8 * WindowCacheConfig.KB); + c.setPackedGitMMAP(useMMAP); + c.setDeltaBaseCacheLimit(8 * WindowCacheConfig.KB); + WindowCache.reconfigure(c); + } + + @Override + protected void tearDown() throws Exception { + RepositoryCache.clear(); + for (Repository r : toClose) + r.close(); + toClose.clear(); + + // Since memory mapping is controlled by the GC we need to + // tell it this is a good time to clean up and unlock + // memory mapped files. + // + if (useMMAP) + System.gc(); + + recursiveDelete(testName(), trash, false, true); + super.tearDown(); + } + + /** Increment the {@link #author} and {@link #committer} times. */ + protected void tick() { + final long delta = TimeUnit.MILLISECONDS.convert(5 * 60, + TimeUnit.SECONDS); + final long now = author.getWhen().getTime() + delta; + final int tz = mockSystemReader.getTimezone(now); + + author = new PersonIdent(author, now, tz); + committer = new PersonIdent(committer, now, tz); + } + + /** + * Recursively delete a directory, failing the test if the delete fails. + * + * @param dir + * the recursively directory to delete, if present. + */ + protected void recursiveDelete(final File dir) { + recursiveDelete(testName(), dir, false, true); + } + + private static boolean recursiveDelete(final String testName, + final File dir, boolean silent, boolean failOnError) { + assert !(silent && failOnError); + if (!dir.exists()) { + return silent; + } + final File[] ls = dir.listFiles(); + if (ls != null) { + for (int k = 0; k < ls.length; k++) { + final File e = ls[k]; + if (e.isDirectory()) { + silent = recursiveDelete(testName, e, silent, failOnError); + } else { + if (!e.delete()) { + if (!silent) { + reportDeleteFailure(testName, failOnError, e); + } + silent = !failOnError; + } + } + } + } + if (!dir.delete()) { + if (!silent) { + reportDeleteFailure(testName, failOnError, dir); + } + silent = !failOnError; + } + return silent; + } + + private static void reportDeleteFailure(final String testName, + final boolean failOnError, final File e) { + final String severity; + if (failOnError) + severity = "ERROR"; + else + severity = "WARNING"; + + final String msg = severity + ": Failed to delete " + e + " in " + + testName; + if (failOnError) + fail(msg); + else + System.err.println(msg); + } + + /** + * Creates a new empty bare repository. + * + * @return the newly created repository, opened for access + * @throws IOException + * the repository could not be created in the temporary area + */ + protected Repository createBareRepository() throws IOException { + return createRepository(true /* bare */); + } + + /** + * Creates a new empty repository within a new empty working directory. + * + * @return the newly created repository, opened for access + * @throws IOException + * the repository could not be created in the temporary area + */ + protected Repository createWorkRepository() throws IOException { + return createRepository(false /* not bare */); + } + + /** + * Creates a new empty repository. + * + * @param bare + * true to create a bare repository; false to make a repository + * within its working directory + * @return the newly created repository, opened for access + * @throws IOException + * the repository could not be created in the temporary area + */ + private Repository createRepository(boolean bare) throws IOException { + String uniqueId = System.currentTimeMillis() + "_" + (testCount++); + String gitdirName = "test" + uniqueId + (bare ? "" : "/") + ".git"; + File gitdir = new File(trash, gitdirName).getCanonicalFile(); + Repository db = new Repository(gitdir); + + assertFalse(gitdir.exists()); + db.create(); + toClose.add(db); + return db; + } + + /** + * Run a hook script in the repository, returning the exit status. + * + * @param db + * repository the script should see in GIT_DIR environment + * @param hook + * path of the hook script to execute, must be executable file + * type on this platform + * @param args + * arguments to pass to the hook script + * @return exit status code of the invoked hook + * @throws IOException + * the hook could not be executed + * @throws InterruptedException + * the caller was interrupted before the hook completed + */ + protected int runHook(final Repository db, final File hook, + final String... args) throws IOException, InterruptedException { + final String[] argv = new String[1 + args.length]; + argv[0] = hook.getAbsolutePath(); + System.arraycopy(args, 0, argv, 1, args.length); + + final Map env = cloneEnv(); + env.put("GIT_DIR", db.getDirectory().getAbsolutePath()); + putPersonIdent(env, "AUTHOR", author); + putPersonIdent(env, "COMMITTER", committer); + + final File cwd = db.getWorkDir(); + final Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd); + p.getOutputStream().close(); + p.getErrorStream().close(); + p.getInputStream().close(); + return p.waitFor(); + } + + private static void putPersonIdent(final Map env, + final String type, final PersonIdent who) { + final String ident = who.toExternalString(); + final String date = ident.substring(ident.indexOf("> ") + 2); + env.put("GIT_" + type + "_NAME", who.getName()); + env.put("GIT_" + type + "_EMAIL", who.getEmailAddress()); + env.put("GIT_" + type + "_DATE", date); + } + + /** + * Create a string to a UTF-8 temporary file and return the path. + * + * @param body + * complete content to write to the file. If the file should end + * with a trailing LF, the string should end with an LF. + * @return path of the temporary file created within the trash area. + * @throws IOException + * the file could not be written. + */ + protected File write(final String body) throws IOException { + final File f = File.createTempFile("temp", "txt", trash); + try { + write(f, body); + return f; + } catch (Error e) { + f.delete(); + throw e; + } catch (RuntimeException e) { + f.delete(); + throw e; + } catch (IOException e) { + f.delete(); + throw e; + } + } + + /** + * Write a string as a UTF-8 file. + * + * @param f + * file to write the string to. Caller is responsible for making + * sure it is in the trash directory or will otherwise be cleaned + * up at the end of the test. If the parent directory does not + * exist, the missing parent directories are automatically + * created. + * @param body + * content to write to the file. + * @throws IOException + * the file could not be written. + */ + protected void write(final File f, final String body) throws IOException { + f.getParentFile().mkdirs(); + Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); + try { + w.write(body); + } finally { + w.close(); + } + } + + /** + * Fully read a UTF-8 file and return as a string. + * + * @param f + * file to read the content of. + * @return UTF-8 decoded content of the file, empty string if the file + * exists but has no content. + * @throws IOException + * the file does not exist, or could not be read. + */ + protected String read(final File f) throws IOException { + final byte[] body = IO.readFully(f); + return new String(body, 0, body.length, "UTF-8"); + } + + private static String[] toEnvArray(final Map env) { + final String[] envp = new String[env.size()]; + int i = 0; + for (Map.Entry e : env.entrySet()) { + envp[i++] = e.getKey() + "=" + e.getValue(); + } + return envp; + } + + private static HashMap cloneEnv() { + return new HashMap(System.getenv()); + } + + private String testName() { + return getClass().getName() + "." + getName(); + } +} diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java new file mode 100644 index 0000000000..87125d280c --- /dev/null +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009, Yann Simon + * 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.junit; + +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; + +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.FileBasedConfig; +import org.eclipse.jgit.util.SystemReader; + +public class MockSystemReader extends SystemReader { + final Map values = new HashMap(); + + FileBasedConfig userGitConfig; + + public MockSystemReader() { + init(Constants.OS_USER_NAME_KEY); + init(Constants.GIT_AUTHOR_NAME_KEY); + init(Constants.GIT_AUTHOR_EMAIL_KEY); + init(Constants.GIT_COMMITTER_NAME_KEY); + init(Constants.GIT_COMMITTER_EMAIL_KEY); + userGitConfig = new FileBasedConfig(null); + } + + private void init(final String n) { + setProperty(n, n); + } + + public void clearProperties() { + values.clear(); + } + + public void setProperty(String key, String value) { + values.put(key, value); + } + + @Override + public String getenv(String variable) { + return values.get(variable); + } + + @Override + public String getProperty(String key) { + return values.get(key); + } + + @Override + public FileBasedConfig openUserConfig() { + return userGitConfig; + } + + @Override + public String getHostname() { + return "fake.host.example.com"; + } + + @Override + public long getCurrentTime() { + return 1250379778668L; // Sat Aug 15 20:12:58 GMT-03:30 2009 + } + + @Override + public int getTimezone(long when) { + return TimeZone.getTimeZone("GMT-03:30").getOffset(when) / (60 * 1000); + } +} diff --git a/pom.xml b/pom.xml index 910b587167..e144f492d9 100644 --- a/pom.xml +++ b/pom.xml @@ -208,6 +208,12 @@ ${project.version} + + org.eclipse.jgit + org.eclipse.jgit.junit + ${project.version} + + org.eclipse.jgit org.eclipse.jgit.ui @@ -229,6 +235,7 @@ org.eclipse.jgit org.eclipse.jgit.ui org.eclipse.jgit.pgm + org.eclipse.jgit.junit org.eclipse.jgit.test -- cgit v1.2.3 From 1e84e8ad935aa22ca0f6f1d00dfed4a07878ef6f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 5 Oct 2009 11:25:43 -0700 Subject: Refactor RepositoryTestCase to use LocalDiskRepository instead Change-Id: I07014d1b8cc2fab0761d644a12e4ae04f0adf3ef Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.test/META-INF/MANIFEST.MF | 1 + org.eclipse.jgit.test/pom.xml | 5 + .../org/eclipse/jgit/lib/ConcurrentRepackTest.java | 8 +- .../tst/org/eclipse/jgit/lib/MockSystemReader.java | 97 --------- .../tst/org/eclipse/jgit/lib/ReflogConfigTest.java | 13 +- .../org/eclipse/jgit/lib/RepositoryCacheTest.java | 4 +- .../org/eclipse/jgit/lib/RepositoryConfigTest.java | 11 +- .../org/eclipse/jgit/lib/RepositoryTestCase.java | 234 ++------------------- .../tst/org/eclipse/jgit/lib/T0003_Basic.java | 51 ++--- .../org/eclipse/jgit/revwalk/RevWalkTestCase.java | 6 +- .../eclipse/jgit/transport/BundleWriterTest.java | 8 +- 11 files changed, 79 insertions(+), 359 deletions(-) delete mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 225611ba9b..32d5efdfc4 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.jcraft.jsch, junit.framework, junit.textui, + org.eclipse.jgit.junit, org.eclipse.jgit.diff, org.eclipse.jgit.dircache, org.eclipse.jgit.errors, diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index 2eb8f9aa78..6938ea60a0 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -67,6 +67,11 @@ org.eclipse.jgit org.eclipse.jgit + + + org.eclipse.jgit + org.eclipse.jgit.junit + diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java index 644c7b366c..9e83aa0e1e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java @@ -72,7 +72,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { IOException { // Create a new object in a new pack, and test that it is present. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -84,7 +84,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { // object into a different pack file, with some other object. We // still should be able to access the objects. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -108,7 +108,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { throws IncorrectObjectTypeException, IOException { // Create an object and pack it. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -141,7 +141,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase { // object into a different pack file, with some other object. We // still should be able to access the objects. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java deleted file mode 100644 index 2e94632cee..0000000000 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2009, Google Inc. - * Copyright (C) 2009, Robin Rosenberg - * Copyright (C) 2009, Yann Simon - * 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.lib; - -import java.util.HashMap; -import java.util.Map; -import java.util.TimeZone; - -import org.eclipse.jgit.util.SystemReader; - -class MockSystemReader extends SystemReader { - final Map values = new HashMap(); - - FileBasedConfig userGitConfig; - - MockSystemReader() { - init(Constants.OS_USER_NAME_KEY); - init(Constants.GIT_AUTHOR_NAME_KEY); - init(Constants.GIT_AUTHOR_EMAIL_KEY); - init(Constants.GIT_COMMITTER_NAME_KEY); - init(Constants.GIT_COMMITTER_EMAIL_KEY); - userGitConfig = new FileBasedConfig(null); - } - - private void init(final String n) { - values.put(n, n); - } - - public String getenv(String variable) { - return values.get(variable); - } - - public String getProperty(String key) { - return values.get(key); - } - - public FileBasedConfig openUserConfig() { - return userGitConfig; - } - - public String getHostname() { - return "fake.host.example.com"; - } - - @Override - public long getCurrentTime() { - return 1250379778668L; // Sat Aug 15 20:12:58 GMT-03:30 2009 - } - - @Override - public int getTimezone(long when) { - return TimeZone.getTimeZone("GMT-3:30").getOffset(when); - } -} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java index e72b7e2156..f3b150fa45 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2009, Christian Halstrick * Copyright (C) 2009, Christian Halstrick, Matthias Sohn, SAP AG + * Copyright (C) 2009, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -61,8 +62,8 @@ public class ReflogConfigTest extends RepositoryTestCase { // written final Tree t = new Tree(db); addFileToTree(t, "i-am-a-file", "and this is the data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); commitTime += 100; assertTrue( "Reflog for HEAD still contain no entry", @@ -74,8 +75,8 @@ public class ReflogConfigTest extends RepositoryTestCase { // do one commit and check that reflog size is increased to 1 addFileToTree(t, "i-am-another-file", "and this is other data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); commitTime += 100; assertTrue( "Reflog for HEAD should contain one entry", @@ -88,8 +89,8 @@ public class ReflogConfigTest extends RepositoryTestCase { // do one commit and check that reflog size is 2 addFileToTree(t, "i-am-anotheranother-file", "and this is other other data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); assertTrue( "Reflog for HEAD should contain two entries", db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index c0591755f4..f05889308d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -64,7 +64,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { } public void testBareFileKey() throws IOException { - Repository bare = createNewEmptyRepo(true); + Repository bare = createBareRepository(); File gitdir = bare.getDirectory(); File parent = gitdir.getParentFile(); String name = gitdir.getName(); @@ -92,7 +92,7 @@ public class RepositoryCacheTest extends RepositoryTestCase { } public void testFileKeyOpenNew() throws IOException { - final Repository n = createNewEmptyRepo(true); + final Repository n = createBareRepository(); final File gitdir = n.getDirectory(); n.close(); recursiveDelete(gitdir); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java index 08e701ab50..2cbfc682ca 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java @@ -53,6 +53,7 @@ import java.util.LinkedList; import junit.framework.TestCase; import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.SystemReader; /** @@ -115,9 +116,9 @@ public class RepositoryConfigTest extends TestCase { final MockSystemReader mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); final String hostname = mockSystemReader.getHostname(); - final Config userGitConfig = mockSystemReader.userGitConfig; + final Config userGitConfig = mockSystemReader.openUserConfig(); final Config localConfig = new Config(userGitConfig); - mockSystemReader.values.clear(); + mockSystemReader.clearProperties(); String authorName; String authorEmail; @@ -129,7 +130,7 @@ public class RepositoryConfigTest extends TestCase { assertEquals(Constants.UNKNOWN_USER_DEFAULT + "@" + hostname, authorEmail); // the system user name is defined - mockSystemReader.values.put(Constants.OS_USER_NAME_KEY, "os user name"); + mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "os user name"); localConfig.uncache(UserConfig.KEY); authorName = localConfig.get(UserConfig.KEY).getAuthorName(); assertEquals("os user name", authorName); @@ -140,8 +141,8 @@ public class RepositoryConfigTest extends TestCase { } // the git environment variables are defined - mockSystemReader.values.put(Constants.GIT_AUTHOR_NAME_KEY, "git author name"); - mockSystemReader.values.put(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email"); + mockSystemReader.setProperty(Constants.GIT_AUTHOR_NAME_KEY, "git author name"); + mockSystemReader.setProperty(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email"); localConfig.uncache(UserConfig.KEY); authorName = localConfig.get(UserConfig.KEY).getAuthorName(); authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index ac8881b1fc..ecbb7e073a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -1,6 +1,9 @@ /* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008-2009, Jonas Fonseca * Copyright (C) 2007-2009, Robin Rosenberg - * Copyright (C) 2007, Shawn O. Pearce + * Copyright (C) 2006-2007, Shawn O. Pearce + * Copyright (C) 2009, Yann Simon * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -49,117 +52,18 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.io.Reader; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; +import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.util.JGitTestUtil; -import org.eclipse.jgit.util.SystemReader; /** * Base class for most JGit unit tests. * * Sets up a predefined test repository and has support for creating additional * repositories and destroying them when the tests are finished. - * - * A system property jgit.junit.usemmap defines whether memory mapping - * is used. Memory mapping has an effect on the file system, in that memory - * mapped files in java cannot be deleted as long as they mapped arrays have not - * been reclaimed by the garbage collector. The programmer cannot control this - * with precision, though hinting using {@link java.lang.System#gc} - * often helps. */ -public abstract class RepositoryTestCase extends TestCase { - - protected final File trashParent = new File("trash"); - - protected File trash; - - protected File trash_git; - - protected static final PersonIdent jauthor; - - protected static final PersonIdent jcommitter; - - static { - jauthor = new PersonIdent("J. Author", "jauthor@example.com"); - jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com"); - } - - protected boolean packedGitMMAP; - - /** - * Configure JGit before setting up test repositories. - */ - protected void configure() { - final WindowCacheConfig c = new WindowCacheConfig(); - c.setPackedGitLimit(128 * WindowCacheConfig.KB); - c.setPackedGitWindowSize(8 * WindowCacheConfig.KB); - c.setPackedGitMMAP("true".equals(System.getProperty("jgit.junit.usemmap"))); - c.setDeltaBaseCacheLimit(8 * WindowCacheConfig.KB); - WindowCache.reconfigure(c); - } - - /** - * Utility method to delete a directory recursively. It is - * also used internally. If a file or directory cannot be removed - * it throws an AssertionFailure. - * - * @param dir - */ - protected void recursiveDelete(final File dir) { - recursiveDelete(dir, false, getClass().getName() + "." + getName(), true); - } - - protected static boolean recursiveDelete(final File dir, boolean silent, - final String name, boolean failOnError) { - assert !(silent && failOnError); - if (!dir.exists()) - return silent; - final File[] ls = dir.listFiles(); - if (ls != null) { - for (int k = 0; k < ls.length; k++) { - final File e = ls[k]; - if (e.isDirectory()) { - silent = recursiveDelete(e, silent, name, failOnError); - } else { - if (!e.delete()) { - if (!silent) { - reportDeleteFailure(name, failOnError, e); - } - silent = !failOnError; - } - } - } - } - if (!dir.delete()) { - if (!silent) { - reportDeleteFailure(name, failOnError, dir); - } - silent = !failOnError; - } - return silent; - } - - private static void reportDeleteFailure(final String name, - boolean failOnError, final File e) { - String severity; - if (failOnError) - severity = "Error"; - else - severity = "Warning"; - String msg = severity + ": Failed to delete " + e; - if (name != null) - msg += " in " + name; - if (failOnError) - fail(msg); - else - System.out.println(msg); - } - +public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected static void copyFile(final File src, final File dst) throws IOException { final FileInputStream fis = new FileInputStream(src); @@ -181,18 +85,9 @@ public abstract class RepositoryTestCase extends TestCase { protected File writeTrashFile(final String name, final String data) throws IOException { - File tf = new File(trash, name); - File tfp = tf.getParentFile(); - if (!tfp.exists() && !tf.getParentFile().mkdirs()) - throw new Error("Could not create directory " + tf.getParentFile()); - final OutputStreamWriter fw = new OutputStreamWriter( - new FileOutputStream(tf), "UTF-8"); - try { - fw.write(data); - } finally { - fw.close(); - } - return tf; + File path = new File(db.getWorkDir(), name); + write(path, data); + return path; } protected static void checkFile(File f, final String checkData) @@ -208,46 +103,17 @@ public abstract class RepositoryTestCase extends TestCase { } } + /** Test repository, initialized for this test case. */ protected Repository db; - private static Thread shutdownhook; - private static List shutDownCleanups = new ArrayList(); - private static int testcount; - - private ArrayList repositoriesToClose = new ArrayList(); + /** Working directory of {@link #db}. */ + protected File trash; - public void setUp() throws Exception { + @Override + protected void setUp() throws Exception { super.setUp(); - configure(); - final String name = getClass().getName() + "." + getName(); - recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff - trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++)); - trash_git = new File(trash, ".git").getCanonicalFile(); - if (shutdownhook == null) { - shutdownhook = new Thread() { - @Override - public void run() { - // This may look superfluous, but is an extra attempt - // to clean up. First GC to release as many resources - // as possible and then try to clean up one test repo - // at a time (to record problems) and finally to drop - // the directory containing all test repositories. - System.gc(); - for (Runnable r : shutDownCleanups) - r.run(); - recursiveDelete(trashParent, false, null, false); - } - }; - Runtime.getRuntime().addShutdownHook(shutdownhook); - } - - final MockSystemReader mockSystemReader = new MockSystemReader(); - mockSystemReader.userGitConfig = new FileBasedConfig(new File( - trash_git, "usergitconfig")); - SystemReader.setInstance(mockSystemReader); - - db = new Repository(trash_git); - db.create(); + db = createWorkRepository(); + trash = db.getWorkDir(); final String[] packs = { "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f", @@ -259,70 +125,12 @@ public abstract class RepositoryTestCase extends TestCase { "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12" }; final File packDir = new File(db.getObjectsDirectory(), "pack"); - for (int k = 0; k < packs.length; k++) { - copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".pack"), new File(packDir, - packs[k] + ".pack")); - copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".idx"), new File(packDir, - packs[k] + ".idx")); + for (String n : packs) { + copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack")); + copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx")); } - copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(trash_git,"packed-refs")); - } - - protected void tearDown() throws Exception { - RepositoryCache.clear(); - db.close(); - for (Repository r : repositoriesToClose) - r.close(); - - // Since memory mapping is controlled by the GC we need to - // tell it this is a good time to clean up and unlock - // memory mapped files. - if (packedGitMMAP) - System.gc(); - - final String name = getClass().getName() + "." + getName(); - recursiveDelete(trash, false, name, true); - for (Repository r : repositoriesToClose) - recursiveDelete(r.getWorkDir(), false, name, true); - repositoriesToClose.clear(); - - super.tearDown(); - } - - /** - * Helper for creating extra empty repos - * - * @return a new empty git repository for testing purposes - * - * @throws IOException - */ - protected Repository createNewEmptyRepo() throws IOException { - return createNewEmptyRepo(false); - } - - /** - * Helper for creating extra empty repos - * - * @param bare if true, create a bare repository. - * @return a new empty git repository for testing purposes - * - * @throws IOException - */ - protected Repository createNewEmptyRepo(boolean bare) throws IOException { - final File newTestRepo = new File(trashParent, "new" - + System.currentTimeMillis() + "." + (testcount++) - + (bare ? "" : "/") + ".git").getCanonicalFile(); - assertFalse(newTestRepo.exists()); - final Repository newRepo = new Repository(newTestRepo); - newRepo.create(); - final String name = getClass().getName() + "." + getName(); - shutDownCleanups.add(new Runnable() { - public void run() { - recursiveDelete(newTestRepo, false, name, false); - } - }); - repositoriesToClose.add(newRepo); - return newRepo; + copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(db + .getDirectory(), "packed-refs")); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java index 74e98f1d8c..f7346a61fb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java @@ -83,7 +83,7 @@ public class T0003_Basic extends RepositoryTestCase { // open when we create it we won't write the object file out as a loose // object (as it already exists in the pack). // - final Repository newdb = createNewEmptyRepo(); + final Repository newdb = createBareRepository(); final Tree t = new Tree(newdb); t.accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() @@ -101,7 +101,8 @@ public class T0003_Basic extends RepositoryTestCase { t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() .name()); - final File o = new File(new File(new File(trash_git, "objects"), "4b"), + final File o = new File(new File( + new File(db.getDirectory(), "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); assertFalse("Exists " + o, o.isFile()); } @@ -115,12 +116,12 @@ public class T0003_Basic extends RepositoryTestCase { .name()); File o; - o = new File(new File(new File(trash_git, "objects"), "7b"), + o = new File(new File(new File(db.getDirectory(), "objects"), "7b"), "b943559a305bdd6bdee2cef6e5df2413c3d30a"); assertTrue("Exists " + o, o.isFile()); assertTrue("Read-only " + o, !o.canWrite()); - o = new File(new File(new File(trash_git, "objects"), "e6"), + o = new File(new File(new File(db.getDirectory(), "objects"), "e6"), "9de29bb2d1d6434b8b29ae775ad8c2e48c5391"); assertTrue("Exists " + o, o.isFile()); assertTrue("Read-only " + o, !o.canWrite()); @@ -202,8 +203,8 @@ public class T0003_Basic extends RepositoryTestCase { t.getTreeId()); final Commit c = new Commit(db); - c.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c.setMessage("A Commit\n"); c.setTree(t); assertEquals(t.getTreeId(), c.getTreeId()); @@ -258,7 +259,7 @@ public class T0003_Basic extends RepositoryTestCase { t.setObjId(emptyId); t.setType("blob"); t.setTag("test020"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test020 tagged\n"); t.tag(); assertEquals("6759556b09fbb4fd8ae5e315134481cc25d46954", t.getTagId().name()); @@ -266,7 +267,7 @@ public class T0003_Basic extends RepositoryTestCase { Tag mapTag = db.mapTag("test020"); assertEquals("blob", mapTag.getType()); assertEquals("test020 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().name()); } @@ -292,7 +293,7 @@ public class T0003_Basic extends RepositoryTestCase { t.setObjId(almostEmptyTreeId); t.setType("tree"); t.setTag("test021"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test021 tagged\n"); t.tag(); assertEquals("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.getTagId().name()); @@ -300,7 +301,7 @@ public class T0003_Basic extends RepositoryTestCase { Tag mapTag = db.mapTag("test021"); assertEquals("tree", mapTag.getType()); assertEquals("test021 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().name()); } @@ -310,8 +311,8 @@ public class T0003_Basic extends RepositoryTestCase { almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree); final Commit almostEmptyCommit = new Commit(db); - almostEmptyCommit.setAuthor(new PersonIdent(jauthor, 1154236443000L, -2 * 60)); // not exactly the same - almostEmptyCommit.setCommitter(new PersonIdent(jauthor, 1154236443000L, -2 * 60)); + almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same + almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60)); almostEmptyCommit.setMessage("test022\n"); almostEmptyCommit.setTreeId(almostEmptyTreeId); ObjectId almostEmptyCommitId = new ObjectWriter(db).writeCommit(almostEmptyCommit); @@ -319,7 +320,7 @@ public class T0003_Basic extends RepositoryTestCase { t.setObjId(almostEmptyCommitId); t.setType("commit"); t.setTag("test022"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test022 tagged\n"); t.tag(); assertEquals("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.getTagId().name()); @@ -327,7 +328,7 @@ public class T0003_Basic extends RepositoryTestCase { Tag mapTag = db.mapTag("test022"); assertEquals("commit", mapTag.getType()); assertEquals("test022 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObjId().name()); } @@ -392,19 +393,19 @@ public class T0003_Basic extends RepositoryTestCase { assertNotNull("have tag test020", mapTag20); assertEquals("blob", mapTag20.getType()); assertEquals("test020 tagged\n", mapTag20.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag20.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag20.getAuthor()); assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.getObjId().name()); Tag mapTag21 = db.mapTag("test021"); assertEquals("tree", mapTag21.getType()); assertEquals("test021 tagged\n", mapTag21.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag21.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag21.getAuthor()); assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.getObjId().name()); Tag mapTag22 = db.mapTag("test022"); assertEquals("commit", mapTag22.getType()); assertEquals("test022 tagged\n", mapTag22.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag22.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag22.getAuthor()); assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.getObjId().name()); } @@ -426,8 +427,8 @@ public class T0003_Basic extends RepositoryTestCase { t.getTreeId()); final Commit c1 = new Commit(db); - c1.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c1.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c1.setMessage("A Commit\n"); c1.setTree(t); assertEquals(t.getTreeId(), c1.getTreeId()); @@ -437,8 +438,8 @@ public class T0003_Basic extends RepositoryTestCase { assertEquals(cmtid1, c1.getCommitId()); final Commit c2 = new Commit(db); - c2.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c2.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c2.setMessage("A Commit 2\n"); c2.setTree(t); assertEquals(t.getTreeId(), c2.getTreeId()); @@ -458,8 +459,8 @@ public class T0003_Basic extends RepositoryTestCase { assertEquals(c1.getCommitId(), rm2.getParentIds()[0]); final Commit c3 = new Commit(db); - c3.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c3.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c3.setMessage("A Commit 3\n"); c3.setTree(t); assertEquals(t.getTreeId(), c3.getTreeId()); @@ -480,8 +481,8 @@ public class T0003_Basic extends RepositoryTestCase { assertEquals(c2.getCommitId(), rm3.getParentIds()[1]); final Commit c4 = new Commit(db); - c4.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c4.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c4.setMessage("A Commit 4\n"); c4.setTree(t); assertEquals(t.getTreeId(), c3.getTreeId()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java index 50fbce41aa..312fc00b13 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java @@ -147,8 +147,8 @@ public abstract class RevWalkTestCase extends RepositoryTestCase { final Commit c = new Commit(db); c.setTreeId(tree); c.setParentIds(parents); - c.setAuthor(new PersonIdent(jauthor, new Date(nowTick))); - c.setCommitter(new PersonIdent(jcommitter, new Date(nowTick))); + c.setAuthor(new PersonIdent(author, new Date(nowTick))); + c.setCommitter(new PersonIdent(committer, new Date(nowTick))); c.setMessage(""); return rw.lookupCommit(ow.writeCommit(c)); } @@ -159,7 +159,7 @@ public abstract class RevWalkTestCase extends RepositoryTestCase { t.setType(Constants.typeString(dst.getType())); t.setObjId(dst.toObjectId()); t.setTag(name); - t.setTagger(new PersonIdent(jcommitter, new Date(nowTick))); + t.setTagger(new PersonIdent(committer, new Date(nowTick))); t.setMessage(""); return (RevTag) rw.lookupAny(ow.writeTag(t), Constants.OBJ_TAG); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index 6a6b63cab8..39ea2f2e42 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Google Inc. + * Copyright (C) 2008-2009, Google Inc. * Copyright (C) 2008, Mike Ralphson * Copyright (C) 2008, Robin Rosenberg * and other copyright owners as documented in the project's IP log. @@ -74,7 +74,7 @@ public class BundleWriterTest extends RepositoryTestCase { // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could read the bundle we created. - Repository newRepo = createNewEmptyRepo(); + Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult .getAdvertisedRef("refs/heads/firstcommit"); @@ -101,7 +101,7 @@ public class BundleWriterTest extends RepositoryTestCase { // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could read the bundle we created. - Repository newRepo = createNewEmptyRepo(); + Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult.getAdvertisedRef("refs/heads/aa"); @@ -123,7 +123,7 @@ public class BundleWriterTest extends RepositoryTestCase { try { // Check that we actually needed the first bundle - Repository newRepo2 = createNewEmptyRepo(); + Repository newRepo2 = createBareRepository(); fetchResult = fetchFromBundle(newRepo2, bundle); fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled"); } catch (MissingBundlePrerequisiteException e) { -- cgit v1.2.3 From b28aadf10f5ea8ccbf5007e0f8dfa630e0760ddd Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 18:07:24 -0700 Subject: Move T0007_Index to exttst This test depends upon the external git binary, and this isn't really a pure Java test like our module tries to claim itself is. So we move it out to exttst with other tests that require additional external resources and/or executable code. Change-Id: Ic9be0280c8bb50a5768336c64de794eb0a492b3d Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/lib/T0007_GitIndexTest.java | 460 +++++++++++++++++++++ .../tst/org/eclipse/jgit/lib/T0007_Index.java | 455 -------------------- 2 files changed, 460 insertions(+), 455 deletions(-) create mode 100644 org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java delete mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0007_Index.java diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java new file mode 100644 index 0000000000..21dcdffbfd --- /dev/null +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java @@ -0,0 +1,460 @@ +/* + * Copyright (C) 2007, Robin Rosenberg + * Copyright (C) 2008, Shawn O. Pearce + * 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.lib; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; +import org.eclipse.jgit.lib.GitIndex.Entry; +import org.eclipse.jgit.util.FS; + +public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase { + + static boolean canrungitstatus; + static { + try { + canrungitstatus = system(new File("."),"git --version") == 0; + } catch (IOException e) { + System.out.println("Warning: cannot invoke native git to validate index"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static int system(File dir, String cmd) throws IOException, + InterruptedException { + final Process process = Runtime.getRuntime().exec(cmd, null, dir); + new Thread() { + public void run() { + try { + InputStream s = process.getErrorStream(); + for (int c = s.read(); c != -1; c = s.read()) { + System.err.print((char) c); + } + s.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }.start(); + final Thread t2 = new Thread() { + public void run() { + synchronized (this) { + try { + InputStream e = process.getInputStream(); + for (int c = e.read(); c != -1; c = e.read()) { + System.out.print((char) c); + } + e.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + }; + t2.start(); + process.getOutputStream().close(); + int ret = process.waitFor(); + synchronized (t2) { + return ret; + } + } + + private Repository db; + + private File trash; + + @Override + protected void setUp() throws Exception { + super.setUp(); + db = createWorkRepository(); + trash = db.getWorkDir(); + } + + public void testCreateEmptyIndex() throws Exception { + GitIndex index = new GitIndex(db); + index.write(); +// native git doesn't like an empty index +// assertEquals(0,system(trash,"git status")); + + GitIndex indexr = new GitIndex(db); + indexr.read(); + assertEquals(0, indexr.getMembers().length); + } + + public void testReadWithNoIndex() throws Exception { + GitIndex index = new GitIndex(db); + index.read(); + assertEquals(0, index.getMembers().length); + } + + public void testCreateSimpleSortTestIndex() throws Exception { + GitIndex index = new GitIndex(db); + writeTrashFile("a/b", "data:a/b"); + writeTrashFile("a:b", "data:a:b"); + writeTrashFile("a.b", "data:a.b"); + index.add(trash, new File(trash, "a/b")); + index.add(trash, new File(trash, "a:b")); + index.add(trash, new File(trash, "a.b")); + index.write(); + + assertEquals("a/b", index.getEntry("a/b").getName()); + assertEquals("a:b", index.getEntry("a:b").getName()); + assertEquals("a.b", index.getEntry("a.b").getName()); + assertNull(index.getEntry("a*b")); + + // Repeat test for re-read index + GitIndex indexr = new GitIndex(db); + indexr.read(); + assertEquals("a/b", indexr.getEntry("a/b").getName()); + assertEquals("a:b", indexr.getEntry("a:b").getName()); + assertEquals("a.b", indexr.getEntry("a.b").getName()); + assertNull(indexr.getEntry("a*b")); + + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void testUpdateSimpleSortTestIndex() throws Exception { + GitIndex index = new GitIndex(db); + writeTrashFile("a/b", "data:a/b"); + writeTrashFile("a:b", "data:a:b"); + writeTrashFile("a.b", "data:a.b"); + index.add(trash, new File(trash, "a/b")); + index.add(trash, new File(trash, "a:b")); + index.add(trash, new File(trash, "a.b")); + writeTrashFile("a/b", "data:a/b modified"); + index.add(trash, new File(trash, "a/b")); + index.write(); + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void testWriteTree() throws Exception { + GitIndex index = new GitIndex(db); + writeTrashFile("a/b", "data:a/b"); + writeTrashFile("a:b", "data:a:b"); + writeTrashFile("a.b", "data:a.b"); + index.add(trash, new File(trash, "a/b")); + index.add(trash, new File(trash, "a:b")); + index.add(trash, new File(trash, "a.b")); + index.write(); + + ObjectId id = index.writeTree(); + assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); + + writeTrashFile("a/b", "data:a/b"); + index.add(trash, new File(trash, "a/b")); + + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void testReadTree() throws Exception { + // Prepare tree + GitIndex index = new GitIndex(db); + writeTrashFile("a/b", "data:a/b"); + writeTrashFile("a:b", "data:a:b"); + writeTrashFile("a.b", "data:a.b"); + index.add(trash, new File(trash, "a/b")); + index.add(trash, new File(trash, "a:b")); + index.add(trash, new File(trash, "a.b")); + index.write(); + + ObjectId id = index.writeTree(); + System.out.println("wrote id " + id); + assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); + GitIndex index2 = new GitIndex(db); + + index2.readTree(db.mapTree(ObjectId.fromString( + "c696abc3ab8e091c665f49d00eb8919690b3aec3"))); + Entry[] members = index2.getMembers(); + assertEquals(3, members.length); + assertEquals("a.b", members[0].getName()); + assertEquals("a/b", members[1].getName()); + assertEquals("a:b", members[2].getName()); + assertEquals(3, members.length); + + GitIndex indexr = new GitIndex(db); + indexr.read(); + Entry[] membersr = indexr.getMembers(); + assertEquals(3, membersr.length); + assertEquals("a.b", membersr[0].getName()); + assertEquals("a/b", membersr[1].getName()); + assertEquals("a:b", membersr[2].getName()); + assertEquals(3, membersr.length); + + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void testReadTree2() throws Exception { + // Prepare a larger tree to test some odd cases in tree writing + GitIndex index = new GitIndex(db); + File f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); + File f2 = writeTrashFile("a/c/c", "data:a/c/c"); + File f3 = writeTrashFile("a/b", "data:a/b"); + File f4 = writeTrashFile("a:b", "data:a:b"); + File f5 = writeTrashFile("a/d", "data:a/d"); + File f6 = writeTrashFile("a.b", "data:a.b"); + index.add(trash, f1); + index.add(trash, f2); + index.add(trash, f3); + index.add(trash, f4); + index.add(trash, f5); + index.add(trash, f6); + index.write(); + ObjectId id = index.writeTree(); + System.out.println("wrote id " + id); + assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.name()); + GitIndex index2 = new GitIndex(db); + + index2.readTree(db.mapTree(ObjectId.fromString( + "ba78e065e2c261d4f7b8f42107588051e87e18e9"))); + Entry[] members = index2.getMembers(); + assertEquals(6, members.length); + assertEquals("a.b", members[0].getName()); + assertEquals("a/a/a/a", members[1].getName()); + assertEquals("a/b", members[2].getName()); + assertEquals("a/c/c", members[3].getName()); + assertEquals("a/d", members[4].getName()); + assertEquals("a:b", members[5].getName()); + + // reread and test + GitIndex indexr = new GitIndex(db); + indexr.read(); + Entry[] membersr = indexr.getMembers(); + assertEquals(6, membersr.length); + assertEquals("a.b", membersr[0].getName()); + assertEquals("a/a/a/a", membersr[1].getName()); + assertEquals("a/b", membersr[2].getName()); + assertEquals("a/c/c", membersr[3].getName()); + assertEquals("a/d", membersr[4].getName()); + assertEquals("a:b", membersr[5].getName()); + } + + public void testDelete() throws Exception { + GitIndex index = new GitIndex(db); + writeTrashFile("a/b", "data:a/b"); + writeTrashFile("a:b", "data:a:b"); + writeTrashFile("a.b", "data:a.b"); + index.add(trash, new File(trash, "a/b")); + index.add(trash, new File(trash, "a:b")); + index.add(trash, new File(trash, "a.b")); + index.write(); + index.writeTree(); + index.remove(trash, new File(trash, "a:b")); + index.write(); + assertEquals("a.b", index.getMembers()[0].getName()); + assertEquals("a/b", index.getMembers()[1].getName()); + + GitIndex indexr = new GitIndex(db); + indexr.read(); + assertEquals("a.b", indexr.getMembers()[0].getName()); + assertEquals("a/b", indexr.getMembers()[1].getName()); + + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void testCheckout() throws Exception { + // Prepare tree, remote it and checkout + GitIndex index = new GitIndex(db); + File aslashb = writeTrashFile("a/b", "data:a/b"); + File acolonb = writeTrashFile("a:b", "data:a:b"); + File adotb = writeTrashFile("a.b", "data:a.b"); + index.add(trash, aslashb); + index.add(trash, acolonb); + index.add(trash, adotb); + index.write(); + index.writeTree(); + delete(aslashb); + delete(acolonb); + delete(adotb); + delete(aslashb.getParentFile()); + + GitIndex index2 = new GitIndex(db); + assertEquals(0, index2.getMembers().length); + + index2.readTree(db.mapTree(ObjectId.fromString( + "c696abc3ab8e091c665f49d00eb8919690b3aec3"))); + + index2.checkout(trash); + assertEquals("data:a/b", read(aslashb)); + assertEquals("data:a:b", read(acolonb)); + assertEquals("data:a.b", read(adotb)); + + if (canrungitstatus) + assertEquals(0, system(trash, "git status")); + } + + public void test030_executeBit_coreModeTrue() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { + if (!FS.INSTANCE.supportsExecute()) { + System.err.println("Test ignored since platform FS does not support the execute permission"); + return; + } + try { + // coremode true is the default, typically set to false + // by git init (but not jgit!) + Method canExecute = File.class.getMethod("canExecute", (Class[])null); + Method setExecute = File.class.getMethod("setExecutable", new Class[] { Boolean.TYPE }); + File execFile = writeTrashFile("exec","exec"); + if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.TRUE })).booleanValue()) + throw new Error("could not set execute bit on "+execFile.getAbsolutePath()+"for test"); + File nonexecFile = writeTrashFile("nonexec","nonexec"); + if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.FALSE })).booleanValue()) + throw new Error("could not clear execute bit on "+nonexecFile.getAbsolutePath()+"for test"); + + GitIndex index = new GitIndex(db); + index.filemode = Boolean.TRUE; // TODO: we need a way to set this using config + index.add(trash, execFile); + index.add(trash, nonexecFile); + Tree tree = db.mapTree(index.writeTree()); + assertEquals(FileMode.EXECUTABLE_FILE, tree.findBlobMember(execFile.getName()).getMode()); + assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode()); + + index.write(); + + if (!execFile.delete()) + throw new Error("Problem in test, cannot delete test file "+execFile.getAbsolutePath()); + if (!nonexecFile.delete()) + throw new Error("Problem in test, cannot delete test file "+nonexecFile.getAbsolutePath()); + GitIndex index2 = new GitIndex(db); + index2.filemode = Boolean.TRUE; // TODO: we need a way to set this using config + index2.read(); + index2.checkout(trash); + assertTrue(((Boolean)canExecute.invoke(execFile,(Object[])null)).booleanValue()); + assertFalse(((Boolean)canExecute.invoke(nonexecFile,(Object[])null)).booleanValue()); + + assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); + assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); + + if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.FALSE })).booleanValue()) + throw new Error("could not clear set execute bit on "+execFile.getAbsolutePath()+"for test"); + if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.TRUE })).booleanValue()) + throw new Error("could set execute bit on "+nonexecFile.getAbsolutePath()+"for test"); + + assertTrue(index2.getEntry(execFile.getName()).isModified(trash)); + assertTrue(index2.getEntry(nonexecFile.getName()).isModified(trash)); + + } catch (NoSuchMethodException e) { + System.err.println("Test ignored when running under JDK < 1.6"); + return; + } + } + + public void test031_executeBit_coreModeFalse() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { + if (!FS.INSTANCE.supportsExecute()) { + System.err.println("Test ignored since platform FS does not support the execute permission"); + return; + } + try { + // coremode true is the default, typically set to false + // by git init (but not jgit!) + Method canExecute = File.class.getMethod("canExecute", (Class[])null); + Method setExecute = File.class.getMethod("setExecutable", new Class[] { Boolean.TYPE }); + File execFile = writeTrashFile("exec","exec"); + if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.TRUE })).booleanValue()) + throw new Error("could not set execute bit on "+execFile.getAbsolutePath()+"for test"); + File nonexecFile = writeTrashFile("nonexec","nonexec"); + if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.FALSE })).booleanValue()) + throw new Error("could not clear execute bit on "+nonexecFile.getAbsolutePath()+"for test"); + + GitIndex index = new GitIndex(db); + index.filemode = Boolean.FALSE; // TODO: we need a way to set this using config + index.add(trash, execFile); + index.add(trash, nonexecFile); + Tree tree = db.mapTree(index.writeTree()); + assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(execFile.getName()).getMode()); + assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode()); + + index.write(); + + if (!execFile.delete()) + throw new Error("Problem in test, cannot delete test file "+execFile.getAbsolutePath()); + if (!nonexecFile.delete()) + throw new Error("Problem in test, cannot delete test file "+nonexecFile.getAbsolutePath()); + GitIndex index2 = new GitIndex(db); + index2.filemode = Boolean.FALSE; // TODO: we need a way to set this using config + index2.read(); + index2.checkout(trash); + assertFalse(((Boolean)canExecute.invoke(execFile,(Object[])null)).booleanValue()); + assertFalse(((Boolean)canExecute.invoke(nonexecFile,(Object[])null)).booleanValue()); + + assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); + assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); + + if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.FALSE })).booleanValue()) + throw new Error("could not clear set execute bit on "+execFile.getAbsolutePath()+"for test"); + if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.TRUE })).booleanValue()) + throw new Error("could set execute bit on "+nonexecFile.getAbsolutePath()+"for test"); + + // no change since we ignore the execute bit + assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); + assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); + + } catch (NoSuchMethodException e) { + System.err.println("Test ignored when running under JDK < 1.6"); + return; + } + } + + private void delete(File f) throws IOException { + if (!f.delete()) + throw new IOException("Failed to delete f"); + } + + private File writeTrashFile(String name, String body) throws IOException { + final File path = new File(trash, name); + write(path, body); + return path; + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0007_Index.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0007_Index.java deleted file mode 100644 index ca2400cfb8..0000000000 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0007_Index.java +++ /dev/null @@ -1,455 +0,0 @@ -/* - * Copyright (C) 2007-2008, Robin Rosenberg - * Copyright (C) 2008, Shawn O. Pearce - * 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.lib; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.eclipse.jgit.lib.GitIndex.Entry; -import org.eclipse.jgit.util.FS; - -public class T0007_Index extends RepositoryTestCase { - - static boolean canrungitstatus; - static { - try { - canrungitstatus = system(new File("."),"git --version") == 0; - } catch (IOException e) { - System.out.println("Warning: cannot invoke native git to validate index"); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - private static int system(File dir, String cmd) throws IOException, - InterruptedException { - final Process process = Runtime.getRuntime().exec(cmd, null, dir); - new Thread() { - public void run() { - try { - InputStream s = process.getErrorStream(); - for (int c = s.read(); c != -1; c = s.read()) { - System.err.print((char) c); - } - s.close(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }.start(); - final Thread t2 = new Thread() { - public void run() { - synchronized (this) { - try { - InputStream e = process.getInputStream(); - for (int c = e.read(); c != -1; c = e.read()) { - System.out.print((char) c); - } - e.close(); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - } - }; - t2.start(); - process.getOutputStream().close(); - int ret = process.waitFor(); - synchronized (t2) { - return ret; - } - } - - public void testCreateEmptyIndex() throws Exception { - GitIndex index = new GitIndex(db); - index.write(); -// native git doesn't like an empty index -// assertEquals(0,system(trash,"git status")); - - GitIndex indexr = new GitIndex(db); - indexr.read(); - assertEquals(0, indexr.getMembers().length); - } - - public void testReadWithNoIndex() throws Exception { - GitIndex index = new GitIndex(db); - index.read(); - assertEquals(0, index.getMembers().length); - } - - public void testCreateSimpleSortTestIndex() throws Exception { - GitIndex index = new GitIndex(db); - writeTrashFile("a/b", "data:a/b"); - writeTrashFile("a:b", "data:a:b"); - writeTrashFile("a.b", "data:a.b"); - index.add(trash, new File(trash, "a/b")); - index.add(trash, new File(trash, "a:b")); - index.add(trash, new File(trash, "a.b")); - index.write(); - - assertEquals("a/b", index.getEntry("a/b").getName()); - assertEquals("a:b", index.getEntry("a:b").getName()); - assertEquals("a.b", index.getEntry("a.b").getName()); - assertNull(index.getEntry("a*b")); - - // Repeat test for re-read index - GitIndex indexr = new GitIndex(db); - indexr.read(); - assertEquals("a/b", indexr.getEntry("a/b").getName()); - assertEquals("a:b", indexr.getEntry("a:b").getName()); - assertEquals("a.b", indexr.getEntry("a.b").getName()); - assertNull(indexr.getEntry("a*b")); - - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void testUpdateSimpleSortTestIndex() throws Exception { - GitIndex index = new GitIndex(db); - writeTrashFile("a/b", "data:a/b"); - writeTrashFile("a:b", "data:a:b"); - writeTrashFile("a.b", "data:a.b"); - index.add(trash, new File(trash, "a/b")); - index.add(trash, new File(trash, "a:b")); - index.add(trash, new File(trash, "a.b")); - writeTrashFile("a/b", "data:a/b modified"); - index.add(trash, new File(trash, "a/b")); - index.write(); - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void testWriteTree() throws Exception { - GitIndex index = new GitIndex(db); - writeTrashFile("a/b", "data:a/b"); - writeTrashFile("a:b", "data:a:b"); - writeTrashFile("a.b", "data:a.b"); - index.add(trash, new File(trash, "a/b")); - index.add(trash, new File(trash, "a:b")); - index.add(trash, new File(trash, "a.b")); - index.write(); - - ObjectId id = index.writeTree(); - assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); - - writeTrashFile("a/b", "data:a/b"); - index.add(trash, new File(trash, "a/b")); - - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void testReadTree() throws Exception { - // Prepare tree - GitIndex index = new GitIndex(db); - writeTrashFile("a/b", "data:a/b"); - writeTrashFile("a:b", "data:a:b"); - writeTrashFile("a.b", "data:a.b"); - index.add(trash, new File(trash, "a/b")); - index.add(trash, new File(trash, "a:b")); - index.add(trash, new File(trash, "a.b")); - index.write(); - - ObjectId id = index.writeTree(); - System.out.println("wrote id " + id); - assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); - GitIndex index2 = new GitIndex(db); - - index2.readTree(db.mapTree(ObjectId.fromString( - "c696abc3ab8e091c665f49d00eb8919690b3aec3"))); - Entry[] members = index2.getMembers(); - assertEquals(3, members.length); - assertEquals("a.b", members[0].getName()); - assertEquals("a/b", members[1].getName()); - assertEquals("a:b", members[2].getName()); - assertEquals(3, members.length); - - GitIndex indexr = new GitIndex(db); - indexr.read(); - Entry[] membersr = indexr.getMembers(); - assertEquals(3, membersr.length); - assertEquals("a.b", membersr[0].getName()); - assertEquals("a/b", membersr[1].getName()); - assertEquals("a:b", membersr[2].getName()); - assertEquals(3, membersr.length); - - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void testReadTree2() throws Exception { - // Prepare a larger tree to test some odd cases in tree writing - GitIndex index = new GitIndex(db); - File f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); - File f2 = writeTrashFile("a/c/c", "data:a/c/c"); - File f3 = writeTrashFile("a/b", "data:a/b"); - File f4 = writeTrashFile("a:b", "data:a:b"); - File f5 = writeTrashFile("a/d", "data:a/d"); - File f6 = writeTrashFile("a.b", "data:a.b"); - index.add(trash, f1); - index.add(trash, f2); - index.add(trash, f3); - index.add(trash, f4); - index.add(trash, f5); - index.add(trash, f6); - index.write(); - ObjectId id = index.writeTree(); - System.out.println("wrote id " + id); - assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.name()); - GitIndex index2 = new GitIndex(db); - - index2.readTree(db.mapTree(ObjectId.fromString( - "ba78e065e2c261d4f7b8f42107588051e87e18e9"))); - Entry[] members = index2.getMembers(); - assertEquals(6, members.length); - assertEquals("a.b", members[0].getName()); - assertEquals("a/a/a/a", members[1].getName()); - assertEquals("a/b", members[2].getName()); - assertEquals("a/c/c", members[3].getName()); - assertEquals("a/d", members[4].getName()); - assertEquals("a:b", members[5].getName()); - - // reread and test - GitIndex indexr = new GitIndex(db); - indexr.read(); - Entry[] membersr = indexr.getMembers(); - assertEquals(6, membersr.length); - assertEquals("a.b", membersr[0].getName()); - assertEquals("a/a/a/a", membersr[1].getName()); - assertEquals("a/b", membersr[2].getName()); - assertEquals("a/c/c", membersr[3].getName()); - assertEquals("a/d", membersr[4].getName()); - assertEquals("a:b", membersr[5].getName()); - } - - public void testDelete() throws Exception { - GitIndex index = new GitIndex(db); - writeTrashFile("a/b", "data:a/b"); - writeTrashFile("a:b", "data:a:b"); - writeTrashFile("a.b", "data:a.b"); - index.add(trash, new File(trash, "a/b")); - index.add(trash, new File(trash, "a:b")); - index.add(trash, new File(trash, "a.b")); - index.write(); - index.writeTree(); - index.remove(trash, new File(trash, "a:b")); - index.write(); - assertEquals("a.b", index.getMembers()[0].getName()); - assertEquals("a/b", index.getMembers()[1].getName()); - - GitIndex indexr = new GitIndex(db); - indexr.read(); - assertEquals("a.b", indexr.getMembers()[0].getName()); - assertEquals("a/b", indexr.getMembers()[1].getName()); - - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void testCheckout() throws Exception { - // Prepare tree, remote it and checkout - GitIndex index = new GitIndex(db); - File aslashb = writeTrashFile("a/b", "data:a/b"); - File acolonb = writeTrashFile("a:b", "data:a:b"); - File adotb = writeTrashFile("a.b", "data:a.b"); - index.add(trash, aslashb); - index.add(trash, acolonb); - index.add(trash, adotb); - index.write(); - index.writeTree(); - delete(aslashb); - delete(acolonb); - delete(adotb); - delete(aslashb.getParentFile()); - - GitIndex index2 = new GitIndex(db); - assertEquals(0, index2.getMembers().length); - - index2.readTree(db.mapTree(ObjectId.fromString( - "c696abc3ab8e091c665f49d00eb8919690b3aec3"))); - - index2.checkout(trash); - assertEquals("data:a/b", content(aslashb)); - assertEquals("data:a:b", content(acolonb)); - assertEquals("data:a.b", content(adotb)); - - if (canrungitstatus) - assertEquals(0, system(trash, "git status")); - } - - public void test030_executeBit_coreModeTrue() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { - if (!FS.INSTANCE.supportsExecute()) { - System.err.println("Test ignored since platform FS does not support the execute permission"); - return; - } - try { - // coremode true is the default, typically set to false - // by git init (but not jgit!) - Method canExecute = File.class.getMethod("canExecute", (Class[])null); - Method setExecute = File.class.getMethod("setExecutable", new Class[] { Boolean.TYPE }); - File execFile = writeTrashFile("exec","exec"); - if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.TRUE })).booleanValue()) - throw new Error("could not set execute bit on "+execFile.getAbsolutePath()+"for test"); - File nonexecFile = writeTrashFile("nonexec","nonexec"); - if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.FALSE })).booleanValue()) - throw new Error("could not clear execute bit on "+nonexecFile.getAbsolutePath()+"for test"); - - GitIndex index = new GitIndex(db); - index.filemode = Boolean.TRUE; // TODO: we need a way to set this using config - index.add(trash, execFile); - index.add(trash, nonexecFile); - Tree tree = db.mapTree(index.writeTree()); - assertEquals(FileMode.EXECUTABLE_FILE, tree.findBlobMember(execFile.getName()).getMode()); - assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode()); - - index.write(); - - if (!execFile.delete()) - throw new Error("Problem in test, cannot delete test file "+execFile.getAbsolutePath()); - if (!nonexecFile.delete()) - throw new Error("Problem in test, cannot delete test file "+nonexecFile.getAbsolutePath()); - GitIndex index2 = new GitIndex(db); - index2.filemode = Boolean.TRUE; // TODO: we need a way to set this using config - index2.read(); - index2.checkout(trash); - assertTrue(((Boolean)canExecute.invoke(execFile,(Object[])null)).booleanValue()); - assertFalse(((Boolean)canExecute.invoke(nonexecFile,(Object[])null)).booleanValue()); - - assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); - assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); - - if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.FALSE })).booleanValue()) - throw new Error("could not clear set execute bit on "+execFile.getAbsolutePath()+"for test"); - if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.TRUE })).booleanValue()) - throw new Error("could set execute bit on "+nonexecFile.getAbsolutePath()+"for test"); - - assertTrue(index2.getEntry(execFile.getName()).isModified(trash)); - assertTrue(index2.getEntry(nonexecFile.getName()).isModified(trash)); - - } catch (NoSuchMethodException e) { - System.err.println("Test ignored when running under JDK < 1.6"); - return; - } - } - - public void test031_executeBit_coreModeFalse() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, Error, Exception { - if (!FS.INSTANCE.supportsExecute()) { - System.err.println("Test ignored since platform FS does not support the execute permission"); - return; - } - try { - // coremode true is the default, typically set to false - // by git init (but not jgit!) - Method canExecute = File.class.getMethod("canExecute", (Class[])null); - Method setExecute = File.class.getMethod("setExecutable", new Class[] { Boolean.TYPE }); - File execFile = writeTrashFile("exec","exec"); - if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.TRUE })).booleanValue()) - throw new Error("could not set execute bit on "+execFile.getAbsolutePath()+"for test"); - File nonexecFile = writeTrashFile("nonexec","nonexec"); - if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.FALSE })).booleanValue()) - throw new Error("could not clear execute bit on "+nonexecFile.getAbsolutePath()+"for test"); - - GitIndex index = new GitIndex(db); - index.filemode = Boolean.FALSE; // TODO: we need a way to set this using config - index.add(trash, execFile); - index.add(trash, nonexecFile); - Tree tree = db.mapTree(index.writeTree()); - assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(execFile.getName()).getMode()); - assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode()); - - index.write(); - - if (!execFile.delete()) - throw new Error("Problem in test, cannot delete test file "+execFile.getAbsolutePath()); - if (!nonexecFile.delete()) - throw new Error("Problem in test, cannot delete test file "+nonexecFile.getAbsolutePath()); - GitIndex index2 = new GitIndex(db); - index2.filemode = Boolean.FALSE; // TODO: we need a way to set this using config - index2.read(); - index2.checkout(trash); - assertFalse(((Boolean)canExecute.invoke(execFile,(Object[])null)).booleanValue()); - assertFalse(((Boolean)canExecute.invoke(nonexecFile,(Object[])null)).booleanValue()); - - assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); - assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); - - if (!((Boolean)setExecute.invoke(execFile, new Object[] { Boolean.FALSE })).booleanValue()) - throw new Error("could not clear set execute bit on "+execFile.getAbsolutePath()+"for test"); - if (!((Boolean)setExecute.invoke(nonexecFile, new Object[] { Boolean.TRUE })).booleanValue()) - throw new Error("could set execute bit on "+nonexecFile.getAbsolutePath()+"for test"); - - // no change since we ignore the execute bit - assertFalse(index2.getEntry(execFile.getName()).isModified(trash)); - assertFalse(index2.getEntry(nonexecFile.getName()).isModified(trash)); - - } catch (NoSuchMethodException e) { - System.err.println("Test ignored when running under JDK < 1.6"); - return; - } - } - - private String content(File f) throws IOException { - byte[] buf = new byte[(int) f.length()]; - FileInputStream is = new FileInputStream(f); - try { - int read = is.read(buf); - assertEquals(f.length(), read); - return new String(buf, 0); - } finally { - is.close(); - } - } - - private void delete(File f) throws IOException { - if (!f.delete()) - throw new IOException("Failed to delete f"); - } -} -- cgit v1.2.3 From e336bad367516c593699d42100cf1654059ee7c7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 2 Oct 2009 18:58:22 -0700 Subject: Only import the sample data packs on tests that need them Not all of our test cases really require the sample data packs, and we are better off not using them because its hard to see exactly what condition a test is testing when looking only at the Java code. Clarify the dependency by only making the packs available when there is a real need for it. Change-Id: Id8a76ee7ee1f7efba585be4bed19a8fb5b3b3585 Signed-off-by: Shawn O. Pearce --- .../tst/org/eclipse/jgit/lib/PackWriterTest.java | 2 +- .../tst/org/eclipse/jgit/lib/RefTest.java | 2 +- .../tst/org/eclipse/jgit/lib/RefUpdateTest.java | 2 +- .../tst/org/eclipse/jgit/lib/ReflogConfigTest.java | 3 +- .../tst/org/eclipse/jgit/lib/ReflogReaderTest.java | 2 +- .../org/eclipse/jgit/lib/RepositoryTestCase.java | 22 +------ .../jgit/lib/SampleDataRepositoryTestCase.java | 77 ++++++++++++++++++++++ .../tst/org/eclipse/jgit/lib/T0002_Tree.java | 2 +- .../tst/org/eclipse/jgit/lib/T0003_Basic.java | 2 +- .../tst/org/eclipse/jgit/lib/T0004_PackReader.java | 2 +- .../org/eclipse/jgit/lib/T0008_testparserev.java | 3 +- .../org/eclipse/jgit/lib/WindowCacheGetTest.java | 2 +- .../org/eclipse/jgit/merge/SimpleMergeTest.java | 4 +- .../eclipse/jgit/transport/BundleWriterTest.java | 4 +- .../eclipse/jgit/transport/PushProcessTest.java | 4 +- .../org/eclipse/jgit/transport/TransportTest.java | 4 +- 16 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackWriterTest.java index 7032907496..ca626d4db5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackWriterTest.java @@ -65,7 +65,7 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.transport.IndexPack; import org.eclipse.jgit.util.JGitTestUtil; -public class PackWriterTest extends RepositoryTestCase { +public class PackWriterTest extends SampleDataRepositoryTestCase { private static final List EMPTY_LIST_OBJECT = Collections . emptyList(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java index d7b6193ce1..67ed6abb21 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java @@ -56,7 +56,7 @@ import org.eclipse.jgit.lib.RefUpdate.Result; * Misc tests for refs. A lot of things are tested elsewhere so not having a * test for a ref related method, does not mean it is untested. */ -public class RefTest extends RepositoryTestCase { +public class RefTest extends SampleDataRepositoryTestCase { public void testReadAllIncludingSymrefs() throws Exception { ObjectId masterId = db.resolve("refs/heads/master"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java index 3704c56173..fa77c6a8d2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java @@ -54,7 +54,7 @@ import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; -public class RefUpdateTest extends RepositoryTestCase { +public class RefUpdateTest extends SampleDataRepositoryTestCase { private RefUpdate updateRef(final String name) throws IOException { final RefUpdate ref = db.updateRef(name); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java index f3b150fa45..8e5f6fc83b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java @@ -54,8 +54,7 @@ public class ReflogConfigTest extends RepositoryTestCase { // check that there are no entries in the reflog and turn off writing // reflogs - assertTrue("there should be no entries in reflog", db.getReflogReader( - Constants.HEAD).getReverseEntries().size() == 0); + assertNull(db.getReflogReader(Constants.HEAD)); db.getConfig().setBoolean("core", null, "logallrefupdates", false); // do one commit and check that reflog size is 0: no reflogs should be diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java index 1f2f25d5e2..6144851fcd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java @@ -53,7 +53,7 @@ import java.util.List; import org.eclipse.jgit.lib.ReflogReader.Entry; -public class ReflogReaderTest extends RepositoryTestCase { +public class ReflogReaderTest extends SampleDataRepositoryTestCase { static byte[] oneLine = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too 1243028200 +0200\tcommit: Add a toString for debugging to RemoteRefUpdate\n" .getBytes(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index ecbb7e073a..c5c6d998bb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -1,7 +1,6 @@ /* * Copyright (C) 2009, Google Inc. - * Copyright (C) 2008-2009, Jonas Fonseca - * Copyright (C) 2007-2009, Robin Rosenberg + * Copyright (C) 2007-2008, Robin Rosenberg * Copyright (C) 2006-2007, Shawn O. Pearce * Copyright (C) 2009, Yann Simon * and other copyright owners as documented in the project's IP log. @@ -55,7 +54,6 @@ import java.io.InputStreamReader; import java.io.Reader; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; -import org.eclipse.jgit.util.JGitTestUtil; /** * Base class for most JGit unit tests. @@ -114,23 +112,5 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { super.setUp(); db = createWorkRepository(); trash = db.getWorkDir(); - - final String[] packs = { - "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f", - "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371", - "pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745", - "pack-546ff360fe3488adb20860ce3436a2d6373d2796", - "pack-cbdeda40019ae0e6e789088ea0f51f164f489d14", - "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa", - "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12" - }; - final File packDir = new File(db.getObjectsDirectory(), "pack"); - for (String n : packs) { - copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack")); - copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx")); - } - - copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(db - .getDirectory(), "packed-refs")); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java new file mode 100644 index 0000000000..10c005679b --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008-2009, Jonas Fonseca + * Copyright (C) 2007-2009, Robin Rosenberg + * Copyright (C) 2006-2007, Shawn O. Pearce + * 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.lib; + +import java.io.File; + +import org.eclipse.jgit.util.JGitTestUtil; + +/** Test case which includes C Git generated pack files for testing. */ +public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + + final String[] packs = { + "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f", + "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371", + "pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745", + "pack-546ff360fe3488adb20860ce3436a2d6373d2796", + "pack-cbdeda40019ae0e6e789088ea0f51f164f489d14", + "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa", + "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12" + }; + final File packDir = new File(db.getObjectsDirectory(), "pack"); + for (String n : packs) { + copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack")); + copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx")); + } + + copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(db + .getDirectory(), "packed-refs")); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java index 66c3c75f18..7731880fd6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_Tree.java @@ -49,7 +49,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; -public class T0002_Tree extends RepositoryTestCase { +public class T0002_Tree extends SampleDataRepositoryTestCase { private static final ObjectId SOME_FAKE_ID = ObjectId.fromString( "0123456789abcdef0123456789abcdef01234567"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java index f7346a61fb..d1dfdf4fae 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java @@ -55,7 +55,7 @@ import java.io.PrintWriter; import org.eclipse.jgit.errors.ConfigInvalidException; -public class T0003_Basic extends RepositoryTestCase { +public class T0003_Basic extends SampleDataRepositoryTestCase { public void test001_Initalize() { final File gitdir = new File(trash, ".git"); final File objects = new File(gitdir, "objects"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java index be801e4940..b78b7b8554 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java @@ -51,7 +51,7 @@ import java.io.IOException; import org.eclipse.jgit.util.JGitTestUtil; -public class T0004_PackReader extends RepositoryTestCase { +public class T0004_PackReader extends SampleDataRepositoryTestCase { private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0008_testparserev.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0008_testparserev.java index ac730ff6a2..ba8dbdb7b8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0008_testparserev.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0008_testparserev.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009, Google Inc. * Copyright (C) 2008, Jonas Fonseca * Copyright (C) 2007-2008, Robin Rosenberg * Copyright (C) 2006, Shawn O. Pearce @@ -47,7 +48,7 @@ package org.eclipse.jgit.lib; import java.io.IOException; -public class T0008_testparserev extends RepositoryTestCase { +public class T0008_testparserev extends SampleDataRepositoryTestCase { public void testObjectId_existing() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0").name()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheGetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheGetTest.java index 55b568d8fd..8ff022ddc4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheGetTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheGetTest.java @@ -54,7 +54,7 @@ import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.util.JGitTestUtil; import org.eclipse.jgit.util.MutableInteger; -public class WindowCacheGetTest extends RepositoryTestCase { +public class WindowCacheGetTest extends SampleDataRepositoryTestCase { private List toLoad; @Override diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java index 0e50220067..690b166cbc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java @@ -56,10 +56,10 @@ import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectWriter; import org.eclipse.jgit.lib.PersonIdent; -import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.treewalk.TreeWalk; -public class SimpleMergeTest extends RepositoryTestCase { +public class SimpleMergeTest extends SampleDataRepositoryTestCase { public void testOurs() throws IOException { Merger ourMerger = MergeStrategy.OURS.newMerger(db); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index 39ea2f2e42..2d6aa28d5a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -60,11 +60,11 @@ import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; -public class BundleWriterTest extends RepositoryTestCase { +public class BundleWriterTest extends SampleDataRepositoryTestCase { public void testWrite0() throws Exception { // Create a tiny bundle, (well one of) the first commits only diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java index 4a47456f69..8e997e3f8c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushProcessTest.java @@ -54,12 +54,12 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; -public class PushProcessTest extends RepositoryTestCase { +public class PushProcessTest extends SampleDataRepositoryTestCase { private PushProcess process; private MockTransport transport; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java index 75e661bcf9..e3518251fe 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java @@ -49,9 +49,9 @@ import java.util.Collection; import java.util.Collections; import org.eclipse.jgit.lib.RepositoryConfig; -import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; -public class TransportTest extends RepositoryTestCase { +public class TransportTest extends SampleDataRepositoryTestCase { private Transport transport; private RemoteConfig remoteConfig; -- cgit v1.2.3 From 9108035763f7d9504671bc9bbddfb467100095e7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 3 Oct 2009 16:52:33 -0700 Subject: Refactor the cached Authenticator data out of AwtAuthenticator This makes it easier to swap out authenticator implementations and yet still rely upon being able to configure at least one Authenticator instance in the JVM and program it with data obtained from outside of the user interface. Change-Id: I8c1a0eb8acee1d306f4c3b40a790b7fa0c3abb70 Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.pgm/META-INF/MANIFEST.MF | 1 + .../src/org/eclipse/jgit/pgm/Main.java | 6 +- .../org/eclipse/jgit/awtui/AwtAuthenticator.java | 76 ++----------- .../org/eclipse/jgit/util/CachedAuthenticator.java | 126 +++++++++++++++++++++ 4 files changed, 139 insertions(+), 70 deletions(-) create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index 4d0bacc664..fe59357ab8 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Import-Package: org.eclipse.jgit.awtui, org.eclipse.jgit.transport, org.eclipse.jgit.treewalk, org.eclipse.jgit.treewalk.filter, + org.eclipse.jgit.util, org.kohsuke.args4j, org.kohsuke.args4j.spi Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 281e2f3894..7c74ee5480 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -55,6 +55,7 @@ import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.pgm.opt.SubcommandHandler; +import org.eclipse.jgit.util.CachedAuthenticator; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.ExampleMode; @@ -215,8 +216,9 @@ public class Main { final int c = userpass.indexOf(':'); final String user = userpass.substring(0, c); final String pass = userpass.substring(c + 1); - AwtAuthenticator.add(new AwtAuthenticator.CachedAuthentication( - proxyHost, proxyPort, user, pass)); + CachedAuthenticator + .add(new CachedAuthenticator.CachedAuthentication( + proxyHost, proxyPort, user, pass)); } } } diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java index 995fe9a935..1d2f9d765c 100644 --- a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java +++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtAuthenticator.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009, Google Inc. * Copyright (C) 2008, Shawn O. Pearce * and other copyright owners as documented in the project's IP log. * @@ -47,10 +48,7 @@ import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.net.Authenticator; import java.net.PasswordAuthentication; -import java.util.ArrayList; -import java.util.Collection; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -58,37 +56,17 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; -/** Basic network prompt for username/password when using AWT. */ -public class AwtAuthenticator extends Authenticator { - private static final AwtAuthenticator me = new AwtAuthenticator(); +import org.eclipse.jgit.util.CachedAuthenticator; +/** Basic network prompt for username/password when using AWT. */ +public class AwtAuthenticator extends CachedAuthenticator { /** Install this authenticator implementation into the JVM. */ public static void install() { - setDefault(me); - } - - /** - * Add a cached authentication for future use. - * - * @param ca - * the information we should remember. - */ - public static void add(final CachedAuthentication ca) { - synchronized (me) { - me.cached.add(ca); - } + setDefault(new AwtAuthenticator()); } - private final Collection cached = new ArrayList(); - @Override - protected PasswordAuthentication getPasswordAuthentication() { - for (final CachedAuthentication ca : cached) { - if (ca.host.equals(getRequestingHost()) - && ca.port == getRequestingPort()) - return ca.toPasswordAuthentication(); - } - + protected PasswordAuthentication promptPasswordAuthentication() { final GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); @@ -150,48 +128,10 @@ public class AwtAuthenticator extends Authenticator { if (JOptionPane.showConfirmDialog(null, panel, "Authentication Required", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) { - final CachedAuthentication ca = new CachedAuthentication( - getRequestingHost(), getRequestingPort(), username - .getText(), new String(password.getPassword())); - cached.add(ca); - return ca.toPasswordAuthentication(); + return new PasswordAuthentication(username.getText(), password + .getPassword()); } return null; // cancel } - - /** Authentication data to remember and reuse. */ - public static class CachedAuthentication { - final String host; - - final int port; - - final String user; - - final String pass; - - /** - * Create a new cached authentication. - * - * @param aHost - * system this is for. - * @param aPort - * port number of the service. - * @param aUser - * username at the service. - * @param aPass - * password at the service. - */ - public CachedAuthentication(final String aHost, final int aPort, - final String aUser, final String aPass) { - host = aHost; - port = aPort; - user = aUser; - pass = aPass; - } - - PasswordAuthentication toPasswordAuthentication() { - return new PasswordAuthentication(user, pass.toCharArray()); - } - } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java new file mode 100644 index 0000000000..6828185a8a --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Shawn O. Pearce + * 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.util; + +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.util.Collection; +import java.util.concurrent.CopyOnWriteArrayList; + +/** Abstract authenticator which remembers prior authentications. */ +public abstract class CachedAuthenticator extends Authenticator { + private static final Collection cached = new CopyOnWriteArrayList(); + + /** + * Add a cached authentication for future use. + * + * @param ca + * the information we should remember. + */ + public static void add(final CachedAuthentication ca) { + cached.add(ca); + } + + @Override + protected final PasswordAuthentication getPasswordAuthentication() { + final String host = getRequestingHost(); + final int port = getRequestingPort(); + for (final CachedAuthentication ca : cached) { + if (ca.host.equals(host) && ca.port == port) + return ca.toPasswordAuthentication(); + } + PasswordAuthentication pa = promptPasswordAuthentication(); + if (pa != null) { + CachedAuthentication ca = new CachedAuthentication(host, port, pa + .getUserName(), new String(pa.getPassword())); + add(ca); + return ca.toPasswordAuthentication(); + } + return null; + } + + /** + * Prompt for and request authentication from the end-user. + * + * @return the authentication data; null if the user canceled the request + * and does not want to continue. + */ + protected abstract PasswordAuthentication promptPasswordAuthentication(); + + /** Authentication data to remember and reuse. */ + public static class CachedAuthentication { + final String host; + + final int port; + + final String user; + + final String pass; + + /** + * Create a new cached authentication. + * + * @param aHost + * system this is for. + * @param aPort + * port number of the service. + * @param aUser + * username at the service. + * @param aPass + * password at the service. + */ + public CachedAuthentication(final String aHost, final int aPort, + final String aUser, final String aPass) { + host = aHost; + port = aPort; + user = aUser; + pass = aPass; + } + + PasswordAuthentication toPasswordAuthentication() { + return new PasswordAuthentication(user, pass.toCharArray()); + } + } +} -- cgit v1.2.3 From 27a497f83e683d384d379ee75570f8c25a7aa624 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 31 Oct 2009 19:42:01 -0700 Subject: Move AWT based SSH authenticator to ui bundle This way SWT based applications don't wind up loading this AWT based code when using SSH. Change-Id: I9080f3dd029c2a087e6b687480018997cc5c5d23 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/pgm/Main.java | 2 + org.eclipse.jgit.ui/META-INF/MANIFEST.MF | 7 +- .../eclipse/jgit/awtui/AwtSshSessionFactory.java | 185 +++++++++++++++++++++ .../jgit/transport/DefaultSshSessionFactory.java | 120 +------------ 4 files changed, 197 insertions(+), 117 deletions(-) create mode 100644 org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtSshSessionFactory.java diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 7c74ee5480..3579b65e31 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.awtui.AwtAuthenticator; +import org.eclipse.jgit.awtui.AwtSshSessionFactory; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.opt.CmdLineParser; @@ -88,6 +89,7 @@ public class Main { final Main me = new Main(); try { AwtAuthenticator.install(); + AwtSshSessionFactory.install(); configureHttpProxy(); me.execute(argv); } catch (Die err) { diff --git a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF index a2c17a6a2a..a6710cd526 100644 --- a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF @@ -7,6 +7,9 @@ Bundle-Version: 0.6.0.qualifier Bundle-Vendor: %provider_name Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.eclipse.jgit.awtui;version="0.6.0" -Import-Package: org.eclipse.jgit.lib, +Import-Package: com.jcraft.jsch, + org.eclipse.jgit.lib;version="0.6.0", + org.eclipse.jgit.transport, org.eclipse.jgit.revplot, - org.eclipse.jgit.revwalk;version="0.6.0" + org.eclipse.jgit.revwalk, + org.eclipse.jgit.util diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtSshSessionFactory.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtSshSessionFactory.java new file mode 100644 index 0000000000..f6710854b4 --- /dev/null +++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtSshSessionFactory.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2008, Robin Rosenberg + * Copyright (C) 2008, Shawn O. Pearce + * 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.awtui; + +import java.awt.Container; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +import org.eclipse.jgit.transport.OpenSshConfig; +import org.eclipse.jgit.transport.SshConfigSessionFactory; +import org.eclipse.jgit.transport.SshSessionFactory; + +import com.jcraft.jsch.Session; +import com.jcraft.jsch.UIKeyboardInteractive; +import com.jcraft.jsch.UserInfo; + +/** + * Loads known hosts and private keys from $HOME/.ssh. + *

+ * This is the default implementation used by JGit and provides most of the + * compatibility necessary to match OpenSSH, a popular implementation of SSH + * used by C Git. + *

+ * If user interactivity is required by SSH (e.g. to obtain a password) AWT is + * used to display a password input field to the end-user. + */ +public class AwtSshSessionFactory extends SshConfigSessionFactory { + /** Install this session factory implementation into the JVM. */ + public static void install() { + SshSessionFactory.setInstance(new AwtSshSessionFactory()); + } + + @Override + protected void configure(final OpenSshConfig.Host hc, final Session session) { + if (!hc.isBatchMode()) + session.setUserInfo(new AWT_UserInfo()); + } + + private static class AWT_UserInfo implements UserInfo, + UIKeyboardInteractive { + private String passwd; + + private String passphrase; + + public void showMessage(final String msg) { + JOptionPane.showMessageDialog(null, msg); + } + + public boolean promptYesNo(final String msg) { + return JOptionPane.showConfirmDialog(null, msg, "Warning", + JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; + } + + public boolean promptPassword(final String msg) { + passwd = null; + final JPasswordField passwordField = new JPasswordField(20); + final int result = JOptionPane.showConfirmDialog(null, + new Object[] { passwordField }, msg, + JOptionPane.OK_CANCEL_OPTION); + if (result == JOptionPane.OK_OPTION) { + passwd = new String(passwordField.getPassword()); + return true; + } + return false; + } + + public boolean promptPassphrase(final String msg) { + passphrase = null; + final JPasswordField passwordField = new JPasswordField(20); + final int result = JOptionPane.showConfirmDialog(null, + new Object[] { passwordField }, msg, + JOptionPane.OK_CANCEL_OPTION); + if (result == JOptionPane.OK_OPTION) { + passphrase = new String(passwordField.getPassword()); + return true; + } + return false; + } + + public String getPassword() { + return passwd; + } + + public String getPassphrase() { + return passphrase; + } + + public String[] promptKeyboardInteractive(final String destination, + final String name, final String instruction, + final String[] prompt, final boolean[] echo) { + final GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, + 1, 1, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); + final Container panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + + gbc.weightx = 1.0; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.gridx = 0; + panel.add(new JLabel(instruction), gbc); + gbc.gridy++; + + gbc.gridwidth = GridBagConstraints.RELATIVE; + + final JTextField[] texts = new JTextField[prompt.length]; + for (int i = 0; i < prompt.length; i++) { + gbc.fill = GridBagConstraints.NONE; + gbc.gridx = 0; + gbc.weightx = 1; + panel.add(new JLabel(prompt[i]), gbc); + + gbc.gridx = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weighty = 1; + if (echo[i]) { + texts[i] = new JTextField(20); + } else { + texts[i] = new JPasswordField(20); + } + panel.add(texts[i], gbc); + gbc.gridy++; + } + + if (JOptionPane.showConfirmDialog(null, panel, destination + ": " + + name, JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) { + String[] response = new String[prompt.length]; + for (int i = 0; i < prompt.length; i++) { + response[i] = texts[i].getText(); + } + return response; + } + return null; // cancel + } + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java index 6ff3d4b2f3..53c1a2ce3a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java @@ -1,4 +1,6 @@ /* + * Copyright (C) 2009, Constantine Plotnikov + * Copyright (C) 2009, Google Inc. * Copyright (C) 2008, Robin Rosenberg * Copyright (C) 2008, Shawn O. Pearce * and other copyright owners as documented in the project's IP log. @@ -44,20 +46,7 @@ package org.eclipse.jgit.transport; -import java.awt.Container; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; - -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JTextField; - import com.jcraft.jsch.Session; -import com.jcraft.jsch.UIKeyboardInteractive; -import com.jcraft.jsch.UserInfo; /** * Loads known hosts and private keys from $HOME/.ssh. @@ -66,110 +55,11 @@ import com.jcraft.jsch.UserInfo; * compatibility necessary to match OpenSSH, a popular implementation of SSH * used by C Git. *

- * If user interactivity is required by SSH (e.g. to obtain a password) AWT is - * used to display a password input field to the end-user. + * If user interactivity is required by SSH (e.g. to obtain a password), the + * connection will immediately fail. */ class DefaultSshSessionFactory extends SshConfigSessionFactory { protected void configure(final OpenSshConfig.Host hc, final Session session) { - if (!hc.isBatchMode()) - session.setUserInfo(new AWT_UserInfo()); - } - - private static class AWT_UserInfo implements UserInfo, - UIKeyboardInteractive { - private String passwd; - - private String passphrase; - - public void showMessage(final String msg) { - JOptionPane.showMessageDialog(null, msg); - } - - public boolean promptYesNo(final String msg) { - return JOptionPane.showConfirmDialog(null, msg, "Warning", - JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; - } - - public boolean promptPassword(final String msg) { - passwd = null; - final JPasswordField passwordField = new JPasswordField(20); - final int result = JOptionPane.showConfirmDialog(null, - new Object[] { passwordField }, msg, - JOptionPane.OK_CANCEL_OPTION); - if (result == JOptionPane.OK_OPTION) { - passwd = new String(passwordField.getPassword()); - return true; - } - return false; - } - - public boolean promptPassphrase(final String msg) { - passphrase = null; - final JPasswordField passwordField = new JPasswordField(20); - final int result = JOptionPane.showConfirmDialog(null, - new Object[] { passwordField }, msg, - JOptionPane.OK_CANCEL_OPTION); - if (result == JOptionPane.OK_OPTION) { - passphrase = new String(passwordField.getPassword()); - return true; - } - return false; - } - - public String getPassword() { - return passwd; - } - - public String getPassphrase() { - return passphrase; - } - - public String[] promptKeyboardInteractive(final String destination, - final String name, final String instruction, - final String[] prompt, final boolean[] echo) { - final GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, - 1, 1, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); - final Container panel = new JPanel(); - panel.setLayout(new GridBagLayout()); - - gbc.weightx = 1.0; - gbc.gridwidth = GridBagConstraints.REMAINDER; - gbc.gridx = 0; - panel.add(new JLabel(instruction), gbc); - gbc.gridy++; - - gbc.gridwidth = GridBagConstraints.RELATIVE; - - final JTextField[] texts = new JTextField[prompt.length]; - for (int i = 0; i < prompt.length; i++) { - gbc.fill = GridBagConstraints.NONE; - gbc.gridx = 0; - gbc.weightx = 1; - panel.add(new JLabel(prompt[i]), gbc); - - gbc.gridx = 1; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.weighty = 1; - if (echo[i]) { - texts[i] = new JTextField(20); - } else { - texts[i] = new JPasswordField(20); - } - panel.add(texts[i], gbc); - gbc.gridy++; - } - - if (JOptionPane.showConfirmDialog(null, panel, destination + ": " - + name, JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) { - String[] response = new String[prompt.length]; - for (int i = 0; i < prompt.length; i++) { - response[i] = texts[i].getText(); - } - return response; - } - return null; // cancel - } + // No additional configuration required. } } -- cgit v1.2.3 From 7e8dc53881a4f7babbab9cd9979a49edb7ad03f1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 31 Oct 2009 19:39:18 -0700 Subject: Prompt for passwords from the console in jgit command line tools If we are on a Java 6 JVM we should have the Console class available, unless the user has redirected /dev/null to stdin. When there is a console present we would prefer to use that for command line prompts as that is what the user expects from a command line tool. Change-Id: Ibaf87bb5540371d94d96d1b7e94ca002f752e5bd Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.console/.classpath | 7 + org.eclipse.jgit.console/.gitignore | 2 + org.eclipse.jgit.console/.project | 34 +++ .../.settings/org.eclipse.core.resources.prefs | 3 + .../.settings/org.eclipse.core.runtime.prefs | 3 + .../.settings/org.eclipse.jdt.core.prefs | 331 +++++++++++++++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 61 ++++ .../.settings/org.eclipse.pde.core.prefs | 3 + org.eclipse.jgit.console/META-INF/MANIFEST.MF | 12 + org.eclipse.jgit.console/build.properties | 5 + org.eclipse.jgit.console/plugin.properties | 2 + org.eclipse.jgit.console/pom.xml | 105 +++++++ .../eclipse/jgit/console/ConsoleAuthenticator.java | 94 ++++++ .../jgit/console/ConsoleSshSessionFactory.java | 145 +++++++++ org.eclipse.jgit.pgm/pom.xml | 16 + .../src/org/eclipse/jgit/pgm/Main.java | 46 ++- pom.xml | 15 + 17 files changed, 882 insertions(+), 2 deletions(-) create mode 100644 org.eclipse.jgit.console/.classpath create mode 100644 org.eclipse.jgit.console/.gitignore create mode 100644 org.eclipse.jgit.console/.project create mode 100644 org.eclipse.jgit.console/.settings/org.eclipse.core.resources.prefs create mode 100644 org.eclipse.jgit.console/.settings/org.eclipse.core.runtime.prefs create mode 100644 org.eclipse.jgit.console/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.jgit.console/.settings/org.eclipse.jdt.ui.prefs create mode 100644 org.eclipse.jgit.console/.settings/org.eclipse.pde.core.prefs create mode 100644 org.eclipse.jgit.console/META-INF/MANIFEST.MF create mode 100644 org.eclipse.jgit.console/build.properties create mode 100644 org.eclipse.jgit.console/plugin.properties create mode 100644 org.eclipse.jgit.console/pom.xml create mode 100644 org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleAuthenticator.java create mode 100644 org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleSshSessionFactory.java diff --git a/org.eclipse.jgit.console/.classpath b/org.eclipse.jgit.console/.classpath new file mode 100644 index 0000000000..ad32c83a78 --- /dev/null +++ b/org.eclipse.jgit.console/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.jgit.console/.gitignore b/org.eclipse.jgit.console/.gitignore new file mode 100644 index 0000000000..934e0e06ff --- /dev/null +++ b/org.eclipse.jgit.console/.gitignore @@ -0,0 +1,2 @@ +/bin +/target diff --git a/org.eclipse.jgit.console/.project b/org.eclipse.jgit.console/.project new file mode 100644 index 0000000000..4f272a7ccc --- /dev/null +++ b/org.eclipse.jgit.console/.project @@ -0,0 +1,34 @@ + + + org.eclipse.jgit.console + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/org.eclipse.jgit.console/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jgit.console/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..190e5c57d0 --- /dev/null +++ b/org.eclipse.jgit.console/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Sun Oct 11 08:00:39 EEST 2009 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.jgit.console/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.jgit.console/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..dc570415b6 --- /dev/null +++ b/org.eclipse.jgit.console/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Sun Oct 11 08:00:39 EEST 2009 +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.jgit.console/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.console/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..214c48957a --- /dev/null +++ b/org.eclipse.jgit.console/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,331 @@ +#Sat Oct 31 19:37:20 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=error +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected +org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=error +org.eclipse.jdt.core.compiler.problem.unusedLocal=error +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=80 +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=80 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true diff --git a/org.eclipse.jgit.console/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jgit.console/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..ccd15c2328 --- /dev/null +++ b/org.eclipse.jgit.console/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,61 @@ +#Sat Oct 31 16:20:21 PDT 2009 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_JGit Format +formatter_settings_version=11 +org.eclipse.jdt.ui.ignorelowercasenames=true +org.eclipse.jdt.ui.importorder=java;javax;org;com; +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +org.eclipse.jdt.ui.text.custom_code_templates= +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.jgit.console/.settings/org.eclipse.pde.core.prefs b/org.eclipse.jgit.console/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000000..9482745744 --- /dev/null +++ b/org.eclipse.jgit.console/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +#Sun Oct 11 07:58:06 EEST 2009 +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/org.eclipse.jgit.console/META-INF/MANIFEST.MF b/org.eclipse.jgit.console/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ed12693f0c --- /dev/null +++ b/org.eclipse.jgit.console/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Bundle-Localization: plugin +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin_name +Bundle-SymbolicName: org.eclipse.jgit.console +Bundle-Version: 0.6.0.qualifier +Bundle-Vendor: %provider_name +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.eclipse.jgit.console;version="0.6.0" +Import-Package: com.jcraft.jsch;version="0.1.41", + org.eclipse.jgit.transport;version="0.6.0", + org.eclipse.jgit.util diff --git a/org.eclipse.jgit.console/build.properties b/org.eclipse.jgit.console/build.properties new file mode 100644 index 0000000000..aa1a008269 --- /dev/null +++ b/org.eclipse.jgit.console/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/org.eclipse.jgit.console/plugin.properties b/org.eclipse.jgit.console/plugin.properties new file mode 100644 index 0000000000..a86bcd86b8 --- /dev/null +++ b/org.eclipse.jgit.console/plugin.properties @@ -0,0 +1,2 @@ +plugin_name=Java Git Console User Interface (Incubation) +provider_name=eclipse.org diff --git a/org.eclipse.jgit.console/pom.xml b/org.eclipse.jgit.console/pom.xml new file mode 100644 index 0000000000..98b1511ec1 --- /dev/null +++ b/org.eclipse.jgit.console/pom.xml @@ -0,0 +1,105 @@ + + + + + 4.0.0 + + + org.eclipse.jgit + jgit-parent + 0.6.0-SNAPSHOT + + + org.eclipse.jgit.console + JGit - Console User Interface + + + Console based user interface + + + + + org.eclipse.jgit + org.eclipse.jgit + + + + + src/ + + + + . + + plugin.properties + + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + UTF-8 + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + + + + + + diff --git a/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleAuthenticator.java b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleAuthenticator.java new file mode 100644 index 0000000000..84fd520f75 --- /dev/null +++ b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleAuthenticator.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Shawn O. Pearce + * 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.console; + +import java.io.Console; +import java.net.Authenticator; +import java.net.PasswordAuthentication; + +import org.eclipse.jgit.util.CachedAuthenticator; + +/** Basic network prompt for username/password when using the console. */ +public class ConsoleAuthenticator extends CachedAuthenticator { + /** Install this authenticator implementation into the JVM. */ + public static void install() { + final ConsoleAuthenticator c = new ConsoleAuthenticator(); + if (c.cons == null) + throw new NoClassDefFoundError("No System.console available"); + Authenticator.setDefault(c); + } + + private final Console cons = System.console(); + + @Override + protected PasswordAuthentication promptPasswordAuthentication() { + final String realm = formatRealm(); + String username = cons.readLine("Username for %s: ", realm); + if (username == null || username.isEmpty()) { + return null; + } + char[] password = cons.readPassword("Password: "); + if (password == null) { + password = new char[0]; + } + return new PasswordAuthentication(username, password); + } + + private String formatRealm() { + final StringBuilder realm = new StringBuilder(); + if (getRequestorType() == RequestorType.PROXY) { + realm.append(getRequestorType()); + realm.append(" "); + realm.append(getRequestingHost()); + if (getRequestingPort() > 0) { + realm.append(":"); + realm.append(getRequestingPort()); + } + } else { + realm.append(getRequestingURL()); + } + return realm.toString(); + } +} diff --git a/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleSshSessionFactory.java b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleSshSessionFactory.java new file mode 100644 index 0000000000..7d36dded48 --- /dev/null +++ b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleSshSessionFactory.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Robin Rosenberg + * Copyright (C) 2008, Shawn O. Pearce + * 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.console; + +import java.io.Console; + +import org.eclipse.jgit.transport.OpenSshConfig; +import org.eclipse.jgit.transport.SshConfigSessionFactory; +import org.eclipse.jgit.transport.SshSessionFactory; + +import com.jcraft.jsch.Session; +import com.jcraft.jsch.UIKeyboardInteractive; +import com.jcraft.jsch.UserInfo; + +/** + * Loads known hosts and private keys from $HOME/.ssh. + *

+ * This is the default implementation used by JGit and provides most of the + * compatibility necessary to match OpenSSH, a popular implementation of SSH + * used by C Git. + *

+ * If user interactivity is required by SSH (e.g. to obtain a password) the + * system console is used to display a prompt to the end-user. + */ +public class ConsoleSshSessionFactory extends SshConfigSessionFactory { + /** Install this session factory implementation into the JVM. */ + public static void install() { + final ConsoleSshSessionFactory c = new ConsoleSshSessionFactory(); + if (c.cons == null) + throw new NoClassDefFoundError("No System.console available"); + SshSessionFactory.setInstance(c); + } + + private final Console cons = System.console(); + + @Override + protected void configure(final OpenSshConfig.Host hc, final Session session) { + if (!hc.isBatchMode()) + session.setUserInfo(new ConsoleUserInfo()); + } + + private class ConsoleUserInfo implements UserInfo, UIKeyboardInteractive { + private String passwd; + + private String passphrase; + + public void showMessage(final String msg) { + cons.printf("%s\n", msg); + cons.flush(); + } + + public boolean promptYesNo(final String msg) { + String r = cons.readLine("%s [y/n]? ", msg); + return "y".equalsIgnoreCase(r); + } + + public boolean promptPassword(final String msg) { + passwd = null; + char[] p = cons.readPassword("%s: ", msg); + if (p != null) { + passwd = new String(p); + return true; + } + return false; + } + + public boolean promptPassphrase(final String msg) { + passphrase = null; + char[] p = cons.readPassword("%s: ", msg); + if (p != null) { + passphrase = new String(p); + return true; + } + return false; + } + + public String getPassword() { + return passwd; + } + + public String getPassphrase() { + return passphrase; + } + + public String[] promptKeyboardInteractive(final String destination, + final String name, final String instruction, + final String[] prompt, final boolean[] echo) { + cons.printf("%s: %s\n", destination, name); + cons.printf("%s\n", instruction); + final String[] response = new String[prompt.length]; + for (int i = 0; i < prompt.length; i++) { + if (echo[i]) { + response[i] = cons.readLine("%s: ", prompt[i]); + } else { + final char[] p = cons.readPassword("%s: ", prompt[i]); + response[i] = p != null ? new String(p) : ""; + } + } + return response; + } + } +} diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml index 8f2312b85e..e06dbc2d02 100644 --- a/org.eclipse.jgit.pgm/pom.xml +++ b/org.eclipse.jgit.pgm/pom.xml @@ -77,6 +77,22 @@ + + + java6 + + true + + + + org.eclipse.jgit + org.eclipse.jgit.console + ${project.version} + + + + + src/ diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 3579b65e31..18cf8be467 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.pgm; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -88,8 +89,10 @@ public class Main { public static void main(final String[] argv) { final Main me = new Main(); try { - AwtAuthenticator.install(); - AwtSshSessionFactory.install(); + if (!installConsole()) { + AwtAuthenticator.install(); + AwtSshSessionFactory.install(); + } configureHttpProxy(); me.execute(argv); } catch (Die err) { @@ -184,6 +187,45 @@ public class Main { return null; } + private static boolean installConsole() { + try { + install("org.eclipse.jgit.console.ConsoleAuthenticator"); + install("org.eclipse.jgit.console.ConsoleSshSessionFactory"); + return true; + } catch (ClassNotFoundException e) { + return false; + } catch (NoClassDefFoundError e) { + return false; + } catch (UnsupportedClassVersionError e) { + return false; + + } catch (IllegalArgumentException e) { + throw new RuntimeException("Cannot setup console", e); + } catch (SecurityException e) { + throw new RuntimeException("Cannot setup console", e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Cannot setup console", e); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot setup console", e); + } catch (NoSuchMethodException e) { + throw new RuntimeException("Cannot setup console", e); + } + } + + private static void install(final String name) + throws IllegalAccessException, InvocationTargetException, + NoSuchMethodException, ClassNotFoundException { + try { + Class.forName(name).getMethod("install").invoke(null); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof RuntimeException) + throw (RuntimeException) e.getCause(); + if (e.getCause() instanceof Error) + throw (Error) e.getCause(); + throw e; + } + } + /** * Configure the JRE's standard HTTP based on http_proxy. *

diff --git a/pom.xml b/pom.xml index e144f492d9..974b58f93a 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,21 @@ + + + + java6 + + + !jgit.java6.skip + + + + org.eclipse.jgit.console + + + + org.eclipse.jgit org.eclipse.jgit.ui -- cgit v1.2.3