Introduce utility method to load test resources
PATCH 1/3 Introduce utility method to load test resources
From: Imran M Yousuf <[email protected]>
Previously test resources were being loaded from the sources but code for loading them was done in different locations, thus introduced a utility class that will contain utility operations and the first one's responsibility would be to load test resources.
--- .../dircache/DirCacheCGitCompatabilityTest.java | 3 +- .../tst/org/spearce/jgit/lib/PackIndexV1Test.java | 9 ++++--- .../tst/org/spearce/jgit/lib/PackIndexV2Test.java | 5 ++- .../org/spearce/jgit/lib/PackReverseIndexTest.java | 5 +-- .../tst/org/spearce/jgit/lib/PackWriterTest.java | 3 +- .../org/spearce/jgit/lib/RepositoryTestCase.java | 8 +++--- .../tst/org/spearce/jgit/lib/T0004_PackReader.java | 8 ++++-- .../org/spearce/jgit/transport/IndexPackTest.java | 6 ++-- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 25 +++++++++---------- 9 files changed, 38 insertions(+), 34 deletions(-) copy org.spearce.jgit/src/org/spearce/jgit/util/FS_POSIX_Java5.java => org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java (80%)
org.spearce.jgit.test/tst/org/spearce/jgit/dircache/DirCacheCGitCompatabilityTest.java +2 -1
@@ -50,6 +50,7 @@ import org.spearce.jgit.lib.ObjectId; import org.spearce.jgit.lib.RepositoryTestCase; import org.spearce.jgit.treewalk.TreeWalk; +import org.spearce.jgit.util.JGitTestUtil; public class DirCacheCGitCompatabilityTest extends RepositoryTestCase { private final File index = pathOf("gitgit.index");
@@ -138,7 +139,7 @@ assertEquals(ObjectId } private File pathOf(final String name) { - return new File("tst", name); + return JGitTestUtil.getTestResourceFile(name); } private Map<String, CGitIndexRecord> readLsFiles() throws Exception {
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java +5 -4
@@ -40,18 +40,19 @@ import java.io.File; import org.spearce.jgit.errors.MissingObjectException; +import org.spearce.jgit.util.JGitTestUtil; public class PackIndexV1Test extends PackIndexTest { @Override public File getFileForPack34be9032() { - return new File(new File("tst"), - "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx"); + return JGitTestUtil.getTestResourceFile( + "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx"); } @Override public File getFileForPackdf2982f28() { - return new File(new File("tst"), - "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx"); + return JGitTestUtil.getTestResourceFile( + "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx"); } /**
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java +3 -2
@@ -40,17 +40,18 @@ import java.io.File; import org.spearce.jgit.errors.MissingObjectException; +import org.spearce.jgit.util.JGitTestUtil; public class PackIndexV2Test extends PackIndexTest { @Override public File getFileForPack34be9032() { - return new File(new File("tst"), + return JGitTestUtil.getTestResourceFile( "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"); } @Override public File getFileForPackdf2982f28() { - return new File(new File("tst"), + return JGitTestUtil.getTestResourceFile( "pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2"); }
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java +2 -3
@@ -37,10 +37,9 @@ package org.spearce.jgit.lib; -import java.io.File; - import org.spearce.jgit.errors.CorruptObjectException; import org.spearce.jgit.lib.PackIndex.MutableEntry; +import org.spearce.jgit.util.JGitTestUtil; public class PackReverseIndexTest extends RepositoryTestCase {
@@ -54,7 +53,7 @@ public void setUp() throws Exception { super.setUp(); // index with both small (< 2^31) and big offsets - idx = PackIndex.open(new File(new File("tst"), + idx = PackIndex.open(JGitTestUtil.getTestResourceFile( "pack-huge.idx")); reverseIdx = new PackReverseIndex(idx); }
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java +2 -1
@@ -57,6 +57,7 @@ import org.spearce.jgit.revwalk.RevWalk; import org.spearce.jgit.transport.IndexPack; import org.spearce.jgit.util.CountingOutputStream; +import org.spearce.jgit.util.JGitTestUtil; public class PackWriterTest extends RepositoryTestCase {
@@ -239,7 +240,7 @@ public void testWritePack2DeltasCRC32Copy() throws IOException { "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); final File crc32Idx = new File(packDir, "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx"); - copyFile(new File(new File("tst"), + copyFile(JGitTestUtil.getTestResourceFile( "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2"), crc32Idx); db.openPack(crc32Pack, crc32Idx);
org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java +4 -4
@@ -47,6 +47,7 @@ import java.io.Reader; import junit.framework.TestCase; +import org.spearce.jgit.util.JGitTestUtil; public abstract class RepositoryTestCase extends TestCase {
@@ -142,16 +143,15 @@ public void run() { "pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745", "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa" }; - final File tst = new File("tst"); final File packDir = new File(db.getObjectsDirectory(), "pack"); for (int k = 0; k < packs.length; k++) { - copyFile(new File(tst, packs[k] + ".pack"), new File(packDir, + copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".pack"), new File(packDir, packs[k] + ".pack")); - copyFile(new File(tst, packs[k] + ".idx"), new File(packDir, + copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".idx"), new File(packDir, packs[k] + ".idx")); } - copyFile(new File(tst, "packed-refs"), new File(trash_git,"packed-refs")); + copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(trash_git,"packed-refs")); db.scanForPacks(); }
org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0004_PackReader.java +5 -3
@@ -41,10 +41,12 @@ import java.io.File; import java.io.IOException; +import org.spearce.jgit.util.JGitTestUtil; + public class T0004_PackReader extends RepositoryTestCase { private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; - private static final File TEST_PACK = new File(new File("tst"), PACK_NAME + ".pack"); - private static final File TEST_IDX = new File(TEST_PACK.getParentFile(), PACK_NAME + ".idx"); + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); public void test003_lookupCompressedObject() throws IOException { final PackFile pr;
@@ -77,7 +79,7 @@ public void test004_lookupDeltifiedObject() throws IOException { } public void test005_todopack() throws IOException { - final File todopack = new File(new File("tst"), "todopack"); + final File todopack = JGitTestUtil.getTestResourceFile("todopack"); if (!todopack.isDirectory()) { System.err.println("Skipping " + getName() + ": no " + todopack); return;
org.spearce.jgit.test/tst/org/spearce/jgit/transport/IndexPackTest.java +3 -3
@@ -47,7 +47,7 @@ import org.spearce.jgit.lib.PackFile; import org.spearce.jgit.lib.RepositoryTestCase; import org.spearce.jgit.lib.TextProgressMonitor; -import org.spearce.jgit.transport.IndexPack; +import org.spearce.jgit.util.JGitTestUtil; /** * Test indexing of git packs. A pack is read from a stream, copied
@@ -63,7 +63,7 @@ * @throws IOException */ public void test1() throws IOException { - File packFile = new File("tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); + File packFile = JGitTestUtil.getTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); final InputStream is = new FileInputStream(packFile); try { IndexPack pack = new IndexPack(db, is, new File(trash, "tmp_pack1"));
@@ -89,7 +89,7 @@ public void test1() throws IOException { * @throws IOException */ public void test2() throws IOException { - File packFile = new File("tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"); + File packFile = JGitTestUtil.getTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"); final InputStream is = new FileInputStream(packFile); try { IndexPack pack = new IndexPack(db, is, new File(trash, "tmp_pack2"));
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java renamed from org.spearce.jgit/src/org/spearce/jgit/util/FS_POSIX_Java5.java +12 -13
@@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Shawn O. Pearce <[email protected]> + * Copyright (C) 2008, Imran M Yousuf <[email protected]> * * All rights reserved. *
@@ -39,16 +39,15 @@ import java.io.File; -class FS_POSIX_Java5 extends FS { - public boolean supportsExecute() { - return false; - } - - public boolean canExecute(final File f) { - return false; - } - - public boolean setExecute(final File f, final boolean canExec) { - return false; - } +public abstract class JGitTestUtil { + private JGitTestUtil() { + throw new AssertionError(); + } + + public static File getTestResourceFile(String fileName) { + if (fileName == null || fileName.length() <= 0) { + return null; + } + return new File("tst", fileName); + } }
Signature · 1 line
1.5.6
PATCH 2/3 Relocate test resources to classpath and load from there
From: Imran M Yousuf <[email protected]>
Previously test case resources were located in the root directory, this change relocates them to a classpath location and loads the resources from there.
If there is request for any test resource that is not present in classpath then util method will return the same value as it would in previous state.
---
org.spearce.jgit.test/.classpath | 1 +
.../jgit/test/resources}/create-second-pack | 0
.../org/spearce/jgit/test/resources}/gitgit.index | Bin 134799 -> 134799 bytes
.../spearce/jgit/test/resources}/gitgit.lsfiles | 0
.../org/spearce/jgit/test/resources}/gitgit.lstree | 0
...ck-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx | Bin 1256 -> 1256 bytes
...-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 | Bin 1296 -> 1296 bytes
...k-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack | Bin 7811 -> 7811 bytes
...ck-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx | Bin 1088 -> 1088 bytes
...k-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.pack | Bin 164 -> 164 bytes
...ck-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx | Bin 2696 -> 2696 bytes
...-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 | Bin 2976 -> 2976 bytes
...k-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack | Bin 5956 -> 5956 bytes
...ck-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.idx | Bin 1112 -> 1112 bytes
...k-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.pack | Bin 1643 -> 1643 bytes
.../org/spearce/jgit/test/resources}/pack-huge.idx | Bin 2368 -> 2368 bytes
.../org/spearce/jgit/test/resources}/packed-refs | 0
.../tst/org/spearce/jgit/util/JGitTestUtil.java | 15 ++++++++++++++-
18 files changed, 15 insertions(+), 1 deletions(-)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/create-second-pack (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/gitgit.index (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/gitgit.lsfiles (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/gitgit.lstree (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.pack (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.idx (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.pack (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/pack-huge.idx (100%)
rename org.spearce.jgit.test/{tst => tst-rsrc/org/spearce/jgit/test/resources}/packed-refs (100%)org.spearce.jgit.test/.classpath +1 -0
@@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="**/*.idx|**/*.pack" kind="src" path="tst"/> + <classpathentry kind="src" path="tst-rsrc"/> <classpathentry kind="src" path="exttst"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry combineaccessrules="false" kind="src" path="/org.spearce.jgit"/>
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack renamed from org.spearce.jgit.test/tst/create-second-pack +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/gitgit.index renamed from org.spearce.jgit.test/tst/gitgit.index +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/gitgit.lsfiles renamed from org.spearce.jgit.test/tst/gitgit.lsfiles +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/gitgit.lstree renamed from org.spearce.jgit.test/tst/gitgit.lstree +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx renamed from org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 renamed from org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack renamed from org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx renamed from org.spearce.jgit.test/tst/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.pack renamed from org.spearce.jgit.test/tst/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.pack +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx renamed from org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 renamed from org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack renamed from org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.idx renamed from org.spearce.jgit.test/tst/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.idx +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.pack renamed from org.spearce.jgit.test/tst/pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa.pack +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-huge.idx renamed from org.spearce.jgit.test/tst/pack-huge.idx +0 -0
org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs renamed from org.spearce.jgit.test/tst/packed-refs +0 -0
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +14 -1
@@ -38,8 +38,13 @@ package org.spearce.jgit.util; import java.io.File; +import java.net.URL; public abstract class JGitTestUtil { + + public static final String CLASSPATH_TO_RESOURCES = + "/org/spearce/jgit/test/resources/"; + private JGitTestUtil() { throw new AssertionError(); }
@@ -48,6 +53,14 @@ public static File getTestResourceFile(String fileName) { if (fileName == null || fileName.length() <= 0) { return null; } - return new File("tst", fileName); + URL url = JGitTestUtil.class.getResource( + new StringBuilder(CLASSPATH_TO_RESOURCES) + .append(fileName).toString()); + //If URL is null then try to load it as it was being + //loaded previously + if (url == null) { + return new File("tst", fileName); + } + return new File(url.getPath()); } }
Signature · 1 line
1.5.6
PATCH 3/3 Add a POM file for setting JGit library as a Maven project
From: Imran M Yousuf <[email protected]>
Add ignore list for mavenized JGit's artifacts directory.
--- jgit-maven/.gitignore | 1 + jgit-maven/jgit/pom.xml | 169 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 0 deletions(-) create mode 100644 jgit-maven/.gitignore create mode 100644 jgit-maven/jgit/pom.xml
jgit-maven/.gitignore new file +1 -0
@@ -0,0 +1 @@ +target
jgit-maven/jgit/pom.xml new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
1.5.6
Re: [JGIT PATCH 3/3] Add a POM file for setting JGit library as a Maven project
Quoted 3 lines · [email protected] wrote:
From: Imran M Yousuf <[email protected]>
Add ignore list for mavenized JGit's artifacts directory.
Thanks. Maven POM file is now in JGit. ;-)
Signature · 1 line
Shawn.
Re: [JGIT PATCH 3/3] Add a POM file for setting JGit library as a Maven project
Quoted 7 lines · Shawn O. Pearce
Quoted 3 lines · [email protected] wrote:
From: Imran M Yousuf <[email protected]>
Add ignore list for mavenized JGit's artifacts directory.
Thanks. Maven POM file is now in JGit. ;-)
Thanks a lot.
- Imran
Quoted 3 lines
--
Shawn.
Signature · 7 lines
Imran M Yousuf Entrepreneur & Software Engineer Smart IT Engineering Dhaka, Bangladesh Email: [email protected] Blog: http://imyousuf-tech.blogs.smartitengineering.com/ Mobile: +880-1711402557