aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/e1/pdj/JavacCompiler.java
blob: 7f2debe3b7dd02ef4dcb70462632041b29cff165 (plain)
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
package com.e1.pdj;

import com.cycling74.max.MaxSystem;
import java.io.File;

class JavacCompiler extends GenericCompiler {

	public JavacCompiler() {
		super("javac");
	}
	
	String javacPath() {
		String fullPath = System.getProperty("pdj.JAVA_HOME");
		File test = new File(new File(fullPath, "bin"), "javac");
		if ( test.exists() ) {
			return test.getAbsolutePath();
		}
        MaxSystem.post("unable to find 'bin/javac' from the JAVA_HOME, using PATH");
		return "javac";
	}
    
	void compileClass() throws PDJClassLoaderException {
		String args = javacPath() + " " + resolvJavaFile() + 
		    " -classpath " + getConfigurationClassPath() + 
			" -sourcepath " + PDJClassLoader.fclasses.toString();
		
		int rc = exec(args);
		
		if ( rc != 0 ) {
			throw new PDJClassLoaderException("pdj: compiler returned: "+ rc + ",args: " +args);
		}
		MaxSystem.post("pdj: compile successful");
	}
}