blob: 70e91ca69b4b605516d2a227ac0bb828c3303d10 (
plain) (
blame)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package org.eclipse.pde.internal.core;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Vector;
/**
* Compiler adapter for the JDT Compiler
*/
public class JDTCompilerAdapter extends DefaultCompilerAdapter {
private static String compilerClass = "org.eclipse.jdt.internal.compiler.batch.Main";
/**
* Performs a compile using the JDT batch compiler
*/
public boolean execute() throws BuildException {
attributes.log("Using JDT compiler", Project.MSG_VERBOSE);
Commandline cmd = setupJavacCommand();
try {
Class c = Class.forName(compilerClass);
Method compile = c.getMethod("main", new Class[] { String[].class });
compile.invoke(null, new Object[] { cmd.getArguments()});
} catch (ClassNotFoundException cnfe) {
String msg = "Cannot find the JDT compiler";
throw new BuildException(msg);
} catch (Exception ex) {
throw new BuildException(ex);
}
return true;
}
/**
* Performs a compile using the JDT batch compiler
*/
protected Path getCompileClasspath() {
includeAntRuntime = false;
includeJavaRuntime = false;
Path result = super.getCompileClasspath();
// add in rt.jar. We don't want all of the runtime stuff since in VAJ and VAME there is
// more on the development-time classpath than we really would like.
result.addExisting(new Path(null, System.getProperty("java.home") + "/lib/rt.jar"));
return result;
}
protected Commandline setupJavacCommand() {
Commandline cmd = new Commandline();
if (deprecation == true)
cmd.createArgument().setValue("-deprecation");
if (destDir != null) {
cmd.createArgument().setValue("-d");
cmd.createArgument().setFile(destDir.getAbsoluteFile());
}
cmd.createArgument().setValue("-classpath");
cmd.createArgument().setPath(getCompileClasspath());
if (target != null) {
cmd.createArgument().setValue("-target");
cmd.createArgument().setValue(target);
}
if (debug)
cmd.createArgument().setValue("-g");
if (optimize)
cmd.createArgument().setValue("-O");
if (bootclasspath != null) {
cmd.createArgument().setValue("-bootclasspath");
cmd.createArgument().setPath(bootclasspath);
}
if (extdirs != null) {
cmd.createArgument().setValue("-extdirs");
cmd.createArgument().setPath(extdirs);
}
if (verbose) {
cmd.createArgument().setValue("-log");
cmd.createArgument().setValue(destDir.getAbsolutePath() + ".log");
}
if (!attributes.getFailonerror())
cmd.createArgument().setValue("-proceedOnError");
cmd.createArgument().setValue("-warn:constructorName,packageDefaultMethod,maskedCatchBlocks,deprecation,syntheticAccess");
cmd.createArgument().setValue("-time");
cmd.createArgument().setValue("-noImportError");
cmd.createArgument().setValue("-g");
cmd.createArgument().setValue("-noExit");
logAndAddFilesToCompile(cmd);
return cmd;
}
}
|