add -classpath to ConsoleInterface. Fix bug

This commit is contained in:
JanUlrich 2020-01-11 20:19:23 +01:00
parent d1138540de
commit f3d6fcb417
4 changed files with 24 additions and 10 deletions

View File

@ -814,7 +814,7 @@ public class BytecodeGenMethod implements StatementVisitor {
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
}else {
try {
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)}, classLoader);
cLoader2 = new URLClassLoader(new URL[] {new URL("file://" + path + "/")}, classLoader);
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
System.out.println("Methods of " + receiverName + " ");
for(int i = 0; i<methods.length; i++) {

View File

@ -20,7 +20,7 @@ public class ConsoleInterface {
outputPath = it.next();
}else if(arg.startsWith("-d")) {
outputPath = arg.substring(2);
}else if(arg.equals("-cp")){
}else if(arg.equals("-cp") || arg.equals("-classpath")){
String[] cps = it.next().split(":");
for(String cp : cps){
classpath.add(new URL("file://"+cp));

View File

@ -791,24 +791,25 @@ public class JavaTXCompiler {
}
/**
* @param path - can be null, then class file output is in the same directory as the parsed source files
* @param outputPath - can be null, then class file output is in the same directory as the parsed source files
* @param typeinferenceResult
* @param simplifyResultsForAllSourceFiles
* @throws IOException
*/
public void generateBytecode(String path, List<ResultSet> typeinferenceResult,
public void generateBytecode(String outputPath, List<ResultSet> typeinferenceResult,
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles) throws IOException {
for (File f : sourceFiles.keySet()) {
HashMap<JavaClassName, byte[]> classFiles = new HashMap<>();
SourceFile sf = sourceFiles.get(f);
String path;
if(outputPath == null){
path = f.getParent(); //Set path to path of the parsed .jav file
}else{
path = outputPath + sf.getPkgName().replace(".","/"); //add package path to root path
}
BytecodeGen bytecodeGen = new BytecodeGen(classFiles, typeinferenceResult, simplifyResultsForAllSourceFiles,
sf, path, classLoader);
bytecodeGen.visit(sf);
if(path == null){
path = f.getParent(); //Set path to path of the parsed .jav file
}else{
path += sf.getPkgName().replace(".","/"); //add package path to root path
}
writeClassFile(bytecodeGen.getClassFiles(), path);
}
}

View File

@ -29,11 +29,24 @@ public class LoadDefaultPackageClassesTest extends TestCase {
public void testLoadGenClass() throws IOException, ClassNotFoundException {
CompilationEnvironment.loadDefaultPackageClasses(new File( rootDirectory + "Test.jav"), ClassLoader.getSystemClassLoader());
}
public void testURLClassLoader() throws IOException, ClassNotFoundException {
URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file://"+rootDirectory)}, ClassLoader.getSystemClassLoader());
cl.loadClass("Gen");
}
public void testE2E() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"OL.jav"));
compiler.typeInference();
compiler.generateBytecode();
File f = new File(rootDirectory + "OL.class");
assertTrue(f.exists());
compiler = new JavaTXCompiler(new File(rootDirectory+"OLMain.jav"));
compiler.typeInference();
compiler.generateBytecode();
f = new File(rootDirectory + "OLMain.class");
assertTrue(f.exists());
}
}