Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JVMClassFileContainer#getClassURL to comply with Module System #100

Merged
merged 5 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@
<copy file=".version" todir="build/main/gov/nasa/jpf" failonerror="false"/>

<jar jarfile="build/jpf-classes.jar">
<fileset dir="build/classes/java.base"/>
<fileset dir="build/classes/java.logging"/>

<fileset dir="build/classes"/>
<fileset dir="build/annotations"/>

<fileset dir="build/main">
Expand Down
4 changes: 2 additions & 2 deletions src/main/gov/nasa/jpf/jvm/DirClassFileContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public DirClassFileContainer(File dir) {

@Override
public ClassFileMatch getMatch(String clsName) throws ClassParseException {
String pn = clsName.replace('.', File.separatorChar) + ".class";
File f = new File(dir, pn);
String classEntryURL = getClassEntryURL(clsName);
File f = new File(dir, classEntryURL);

if (f.isFile()) {
FileInputStream fis = null;
Expand Down
41 changes: 39 additions & 2 deletions src/main/gov/nasa/jpf/jvm/JVMClassFileContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

package gov.nasa.jpf.jvm;

import gov.nasa.jpf.JPFException;
import gov.nasa.jpf.vm.AnnotationInfo;
import gov.nasa.jpf.vm.ClassFileContainer;
import gov.nasa.jpf.vm.ClassFileMatch;
import gov.nasa.jpf.vm.ClassLoaderInfo;
import gov.nasa.jpf.vm.ClassParseException;

import java.io.File;

/**
* ClassFileContainer that holds Java classfiles
*/
Expand Down Expand Up @@ -70,10 +73,44 @@ public AnnotationInfo createAnnotationInfo (ClassLoaderInfo loader) throws Class
protected JVMClassFileContainer (String name, String url) {
super(name, url);
}


/**
* @return the path to .class file including the source path of the container
* eg:-
* jar:file:/path/to/jpf-classes.jar!/java.base/java/lang/Object.class
*
* /path/to/build/tests/TypeNameTest.class
*/
@Override
public String getClassURL (String typeName){
return getURL() + typeName.replace('.', '/') + ".class";
return getURL() + getClassEntryURL(typeName);
}

/**
* @param typeName in the format java.lang.Object
* @return Returns a path to .class file including the module name
* in a format similar to java.base/java/lang/Object.class
*
* If the module for the typeName is an unnamed module, returns a path in a format similar to
* java/lang/Object.class
*/
static String getClassEntryURL(String typeName) {
String moduleName = getModuleName(typeName);
if (moduleName == null) {
return typeName.replace('.', File.separatorChar) + ".class";
}
return moduleName + File.separator + typeName.replace('.', File.separatorChar) + ".class";
}

/**
* @return the module name for the given typeName or null if the module is an unnamed module
*/
static String getModuleName(String typeName) {
try {
return Class.forName(typeName.split("\\$")[0]).getModule().getName();
} catch (ClassNotFoundException e) {
throw new JPFException("Class for typename " + typeName + " not found", e);
}
}

}
6 changes: 3 additions & 3 deletions src/main/gov/nasa/jpf/jvm/JarClassFileContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ static String getPath(File file, String pathPrefix){

@Override
public ClassFileMatch getMatch(String clsName) throws ClassParseException {
String pn = clsName.replace('.', '/') + ".class";
String classEntryURL = getClassEntryURL(clsName);

if (pathPrefix != null){
pn = pathPrefix + pn;
classEntryURL = pathPrefix + classEntryURL;
}

JarEntry e = jar.getJarEntry(pn);
JarEntry e = jar.getJarEntry(classEntryURL);

if (e != null) {
InputStream is = null;
Expand Down
7 changes: 7 additions & 0 deletions src/main/gov/nasa/jpf/vm/ClassFileContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public String getName() {
return name;
}

/**
* @return the path of the container
* eg :-
* /path/to/root/dir/that/contains/class/files
*
* jar:file:/path/to/jpf-classes.jar!/
*/
public String getURL() {
return url;
}
Expand Down