29import java.io.IOException;
31import java.net.URISyntaxException;
33import java.net.URLClassLoader;
35import org.jau.lang.ReflectionUtil;
36import org.jau.net.Uri;
37import org.jau.pkg.JarUtil;
38import org.jau.sys.AndroidVersion;
39import org.jau.sys.RuntimeProps;
40import org.junit.Assert;
41import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
45import jau.test.junit.util.JunitTracer;
46import jau.test.junit.util.MiscUtils;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
72 static class TestClassLoader
extends URLClassLoader {
73 public TestClassLoader(
final URL[] urls) {
76 public TestClassLoader(
final URL[] urls,
final ClassLoader parent) {
84 testTempJarCacheOddJarPathImpl(
"simpletons/");
90 testTempJarCacheOddJarPathImpl(
"A$-B^-C~-D#-E]-F[-öä/");
111 private void testTempJarCacheOddJarPathImpl(
final String subPathUTF)
throws IOException, IllegalArgumentException, URISyntaxException {
112 if(AndroidVersion.isAvailable) { System.err.println(
"n/a on Android");
return; }
114 final Uri.Encoded subPathEncoded =
new Uri.Encoded(subPathUTF, Uri.PATH_LEGAL);
115 final String reservedCharPathUnencoded =
"test/build/"+getClass().getSimpleName()+
"/"+getTestMethodName()+
"/"+subPathUTF;
116 final Uri.Encoded reservedCharPathEncoded = Uri.Encoded.cast(
"test/build/"+getClass().getSimpleName()+
"/"+getTestMethodName()+
"/").concat(subPathEncoded);
118 System.err.println(
"0 Unencoded: "+reservedCharPathUnencoded);
119 System.err.println(
"0 Encoded: "+reservedCharPathEncoded);
122 final Uri jarFileURI = JarUtil.getJarFileUri(RuntimeProps.class.getName(), getClass().getClassLoader());
123 System.err.println(
"1 jarFileURI: "+jarFileURI.toString());
125 final Uri.Encoded jarBasename = JarUtil.getJarBasename(jarFileURI);
126 System.err.println(
"2 jarBasename: "+jarBasename);
129 final Uri fileURI = jarFileURI.getContainedUri();
130 System.err.println(
"3 fileURI: "+fileURI.toString());
132 final Uri fileFolderURI = fileURI.getParent();
133 System.err.println(
"4 fileFolderURI: "+fileFolderURI.toString());
135 final Uri fileNewFolderURI = fileFolderURI.concat(reservedCharPathEncoded);
136 System.err.println(
"5 fileNewFolderURI: "+fileNewFolderURI.toString());
138 final File srcFolder = fileFolderURI.toFile();
139 final File dstFolder = fileNewFolderURI.toFile();
140 System.err.println(
"6 srcFolder: "+srcFolder.toString());
141 System.err.println(
"7 dstFolder: "+dstFolder.toString());
143 final MiscUtils.CopyStats copyStats = MiscUtils.copy(srcFolder, dstFolder, 1,
true);
144 copyStats.dump(
"Copy ",
true);
145 Assert.assertEquals(1, copyStats.totalFolders);
146 Assert.assertTrue(copyStats.totalBytes > 0);
147 Assert.assertEquals(0, copyStats.currentDepth);
149 final URI jarFileNewFolderURI =
new URI(fileNewFolderURI.toString()+jarBasename);
150 System.err.println(
"8 jarFileNewFolderURI: "+jarFileNewFolderURI.toString());
152 final URL[] urls =
new URL[] { jarFileNewFolderURI.toURL() };
153 System.err.println(
"url: "+urls[0]);
155 final ClassLoader cl =
new TestClassLoader(urls,
null);
156 ReflectionUtil.callStaticMethod(RuntimeProps.class.getName(),
"initSingleton",
null,
null, cl);
163 public static void main(
final String args[])
throws IOException {
165 org.junit.runner.JUnitCore.
main(tstname);
Bug 908: Automated test, launching GlueGen jar file from an odd pathname.
void test00TempJarCacheSimplePath()
static void main(final String args[])
void test01TempJarCacheOddPath()