KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > bridge > impl > NbBuildLogger


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.bridge.impl;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.Comparator JavaDoc;
31 import java.util.Enumeration JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.LinkedHashSet JavaDoc;
34 import java.util.LinkedList JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Set JavaDoc;
38 import java.util.regex.Matcher JavaDoc;
39 import java.util.regex.Pattern JavaDoc;
40 import org.apache.tools.ant.BuildEvent;
41 import org.apache.tools.ant.BuildException;
42 import org.apache.tools.ant.BuildListener;
43 import org.apache.tools.ant.Location;
44 import org.apache.tools.ant.Project;
45 import org.apache.tools.ant.RuntimeConfigurable;
46 import org.apache.tools.ant.Target;
47 import org.apache.tools.ant.Task;
48 import org.apache.tools.ant.module.bridge.AntBridge;
49 import org.apache.tools.ant.module.run.Hyperlink;
50 import org.apache.tools.ant.module.run.LoggerTrampoline;
51 import org.apache.tools.ant.module.spi.AntEvent;
52 import org.apache.tools.ant.module.spi.AntLogger;
53 import org.apache.tools.ant.module.spi.AntSession;
54 import org.apache.tools.ant.module.spi.TaskStructure;
55 import org.netbeans.api.progress.ProgressHandle;
56 import org.openide.ErrorManager;
57 import org.openide.awt.StatusDisplayer;
58 import org.openide.util.Lookup;
59 import org.openide.util.NbBundle;
60 import org.openide.util.NbCollections;
61 import org.openide.util.RequestProcessor;
62 import org.openide.util.WeakSet;
63 import org.openide.windows.OutputListener;
64 import org.openide.windows.OutputWriter;
65
66 /**
67  * NetBeans-sensitive build logger.
68  * Just delegates all events to the registered SPI loggers
69  * through an abstraction layer.
70  * Synchronization: all callbacks are synchronized, both to protect access to logger
71  * caches, and to prevent AntBridge.suspend/resumeDelegation from being called with
72  * dynamic overlaps.
73  * @author Jesse Glick
74  */

75 final class NbBuildLogger implements BuildListener, LoggerTrampoline.AntSessionImpl {
76     
77     private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(NbBuildLogger.class.getName());
78     /** hack for debugging unit tests */
79     private static final int EM_LEVEL = Boolean.getBoolean(NbBuildLogger.class.getName() + ".LOG_AT_WARNING") ? // NOI18N
80
ErrorManager.WARNING : ErrorManager.INFORMATIONAL;
81     private static final boolean LOGGABLE = ERR.isLoggable(EM_LEVEL);
82     
83     private final AntSession thisSession;
84     
85     private final File JavaDoc origScript;
86     private String JavaDoc[] targets = null;
87     private final OutputWriter out;
88     private final OutputWriter err;
89     private final int verbosity;
90     private final String JavaDoc displayName;
91     private final Runnable JavaDoc interestingOutputCallback;
92     private final ProgressHandle handle;
93     private final RequestProcessor.Task sleepTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
94         public void run() {
95             handle.suspend("");
96         }
97     });
98     private static final int SLEEP_DELAY = 5000;
99     
100     private final Map JavaDoc<AntLogger,Object JavaDoc> customData = new HashMap JavaDoc<AntLogger,Object JavaDoc>();
101     
102     private List JavaDoc<AntLogger> interestedLoggers = null;
103     private Map JavaDoc<File JavaDoc/*|null*/,Collection JavaDoc<AntLogger>> interestedLoggersByScript = new HashMap JavaDoc<File JavaDoc,Collection JavaDoc<AntLogger>>();
104     private Map JavaDoc<String JavaDoc/*|null*/,Collection JavaDoc<AntLogger>> interestedLoggersByTarget = new HashMap JavaDoc<String JavaDoc,Collection JavaDoc<AntLogger>>();
105     private Map JavaDoc<String JavaDoc/*|null*/,Collection JavaDoc<AntLogger>> interestedLoggersByTask = new HashMap JavaDoc<String JavaDoc,Collection JavaDoc<AntLogger>>();
106     private Map JavaDoc<Integer JavaDoc,Collection JavaDoc<AntLogger>> interestedLoggersByLevel = new HashMap JavaDoc<Integer JavaDoc,Collection JavaDoc<AntLogger>>();
107     
108     private final Set JavaDoc<Project> projectsWithProperties = Collections.synchronizedSet(new WeakSet<Project>());
109     
110     private final Set JavaDoc<Throwable JavaDoc> consumedExceptions = new WeakSet<Throwable JavaDoc>();
111     
112     /** whether this process should be halted at the next safe point */
113     private boolean stop = false;
114     /** whether this process is thought to be still running */
115     private boolean running = true;
116     
117     /**
118      * Map from master build scripts to maps from imported target names to imported locations.
119      * Hack for lack of Target.getLocation() in Ant 1.6.2 and earlier.
120      * Unused if targetGetLocation is not null.
121      */

122     private final Map JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> knownImportedTargets = Collections.synchronizedMap(new HashMap JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>>());
123     /**
124      * Main script known to be being parsed at the moment.
125      * Unused if targetGetLocation is not null.
126      */

127     private String JavaDoc currentlyParsedMainScript = null;
128     /**
129      * Imported script known to be being parsed at the moment.
130      * Unused if targetGetLocation is not null.
131      */

132     private String JavaDoc currentlyParsedImportedScript = null;
133     /**
134      * Last task which was known to be running. Heuristic. Cf. #49464.
135      */

136     private Task lastTask = null;
137     
138     public NbBuildLogger(File JavaDoc origScript, OutputWriter out, OutputWriter err, int verbosity, String JavaDoc displayName, Runnable JavaDoc interestingOutputCallback, ProgressHandle handle) {
139         thisSession = LoggerTrampoline.ANT_SESSION_CREATOR.makeAntSession(this);
140         this.origScript = origScript;
141         this.out = out;
142         this.err = err;
143         this.verbosity = verbosity;
144         this.displayName = displayName;
145         this.interestingOutputCallback = interestingOutputCallback;
146         this.handle = handle;
147         if (LOGGABLE) {
148             ERR.log(EM_LEVEL, "---- Initializing build of " + origScript + " \"" + displayName + "\" at verbosity " + verbosity + " ----");
149         }
150     }
151     
152     /** Try to stop running at the next safe point. */
153     public void stop() {
154         stop = true;
155     }
156     
157     /** Stop the build now if requested. Also restarts sleep timer. */
158     private void checkForStop() {
159         if (stop) {
160             StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(NbBuildLogger.class, "MSG_stopped", displayName));
161             throw new ThreadDeath JavaDoc();
162         }
163         if (running) {
164             handle.switchToIndeterminate();
165             sleepTask.schedule(SLEEP_DELAY);
166         }
167     }
168
169     /**
170      * Notify this process that it has been shut down.
171      * Refuse any further queries on AntEvent etc.
172      * @see "#71266"
173      */

174     public void shutdown() {
175         running = false;
176         out.close();
177         err.close();
178         handle.finish();
179         sleepTask.cancel();
180     }
181     
182     private void verifyRunning() {
183         if (!running) {
184             throw new IllegalStateException JavaDoc("AntSession/AntEvent/TaskStructure method called after completion of Ant process"); // NOI18N
185
}
186     }
187     
188     /**
189      * Compute a list of loggers to use for this session.
190      * Do not do it in the constructor since the actual targets will not have been
191      * set and some loggers may care about the targets. However if buildInitializationFailed
192      * is called before then, initialize them anyway.
193      */

194     private synchronized void initInterestedLoggers() {
195         if (interestedLoggers == null) {
196             interestedLoggers = new ArrayList JavaDoc<AntLogger>();
197             for (AntLogger l : Lookup.getDefault().lookupAll(AntLogger.class)) {
198                 if (l.interestedInSession(thisSession)) {
199                     interestedLoggers.add(l);
200                 }
201             }
202             if (LOGGABLE) {
203                 ERR.log(EM_LEVEL, "getInterestedLoggers: loggers=" + interestedLoggers);
204             }
205         }
206     }
207
208     @SuppressWarnings JavaDoc("unchecked") // could use List<Collection<AntLogger>> but too slow?
209
private final Collection JavaDoc<AntLogger>[] interestedLoggersByVariousCriteria = new Collection JavaDoc[4];
210     private static final Comparator JavaDoc<Collection JavaDoc<AntLogger>> INTERESTED_LOGGERS_SORTER = new Comparator JavaDoc<Collection JavaDoc<AntLogger>>() {
211         public int compare(Collection JavaDoc<AntLogger> c1, Collection JavaDoc<AntLogger> c2) {
212             int x = c1.size() - c2.size(); // reverse sort by size
213
if (x != 0) {
214                 return x;
215             } else {
216                 return System.identityHashCode(c1) - System.identityHashCode(c2);
217             }
218         }
219     };
220     /**
221      * Get those loggers interested in a given event.
222      */

223     private synchronized Collection JavaDoc<AntLogger> getInterestedLoggersByEvent(AntEvent e) {
224         initInterestedLoggers();
225         // Start with the smallest one and go down.
226
interestedLoggersByVariousCriteria[0] = getInterestedLoggersByScript(e.getScriptLocation());
227         interestedLoggersByVariousCriteria[1] = getInterestedLoggersByTarget(e.getTargetName());
228         interestedLoggersByVariousCriteria[2] = getInterestedLoggersByTask(e.getTaskName());
229         interestedLoggersByVariousCriteria[3] = getInterestedLoggersByLevel(e.getLogLevel());
230         Arrays.sort(interestedLoggersByVariousCriteria, INTERESTED_LOGGERS_SORTER);
231         if (LOGGABLE) {
232             ERR.log(EM_LEVEL, "getInterestedLoggersByVariousCriteria: event=" + e + " loggers=" + Arrays.asList(interestedLoggersByVariousCriteria));
233         }
234         // XXX could probably be even a bit more efficient by iterating on the fly...
235
// and by skipping the sorting which is probably overkill for a small number of a loggers (or hardcode the sort)
236
List JavaDoc<AntLogger> loggers = new LinkedList JavaDoc<AntLogger>(interestedLoggersByVariousCriteria[0]);
237         for (int i = 1; i < 4; i++) {
238             loggers.retainAll(interestedLoggersByVariousCriteria[i]);
239         }
240         if (LOGGABLE) {
241             ERR.log(EM_LEVEL, "getInterestedLoggersByEvent: event=" + e + " loggers=" + loggers);
242         }
243         return loggers;
244     }
245     
246     private synchronized Collection JavaDoc<AntLogger> getInterestedLoggersByScript(File JavaDoc script) {
247         Collection JavaDoc<AntLogger> c = interestedLoggersByScript.get(script);
248         if (c == null) {
249             c = new LinkedHashSet JavaDoc<AntLogger>(interestedLoggers.size());
250             interestedLoggersByScript.put(script, c);
251             for (AntLogger l : interestedLoggers) {
252                 if (l.interestedInAllScripts(thisSession) || (script != null && l.interestedInScript(script, thisSession))) {
253                     c.add(l);
254                 }
255             }
256             if (LOGGABLE) {
257                 ERR.log(EM_LEVEL, "getInterestedLoggersByScript: script=" + script + " loggers=" + c);
258             }
259         }
260         return c;
261     }
262     
263     private synchronized Collection JavaDoc<AntLogger> getInterestedLoggersByTarget(String JavaDoc target) {
264         Collection JavaDoc<AntLogger> c = interestedLoggersByTarget.get(target);
265         if (c == null) {
266             c = new LinkedHashSet JavaDoc<AntLogger>(interestedLoggers.size());
267             interestedLoggersByTarget.put(target, c);
268             for (AntLogger l : interestedLoggers) {
269                 String JavaDoc[] targets = l.interestedInTargets(thisSession);
270                 if (targets == AntLogger.ALL_TARGETS ||
271                         (target != null && Arrays.asList(targets).contains(target)) ||
272                         (target == null && targets == AntLogger.NO_TARGETS)) {
273                     c.add(l);
274                 }
275             }
276             if (LOGGABLE) {
277                 ERR.log(EM_LEVEL, "getInterestedLoggersByTarget: target=" + target + " loggers=" + c);
278             }
279         }
280         return c;
281     }
282     
283     private synchronized Collection JavaDoc<AntLogger> getInterestedLoggersByTask(String JavaDoc task) {
284         Collection JavaDoc<AntLogger> c = interestedLoggersByTask.get(task);
285         if (c == null) {
286             c = new LinkedHashSet JavaDoc<AntLogger>(interestedLoggers.size());
287             interestedLoggersByTask.put(task, c);
288             for (AntLogger l : interestedLoggers) {
289                 String JavaDoc[] tasks = l.interestedInTasks(thisSession);
290                 if (tasks == AntLogger.ALL_TASKS ||
291                         (task != null && Arrays.asList(tasks).contains(task)) ||
292                         (task == null && tasks == AntLogger.NO_TASKS)) {
293                     c.add(l);
294                 }
295             }
296             if (LOGGABLE) {
297                 ERR.log(EM_LEVEL, "getInterestedLoggersByTask: task=" + task + " loggers=" + c);
298             }
299         }
300         return c;
301     }
302     
303     private synchronized Collection JavaDoc<AntLogger> getInterestedLoggersByLevel(int level) {
304         Collection JavaDoc<AntLogger> c = interestedLoggersByLevel.get(level);
305         if (c == null) {
306             c = new LinkedHashSet JavaDoc<AntLogger>(interestedLoggers.size());
307             interestedLoggersByLevel.put(level, c);
308             for (AntLogger l : interestedLoggers) {
309                 if (level == -1) {
310                     c.add(l);
311                 } else {
312                     int[] levels = l.interestedInLogLevels(thisSession);
313                     for (int _level : levels) {
314                         if (_level == level) {
315                             c.add(l);
316                             break;
317                         }
318                     }
319                 }
320             }
321             if (LOGGABLE) {
322                 ERR.log(EM_LEVEL, "getInterestedLoggersByLevel: level=" + level + " loggers=" + c);
323             }
324         }
325         return c;
326     }
327     
328     synchronized void setActualTargets(String JavaDoc[] targets) {
329         this.targets = targets;
330     }
331     
332     void buildInitializationFailed(BuildException be) {
333         initInterestedLoggers();
334         AntEvent ev = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(be));
335         if (LOGGABLE) {
336             ERR.log(EM_LEVEL, "buildInitializationFailed: " + ev);
337         }
338         for (AntLogger l : getInterestedLoggersByScript(null)) {
339             l.buildInitializationFailed(ev);
340         }
341     }
342     
343     public void buildStarted(BuildEvent ev) {
344         AntBridge.suspendDelegation();
345         try {
346             checkForStop();
347             initInterestedLoggers();
348             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
349             if (LOGGABLE) {
350                 ERR.log(EM_LEVEL, "buildStarted: " + e);
351             }
352             for (AntLogger l : interestedLoggers) {
353                 try {
354                     l.buildStarted(e);
355                 } catch (RuntimeException JavaDoc x) {
356                     ERR.notify(EM_LEVEL, x);
357                 }
358             }
359         } finally {
360             AntBridge.resumeDelegation();
361         }
362     }
363     
364     public void buildFinished(BuildEvent ev) {
365         AntBridge.suspendDelegation();
366         try {
367             // #82160: do not call checkForStop() here
368
stop = false; // do not throw ThreadDeath on messageLogged from BridgeImpl cleanup code
369
lastTask = null;
370             initInterestedLoggers(); // just in case
371
AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
372             if (LOGGABLE) {
373                 ERR.log(EM_LEVEL, "buildFinished: " + e);
374                 if (e.getException() != null) {
375                     ERR.notify(EM_LEVEL, e.getException());
376                 }
377             }
378             for (AntLogger l : interestedLoggers) {
379                 try {
380                     l.buildFinished(e);
381                 } catch (RuntimeException JavaDoc x) {
382                     ERR.notify(EM_LEVEL, x);
383                 } catch (Error JavaDoc x) {
384                     ERR.notify(EM_LEVEL, x);
385                 }
386             }
387         } finally {
388             AntBridge.resumeDelegation();
389         }
390     }
391     
392     public void targetStarted(BuildEvent ev) {
393         AntBridge.suspendDelegation();
394         try {
395             checkForStop();
396             lastTask = null;
397             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
398             if (LOGGABLE) {
399                 ERR.log(EM_LEVEL, "targetStarted: " + e);
400             }
401             for (AntLogger l : getInterestedLoggersByEvent(e)) {
402                 try {
403                     l.targetStarted(e);
404                 } catch (RuntimeException JavaDoc x) {
405                     ERR.notify(EM_LEVEL, x);
406                 }
407             }
408             // Update progress handle label so user can see what is being run.
409
Project p = ev.getProject();
410             String JavaDoc projectName = null;
411             if (p != null) {
412                 projectName = p.getName();
413             }
414             String JavaDoc targetName = e.getTargetName();
415             if (targetName != null) {
416                 String JavaDoc message;
417                 if (projectName != null) {
418                     message = NbBundle.getMessage(NbBuildLogger.class, "MSG_progress_target", projectName, targetName);
419                 } else {
420                     message = targetName;
421                 }
422                 /*
423                 if (message.equals(displayName)) {
424                     // Redundant in this case.
425                     message = "";
426                 }
427                  */

428                 handle.progress(message);
429             }
430         } finally {
431             AntBridge.resumeDelegation();
432         }
433     }
434     
435     public void targetFinished(BuildEvent ev) {
436         AntBridge.suspendDelegation();
437         try {
438             checkForStop();
439             lastTask = null;
440             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
441             if (LOGGABLE) {
442                 ERR.log(EM_LEVEL, "targetFinished: " + e);
443             }
444             for (AntLogger l : getInterestedLoggersByEvent(e)) {
445                 try {
446                     l.targetFinished(e);
447                 } catch (RuntimeException JavaDoc x) {
448                     ERR.notify(EM_LEVEL, x);
449                 }
450             }
451         } finally {
452             AntBridge.resumeDelegation();
453         }
454     }
455     
456     public void taskStarted(BuildEvent ev) {
457         AntBridge.suspendDelegation();
458         try {
459             checkForStop();
460             lastTask = ev.getTask();
461             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
462             if (LOGGABLE) {
463                 ERR.log(EM_LEVEL, "taskStarted: " + e);
464             }
465             for (AntLogger l : getInterestedLoggersByEvent(e)) {
466                 try {
467                     l.taskStarted(e);
468                 } catch (RuntimeException JavaDoc x) {
469                     ERR.notify(EM_LEVEL, x);
470                 }
471             }
472             if ("input".equals(e.getTaskName())) { // #81139; NOI18N
473
TaskStructure s = e.getTaskStructure();
474                 if (s != null) {
475                     String JavaDoc def = s.getAttribute("defaultvalue"); // NOI18N
476
if (def != null) {
477                         NbInputHandler.setDefaultValue(e.evaluate(def));
478                     }
479                 }
480             }
481         } finally {
482             AntBridge.resumeDelegation();
483         }
484     }
485     
486     public void taskFinished(BuildEvent ev) {
487         AntBridge.suspendDelegation();
488         try {
489             checkForStop();
490             lastTask = null;
491             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false));
492             if (LOGGABLE) {
493                 ERR.log(EM_LEVEL, "taskFinished: " + e);
494             }
495             for (AntLogger l : getInterestedLoggersByEvent(e)) {
496                 try {
497                     l.taskFinished(e);
498                 } catch (RuntimeException JavaDoc x) {
499                     ERR.notify(EM_LEVEL, x);
500                 }
501             }
502             NbInputHandler.setDefaultValue(null);
503         } finally {
504             AntBridge.resumeDelegation();
505         }
506     }
507     
508     /**
509      * Pattern matching an Ant message logged when it is parsing a build script.
510      * Hack for lack of Target.getLocation() in Ant 1.6.2 and earlier.
511      * Captured groups:
512      * <ol>
513      * <li>absolute path of build script
514      * </ol>
515      */

516     private static final Pattern JavaDoc PARSING_BUILDFILE_MESSAGE =
517         Pattern.compile("parsing buildfile (.+) with URI = (?:.+)"); // NOI18N
518

519     /**
520      * Pattern matching an Ant message logged when it is importing a build script.
521      * Hack for lack of Target.getLocation() in Ant 1.6.2 and earlier.
522      * Captured groups:
523      * <ol>
524      * <li>absolute path of build script which is doing the importing
525      * </ol>
526      */

527     private static final Pattern JavaDoc IMPORTING_FILE_MESSAGE =
528         Pattern.compile("Importing file (?:.+) from (.+)"); // NOI18N
529

530     /**
531      * Pattern matching an Ant message logged when it has encountered a target in some build script.
532      * Hack for lack of Target.getLocation() in Ant 1.6.2 and earlier.
533      * Captured groups:
534      * <ol>
535      * <li>target name
536      * </ol>
537      */

538     private static final Pattern JavaDoc PARSED_TARGET_MESSAGE =
539         Pattern.compile(" \\+Target: (.+)"); // NOI18N
540

541     public void messageLogged(BuildEvent ev) {
542         AntBridge.suspendDelegation();
543         try {
544             checkForStop();
545             AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, true));
546             if (LOGGABLE) {
547                 ERR.log(EM_LEVEL, "messageLogged: " + e);
548             }
549             for (AntLogger l : getInterestedLoggersByEvent(e)) {
550                 try {
551                     l.messageLogged(e);
552                 } catch (RuntimeException JavaDoc x) {
553                     ERR.notify(EM_LEVEL, x);
554                 }
555             }
556             // Let the hacks begin!
557
String JavaDoc msg = ev.getMessage();
558             if (msg.contains("ant.PropertyHelper") || /* #71816 */ msg.contains("ant.projectHelper")) { // NOI18N
559
// Only after this has been defined can we get any properties.
560
// Even trying earlier will give a recursion error since this pseudoprop
561
// is set lazily, which produces a new message logged event.
562
projectsWithProperties.add(ev.getProject());
563             }
564             if (targetGetLocation == null) {
565                 // Try to figure out which imported targets belong to which actual scripts.
566
// XXX consider keeping a singleton Matcher for each pattern and reusing it
567
// or just doing string comparisons
568
Matcher JavaDoc matcher;
569                 if ((matcher = PARSING_BUILDFILE_MESSAGE.matcher(msg)).matches()) {
570                     if (currentlyParsedMainScript != null) {
571                         currentlyParsedImportedScript = matcher.group(1);
572                     }
573                     if (LOGGABLE) {
574                         ERR.log(EM_LEVEL, "Got PARSING_BUILDFILE_MESSAGE: " + currentlyParsedImportedScript);
575                     }
576                     lastTask = null;
577                 } else if ((matcher = IMPORTING_FILE_MESSAGE.matcher(msg)).matches()) {
578                     currentlyParsedMainScript = matcher.group(1);
579                     currentlyParsedImportedScript = null;
580                     if (LOGGABLE) {
581                         ERR.log(EM_LEVEL, "Got IMPORTING_FILE_MESSAGE: " + currentlyParsedMainScript);
582                     }
583                     lastTask = null;
584                 } else if ((matcher = PARSED_TARGET_MESSAGE.matcher(msg)).matches()) {
585                     if (currentlyParsedMainScript != null && currentlyParsedImportedScript != null) {
586                         Map JavaDoc<String JavaDoc,String JavaDoc> targetLocations = knownImportedTargets.get(currentlyParsedMainScript);
587                         if (targetLocations == null) {
588                             targetLocations = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
589                             knownImportedTargets.put(currentlyParsedMainScript, targetLocations);
590                         }
591                         targetLocations.put(matcher.group(1), currentlyParsedImportedScript);
592                     }
593                     if (LOGGABLE) {
594                         ERR.log(EM_LEVEL, "Got PARSED_TARGET_MESSAGE: " + matcher.group(1));
595                     }
596                     lastTask = null;
597                 }
598             }
599         } finally {
600             AntBridge.resumeDelegation();
601         }
602     }
603     
604     public File JavaDoc getOriginatingScript() {
605         verifyRunning();
606         return origScript;
607     }
608     
609     public String JavaDoc[] getOriginatingTargets() {
610         verifyRunning();
611         return targets != null ? targets : new String JavaDoc[0];
612     }
613     
614     public synchronized Object JavaDoc getCustomData(AntLogger logger) {
615         verifyRunning();
616         return customData.get(logger);
617     }
618     
619     public synchronized void putCustomData(AntLogger logger, Object JavaDoc data) {
620         verifyRunning();
621         customData.put(logger, data);
622     }
623     
624     public void println(String JavaDoc message, boolean error, OutputListener listener) {
625         verifyRunning();
626         if (LOGGABLE) {
627             ERR.log(EM_LEVEL, "println: error=" + error + " listener=" + listener + " message=" + message);
628         }
629         OutputWriter ow = error ? err : out;
630         try {
631             if (listener != null) {
632                 // XXX factor out into AntLogger API!
633
boolean important = (message.indexOf("[deprecation]") == -1 &&
634                                      message.indexOf("warning") == -1 &&
635                                      message.indexOf("stopped") == -1);
636                 ow.println(message, listener, important);
637                 interestingOutputCallback.run();
638             } else {
639                 ow.println(message);
640             }
641         } catch (IOException JavaDoc e) {
642             ERR.notify(e);
643         }
644     }
645     
646     public void deliverMessageLogged(AntEvent originalEvent, String JavaDoc message, int level) {
647         verifyRunning();
648         if (originalEvent == null) {
649             throw new IllegalArgumentException JavaDoc("Must pass an original event to deliverMessageLogged"); // NOI18N
650
}
651         if (message == null) {
652             throw new IllegalArgumentException JavaDoc("Must pass a message to deliverMessageLogged"); // NOI18N
653
}
654         if (level < AntEvent.LOG_ERR || level > AntEvent.LOG_DEBUG) {
655             throw new IllegalArgumentException JavaDoc("Unknown log level for reposted log event: " + level); // NOI18N
656
}
657         if (LOGGABLE) {
658             ERR.log(EM_LEVEL, "deliverMessageLogged: level=" + level + " message=" + message);
659         }
660         AntEvent newEvent = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new RepostedEvent(originalEvent, message, level));
661         for (AntLogger l : getInterestedLoggersByEvent(newEvent)) {
662             try {
663                 l.messageLogged(newEvent);
664             } catch (RuntimeException JavaDoc x) {
665                 ERR.notify(EM_LEVEL, x);
666             }
667         }
668     }
669     
670     public synchronized void consumeException(Throwable JavaDoc t) throws IllegalStateException JavaDoc {
671         verifyRunning();
672         if (isExceptionConsumed(t)) {
673             throw new IllegalStateException JavaDoc("Already consumed " + t); // NOI18N
674
}
675         consumedExceptions.add(t);
676     }
677     
678     public synchronized boolean isExceptionConsumed(Throwable JavaDoc t) {
679         verifyRunning();
680         if (consumedExceptions.contains(t)) {
681             return true;
682         }
683         // Check for nested exceptions too.
684
Throwable JavaDoc nested = t.getCause();
685         if (nested != null && isExceptionConsumed(nested)) {
686             // cache that
687
consumedExceptions.add(t);
688             return true;
689         }
690         return false;
691     }
692     
693     public int getVerbosity() {
694         verifyRunning();
695         return verbosity;
696     }
697     
698     String JavaDoc getDisplayNameNoLock() {
699         return displayName;
700     }
701     
702     public String JavaDoc getDisplayName() {
703         verifyRunning();
704         return displayName;
705     }
706
707     public OutputListener createStandardHyperlink(URL JavaDoc file, String JavaDoc message, int line1, int column1, int line2, int column2) {
708         verifyRunning();
709         return new Hyperlink(file, message, line1, column1, line2, column2);
710     }
711     
712     // Accessors for stuff which is specific to particular versions of Ant.
713
private static final Method JavaDoc targetGetLocation; // 1.6.2+
714
private static final Method JavaDoc locationGetFileName; // 1.6+
715
private static final Method JavaDoc locationGetLineNumber; // 1.6+
716
private static final Method JavaDoc runtimeConfigurableGetAttributeMap; // 1.6+
717
private static final Method JavaDoc runtimeConfigurableGetChildren; // 1.6+
718
private static final Method JavaDoc runtimeConfigurableGetText; // 1.6+
719
static {
720         Method JavaDoc _targetGetLocation = null;
721         try {
722             _targetGetLocation = Target.class.getMethod("getLocation"); // NOI18N
723
if (AntBridge.getInterface().getAntVersion().indexOf("1.6.2") != -1) { // NOI18N
724
// Unfortunately in 1.6.2 the method exists but it doesn't work (Ant #28599):
725
_targetGetLocation = null;
726             }
727         } catch (NoSuchMethodException JavaDoc e) {
728             // OK
729
} catch (Exception JavaDoc e) {
730             ERR.notify(EM_LEVEL, e);
731         }
732         targetGetLocation = _targetGetLocation;
733         Method JavaDoc _locationGetFileName = null;
734         try {
735             _locationGetFileName = Location.class.getMethod("getFileName"); // NOI18N
736
} catch (NoSuchMethodException JavaDoc e) {
737             // OK
738
} catch (Exception JavaDoc e) {
739             ERR.notify(EM_LEVEL, e);
740         }
741         locationGetFileName = _locationGetFileName;
742         Method JavaDoc _locationGetLineNumber = null;
743         try {
744             _locationGetLineNumber = Location.class.getMethod("getLineNumber"); // NOI18N
745
} catch (NoSuchMethodException JavaDoc e) {
746             // OK
747
} catch (Exception JavaDoc e) {
748             ERR.notify(EM_LEVEL, e);
749         }
750         locationGetLineNumber = _locationGetLineNumber;
751         Method JavaDoc _runtimeConfigurableGetAttributeMap = null;
752         try {
753             _runtimeConfigurableGetAttributeMap = RuntimeConfigurable.class.getMethod("getAttributeMap"); // NOI18N
754
} catch (NoSuchMethodException JavaDoc e) {
755             // OK
756
} catch (Exception JavaDoc e) {
757             ERR.notify(EM_LEVEL, e);
758         }
759         runtimeConfigurableGetAttributeMap = _runtimeConfigurableGetAttributeMap;
760         Method JavaDoc _runtimeConfigurableGetChildren = null;
761         try {
762             _runtimeConfigurableGetChildren = RuntimeConfigurable.class.getMethod("getChildren"); // NOI18N
763
} catch (NoSuchMethodException JavaDoc e) {
764             // OK
765
} catch (Exception JavaDoc e) {
766             ERR.notify(EM_LEVEL, e);
767         }
768         runtimeConfigurableGetChildren = _runtimeConfigurableGetChildren;
769         Method JavaDoc _runtimeConfigurableGetText = null;
770         try {
771             _runtimeConfigurableGetText = RuntimeConfigurable.class.getMethod("getText"); // NOI18N
772
} catch (NoSuchMethodException JavaDoc e) {
773             // OK
774
} catch (Exception JavaDoc e) {
775             ERR.notify(EM_LEVEL, e);
776         }
777         runtimeConfigurableGetText = _runtimeConfigurableGetText;
778     }
779
780     /**
781      * Try to find the location of an Ant target.
782      * @param project if not null, the main project from which this target might have been imported
783      */

784     private Location getLocationOfTarget(Target target, Project project) {
785         if (targetGetLocation != null) {
786             try {
787                 return (Location) targetGetLocation.invoke(target);
788             } catch (Exception JavaDoc e) {
789                 ERR.notify(EM_LEVEL, e);
790             }
791         }
792         // For Ant 1.6.2 and earlier, hope we got the right info from the hacks above.
793
if (LOGGABLE) {
794             ERR.log(EM_LEVEL, "knownImportedTargets: " + knownImportedTargets);
795         }
796         if (project != null) {
797             String JavaDoc file = project.getProperty("ant.file"); // NOI18N
798
if (file != null) {
799                 Map JavaDoc<String JavaDoc,String JavaDoc> targetLocations = knownImportedTargets.get(file);
800                 if (targetLocations != null) {
801                     String JavaDoc importedFile = targetLocations.get(target.getName());
802                     if (importedFile != null) {
803                         // Have no line number, note.
804
return new Location(importedFile);
805                     }
806                 }
807             }
808         }
809         // Dunno.
810
return null;
811     }
812     
813     private static String JavaDoc getFileNameOfLocation(Location loc) {
814         if (locationGetFileName != null) {
815             try {
816                 return (String JavaDoc) locationGetFileName.invoke(loc);
817             } catch (Exception JavaDoc e) {
818                 ERR.notify(EM_LEVEL, e);
819             }
820         }
821         // OK, using Ant 1.5.x.
822
String JavaDoc locs = loc.toString();
823         // Format: "$file:$line: " or "$file: " or ""
824
int x = locs.indexOf(':');
825         if (x != -1) {
826             return locs.substring(0, x);
827         } else {
828             return null;
829         }
830     }
831     
832     private static int getLineNumberOfLocation(Location loc) {
833         if (locationGetLineNumber != null) {
834             try {
835                 return (Integer JavaDoc) locationGetLineNumber.invoke(loc);
836             } catch (Exception JavaDoc e) {
837                 ERR.notify(EM_LEVEL, e);
838             }
839         }
840         // OK, using Ant 1.5.x.
841
String JavaDoc locs = loc.toString();
842         // Format: "$file:$line: " or "$file: " or ""
843
int x = locs.indexOf(':');
844         if (x != -1) {
845             int x2 = locs.indexOf(':', x + 1);
846             if (x2 != -1) {
847                 String JavaDoc line = locs.substring(x + 1, x2);
848                 try {
849                     return Integer.parseInt(line);
850                 } catch (NumberFormatException JavaDoc e) {
851                     // ignore?
852
}
853             }
854         }
855         return 0;
856     }
857     
858     @SuppressWarnings JavaDoc("unchecked")
859     private static Map JavaDoc<String JavaDoc,String JavaDoc> getAttributeMapOfRuntimeConfigurable(RuntimeConfigurable rc) {
860         if (runtimeConfigurableGetAttributeMap != null) {
861             try {
862                 return (Map JavaDoc<String JavaDoc,String JavaDoc>) runtimeConfigurableGetAttributeMap.invoke(rc);
863             } catch (Exception JavaDoc e) {
864                 ERR.notify(EM_LEVEL, e);
865             }
866         }
867         return Collections.emptyMap();
868     }
869
870     @SuppressWarnings JavaDoc("unchecked")
871     private static Enumeration JavaDoc<RuntimeConfigurable> getChildrenOfRuntimeConfigurable(RuntimeConfigurable rc) {
872         if (runtimeConfigurableGetChildren != null) {
873             try {
874                 return (Enumeration JavaDoc<RuntimeConfigurable>) runtimeConfigurableGetChildren.invoke(rc);
875             } catch (Exception JavaDoc e) {
876                 ERR.notify(EM_LEVEL, e);
877             }
878         }
879         return Collections.enumeration(Collections.<RuntimeConfigurable>emptySet());
880     }
881     
882     private static String JavaDoc getTextOfRuntimeConfigurable(RuntimeConfigurable rc) {
883         if (runtimeConfigurableGetText != null) {
884             try {
885                 return ((StringBuffer JavaDoc) runtimeConfigurableGetText.invoke(rc)).toString();
886             } catch (Exception JavaDoc e) {
887                 ERR.notify(EM_LEVEL, e);
888             }
889         }
890         return "";
891     }
892     
893     /**
894      * Standard event implemention, delegating to the Ant BuildEvent and Project.
895      */

896     private final class Event implements LoggerTrampoline.AntEventImpl {
897         
898         private boolean consumed = false;
899         private final BuildEvent e;
900         private final Throwable JavaDoc exception;
901         private final int level;
902         private File JavaDoc scriptLocation;
903         
904         /**
905          * Create a new regular event.
906          * @param e the Ant build event
907          * @param msgLogged true for logged events
908          */

909         public Event(BuildEvent e, boolean msgLogged) {
910             this.e = e;
911             exception = e.getException();
912             if (msgLogged) {
913                 level = e.getPriority();
914             } else {
915                 level = -1;
916             }
917         }
918         
919         /**
920          * Create a new event for buildInitializationFailed.
921          * @param exception the problem
922          */

923         public Event(Throwable JavaDoc exception) {
924             e = null;
925             this.exception = exception;
926             level = -1;
927         }
928         
929         public AntSession getSession() {
930             verifyRunning();
931             return thisSession;
932         }
933
934         public void consume() throws IllegalStateException JavaDoc {
935             verifyRunning();
936             if (consumed) {
937                 throw new IllegalStateException JavaDoc("Event already consumed"); // NOI18N
938
}
939             consumed = true;
940         }
941
942         public boolean isConsumed() {
943             verifyRunning();
944             return consumed;
945         }
946
947         public File JavaDoc getScriptLocation() {
948             verifyRunning();
949             if (scriptLocation != null) {
950                 return scriptLocation;
951             }
952             if (e == null) {
953                 return null;
954             }
955             Task task = e.getTask();
956             if (task != null) {
957                 Location l = task.getLocation();
958                 if (l != null) {
959                     String JavaDoc file = getFileNameOfLocation(l);
960                     if (file != null) {
961                         return scriptLocation = new File JavaDoc(file);
962                     }
963                 }
964             }
965             Target target = e.getTarget();
966             Project project = getProjectIfPropertiesDefined();
967             if (target != null) {
968                 Location l = getLocationOfTarget(target, project);
969                 if (l != null) {
970                     String JavaDoc file = getFileNameOfLocation(l);
971                     if (file != null) {
972                         return scriptLocation = new File JavaDoc(file);
973                     }
974                 }
975             }
976             if (project != null) {
977                 String JavaDoc file = project.getProperty("ant.file"); // NOI18N
978
if (file != null) {
979                     return scriptLocation = new File JavaDoc(file);
980                 }
981             }
982             // #49464: guess at task.
983
synchronized (NbBuildLogger.this) {
984                 if (lastTask != null) {
985                     Location l = lastTask.getLocation();
986                     if (l != null) {
987                         String JavaDoc file = getFileNameOfLocation(l);
988                         if (file != null) {
989                             return scriptLocation = new File JavaDoc(file);
990                         }
991                     }
992                 }
993             }
994             return null;
995         }
996         
997         private Project getProjectIfPropertiesDefined() {
998             Project project = e.getProject();
999             if (project != null && projectsWithProperties.contains(project)) {
1000                return project;
1001            } else {
1002                return null;
1003            }
1004        }
1005
1006        public int getLine() {
1007            verifyRunning();
1008            if (e == null) {
1009                return -1;
1010            }
1011            Task task = e.getTask();
1012            if (task != null) {
1013                Location l = task.getLocation();
1014                if (l != null) {
1015                    int line = getLineNumberOfLocation(l);
1016                    if (line > 0) {
1017                        return line;
1018                    }
1019                }
1020            }
1021            Target target = e.getTarget();
1022            if (target != null) {
1023                Location l = getLocationOfTarget(target, getProjectIfPropertiesDefined());
1024                if (l != null) {
1025                    int line = getLineNumberOfLocation(l);
1026                    if (line > 0) {
1027                        return line;
1028                    }
1029                }
1030            }
1031            // #49464: guess at task.
1032
synchronized (NbBuildLogger.this) {
1033                if (lastTask != null) {
1034                    Location l = lastTask.getLocation();
1035                    if (l != null) {
1036                        int line = getLineNumberOfLocation(l);
1037                        if (line > 0) {
1038                            return line;
1039                        }
1040                    }
1041                }
1042            }
1043            return -1;
1044        }
1045
1046        public String JavaDoc getTargetName() {
1047            verifyRunning();
1048            if (e == null) {
1049                return null;
1050            }
1051            Target target = e.getTarget();
1052            if (target != null) {
1053                String JavaDoc name = target.getName();
1054                if (name != null && name.length() > 0) {
1055                    return name;
1056                }
1057            }
1058            // #49464: guess at task.
1059
synchronized (NbBuildLogger.this) {
1060                if (lastTask != null) {
1061                    target = lastTask.getOwningTarget();
1062                    if (target != null) {
1063                        String JavaDoc name = target.getName();
1064                        if (name != null && name.length() > 0) {
1065                            return name;
1066                        }
1067                    }
1068                }
1069            }
1070            return null;
1071        }
1072
1073        public String JavaDoc getTaskName() {
1074            verifyRunning();
1075            if (e == null) {
1076                return null;
1077            }
1078            Task task = e.getTask();
1079            if (task != null) {
1080                return task.getRuntimeConfigurableWrapper().getElementTag();
1081            }
1082            // #49464: guess at task.
1083
synchronized (NbBuildLogger.this) {
1084                if (lastTask != null) {
1085                    return lastTask.getRuntimeConfigurableWrapper().getElementTag();
1086                }
1087            }
1088            return null;
1089        }
1090
1091        public TaskStructure getTaskStructure() {
1092            verifyRunning();
1093            Task task = e.getTask();
1094            if (task != null) {
1095                return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(task.getRuntimeConfigurableWrapper()));
1096            }
1097            // #49464: guess at task.
1098
synchronized (NbBuildLogger.this) {
1099                if (lastTask != null) {
1100                    return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(lastTask.getRuntimeConfigurableWrapper()));
1101                }
1102            }
1103            return null;
1104        }
1105
1106        public String JavaDoc getMessage() {
1107            verifyRunning();
1108            if (e == null) {
1109                return null;
1110            }
1111            return e.getMessage();
1112        }
1113
1114        public int getLogLevel() {
1115            verifyRunning();
1116            return level;
1117        }
1118
1119        public Throwable JavaDoc getException() {
1120            verifyRunning();
1121            return exception;
1122        }
1123
1124        public String JavaDoc getProperty(String JavaDoc name) {
1125            verifyRunning();
1126            Project project = getProjectIfPropertiesDefined();
1127            if (project != null) {
1128                Object JavaDoc o = project.getProperty(name);
1129                if (o instanceof String JavaDoc) {
1130                    return (String JavaDoc) o;
1131                } else {
1132                    return null;
1133                }
1134            } else {
1135                return null;
1136            }
1137        }
1138
1139        public Set JavaDoc<String JavaDoc> getPropertyNames() {
1140            verifyRunning();
1141            Project project = getProjectIfPropertiesDefined();
1142            if (project != null) {
1143                return NbCollections.checkedSetByFilter(project.getProperties().keySet(), String JavaDoc.class, true);
1144            } else {
1145                return Collections.emptySet();
1146            }
1147        }
1148
1149        public String JavaDoc evaluate(String JavaDoc text) {
1150            verifyRunning();
1151            Project project = getProjectIfPropertiesDefined();
1152            if (project != null) {
1153                return project.replaceProperties(text);
1154            } else {
1155                return text;
1156            }
1157        }
1158        
1159        @Override JavaDoc
1160        public String JavaDoc toString() {
1161            return "Event[target=" + getTargetName() + ",task=" + getTaskName() + ",message=" + getMessage() + ",scriptLocation=" + getScriptLocation() + ",exception=" + exception + ",level=" + level + ",consumed=" + consumed + "]"; // NOI18N
1162
}
1163        
1164    }
1165    
1166    /**
1167     * Reposted event delegating to an original one except for message and level.
1168     * @see #deliverMessageLogged
1169     */

1170    private final class RepostedEvent implements LoggerTrampoline.AntEventImpl {
1171        
1172        private final AntEvent originalEvent;
1173        private final String JavaDoc message;
1174        private final int level;
1175        private boolean consumed = false;
1176        
1177        public RepostedEvent(AntEvent originalEvent, String JavaDoc message, int level) {
1178            this.originalEvent = originalEvent;
1179            this.message = message;
1180            this.level = level;
1181        }
1182        
1183        public void consume() throws IllegalStateException JavaDoc {
1184            verifyRunning();
1185            if (consumed) {
1186                throw new IllegalStateException JavaDoc("Event already consumed"); // NOI18N
1187
}
1188            consumed = true;
1189        }
1190
1191        public boolean isConsumed() {
1192            verifyRunning();
1193            return consumed;
1194        }
1195        
1196        public AntSession getSession() {
1197            return originalEvent.getSession();
1198        }
1199        
1200        public File JavaDoc getScriptLocation() {
1201            return originalEvent.getScriptLocation();
1202        }
1203        
1204        public int getLine() {
1205            return originalEvent.getLine();
1206        }
1207        
1208        public String JavaDoc getTargetName() {
1209            return originalEvent.getTargetName();
1210        }
1211        
1212        public String JavaDoc getTaskName() {
1213            return originalEvent.getTaskName();
1214        }
1215        
1216        public TaskStructure getTaskStructure() {
1217            return originalEvent.getTaskStructure();
1218        }
1219        
1220        public String JavaDoc getMessage() {
1221            verifyRunning();
1222            return message;
1223        }
1224        
1225        public int getLogLevel() {
1226            verifyRunning();
1227            return level;
1228        }
1229        
1230        public Throwable JavaDoc getException() {
1231            verifyRunning();
1232            return null;
1233        }
1234        
1235        public String JavaDoc getProperty(String JavaDoc name) {
1236            return originalEvent.getProperty(name);
1237        }
1238        
1239        public Set JavaDoc<String JavaDoc> getPropertyNames() {
1240            return originalEvent.getPropertyNames();
1241        }
1242        
1243        public String JavaDoc evaluate(String JavaDoc text) {
1244            return originalEvent.evaluate(text);
1245        }
1246        
1247        @Override JavaDoc
1248        public String JavaDoc toString() {
1249            return "RepostedEvent[consumed=" + consumed + ",level=" + level + ",message=" + message + /*",orig=" + originalEvent +*/ "]"; // NOI18N
1250
}
1251        
1252    }
1253    
1254    /**
1255     * Implementation of TaskStructure based on an Ant Task.
1256     * @see Event#getTaskStructure
1257     */

1258    private final class TaskStructureImpl implements LoggerTrampoline.TaskStructureImpl {
1259        
1260        private final RuntimeConfigurable rc;
1261        
1262        public TaskStructureImpl(RuntimeConfigurable rc) {
1263            this.rc = rc;
1264        }
1265        
1266        public String JavaDoc getName() {
1267            verifyRunning();
1268            String JavaDoc name = rc.getElementTag();
1269            if (name != null) {
1270                return name;
1271            } else {
1272                // What does this mean?
1273
return "";
1274            }
1275        }
1276        
1277        public String JavaDoc getAttribute(String JavaDoc name) {
1278            verifyRunning();
1279            return getAttributeMapOfRuntimeConfigurable(rc).get(name);
1280        }
1281        
1282        public Set JavaDoc<String JavaDoc> getAttributeNames() {
1283            verifyRunning();
1284            return getAttributeMapOfRuntimeConfigurable(rc).keySet();
1285        }
1286        
1287        public String JavaDoc getText() {
1288            verifyRunning();
1289            String JavaDoc s = getTextOfRuntimeConfigurable(rc);
1290            if (s.length() > 0) {
1291                // XXX is it appropriate to trim() this? probably not
1292
return s;
1293            } else {
1294                return null;
1295            }
1296        }
1297        
1298        public TaskStructure[] getChildren() {
1299            verifyRunning();
1300            List JavaDoc<TaskStructure> structures = new ArrayList JavaDoc<TaskStructure>();
1301            for (RuntimeConfigurable subrc : NbCollections.iterable(getChildrenOfRuntimeConfigurable(rc))) {
1302                structures.add(LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(subrc)));
1303            }
1304            return structures.toArray(new TaskStructure[structures.size()]);
1305        }
1306        
1307    }
1308
1309}
1310
Popular Tags