|
|
@ -23,6 +23,7 @@ package EDU.purdue.cs.bloat.file; |
|
|
|
import java.io.*; |
|
|
|
import java.io.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.zip.*; |
|
|
|
import java.util.zip.*; |
|
|
|
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
|
|
|
|
import EDU.purdue.cs.bloat.reflect.*; |
|
|
|
import EDU.purdue.cs.bloat.reflect.*; |
|
|
|
|
|
|
|
|
|
|
@ -196,6 +197,27 @@ public class ClassFileLoader implements ClassInfoLoader { |
|
|
|
interfaceIndexes, constants, this); |
|
|
|
interfaceIndexes, constants, this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Thhis method tries to load a Class by its ressource. |
|
|
|
|
|
|
|
* @param name the Name of the Class |
|
|
|
|
|
|
|
* @return the ClassInfo |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private ClassInfo loadClassFromRessource(String name){ |
|
|
|
|
|
|
|
name = name.replaceAll("/","."); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Class clazz = Class.forName(name); |
|
|
|
|
|
|
|
int i = name.lastIndexOf('.'); |
|
|
|
|
|
|
|
if (i >= 0 && i < name.length()){ |
|
|
|
|
|
|
|
name = name.substring(i+1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
URL url = clazz.getResource(name + ".class"); |
|
|
|
|
|
|
|
if (url != null){ |
|
|
|
|
|
|
|
return loadClassFromStream(new File(url.getFile()), url.openStream()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) {} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Loads the class with the given name. Searches the class path, including |
|
|
|
* Loads the class with the given name. Searches the class path, including |
|
|
|
* zip files, for the class and then returns a data stream for the class
|
|
|
|
* zip files, for the class and then returns a data stream for the class
|
|
|
@ -227,6 +249,11 @@ public class ClassFileLoader implements ClassInfoLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((file = loadClassFromRessource(name)) != null){ |
|
|
|
|
|
|
|
addToCache(file); |
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, we have a (possibly fully-specified) class name.
|
|
|
|
// Otherwise, we have a (possibly fully-specified) class name.
|
|
|
|
name = name.replace('.', '/'); |
|
|
|
name = name.replace('.', '/'); |
|
|
|
|
|
|
|
|
|
|
@ -377,6 +404,12 @@ public class ClassFileLoader implements ClassInfoLoader { |
|
|
|
throw new ClassNotFoundException(name); |
|
|
|
throw new ClassNotFoundException(name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addToCache(file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addToCache(ClassInfo file) { |
|
|
|
// If we've reached the cache size limit, remove the oldest file
|
|
|
|
// If we've reached the cache size limit, remove the oldest file
|
|
|
|
// in the cache. Then add the new file.
|
|
|
|
// in the cache. Then add the new file.
|
|
|
|
if (cache.size() == ClassFileLoader.CACHE_LIMIT) { |
|
|
|
if (cache.size() == ClassFileLoader.CACHE_LIMIT) { |
|
|
@ -384,8 +417,6 @@ public class ClassFileLoader implements ClassInfoLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cache.addFirst(file); |
|
|
|
cache.addFirst(file); |
|
|
|
|
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|