+<?xml version="1.0" encoding="utf-8"?>\r
+\r
<project xmlns="http://maven.apache.org/POM/4.0.0"\r
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
-\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4_0_0.xsd">\r
<modelVersion>4.0.0</modelVersion>\r
+\r
+ <parent>\r
+ <groupId>jp.sourceforge</groupId>\r
+ <artifactId>stigmata</artifactId>\r
+ <version>4.0-SNAPSHOT</version>\r
+ </parent>\r
+\r
<groupId>jp.sourceforge.stigmata</groupId>\r
<artifactId>digger</artifactId>\r
+ <version>4.0-SNAPSHOT</version>\r
<packaging>jar</packaging>\r
- <version>3.0.0</version>\r
- <name>digger</name>\r
+\r
+ <name>Digger: Class Loading Library for Operating Class Files</name>\r
<description>Dig up class files</description>\r
<url>http://stigmata.sourceforge.jp/digger/</url>\r
<inceptionYear>2008</inceptionYear>\r
\r
- <repositories>\r
- <repository>\r
- <id>stigmata.sourceforge.jp</id>\r
- <name>Stigmata Maven2 Repository in sourceforge.jp</name>\r
- <url>http://stigmata.sourceforge.jp/maven2</url>\r
- </repository>\r
- <repository>\r
- <id>talisman.sourceforge.jp</id>\r
- <name>Talisman Maven2 Repository in sourceforge.jp</name>\r
- <url>http://talisman.sourceforge.jp/maven2</url>\r
- </repository>\r
- </repositories>\r
-\r
- <developers>\r
- <developer>\r
- <id>tama</id>\r
- <name>Haruaki TAMADA</name>\r
- <email>tama3[ at ]users.sourceforge.jp</email>\r
- <organization>sourceforge.jp</organization>\r
- <organizationUrl>http://sourceforge.jp/</organizationUrl>\r
- <timezone>-9</timezone>\r
- </developer>\r
- </developers>\r
-\r
- <organization>\r
- <name>Stigmata Project, Sourceforge.jp</name>\r
- <url>http://stigmata.sourceforge.jp/</url>\r
- </organization>\r
-\r
- <dependencies>\r
- <dependency>\r
- <groupId>asm</groupId>\r
- <artifactId>asm</artifactId>\r
- <version>3.3</version>\r
- <scope>compile</scope>\r
- </dependency>\r
- <dependency>\r
- <groupId>junit</groupId>\r
- <artifactId>junit</artifactId>\r
- <version>4.8</version>\r
- <scope>test</scope>\r
- </dependency>\r
- </dependencies>\r
-\r
- <licenses>\r
- <license>\r
- <name>Apache License 2.0</name>\r
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>\r
- <distribution>repo</distribution>\r
- </license>\r
- </licenses>\r
+ <scm>\r
+ <connection>scm:git:git://git.sourceforge.jp/gitroot/stigmata/digger.git</connection>\r
+ <developerConnection>scm:git:ssh://tama3@git.sourceforge.jp:/gitroot/stigmata/digger.git</developerConnection>\r
+ <url>http://git.sourceforge.jp/view?p=stigmata/digger.git</url>\r
+ </scm>\r
\r
<distributionManagement>\r
- <repository>\r
- <id>shell.sourceforge.jp</id>\r
- <url>scp://tama3@shell.sourceforge.jp/home/groups/s/st/stigmata/htdocs/maven2</url>\r
- </repository>\r
<site>\r
<id>shell.sourceforge.jp</id>\r
- <url>scp://tama3@shell.sourceforge.jp/home/groups/s/st/stigmata/htdocs/digger</url>\r
+ <url>scp://tama3@shell.sourceforge.jp/home/groups/s/st/stigmata/htdocs/digger/</url>\r
</site>\r
</distributionManagement>\r
\r
- <scm>\r
- <connection>scm:svn:http://svn.sourceforge.jp/svnroot/stigmata/digger/trunk</connection>\r
- <developerConnection>scm:svn:svn+ssh://tama3@svn.sourceforge.jp/svnroot/stigmata/digger/trunk/</developerConnection>\r
- <url>http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi/?root=stigmata</url>\r
- </scm>\r
-\r
<build>\r
<plugins>\r
<plugin>\r
<groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-compiler-plugin</artifactId>\r
- <version>2.3.2</version>\r
- <configuration>\r
- <source>1.6</source>\r
- <target>1.6</target>\r
- <encoding>utf-8</encoding>\r
- </configuration>\r
- </plugin>\r
-\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-resources-plugin</artifactId>\r
- <version>2.4.3</version>\r
- <configuration>\r
- <encoding>utf-8</encoding>\r
- </configuration>\r
- </plugin>\r
-\r
- <!-- for JUnit4 -->\r
- <plugin>\r
- <artifactId>maven-surefire-plugin</artifactId>\r
- <version>2.3</version>\r
- </plugin>\r
-\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
<artifactId>maven-dependency-plugin</artifactId>\r
<executions>\r
<execution>\r
package jp.sourceforge.stigmata.digger;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import jp.sourceforge.stigmata.digger.util.WarClassLoader;
-
/**
* Context object of Classpath.
*
/**
* Set searching byte code by current ClassLoader.
- * @see isIncludeSystemClasses
+ * @see #isIncludeSystemClasses
*/
public synchronized void setIncludeSystemClasses(boolean flag){
if(includeSystemClass != flag){
/**
* clears all of classpathes of this context. not clear parent context.
* If you want to clear this context and parent context, use {@link #clearAll <code>clearAll</code>} method.
- * @see clearAll
+ * @see #clearAll
*/
public synchronized void clear(){
classpath.clear();
*/
public synchronized ClassLoader createClassLoader(){
if(loader == null){
- List<URL> list = new ArrayList<URL>();
+ final List<URL> list = new ArrayList<URL>();
for(URL url: this){
list.add(url);
}
parentClassLoader = null;
}
}
- loader = new WarClassLoader(list.toArray(new URL[list.size()]), parentClassLoader);
+ final ClassLoader parent = parentClassLoader;
+ loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run(){
+ return new WarClassLoader(list.toArray(new URL[list.size()]), parent);
+ }
+ });
}
return loader;
}
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
/**
*
public DefaultClassFileArchive(File file){
this.file = file;
- parseClassName();
+ try{
+ parseClassName();
+ } catch(ParseClassNameFailedException e){
+ className = null;
+ }
}
public DefaultClassFileArchive(String file, String className){
try {
return file.toURI().toURL();
} catch (MalformedURLException ex) {
+ return null;
}
- return null;
}
public InputStream getInputStream(ClassFileEntry entry) throws IOException{
return className;
}
- private void parseClassName(){
+ private void parseClassName() throws ParseClassNameFailedException{
FileInputStream in = null;
try {
in = new FileInputStream(file);
this.className = visitor.getClassName();
} catch (FileNotFoundException ex) {
- ex.printStackTrace();
+ throw new ParseClassNameFailedException(ex);
} catch (IOException ex) {
- ex.printStackTrace();
+ throw new ParseClassNameFailedException(ex);
} finally{
if(in != null){
try{
in.close();
} catch(IOException e){
+ throw new ParseClassNameFailedException(e);
}
}
}
}
- private static class ClassNameExtractVisitor implements ClassVisitor{
+ private static class ClassNameExtractVisitor extends ClassVisitor{
private String className;
+ public ClassNameExtractVisitor(){
+ super(Opcodes.ASM4);
+ }
+
public String getClassName(){
return className;
}
list.add(new ClassFileEntry(className, location));
} catch (MalformedURLException ex) {
+ throw new InternalError(ex.getMessage());
}
}
}
return new ClassFileEntry(className, location);
} catch(MalformedURLException e){
+ throw new InternalError(e.getMessage());
}
}
return null;
}
- Enumeration<JarEntry> jarentries(){
+ Enumeration<JarEntry> jarEntries(){
return jarfile.entries();
}
--- /dev/null
+package jp.sourceforge.stigmata.digger;\r
+\r
+public class ParseClassNameFailedException extends Exception{\r
+ private static final long serialVersionUID = -5373395187256103446L;\r
+\r
+ public ParseClassNameFailedException(){\r
+ super();\r
+ }\r
+\r
+ public ParseClassNameFailedException(String message, Throwable cause){\r
+ super(message, cause);\r
+ }\r
+\r
+ public ParseClassNameFailedException(String message){\r
+ super(message);\r
+ }\r
+\r
+ public ParseClassNameFailedException(Throwable cause){\r
+ super(cause);\r
+ }\r
+}\r
public Iterator<ClassFileEntry> iterator(){
List<ClassFileEntry> list = new ArrayList<ClassFileEntry>();
- for(Enumeration<JarEntry> e = jarentries(); e.hasMoreElements(); ){
+ for(Enumeration<JarEntry> e = jarEntries(); e.hasMoreElements(); ){
JarEntry entry = e.nextElement();
if(entry.getName().endsWith(".class")){
URL location = null;
list.add(new ClassFileEntry(className, location));
} catch (MalformedURLException ex) {
- ex.printStackTrace();
+ throw new InternalError(ex.getMessage());
}
}
}
return new ClassFileEntry(className, location);
} catch(MalformedURLException e){
+ throw new InternalError(e.getMessage());
}
}
return null;
-package jp.sourceforge.stigmata.digger.util;
+package jp.sourceforge.stigmata.digger;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
String path = "WEB-INF/classes/" + name.replace('.', '/') + ".class";
for(URL url: getURLs()){
if(url.toString().endsWith(".war")){
+ InputStream in = null;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
URL newurl = new URL("jar:" + url + "!/" + path);
- InputStream in = newurl.openStream();
- ByteArrayOutputStream out = new ByteArrayOutputStream();
+ in = newurl.openStream();
byte[] data = new byte[256];
int read = 0;
while((read = in.read(data, 0, data.length)) != -1){
out.write(data, 0, read);
}
byte[] classdata = out.toByteArray();
- in.close();
- out.close();
-
clazz = defineClass(name, classdata, 0, classdata.length);
- break;
} catch(IOException exp){
+ throw e;
+ } finally{
+ if(in != null){
+ try{ in.close(); }
+ catch(IOException exception){
+ throw new InternalError(exception.getMessage());
+ }
+ }
+ try{
+ out.close();
+ } catch(IOException exception){
+ throw new InternalError(exception.getMessage());
+ }
}
+ break;
}
}
}
* @author Haruaki Tamada
*/
public class ClasspathContextTest{
- private static final String ASM_FILE = "target/asm-3.3.jar";
+ private static final String ASM_FILE = "target/asm-all-4.0.jar";
private ClasspathContext context;
@Before
-package jp.sourceforge.stigmata.digger.util;\r
+package jp.sourceforge.stigmata.digger;\r
\r
import java.io.File;\r
import java.net.URL;\r