|
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 |
| package edu.rice.cs.drjava.model.javadoc; |
|
38 |
| |
|
39 |
| import java.io.File; |
|
40 |
| import java.io.IOException; |
|
41 |
| import java.io.BufferedReader; |
|
42 |
| import java.io.StringReader; |
|
43 |
| import java.util.ArrayList; |
|
44 |
| import java.util.List; |
|
45 |
| import java.util.Properties; |
|
46 |
| import java.awt.EventQueue; |
|
47 |
| |
|
48 |
| import edu.rice.cs.plt.lambda.Thunk; |
|
49 |
| import edu.rice.cs.plt.io.IOUtil; |
|
50 |
| import edu.rice.cs.plt.concurrent.JVMBuilder; |
|
51 |
| import edu.rice.cs.plt.concurrent.ConcurrentUtil; |
|
52 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
53 |
| import edu.rice.cs.plt.text.TextUtil; |
|
54 |
| import edu.rice.cs.drjava.model.DJError; |
|
55 |
| import edu.rice.cs.drjava.model.FileSaveSelector; |
|
56 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
57 |
| import edu.rice.cs.drjava.model.GlobalModel; |
|
58 |
| import edu.rice.cs.drjava.model.FileMovedException; |
|
59 |
| import edu.rice.cs.drjava.model.definitions.InvalidPackageException; |
|
60 |
| |
|
61 |
| import edu.rice.cs.drjava.DrJava; |
|
62 |
| import edu.rice.cs.drjava.config.Configuration; |
|
63 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
64 |
| import edu.rice.cs.drjava.model.DrJavaFileUtils; |
|
65 |
| import edu.rice.cs.drjava.model.compiler.CompilerErrorModel; |
|
66 |
| import edu.rice.cs.drjava.model.compiler.CompilerListener; |
|
67 |
| import edu.rice.cs.drjava.model.compiler.DummyCompilerListener; |
|
68 |
| |
|
69 |
| import edu.rice.cs.util.swing.Utilities; |
|
70 |
| |
|
71 |
| import edu.rice.cs.util.ArgumentTokenizer; |
|
72 |
| import edu.rice.cs.util.DirectorySelector; |
|
73 |
| import edu.rice.cs.util.FileOps; |
|
74 |
| import edu.rice.cs.util.OperationCanceledException; |
|
75 |
| |
|
76 |
| import static edu.rice.cs.plt.debug.DebugUtil.error; |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| public class DefaultJavadocModel implements JavadocModel { |
|
82 |
| |
|
83 |
| |
|
84 |
| private GlobalModel _model; |
|
85 |
| |
|
86 |
| |
|
87 |
| private final JavadocEventNotifier _notifier = new JavadocEventNotifier(); |
|
88 |
| |
|
89 |
| |
|
90 |
| private final JVMBuilder _jvmBuilder; |
|
91 |
| |
|
92 |
| |
|
93 |
| private CompilerErrorModel _javadocErrorModel; |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
2672
| public DefaultJavadocModel(GlobalModel model, File javaCommand, Iterable<File> toolsPath) {
|
|
102 |
2672
| _model = model;
|
|
103 |
2672
| JVMBuilder builder = JVMBuilder.DEFAULT;
|
|
104 |
2512
| if (javaCommand != null) { builder = builder.javaCommand(javaCommand); }
|
|
105 |
2671
| if (toolsPath != null) { builder = builder.classPath(toolsPath); }
|
|
106 |
2672
| _jvmBuilder = builder;
|
|
107 |
2672
| _javadocErrorModel = new CompilerErrorModel();
|
|
108 |
| } |
|
109 |
| |
|
110 |
704
| public boolean isAvailable() { return true; }
|
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
158
| public void addListener(JavadocListener listener) { _notifier.addListener(listener); }
|
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
0
| public void removeListener(JavadocListener listener) { _notifier.removeListener(listener); }
|
|
123 |
| |
|
124 |
| |
|
125 |
0
| public void removeAllListeners() { _notifier.removeAllListeners(); }
|
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
42
| public CompilerErrorModel getJavadocErrorModel() { return _javadocErrorModel; }
|
|
133 |
| |
|
134 |
| |
|
135 |
4
| public void resetJavadocErrors() {
|
|
136 |
4
| _javadocErrorModel = new CompilerErrorModel();
|
|
137 |
| } |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
0
| public void javadocAll(DirectorySelector select, final FileSaveSelector saver) throws IOException {
|
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
0
| if (_model.hasModifiedDocuments() || _model.hasUntitledDocuments()) { return; }
|
|
152 |
| |
|
153 |
0
| Configuration config = DrJava.getConfig();
|
|
154 |
0
| File destDir = config.getSetting(OptionConstants.JAVADOC_DESTINATION);
|
|
155 |
| |
|
156 |
| |
|
157 |
0
| try {
|
|
158 |
0
| if (destDir.equals(FileOps.NULL_FILE)) {
|
|
159 |
| |
|
160 |
| |
|
161 |
0
| destDir = select.getDirectory(null);
|
|
162 |
| } |
|
163 |
| else |
|
164 |
| |
|
165 |
0
| destDir = select.getDirectory(destDir);
|
|
166 |
| |
|
167 |
| |
|
168 |
0
| while (!destDir.exists() || !destDir.isDirectory() || !destDir.canWrite()) {
|
|
169 |
0
| if (!destDir.getPath().equals("") && !destDir.exists()) {
|
|
170 |
| |
|
171 |
0
| boolean create = select.askUser
|
|
172 |
| ("The directory you chose does not exist:\n'" + destDir + "'\nWould you like to create it?", |
|
173 |
| "Create Directory?"); |
|
174 |
0
| if (create) {
|
|
175 |
0
| boolean dirMade = destDir.mkdirs();
|
|
176 |
0
| if (! dirMade) throw new IOException("Could not create directory: " + destDir);
|
|
177 |
| } |
|
178 |
0
| else return;
|
|
179 |
| } |
|
180 |
0
| else if (!destDir.isDirectory() || destDir.getPath().equals("")) {
|
|
181 |
| |
|
182 |
0
| select.warnUser("The file you chose is not a directory:\n" +
|
|
183 |
| "'" + destDir + "'\n" + |
|
184 |
| "Please choose another.", |
|
185 |
| "Not a Directory!"); |
|
186 |
0
| destDir = select.getDirectory(null);
|
|
187 |
| } |
|
188 |
| else { |
|
189 |
| |
|
190 |
0
| select.warnUser("The directory you chose is not writable:\n" +
|
|
191 |
| "'" + destDir + "'\n" + |
|
192 |
| "Please choose another directory.", |
|
193 |
| "Cannot Write to Destination!"); |
|
194 |
0
| destDir = select.getDirectory(null);
|
|
195 |
| } |
|
196 |
| } |
|
197 |
| } |
|
198 |
0
| catch (OperationCanceledException oce) { return; }
|
|
199 |
| |
|
200 |
0
| _notifier.javadocStarted();
|
|
201 |
| |
|
202 |
0
| final File destDirF = destDir;
|
|
203 |
0
| new Thread("DrJava Javadoc Thread") {
|
|
204 |
0
| public void run() { _javadocAllWorker(destDirF, saver); }
|
|
205 |
| }.start(); |
|
206 |
| } |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
0
| private void _javadocAllWorker(final File destDirFile, FileSaveSelector saver) {
|
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
0
| final List<String> docFiles = new ArrayList<String>();
|
|
218 |
| |
|
219 |
0
| final List<OpenDefinitionsDocument> llDocs = new ArrayList<OpenDefinitionsDocument>();
|
|
220 |
0
| for (OpenDefinitionsDocument doc: _model.getOpenDefinitionsDocuments()) {
|
|
221 |
0
| try {
|
|
222 |
| |
|
223 |
0
| File docFile = _getFileFromDocument(doc, saver);
|
|
224 |
0
| final File file = IOUtil.attemptCanonicalFile(docFile);
|
|
225 |
| |
|
226 |
| |
|
227 |
0
| if (DrJavaFileUtils.isLLFile(file)) {
|
|
228 |
| |
|
229 |
0
| llDocs.add(doc);
|
|
230 |
0
| docFiles.add(DrJavaFileUtils.getJavaForLLFile(file).getPath());
|
|
231 |
| } |
|
232 |
| else { |
|
233 |
0
| docFiles.add(file.getPath());
|
|
234 |
| } |
|
235 |
| } |
|
236 |
| catch (IllegalStateException e) { |
|
237 |
| |
|
238 |
| } |
|
239 |
| catch (IOException ioe) { |
|
240 |
| |
|
241 |
| } |
|
242 |
| } |
|
243 |
| |
|
244 |
| |
|
245 |
0
| if (docFiles.size() == 0) {
|
|
246 |
| |
|
247 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(false, destDirFile, true); } });
|
|
248 |
0
| return;
|
|
249 |
| } |
|
250 |
| |
|
251 |
0
| Utilities.invokeLater(new Runnable() { public void run() {
|
|
252 |
0
| if (_model.hasOutOfSyncDocuments(llDocs)) {
|
|
253 |
| |
|
254 |
0
| CompilerListener javadocAfterCompile = new DummyCompilerListener() {
|
|
255 |
0
| @Override public void compileAborted(Exception e) {
|
|
256 |
| |
|
257 |
| |
|
258 |
0
| final CompilerListener listenerThis = this;
|
|
259 |
| |
|
260 |
| |
|
261 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
262 |
0
| public void run() {
|
|
263 |
0
| _model.getCompilerModel().removeListener(listenerThis);
|
|
264 |
| |
|
265 |
0
| _notifier.javadocEnded(false, destDirFile, true);
|
|
266 |
| } |
|
267 |
| }); |
|
268 |
| } |
|
269 |
0
| @Override public void compileEnded(File workDir, List<? extends File> excludedFiles) {
|
|
270 |
0
| final CompilerListener listenerThis = this;
|
|
271 |
0
| try {
|
|
272 |
| |
|
273 |
0
| if (_model.hasOutOfSyncDocuments(llDocs) || _model.getNumCompErrors() > 0) {
|
|
274 |
| |
|
275 |
| |
|
276 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(false, destDirFile, true); } });
|
|
277 |
0
| return;
|
|
278 |
| } |
|
279 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
280 |
0
| public void run() {
|
|
281 |
| |
|
282 |
| |
|
283 |
0
| _runJavadoc(docFiles, destDirFile, IterUtil.<String>empty(), true);
|
|
284 |
| } |
|
285 |
| }); |
|
286 |
| } |
|
287 |
| finally { |
|
288 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
289 |
0
| public void run() { _model.getCompilerModel().removeListener(listenerThis); }
|
|
290 |
| }); |
|
291 |
| } |
|
292 |
| } |
|
293 |
| }; |
|
294 |
| |
|
295 |
0
| _notifyCompileBeforeJavadoc(javadocAfterCompile);
|
|
296 |
0
| return;
|
|
297 |
| } |
|
298 |
| |
|
299 |
| |
|
300 |
0
| _runJavadoc(docFiles, destDirFile, IterUtil.<String>empty(), true);
|
|
301 |
| } }); |
|
302 |
| } |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
0
| public void javadocDocument(final OpenDefinitionsDocument doc, final FileSaveSelector saver) throws IOException {
|
|
315 |
| |
|
316 |
| |
|
317 |
0
| if (doc.isUntitled() || doc.isModifiedSinceSave()) _notifier.saveBeforeJavadoc();
|
|
318 |
| |
|
319 |
| |
|
320 |
0
| if (doc.isUntitled() || doc.isModifiedSinceSave()) return;
|
|
321 |
| |
|
322 |
| |
|
323 |
0
| File docFile = _getFileFromDocument(doc, saver);
|
|
324 |
0
| final File file = IOUtil.attemptCanonicalFile(docFile);
|
|
325 |
0
| final File javaFile = DrJavaFileUtils.getJavaForLLFile(file);
|
|
326 |
| |
|
327 |
0
| Utilities.invokeLater(new Runnable() { public void run() {
|
|
328 |
| |
|
329 |
0
| if (DrJavaFileUtils.isLLFile(file)) {
|
|
330 |
| |
|
331 |
0
| final List<OpenDefinitionsDocument> singleton = new ArrayList<OpenDefinitionsDocument>();
|
|
332 |
0
| singleton.add(doc);
|
|
333 |
0
| if (_model.hasOutOfSyncDocuments(singleton)) {
|
|
334 |
| |
|
335 |
0
| CompilerListener javadocAfterCompile = new DummyCompilerListener() {
|
|
336 |
0
| @Override public void compileAborted(Exception e) {
|
|
337 |
| |
|
338 |
| |
|
339 |
0
| final CompilerListener listenerThis = this;
|
|
340 |
| |
|
341 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
342 |
0
| public void run() {
|
|
343 |
0
| _model.getCompilerModel().removeListener(listenerThis);
|
|
344 |
| |
|
345 |
0
| _notifier.javadocEnded(false, null, false);
|
|
346 |
| } |
|
347 |
| }); |
|
348 |
| } |
|
349 |
0
| @Override public void compileEnded(File workDir, List<? extends File> excludedFiles) {
|
|
350 |
0
| final CompilerListener listenerThis = this;
|
|
351 |
0
| try {
|
|
352 |
| |
|
353 |
0
| if (_model.hasOutOfSyncDocuments(singleton) || _model.getNumCompErrors() > 0) {
|
|
354 |
| |
|
355 |
| |
|
356 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(false, null, false); } });
|
|
357 |
0
| return;
|
|
358 |
| } |
|
359 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
360 |
0
| public void run() {
|
|
361 |
0
| try {
|
|
362 |
| |
|
363 |
0
| _rawJavadocDocument(javaFile);
|
|
364 |
| } |
|
365 |
| catch(IOException ioe) { |
|
366 |
| |
|
367 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(false, null, false); } });
|
|
368 |
| } |
|
369 |
| } |
|
370 |
| }); |
|
371 |
| } |
|
372 |
| finally { |
|
373 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
374 |
0
| public void run() { _model.getCompilerModel().removeListener(listenerThis); }
|
|
375 |
| }); |
|
376 |
| } |
|
377 |
| } |
|
378 |
| }; |
|
379 |
| |
|
380 |
0
| _notifyCompileBeforeJavadoc(javadocAfterCompile);
|
|
381 |
0
| return;
|
|
382 |
| } |
|
383 |
| } |
|
384 |
0
| try {
|
|
385 |
0
| _rawJavadocDocument(javaFile);
|
|
386 |
| } |
|
387 |
| catch(IOException ioe) { |
|
388 |
| |
|
389 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(false, null, false); } });
|
|
390 |
| } |
|
391 |
| } }); |
|
392 |
| } |
|
393 |
| |
|
394 |
0
| private void _rawJavadocDocument(final File file) throws IOException {
|
|
395 |
| |
|
396 |
0
| final File destDir = IOUtil.createAndMarkTempDirectory("DrJava-javadoc", "");
|
|
397 |
| |
|
398 |
0
| _notifier.javadocStarted();
|
|
399 |
| |
|
400 |
0
| new Thread("DrJava Javadoc Thread") {
|
|
401 |
0
| public void run() {
|
|
402 |
0
| Iterable<String> extraArgs = IterUtil.make("-noindex", "-notree", "-nohelp", "-nonavbar");
|
|
403 |
0
| _runJavadoc(IterUtil.make(file.getPath()), destDir, extraArgs, false);
|
|
404 |
| } |
|
405 |
| }.start(); |
|
406 |
| } |
|
407 |
| |
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
0
| private void _notifyCompileBeforeJavadoc(final CompilerListener afterCompile) {
|
|
412 |
0
| Utilities.invokeLater(new Runnable() {
|
|
413 |
0
| public void run() { _notifier.compileBeforeJavadoc(afterCompile); }
|
|
414 |
| }); |
|
415 |
| } |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
3
| public File suggestJavadocDestination(OpenDefinitionsDocument doc) {
|
|
424 |
3
| _attemptSaveAllDocuments();
|
|
425 |
| |
|
426 |
3
| try {
|
|
427 |
3
| File sourceRoot = doc.getSourceRoot();
|
|
428 |
2
| return new File(sourceRoot, SUGGESTED_DIR_NAME);
|
|
429 |
| } |
|
430 |
1
| catch (InvalidPackageException ipe) { return null; }
|
|
431 |
| } |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| |
|
439 |
3
| private void _attemptSaveAllDocuments() {
|
|
440 |
| |
|
441 |
1
| if (_model.hasModifiedDocuments() || _model.hasUntitledDocuments()) _notifier.saveBeforeJavadoc();
|
|
442 |
| } |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
| |
|
451 |
0
| private void _runJavadoc(Iterable<String> files, final File destDir, Iterable<String> extraArgs, final boolean allDocs) {
|
|
452 |
0
| Iterable<String> args = IterUtil.empty();
|
|
453 |
0
| args = IterUtil.compose(args, IterUtil.make("-d", destDir.getPath()));
|
|
454 |
0
| args = IterUtil.compose(args, IterUtil.make("-classpath", IOUtil.pathToString(_model.getClassPath())));
|
|
455 |
0
| args = IterUtil.compose(args, _getLinkArgs());
|
|
456 |
0
| args = IterUtil.compose(args, "-" + DrJava.getConfig().getSetting(OptionConstants.JAVADOC_ACCESS_LEVEL));
|
|
457 |
0
| args = IterUtil.compose(args, extraArgs);
|
|
458 |
0
| String custom = DrJava.getConfig().getSetting(OptionConstants.JAVADOC_CUSTOM_PARAMS);
|
|
459 |
0
| args = IterUtil.compose(args, ArgumentTokenizer.tokenize(custom));
|
|
460 |
0
| args = IterUtil.compose(args, files);
|
|
461 |
| |
|
462 |
0
| List<DJError> errors = new ArrayList<DJError>();
|
|
463 |
0
| try {
|
|
464 |
0
| Process p = _jvmBuilder.start("com.sun.tools.javadoc.Main", args);
|
|
465 |
0
| Thunk<String> outputString = ConcurrentUtil.processOutAsString(p);
|
|
466 |
0
| Thunk<String> errorString = ConcurrentUtil.processErrAsString(p);
|
|
467 |
0
| p.waitFor();
|
|
468 |
0
| errors.addAll(_extractErrors(outputString.value()));
|
|
469 |
0
| errors.addAll(_extractErrors(errorString.value()));
|
|
470 |
| } |
|
471 |
| catch (IOException e) { |
|
472 |
0
| errors.add(new DJError("IOException: " + e.getMessage(), false));
|
|
473 |
| } |
|
474 |
| catch (InterruptedException e) { |
|
475 |
0
| errors.add(new DJError("InterruptedException: " + e.getMessage(), false));
|
|
476 |
| } |
|
477 |
| |
|
478 |
0
| _javadocErrorModel = new CompilerErrorModel(IterUtil.toArray(errors, DJError.class), _model);
|
|
479 |
| |
|
480 |
| |
|
481 |
0
| final boolean success = _javadocErrorModel.hasOnlyWarnings();
|
|
482 |
0
| if (!allDocs) { IOUtil.deleteOnExitRecursively(destDir); }
|
|
483 |
| |
|
484 |
0
| EventQueue.invokeLater(new Runnable() { public void run() { _notifier.javadocEnded(success, destDir, allDocs); } });
|
|
485 |
| } |
|
486 |
| |
|
487 |
0
| private Iterable<String> _getLinkArgs() {
|
|
488 |
0
| Configuration config = DrJava.getConfig();
|
|
489 |
0
| String linkVersion = config.getSetting(OptionConstants.JAVADOC_LINK_VERSION);
|
|
490 |
0
| if (linkVersion.equals(OptionConstants.JAVADOC_1_3_TEXT)) {
|
|
491 |
0
| return IterUtil.make("-link", config.getSetting(OptionConstants.JAVADOC_1_3_LINK));
|
|
492 |
| } |
|
493 |
0
| else if (linkVersion.equals(OptionConstants.JAVADOC_1_4_TEXT)) {
|
|
494 |
0
| return IterUtil.make("-link", config.getSetting(OptionConstants.JAVADOC_1_4_LINK));
|
|
495 |
| } |
|
496 |
0
| else if (linkVersion.equals(OptionConstants.JAVADOC_1_5_TEXT)) {
|
|
497 |
0
| return IterUtil.make("-link", config.getSetting(OptionConstants.JAVADOC_1_5_LINK));
|
|
498 |
| } |
|
499 |
0
| else if (linkVersion.equals(OptionConstants.JAVADOC_1_6_TEXT)) {
|
|
500 |
0
| return IterUtil.make("-link", config.getSetting(OptionConstants.JAVADOC_1_6_LINK));
|
|
501 |
| } |
|
502 |
| else { |
|
503 |
| |
|
504 |
0
| return IterUtil.empty();
|
|
505 |
| } |
|
506 |
| } |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
0
| private List<DJError> _extractErrors(String text) {
|
|
514 |
0
| BufferedReader r = new BufferedReader(new StringReader(text));
|
|
515 |
0
| List<DJError> result = new ArrayList<DJError>();
|
|
516 |
| |
|
517 |
0
| String[] errorIndicators = new String[]{ "Error: ", "Exception: ", "invalid flag:" };
|
|
518 |
| |
|
519 |
0
| try {
|
|
520 |
0
| String output = r.readLine();
|
|
521 |
0
| while (output != null) {
|
|
522 |
0
| if (TextUtil.containsAny(output, errorIndicators)) {
|
|
523 |
| |
|
524 |
0
| result.add(new DJError(output + '\n' + IOUtil.toString(r), false));
|
|
525 |
| } |
|
526 |
| else { |
|
527 |
| |
|
528 |
0
| DJError error = _parseJavadocErrorLine(output);
|
|
529 |
0
| if (error != null) { result.add(error); }
|
|
530 |
| } |
|
531 |
0
| output = r.readLine();
|
|
532 |
| } |
|
533 |
| } |
|
534 |
0
| catch (IOException e) { error.log(e); }
|
|
535 |
| |
|
536 |
0
| return result;
|
|
537 |
| } |
|
538 |
| |
|
539 |
| |
|
540 |
0
| private DJError _parseJavadocErrorLine(String line) {
|
|
541 |
0
| int errStart = line.indexOf(".java:");
|
|
542 |
0
| if (errStart == -1) { return null; }
|
|
543 |
| |
|
544 |
0
| String fileName = line.substring(0, errStart+5);
|
|
545 |
| |
|
546 |
| |
|
547 |
0
| int lineno = -1;
|
|
548 |
0
| final StringBuilder linenoString = new StringBuilder();
|
|
549 |
0
| int pos = errStart+6;
|
|
550 |
0
| while ((line.charAt(pos) >= '0') && (line.charAt(pos) <= '9')) {
|
|
551 |
0
| linenoString.append(line.charAt(pos));
|
|
552 |
0
| pos++;
|
|
553 |
| } |
|
554 |
| |
|
555 |
| |
|
556 |
| |
|
557 |
0
| if (line.charAt(pos) == ':') {
|
|
558 |
0
| try {
|
|
559 |
| |
|
560 |
0
| lineno = Integer.valueOf(linenoString.toString()).intValue() -1;
|
|
561 |
| } catch (NumberFormatException e) { |
|
562 |
| } |
|
563 |
| } else { |
|
564 |
0
| pos = errStart;
|
|
565 |
| } |
|
566 |
| |
|
567 |
| |
|
568 |
0
| String errMessage = line.substring(pos+2);
|
|
569 |
| |
|
570 |
| |
|
571 |
0
| boolean isWarning = false;
|
|
572 |
0
| if (errMessage.substring(0, 7).equalsIgnoreCase("warning")) {
|
|
573 |
0
| isWarning = true;
|
|
574 |
| } |
|
575 |
| |
|
576 |
0
| if (lineno >= 0) { return new DJError(new File(fileName), lineno, 0, errMessage, isWarning); }
|
|
577 |
0
| else { return new DJError(new File(fileName), errMessage, isWarning); }
|
|
578 |
| } |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
| |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
| |
|
592 |
0
| private File _getFileFromDocument(OpenDefinitionsDocument doc, FileSaveSelector saver) throws IOException {
|
|
593 |
0
| try {
|
|
594 |
| |
|
595 |
0
| return doc.getFile();
|
|
596 |
| } |
|
597 |
| catch (FileMovedException fme) { |
|
598 |
| |
|
599 |
| |
|
600 |
0
| if (saver.shouldSaveAfterFileMoved(doc, fme.getFile())) {
|
|
601 |
0
| try {
|
|
602 |
0
| doc.saveFileAs(saver);
|
|
603 |
0
| return doc.getFile();
|
|
604 |
| } |
|
605 |
| catch (FileMovedException fme2) { |
|
606 |
| |
|
607 |
| |
|
608 |
0
| fme2.printStackTrace();
|
|
609 |
0
| throw new IOException("Could not find file: " + fme2);
|
|
610 |
| } |
|
611 |
| } |
|
612 |
| else { |
|
613 |
0
| throw new IllegalStateException("No file exists for this document.");
|
|
614 |
| } |
|
615 |
| } |
|
616 |
| } |
|
617 |
| |
|
618 |
| } |