/** */
public class VfsTest {
@Test
public void allKindsOfShittyUrls() throws Exception {
JavassistAdapter mdAdapter = new JavassistAdapter();
{
URL jar1 = getSomeJar();
assertTrue(jar1.toString().startsWith("file:"));
assertTrue(jar1.toString().contains(".jar"));
assertTrue(Vfs.DefaultUrlTypes.jarFile.matches(jar1));
assertFalse(Vfs.DefaultUrlTypes.jarUrl.matches(jar1));
assertFalse(Vfs.DefaultUrlTypes.directory.matches(jar1));
Vfs.Dir dir = Vfs.DefaultUrlTypes.jarFile.createDir(jar1);
Vfs.File file = null;
for (Vfs.File f : dir.getFiles()) {
if (f.getRelativePath().endsWith(".class")) { file = f; break; }
}
ClassFile stringCF = mdAdapter.getOfCreateClassObject(file);
//noinspection UnusedDeclaration
String className = mdAdapter.getClassName(stringCF);
}
{
URL rtJarUrl = ClasspathHelper.forClass(String.class);
assertTrue(rtJarUrl.toString().startsWith("jar:file:"));
assertTrue(rtJarUrl.toString().contains(".jar!"));
assertFalse(Vfs.DefaultUrlTypes.jarFile.matches(rtJarUrl));
assertTrue(Vfs.DefaultUrlTypes.jarUrl.matches(rtJarUrl));
assertFalse(Vfs.DefaultUrlTypes.directory.matches(rtJarUrl));
Vfs.Dir dir = Vfs.DefaultUrlTypes.jarUrl.createDir(rtJarUrl);
Vfs.File file = null;
for (Vfs.File f : dir.getFiles()) {
if (f.getRelativePath().equals("java/lang/String.class")) { file = f; break; }
}
ClassFile stringCF = mdAdapter.getOfCreateClassObject(file);
String className = mdAdapter.getClassName(stringCF);
assertTrue(className.equals("java.lang.String"));
}
{
URL thisUrl = ClasspathHelper.forClass(getClass());
assertTrue(thisUrl.toString().startsWith("file:"));
assertFalse(thisUrl.toString().contains(".jar"));
assertFalse(Vfs.DefaultUrlTypes.jarFile.matches(thisUrl));
assertFalse(Vfs.DefaultUrlTypes.jarUrl.matches(thisUrl));
assertTrue(Vfs.DefaultUrlTypes.directory.matches(thisUrl));
Vfs.Dir dir = Vfs.DefaultUrlTypes.directory.createDir(thisUrl);
Vfs.File file = null;
for (Vfs.File f : dir.getFiles()) {
if (f.getRelativePath().equals("org/reflections/VfsTest.class")) { file = f; break; }
}
ClassFile stringCF = mdAdapter.getOfCreateClassObject(file);
String className = mdAdapter.getClassName(stringCF);
assertTrue(className.equals(getClass().getName()));
}
{
// create a file, then delete it so we can treat as a non-existing directory
File tempFile = File.createTempFile("nosuch", "dir");