[Bytecde] Generate new directory if given output path doesnt exist yet

This commit is contained in:
JanUlrich 2019-12-14 17:50:23 +01:00
parent af5b23e31a
commit a3b4ea9b1c
2 changed files with 16 additions and 1 deletions

View File

@ -793,7 +793,9 @@ public class JavaTXCompiler {
System.out.println("generating " + name + ".class file ...");
// output = new FileOutputStream(new File(System.getProperty("user.dir") +
// "/testBytecode/generatedBC/" +name+".class"));
output = new FileOutputStream(new File(path + File.separator + name.getClassName() + ".class"));
File outputFile = new File(path + File.separator + name.getClassName() + ".class");
outputFile.getParentFile().mkdirs();
output = new FileOutputStream(outputFile);
output.write(bytecode);
output.close();
System.out.println(name + ".class file generated");

View File

@ -22,4 +22,17 @@ public class Bytecode extends TestCase {
f = new File(rootDirectory + "TestClass.class");
assertTrue(f.exists());
}
@Test
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
compiler.typeInference();
File f = new File(rootDirectory + "output/de/test/TestClass.class");
if(f.exists() && !f.isDirectory()) {
f.delete();
}
compiler.generateBytecode(rootDirectory + "output/");
f = new File(rootDirectory + "output/de/test/TestClass.class");
assertTrue(f.exists());
}
}