|
|
@@ -46,8 +46,10 @@ |
|
|
|
package org.eclipse.jgit.junit; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.io.Writer; |
|
|
|
import java.lang.reflect.Method; |
|
|
@@ -124,13 +126,44 @@ public abstract class JGitTestUtil { |
|
|
|
// loaded previously |
|
|
|
return new File("tst", fileName); |
|
|
|
} |
|
|
|
if ("jar".equals(url.getProtocol())) { |
|
|
|
try { |
|
|
|
File tmp = File.createTempFile("tmp_", "_" + fileName); |
|
|
|
copyTestResource(fileName, tmp); |
|
|
|
return tmp; |
|
|
|
} catch (IOException err) { |
|
|
|
throw new RuntimeException("Cannot create temporary file", err); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
return new File(url.toURI()); |
|
|
|
} catch(URISyntaxException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
throw new IllegalArgumentException(e.getMessage() + " " + url); |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
return new File(url.getPath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void copyTestResource(String name, File dest) |
|
|
|
throws IOException { |
|
|
|
URL url = cl().getResource(CLASSPATH_TO_RESOURCES + name); |
|
|
|
if (url == null) |
|
|
|
throw new FileNotFoundException(name); |
|
|
|
InputStream in = url.openStream(); |
|
|
|
try { |
|
|
|
FileOutputStream out = new FileOutputStream(dest); |
|
|
|
try { |
|
|
|
byte[] buf = new byte[4096]; |
|
|
|
for (int n; (n = in.read(buf)) > 0;) |
|
|
|
out.write(buf, 0, n); |
|
|
|
} finally { |
|
|
|
out.close(); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
in.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static ClassLoader cl() { |
|
|
|
return JGitTestUtil.class.getClassLoader(); |
|
|
|
} |