summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java14
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java20
2 files changed, 18 insertions, 16 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
index 106abf0912..c8c56b21b8 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
@@ -9,10 +9,10 @@
*/
package org.eclipse.jgit.junit;
-import static java.lang.ClassLoader.getSystemClassLoader;
-
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.file.Paths;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
@@ -42,7 +42,13 @@ public class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner {
private static Class<?> loadNewClass(Class<?> klass)
throws InitializationError {
try {
- URL[] urls = ((URLClassLoader) getSystemClassLoader()).getURLs();
+ String pathSeparator = System.getProperty("path.separator");
+ String[] classPathEntries = System.getProperty("java.class.path")
+ .split(pathSeparator);
+ URL[] urls = new URL[classPathEntries.length];
+ for (int i = 0; i < classPathEntries.length; i++) {
+ urls[i] = Paths.get(classPathEntries[i]).toUri().toURL();
+ }
ClassLoader testClassLoader = new URLClassLoader(urls) {
@Override
@@ -56,7 +62,7 @@ public class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner {
}
};
return Class.forName(klass.getName(), true, testClassLoader);
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException | MalformedURLException e) {
throw new InitializationError(e);
}
}
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index fc19de0bdf..54e4a09ee5 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -43,8 +43,10 @@ import org.eclipse.jgit.errors.ObjectWritingException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.internal.storage.file.LockFile;
import org.eclipse.jgit.internal.storage.file.ObjectDirectory;
+import org.eclipse.jgit.internal.storage.file.Pack;
import org.eclipse.jgit.internal.storage.file.PackFile;
import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry;
+import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.internal.storage.pack.PackWriter;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
@@ -775,7 +777,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
rw.writeInfoRefs();
final StringBuilder w = new StringBuilder();
- for (PackFile p : fr.getObjectDatabase().getPacks()) {
+ for (Pack p : fr.getObjectDatabase().getPacks()) {
w.append("P ");
w.append(p.getPackFile().getName());
w.append('\n');
@@ -908,23 +910,22 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
- final File pack, idx;
+ final PackFile pack, idx;
try (PackWriter pw = new PackWriter(db)) {
Set<ObjectId> all = new HashSet<>();
for (Ref r : db.getRefDatabase().getRefs())
all.add(r.getObjectId());
pw.preparePack(m, all, PackWriter.NONE);
- final ObjectId name = pw.computeName();
-
- pack = nameFor(odb, name, ".pack");
+ pack = new PackFile(odb.getPackDirectory(), pw.computeName(),
+ PackExt.PACK);
try (OutputStream out =
new BufferedOutputStream(new FileOutputStream(pack))) {
pw.writePack(m, m, out);
}
pack.setReadOnly();
- idx = nameFor(odb, name, ".idx");
+ idx = pack.create(PackExt.INDEX);
try (OutputStream out =
new BufferedOutputStream(new FileOutputStream(idx))) {
pw.writeIndex(out);
@@ -956,17 +957,12 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
}
private static void prunePacked(ObjectDirectory odb) throws IOException {
- for (PackFile p : odb.getPacks()) {
+ for (Pack p : odb.getPacks()) {
for (MutableEntry e : p)
FileUtils.delete(odb.fileFor(e.toObjectId()));
}
}
- private static File nameFor(ObjectDirectory odb, ObjectId name, String t) {
- File packdir = odb.getPackDirectory();
- return new File(packdir, "pack-" + name.name() + t);
- }
-
private void writeFile(File p, byte[] bin) throws IOException,
ObjectWritingException {
final LockFile lck = new LockFile(p);