/
Assembling.java
63 lines (55 loc) · 1.72 KB
/
Assembling.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.isk.jvmhardcore.pjba;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.isk.jvmhardcore.pjba.structure.ClassFile;
import org.junit.Test;
public class Assembling {
private static String GENERATED_DIRECTORY;
/**
* Find the current directory and set the one that will use used to generate the class files.
*
* @throws Exception
*/
static {
final File directory = new File(".");
try {
if (directory.getCanonicalPath().contains("pjba")) {
GENERATED_DIRECTORY = "02_build/pjb-classes/";
} else {
GENERATED_DIRECTORY = "03_projects/pjba/02_build/pjb-classes/";
}
} catch (IOException e) {
}
}
/**
* Assembles all files in the directory <code>pjb/</code> of the current project.
*
* @throws Exception
*/
@Test
public void assemblePjb() throws Exception {
// TODO: Like in bytecode project
// Without this method we get an error while running tests
}
/**
* Create a class file in the directory <code>02_build/pjb-classes</code>.
*
* @param classFile
* @throws Exception
*/
public static void createFile(final ClassFile classFile) throws Exception {
final String directoryStr = GENERATED_DIRECTORY + classFile.getDirectories();
final File directory = new File(directoryStr);
if (!directory.exists()) {
directory.mkdirs();
}
final FileOutputStream file = new FileOutputStream(directoryStr + classFile.getClassName() + ".class");
final DataOutput bytecode = new DataOutputStream(file);
final Assembler assembler = new Assembler(classFile, bytecode);
assembler.assemble();
file.close();
}
}