Skip to content

Commit aab68da

Browse files
authored
Add support for customizable compiler options (#84)
1 parent 0262104 commit aab68da

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/net/openhft/compiler/CachedCompiler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
public class CachedCompiler implements Closeable {
4242
private static final Logger LOG = LoggerFactory.getLogger(CachedCompiler.class);
4343
private static final PrintWriter DEFAULT_WRITER = new PrintWriter(System.err);
44+
private static final List<String> DEFAULT_OPTIONS = Arrays.asList("-g", "-nowarn");
4445

4546
private final Map<ClassLoader, Map<String, Class<?>>> loadedClassesMap = Collections.synchronizedMap(new WeakHashMap<>());
4647
private final Map<ClassLoader, MyJavaFileManager> fileManagerMap = Collections.synchronizedMap(new WeakHashMap<>());
@@ -49,12 +50,19 @@ public class CachedCompiler implements Closeable {
4950
private final File sourceDir;
5051
@Nullable
5152
private final File classDir;
53+
@NotNull
54+
private final List<String> options;
5255

5356
private final ConcurrentMap<String, JavaFileObject> javaFileObjects = new ConcurrentHashMap<>();
5457

5558
public CachedCompiler(@Nullable File sourceDir, @Nullable File classDir) {
59+
this(sourceDir, classDir, DEFAULT_OPTIONS);
60+
}
61+
62+
public CachedCompiler(@Nullable File sourceDir, @Nullable File classDir, @NotNull List<String> options) {
5663
this.sourceDir = sourceDir;
5764
this.classDir = classDir;
65+
this.options = options;
5866
}
5967

6068
public void close() {
@@ -101,7 +109,6 @@ Map<String, byte[]> compileFromJava(@NotNull String className,
101109
compilationUnits = new ArrayList<>(javaFileObjects.values()); // To prevent CME from compiler code
102110
}
103111
// reuse the same file manager to allow caching of jar files
104-
List<String> options = Arrays.asList("-g", "-nowarn");
105112
boolean ok = s_compiler.getTask(writer, fileManager, new DiagnosticListener<JavaFileObject>() {
106113
@Override
107114
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {

0 commit comments

Comments
 (0)