KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > FixtureExaminer


1 /**
2  * $Id: FixtureExaminer.java 187 2007-03-25 17:59:16Z ssmc $
3  * Copyright 2004-2005,2007 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://antxtras.sf.net/ EMAIL- jware[at]users[dot]sourceforge[dot]net
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx;
30
31 import java.lang.reflect.Method JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 import org.apache.tools.ant.BuildException;
37 import org.apache.tools.ant.Location;
38 import org.apache.tools.ant.Project;
39 import org.apache.tools.ant.PropertyHelper;
40 import org.apache.tools.ant.UnknownElement;
41 import org.apache.tools.ant.types.PropertySet;
42
43 import com.idaremedia.antx.apis.Requester;
44 import com.idaremedia.antx.helpers.GenericParameters;
45 import com.idaremedia.antx.helpers.Tk;
46 import com.idaremedia.antx.parameters.PropertySource;
47
48 /**
49  * Collection of utilities for extracting bits of information from the current
50  * project and/or build-iteration fixture.
51  *
52  * @since JWare/AntX 0.4 (Pulled from various sources)
53  * @author ssmc, &copy;2004-2005,2007 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
54  * @version 0.5
55  * @.safety guarded
56  * @.group impl,helper
57  * @see com.idaremedia.antx.ownhelpers.LocalTk LocalTk
58  * @.stereo utility
59  **/

60
61 public final class FixtureExaminer implements FixtureCore
62 {
63     private static final String JavaDoc IAM_= AntX.AntX+"FixtureExaminer:";
64
65
66     private static Location prethrow(Project project, Requester from,
67                                      String JavaDoc message, int level)
68     {
69         Location loc = Location.UNKNOWN_LOCATION;
70         if (from!=null) {
71             from.log(message, level);
72             loc = from.getLocation();
73         } else {
74             project.log(message,level);
75         }
76         return loc;
77     }
78
79
80     /**
81      * Returns a type-checked referenced object. Common utility that
82      * generates a resource bundle based messages if reference broken.
83      * @param project the source project
84      * @param from [optional] the calling element
85      * @param refid the referred-to thing's identifier (non-null)
86      * @param requiredClass the required class of referred-to thing (non-null)
87      * @throws BuildException if no such reference or object is not compatible
88      **/

89     public static final Object JavaDoc getReferencedObject(Project project,
90                                                    Requester from,
91                                                    String JavaDoc refid,
92                                                    Class JavaDoc requiredClass)
93     {
94         AntX.require_(refid!=null,IAM_,"getRefObj- nonzro id");
95         AntX.require_(project!=null,IAM_,"getRefObj- nonzro project");
96
97         Object JavaDoc o = project.getReference(refid);
98         String JavaDoc error = null;
99
100         if (o==null) {
101             error = AntX.uistrs().get("task.missing.refid", refid);
102         }
103         else if (!requiredClass.isInstance(o)) {
104             error = AntX.uistrs().get("task.bad.refid", refid,
105                                       requiredClass.getName(),
106                                       o.getClass().getName());
107         }
108         if (error!=null) {
109             Location loc = prethrow(project,from,error,Project.MSG_ERR);
110             throw new BuildException(error,loc);
111         }
112         return o;
113     }
114
115
116
117     /**
118      * Returns a referenced object. Common utility that generates a
119      * resource bundle based message if reference undefined.
120      * @param project the source project
121      * @param from [optional] the calling element
122      * @param refid the referred-to thing's identifier (non-null)
123      * @throws BuildException if no such reference
124      **/

125     public static final Object JavaDoc getReferencedObject(Project project,
126                                                    Requester from,
127                                                    String JavaDoc refid)
128     {
129         AntX.require_(refid!=null,IAM_,"getRefObj- nonzro id");
130         AntX.require_(project!=null,IAM_,"getRefObj- nonzro project");
131
132         Object JavaDoc value = project.getReference(refid);
133         if (value==null) {
134             String JavaDoc error = AntX.uistrs().get("task.missing.refid", refid);
135             Location loc = prethrow(project,from,error,Project.MSG_ERR);
136             throw new BuildException(error,loc);
137         }
138
139         return value;
140     }
141
142
143
144     private static String JavaDoc isOneOf(String JavaDoc value, String JavaDoc t0, String JavaDoc t1)
145     {
146         if (value.startsWith(t0)) {
147             return value.substring(t0.length());
148         }
149         if (value.startsWith(t1)) {
150             return value.substring(t1.length());
151         }
152         return null;
153     }
154
155
156
157     /**
158      * Utility that converts a reference to a properties collection to a
159      * standard Java <span class="src">Properties</span> object. Currently
160      * handles references to <span class="src">GenericParameters</span>,
161      * <span class="src">PropertySet</span>s, and
162      * <span class="src>Properties</span> objects
163      * @param project source project (non-null)
164      * @param refid referenced data object (non-null)
165      * @param defaultProperties [optional] set to a fallback properties if
166      * reference does not exist.
167      * @return Properties object if reference is convertible; <i>null</i>
168      * if it is not; <span class="src">defaultProperties</span> if
169      * no such reference.
170      * @since JWare/AntX 0.5
171      **/

172     public static Properties JavaDoc getReferencedProperties(Project project,
173         String JavaDoc refid, Properties JavaDoc defaultProperties)
174     {
175         AntX.require_(refid!=null,IAM_,"getRefPropertiesObj- nonzro refid");
176         AntX.require_(project!=null,IAM_,"getRefPropertiesObj- nonzro project");
177
178         Properties JavaDoc Ps = null;
179         Object JavaDoc o = project.getReference(refid);
180         if (o!=null) {
181             //NB: Extract properties against given project to ensure we
182
// resolve all ${} and @() placeholders!
183
if (o instanceof GenericParameters) {
184                 Ps = ((GenericParameters)o).copyOfSimpleKeyValues(project);
185             } else if (o instanceof PropertySet) {
186                 Ps = ((PropertySet)o).getProperties();
187             } else if (o instanceof Properties JavaDoc) {
188                 Ps = ((Properties JavaDoc)o);
189             }
190         } else {
191             Ps = defaultProperties;
192         }
193         return Ps;
194     }
195
196
197
198     /**
199      * Looks for a top-level property or a nested property (inside a
200      * global reference properties-like holder.
201      * @param key the property lookuup key (non-null)
202      * @param project the source project (non-null)
203      * @return property value or <i>null</i> if undefined
204      * @since JWare/AntX 0.5
205      **/

206     private static String JavaDoc getProperty(String JavaDoc key, Project project)
207     {
208         String JavaDoc value = project.getProperty(key);
209         int i;
210         if (value==null && (i=key.indexOf("->"))>0) {
211             String JavaDoc holder = key.substring(0,i);
212             i += 2;
213             if (i<key.length()) {
214                 key = key.substring(i);
215                 Properties JavaDoc Ps = getReferencedProperties(project,holder,null);
216                 if (Ps!=null) {
217                     value = Ps.getProperty(key);
218                 }
219             }//!malformed
220
}
221         return value;
222     }
223
224
225
226     /**
227      * Determine if given value uri prefix is one of the
228      * AntX-reserved ones. Note that case is ignored when checking
229      * the prefix.
230      * @param name the script-supplied prefix (non-null)
231      * @return <i>true</i> if reserved
232      * @since JWare/AntX 0.5
233      **/

234     public static boolean isBuiltinValueURIScheme(String JavaDoc name)
235     {
236         if (name.charAt(0)=='$') {
237             int n = name.length();
238             int i = name.indexOf(':');
239             if (i>0) {
240                 n = i;
241             }
242             name = name.substring(1,n);
243         }
244
245         boolean reserved = false;
246         name = Tk.lowercaseFrom(name);
247
248         switch(name.charAt(0)) {
249             case 'r': {
250                 if ("ref".equals(name) || "reference".equals(name)) {
251                     reserved = true;
252                 }
253                 break;
254             }
255             case 'v': {
256                 if ("var".equals(name) || "variable".equals(name)) {
257                     reserved = true;
258                 }
259                 break;
260             }
261             case 'p': {
262                 if ("prop".equals(name) || "property".equals(name)) {
263                     reserved = true;
264                 }
265                 break;
266             }
267             case 'i': {
268                 if ("itprop".equals(name)|| "itproperty".equals(name)) {
269                     reserved = true;
270                 }
271                 break;
272             }
273         }
274         return reserved || "null".equals(name);
275     }
276
277
278
279     /**
280      * Looks for an iteration property or a nested iteration property.
281      * @param key the property lookuup key (non-null)
282      * @param project [optional] the source project
283      * @return property value or <i>null</i> if undefined
284      * @since JWare/AntX 0.5
285      **/

286     public static String JavaDoc getIterationProperty(String JavaDoc key, Project project)
287     {
288         Object JavaDoc value = Iteration.getProperty(key);
289         int i;
290         if (value==null && (i=key.indexOf("->"))>0) {
291             String JavaDoc holder = key.substring(0,i);
292             i += 2;
293             if (i<key.length()) {
294                 key = key.substring(i);
295                 value = Iteration.getProperty(holder,key);
296             }
297         }
298         return Iteration.strictStringifier().stringFrom(value,project);
299     }
300
301
302
303     /**
304      * Determine if there is an installed value URI interpreter
305      * in the given project.
306      * @param project the source project (non-null)
307      * @return <i>true</i> if installed, else <i>false</i>
308      * @since JWare/AntX 0.5
309      * @see com.idaremedia.antx.solo.ValueURIManagerTask
310      **/

311     public static boolean valueURIInterpreterInstalled(Project project)
312     {
313         AntX.require_(project!=null,IAM_,"valRdrInstal- nonzro project");
314         Object JavaDoc interpreter = project.getReference(FixtureIds.VALUEURI_INTERPRETER);
315         if (interpreter instanceof PropertyHelper) {
316             return true;
317         }
318         return false;
319     }
320
321
322
323     /**
324      * Determine the value of a standalone (unpiped) value uri. This
325      * method is used by the public API which parses for piped variants.
326      * @param value full value uri (single,non-null)
327      * @param obof originating property being determined (non-null)
328      * @param clnt call controls (non-null)
329      * @return property or value uri results or null if cannot determine.
330      **/

331     private static final String JavaDoc funcValue(String JavaDoc value, String JavaDoc obof,
332                                           Requester clnt)
333     {
334         String JavaDoc dflt=null,key;
335         Project project = clnt.getProject();
336
337         //Hard-coded; cannot override...
338
if ((key = isOneOf(value,"$var:","$variable:"))!=null) {
339             int i = key.lastIndexOf('?');
340             if (i>0) {
341                 dflt = key.substring(i+1);
342                 key = key.substring(0,i);
343             }
344             return ExportedProperties.readstring(key,dflt);
345         }
346         if ((key = isOneOf(value,"$ref:","$reference:"))!=null) {
347             Object JavaDoc o = project.getReference(key);
348             return Iteration.lenientStringifer().stringFrom(o,project);
349         }
350         if ((key = isOneOf(value,"$itprop:","$itproperty:"))!=null) {
351             return getIterationProperty(key,project);
352         }
353         if ((key = isOneOf(value,"$prop:","$property:"))!=null) {
354             int i = key.lastIndexOf('?');
355             if (i>0) {
356                 dflt = key.substring(i+1);
357                 key = key.substring(0,i);
358             }
359             if (!key.equals(obof)) {//NB:zap circular references!
360
String JavaDoc match = getProperty(key,project);
361                 return match==null ? dflt : match;
362             }
363         }
364         //User-coded; whatever...
365
int i = value.indexOf(":");
366         if (i>1) {
367             String JavaDoc scheme = value.substring(1,i);
368             return Iteration.valueURIHandler(scheme).valueFrom
369                 (value.substring(i+1), value, clnt);
370         }
371         return null;
372     }
373
374
375
376     /**
377      * Converts any nested value URIs in given value. Called by AntX's
378      * value uri interpreter and explicitly by a select set of
379      * components like &lt;overlay&gt;.
380      * @param value the encoded value to lookup (prefixed w/ '$type:')
381      * @param obof [optional] originating property source (used to
382      * ensure no circular definitions in property lookups)
383      * @param clnt originating call controls (non-null)
384      * @since JWare/AntX 0.5
385      * @see ValueURIHandler
386      **/

387     public static final String JavaDoc findValue(String JavaDoc value, String JavaDoc obof,
388                                          Requester clnt)
389     {
390         AntX.require_(value!=null,IAM_,"getFlexValue- nonzro values");
391         AntX.require_(clnt!=null && clnt.getProject()!=null,IAM_,
392                 "getFlexValue- nonzro project");
393
394         //@since AntX 0.5 (supports custom valueuri handlers and pipes)
395
String JavaDoc result = null;
396         while (value.length()>2 && value.charAt(0)=='$') {
397             int colon = value.indexOf(":");
398             if (colon <= 1) {
399                 break;
400             }
401             String JavaDoc scheme = value.substring(1,colon);
402             String JavaDoc singleuri = value;
403             int piped = value.indexOf("|$",colon+1);
404             String JavaDoc fragment = null;
405             if (piped>colon) {
406                 fragment = value.substring(colon+1,piped);
407                 singleuri = "$"+scheme+":"+fragment;
408             } else {
409                 fragment = value.substring(colon+1);
410             }
411             //clnt.log("Evaluating value-uri'"+singleuri+"'");
412
String JavaDoc nextresult = funcValue(singleuri,obof,clnt);
413             result = nextresult;
414             if (result==null || singleuri==value) {
415                 break;
416             }
417             colon = value.indexOf(':',piped+2);
418             if (colon<0) {
419                 result = null;//NB:malformed
420
break;
421             }
422             String JavaDoc nextvalue = "$"+value.substring(piped+2,colon+1)+result;
423             if (colon<value.length()-1) {
424                 nextvalue += value.substring(colon+1);
425             }
426             value = nextvalue;
427             //clnt.log(" Next value-uri is '"+value+"'");
428
}
429         return result;
430     }
431
432
433
434     /**
435      * Like {@linkplain #findValue(String,String,Requester)
436      * findValue(String,String,&#8230;)} for anonymous utility-based
437      * lookups.
438      * @param project the source project (non-null)
439      * @param value the encoded value to lookup (prefixed w/ '$type:')
440      * @param obof [optional] originating property source (used to
441      * ensure no circular definitions in property lookups)
442      * @since JWare/AntX 0.4
443      **/

444     public static final String JavaDoc findValue(Project project,
445                                          String JavaDoc value, String JavaDoc obof)
446     {
447         return findValue(value,obof,new Requester.ForProject(project));
448     }
449
450
451
452     /**
453      * Check whether a project property already exists and optionally
454      * barfs if it does. Always emits a warning (at least) if the property
455      * does exist. Most useful for verifying that a user-specified update
456      * property doesn't already exist.
457      * @param project the source project
458      * @param from [optional] the calling element
459      * @param property name of property to check
460      * @param warn <i>true</i> if only issue a warning <em>otherwise
461      * can fail</em>
462      * @return <i>true</i> if property already exists
463      * @throws BuildException if property exists and isn't a warning
464      * @since JWare/AntX 0.3
465      **/

466     public static boolean checkIfProperty(Project project, Requester from,
467                                           String JavaDoc property, boolean warn)
468     {
469         AntX.require_(project!=null,IAM_,"chkProp- nonzro project");
470         AntX.require_(property!=null,IAM_,"chkProp- nonzro nam");
471
472         String JavaDoc it = Tk.getTheProperty(project,property);
473         if (it!=null) {
474             String JavaDoc msg = AntX.uistrs().get("task.warn.property.exists",property);
475             Location loc = prethrow(project, from, msg,
476                                     (warn ? Project.MSG_WARN : Project.MSG_ERR));
477             if (!warn) {
478                 throw new BuildException(msg,loc);
479             }
480         }
481         return it!=null;
482     }
483
484
485
486     /**
487      * Check whether a project reference already exists and optionally
488      * barfs if it does. Always emits a warning (at least) if the
489      * reference does exist. Most useful for verifying that a
490      * user-specified update reference doesn't already exist.
491      * @param project the source project
492      * @param from [optional] the calling element
493      * @param refid name of reference to check
494      * @param warn <i>true</i> if only issue a warning <em>otherwise
495      * can fail</em>
496      * @return <i>true</i> if reference already exists
497      * @throws BuildException if reference exists and isn't a warning
498      **/

499     public static boolean checkIfReference(Project project, Requester from,
500                                            String JavaDoc refid, boolean warn)
501     {
502         AntX.require_(project!=null,IAM_,"chkRef- nonzro project");
503         AntX.require_(refid!=null,IAM_,"chkRef- nonzro refid");
504
505         Object JavaDoc it = project.getReference(refid);
506         if (it!=null) {
507             String JavaDoc msg = AntX.uistrs().get("task.warn.refid.exists",refid);
508             Location loc = prethrow(project, from, msg,
509                                     (warn ? Project.MSG_WARN : Project.MSG_ERR));
510             if (!warn) {
511                 throw new BuildException(msg,loc);
512             }
513         }
514         return it!=null;
515     }
516
517
518
519     /**
520      * Special value object used to indicate a reference that
521      * has yet to be determined (in other target, or out-of-scope).
522      * @.pattern Fowler.SpecialValue
523      * @since JWare/AntX 0.4
524      **/

525     public static final Object JavaDoc IGNORED_REFERENCE= "__ooscope_ref__";
526
527
528
529     /**
530      * Special value object used to indicate a reference that
531      * could not be determined (generated errors).
532      * @.pattern Fowler.SpecialValue
533      * @since JWare/AntX 0.4
534      **/

535     public static final Object JavaDoc PROBLEM_REFERENCE= "__problem_ref__";
536
537
538
539     /**
540      * Special value object used to indicate a reference that
541      * is about to be assigned by a subsequent factory task. Allows
542      * the dynamic creation of reference id to appear atomic to
543      * using tasks.
544      * @.pattern Fowler.SpecialValue
545      * @since JWare/AntX 0.5
546      **/

547     public static final Object JavaDoc PENDING_REFERENCE= "__pending_ref__";
548
549
550     /**
551      * Returns a reference only if that reference has already been
552      * determined by the project. This method tries to differentiate
553      * references that are defined inside out-of-scope targets or
554      * after this caller's location within the current target.
555      * @param P the project used to lookup references (non-null)
556      * @param id the reference id (non-null)
557      * @throws IllegalArgumentException if either parameter is <i>null</i>
558      * @return {@linkplain #IGNORED_REFERENCE} if reference out of scope<br/>
559      * {@linkplain #PROBLEM_REFERENCE} if unable to retrieve reference<br/>
560      * <i>null</i> if no such reference in project
561      * @since JWare/AntX 0.4
562      **/

563     public static Object JavaDoc trueReference(Project P, String JavaDoc id)
564     {
565         AntX.require_(P!=null && id!=null, IAM_, "trueRef- nonzro args");
566
567         Object JavaDoc ref=null;
568         Object JavaDoc ht = P.getReferences();
569         Boolean JavaDoc B=null;
570         Method JavaDoc m=null;
571         try {
572             //Ant 1.6|1.7 internal way
573
if (AntX.ANT_PRE17) {
574                 m = ht.getClass().getMethod("getReal",GET_REAL_METHOD);
575             } else {
576                 m = ht.getClass().getDeclaredMethod("getReal",GET_REAL_METHOD);
577             }
578             B = m.isAccessible() ? Boolean.TRUE : Boolean.FALSE;
579             m.setAccessible(true);
580             ref = m.invoke(ht, new Object JavaDoc[]{id});
581             if (ref instanceof UnknownElement) {
582                 ref = IGNORED_REFERENCE;
583             }
584         } catch(Exception JavaDoc reflectX) {
585             P.log("Unable to call 'Project$AntRefTable.getReal': "+reflectX.getMessage());
586             //Fallback: Public way
587
try {
588                 ref = P.getReference(id);
589             } catch(Exception JavaDoc lookupX) {
590                 P.log(lookupX.getMessage(), Project.MSG_WARN);
591                 ref = PROBLEM_REFERENCE;
592             }
593         } finally {
594             if (m!=null && B!=null & !B.booleanValue()) {
595                 try {
596                     m.setAccessible(false);
597                 } catch(Exception JavaDoc anyX) {
598                     /*burp*/
599                 }
600             }
601         }
602         return ref;
603     }
604
605
606
607     /**
608      * Returns whether the referenced item exists, has been configured,
609      * and can be read. Complement to {@linkplain #trueReference trueReference}.
610      * @param P the project used to lookup references (non-null)
611      * @param id the reference id (non-null)
612      * @since JWare/AntX 0.5
613      **/

614     public static boolean usableReference(Project P, String JavaDoc id)
615     {
616         Object JavaDoc ref = trueReference(P,id);
617         if (ref==IGNORED_REFERENCE || ref==PROBLEM_REFERENCE
618             || ref==PENDING_REFERENCE) {
619             ref= null;
620         }
621         return ref!=null;
622     }
623
624
625
626     /**
627      * Utility to convert a property source to a set of properties.
628      * @param domain source of properties (non-null)
629      * @param P [optional] project from which properties read (if needed)
630      * @throws IllegalArgumentException if domain is <i>null</i>
631      * @throws NullPointerException if project needed and not defined
632      * @since JWare/AntX 0.4
633      **/

634     public static Map JavaDoc copyOfProperties(PropertySource domain, Project P)
635     {
636         AntX.require_(domain!=null,IAM_,"getProps- nonzro domain");
637
638         Map JavaDoc mp=null;//shutup-compiler
639

640         switch (domain.getIndex()) {
641             case PropertySource.ALL_INDEX:
642             case PropertySource.ALLlite_INDEX: {
643                 mp = P.getProperties();
644                 if (domain.getIndex()!=PropertySource.ALL_INDEX) {
645                     removeImmutableJavaProperties(mp);
646                 }
647                 break;
648             }
649             case PropertySource.COMMAND_INDEX: {
650                 mp = P.getUserProperties();
651                 break;
652             }
653             case PropertySource.CONTROL_INDEX: {
654                 Project dumi= new Project();
655                 P.copyInheritedProperties(dumi);
656                 mp = dumi.getProperties();
657                 dumi = null;//gc
658
break;
659             }
660             case PropertySource.SCRIPTlite_INDEX:
661             case PropertySource.SCRIPT_INDEX: {
662                 //NB:inherited properties are also user properties!
663
mp = P.getProperties();
664                 mp.keySet().removeAll(P.getUserProperties().keySet());
665                 if (domain.getIndex()!=PropertySource.SCRIPT_INDEX) {
666                     removeImmutableJavaProperties(mp);
667                 }
668                 break;
669             }
670             case PropertySource.FIXTURE_INDEX: {
671                 mp = AntXFixture.copyOfProperties();
672                 break;
673             }
674             case PropertySource.JRE_INDEX: {
675                 mp = (Map JavaDoc)System.getProperties().clone();
676                 break;
677             }
678             default: {
679                 AntX.verify_(false,IAM_,"init- known domain");
680             }
681         }
682
683         return mp;
684     }
685
686
687
688     /**
689      * Removes the "classic" immutable java runtime properties
690      * including anything that begins with "java&#46;", and
691      * "sun&#46;".
692      * @throws UnsupportedOperationException if
693      * <span class="src">map</span> is a readonly map.
694      * @since JWare/AntX 0.4
695      **/

696     public static void removeImmutableJavaProperties(Map JavaDoc map)
697     {
698         AntX.require_(map!=null,IAM_,"zapSystemProps- nonzro map");
699
700         Iterator JavaDoc itr= map.keySet().iterator();
701         while (itr.hasNext()) {
702             String JavaDoc s = itr.next().toString();
703             if (s.startsWith("java.") || s.startsWith("sun.")) {
704                 itr.remove();
705                 continue;
706             }
707             for (int i=0;i<KEEPERS.length;i++) {
708                 if (KEEPERS[i].equals(s)) {
709                     itr.remove();
710                     continue;
711                 }
712             }
713         }
714     }
715
716
717
718     /**
719      * Always look for these; do not allow them to be
720      * removed in custom list.
721      **/

722     private static final String JavaDoc[] KEEPERS= {
723         "os.name", "os.arch", "os.version",
724         "user.name", "user.home", "user.dir",
725         "user.language", "user.timezone", "user.country", "user.variant",
726         "file.separator", "path.separator",
727         "line.separator"
728     };
729
730
731
732
733     private static final Class JavaDoc[] GET_REAL_METHOD= {Object JavaDoc.class};
734
735
736     /** Only permit generic utility methods. **/
737     private FixtureExaminer()
738     {
739     }
740 }
741
742 /* end-of-FixtureExaminer.java */
743
Popular Tags