68 private ClientCodeWrapper ccw; |
68 private ClientCodeWrapper ccw; |
69 private Main compilerMain; |
69 private Main compilerMain; |
70 private JavaCompiler compiler; |
70 private JavaCompiler compiler; |
71 private Locale locale; |
71 private Locale locale; |
72 private String[] args; |
72 private String[] args; |
|
73 private String[] classNames; |
73 private Context context; |
74 private Context context; |
74 private List<JavaFileObject> fileObjects; |
75 private List<JavaFileObject> fileObjects; |
75 private Map<JavaFileObject, JCCompilationUnit> notYetEntered; |
76 private Map<JavaFileObject, JCCompilationUnit> notYetEntered; |
76 private ListBuffer<Env<AttrContext>> genList; |
77 private ListBuffer<Env<AttrContext>> genList; |
77 private TaskListener taskListener; |
78 private TaskListener taskListener; |
80 |
81 |
81 private Main.Result result = null; |
82 private Main.Result result = null; |
82 |
83 |
83 JavacTaskImpl(Main compilerMain, |
84 JavacTaskImpl(Main compilerMain, |
84 String[] args, |
85 String[] args, |
|
86 String[] classNames, |
85 Context context, |
87 Context context, |
86 List<JavaFileObject> fileObjects) { |
88 List<JavaFileObject> fileObjects) { |
87 this.ccw = ClientCodeWrapper.instance(context); |
89 this.ccw = ClientCodeWrapper.instance(context); |
88 this.compilerMain = compilerMain; |
90 this.compilerMain = compilerMain; |
89 this.args = args; |
91 this.args = args; |
|
92 this.classNames = classNames; |
90 this.context = context; |
93 this.context = context; |
91 this.fileObjects = fileObjects; |
94 this.fileObjects = fileObjects; |
92 setLocale(Locale.getDefault()); |
95 setLocale(Locale.getDefault()); |
93 // null checks |
96 // null checks |
94 compilerMain.getClass(); |
97 compilerMain.getClass(); |
99 JavacTaskImpl(Main compilerMain, |
102 JavacTaskImpl(Main compilerMain, |
100 Iterable<String> flags, |
103 Iterable<String> flags, |
101 Context context, |
104 Context context, |
102 Iterable<String> classes, |
105 Iterable<String> classes, |
103 Iterable<? extends JavaFileObject> fileObjects) { |
106 Iterable<? extends JavaFileObject> fileObjects) { |
104 this(compilerMain, toArray(flags, classes), context, toList(fileObjects)); |
107 this(compilerMain, toArray(flags), toArray(classes), context, toList(fileObjects)); |
105 } |
108 } |
106 |
109 |
107 static private String[] toArray(Iterable<String> flags, Iterable<String> classes) { |
110 static private String[] toArray(Iterable<String> iter) { |
108 ListBuffer<String> result = new ListBuffer<String>(); |
111 ListBuffer<String> result = new ListBuffer<String>(); |
109 if (flags != null) |
112 if (iter != null) |
110 for (String flag : flags) |
113 for (String s : iter) |
111 result.append(flag); |
114 result.append(s); |
112 if (classes != null) |
|
113 for (String cls : classes) |
|
114 result.append(cls); |
|
115 return result.toArray(new String[result.length()]); |
115 return result.toArray(new String[result.length()]); |
116 } |
116 } |
117 |
117 |
118 static private List<JavaFileObject> toList(Iterable<? extends JavaFileObject> fileObjects) { |
118 static private List<JavaFileObject> toList(Iterable<? extends JavaFileObject> fileObjects) { |
119 if (fileObjects == null) |
119 if (fileObjects == null) |
127 public Boolean call() { |
127 public Boolean call() { |
128 if (!used.getAndSet(true)) { |
128 if (!used.getAndSet(true)) { |
129 initContext(); |
129 initContext(); |
130 notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>(); |
130 notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>(); |
131 compilerMain.setAPIMode(true); |
131 compilerMain.setAPIMode(true); |
132 result = compilerMain.compile(args, context, fileObjects, processors); |
132 result = compilerMain.compile(args, classNames, context, fileObjects, processors); |
133 cleanup(); |
133 cleanup(); |
134 return result.isOK(); |
134 return result.isOK(); |
135 } else { |
135 } else { |
136 throw new IllegalStateException("multiple calls to method 'call'"); |
136 throw new IllegalStateException("multiple calls to method 'call'"); |
137 } |
137 } |
157 throw new IllegalStateException(); |
157 throw new IllegalStateException(); |
158 } else { |
158 } else { |
159 initContext(); |
159 initContext(); |
160 compilerMain.setOptions(Options.instance(context)); |
160 compilerMain.setOptions(Options.instance(context)); |
161 compilerMain.filenames = new LinkedHashSet<File>(); |
161 compilerMain.filenames = new LinkedHashSet<File>(); |
162 Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args)); |
162 Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args), classNames); |
163 if (!filenames.isEmpty()) |
163 if (!filenames.isEmpty()) |
164 throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); |
164 throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " ")); |
165 compiler = JavaCompiler.instance(context); |
165 compiler = JavaCompiler.instance(context); |
166 compiler.keepComments = true; |
166 compiler.keepComments = true; |
167 compiler.genEndPos = true; |
167 compiler.genEndPos = true; |
172 notYetEntered.put(file, null); |
172 notYetEntered.put(file, null); |
173 genList = new ListBuffer<Env<AttrContext>>(); |
173 genList = new ListBuffer<Env<AttrContext>>(); |
174 // endContext will be called when all classes have been generated |
174 // endContext will be called when all classes have been generated |
175 // TODO: should handle the case after each phase if errors have occurred |
175 // TODO: should handle the case after each phase if errors have occurred |
176 args = null; |
176 args = null; |
|
177 classNames = null; |
177 } |
178 } |
178 } |
179 } |
179 |
180 |
180 <T> String toString(Iterable<T> items, String sep) { |
181 <T> String toString(Iterable<T> items, String sep) { |
181 String currSep = ""; |
182 String currSep = ""; |