< prev index next >

src/com/sun/javatest/TestEnvironment.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 100      * source of the properties can be identified when browing an environment
 101      * @param propTable a table of properties to be included when environments
 102      * are created
 103      * @see #clearDefaultPropTables
 104      * @throws NullPointerException if either name or propTable is null.
 105      */
 106     public static synchronized void addDefaultPropTable(String name, java.util.Properties propTable) {
 107         addDefaultPropTable(name, Properties.convertToStringProps(propTable));
 108     }
 109 
 110     /**
 111      * Remove all previously registered default property tables.
 112      * @see #addDefaultPropTable
 113      */
 114     public static synchronized void clearDefaultPropTables() {
 115         defaultPropTableNames = new String[0];
 116         defaultPropTables = new Map[0];
 117     }
 118 
 119     static String[] defaultPropTableNames = { };
 120     static Map[] defaultPropTables = { };
 121 
 122     /**
 123      * Construct an environment for a named group of properties.
 124      * @param name      The name by which to identify the group of properties
 125      *                  for this environment
 126      * @param propTable Dictionaries containing (but not limited to) the
 127      *                  properties for this environment.
 128      * @param propTableName
 129      *                  The name of the property table, for use in diagnostics etc
 130      * @throws TestEnvironment.Fault if there is an error in the table
 131      *
 132      */
 133     public TestEnvironment(String name, Map propTable, String propTableName)
 134                 throws Fault {
 135         this(name, (new Map[] {propTable}), (new String[] {propTableName}));
 136     }
 137 
 138     /**
 139      * Construct an environment for a named group of properties.
 140      * @param name      The name by which to identify the group of properties
 141      *                  for this environment
 142      * @param propTables        Dictionaries containing (but not limited to) the
 143      *                  properties for this environment. They should be ordered
 144      *                  so that values specified in later tables override those
 145      *                  specified in subsequent tables.
 146      * @param propTableNames
 147      *                  The names of the property tables, for use in diagnostics etc
 148      * @throws TestEnvironment.Fault if there is an error in the given tables
 149      *
 150      */
 151     public TestEnvironment(String name, Map[] propTables, String[] propTableNames)
 152         throws Fault
 153     {


 161         Vector<String> v = new Vector<>();
 162         for (String n = name, inherit = null; n != null && n.length() > 0; n = inherit, inherit = null) {
 163             if (v.contains(n))
 164                 throw new Fault(i18n, "env.loop", name);
 165 
 166             v.addElement(n);
 167             String prefix = "env." + n + ".";
 168             for (int i = propTables.length - 1; i >= 0 && inherit == null; i--) {
 169                 inherit = (String)(propTables[i].get("env." + n + ".inherits"));
 170             }
 171         }
 172         inherits = new String[v.size()];
 173         v.copyInto(inherits);
 174 
 175         // for this environment, and its inherited environments, scan for
 176         // properties of the form env.NAME.KEY=value and add KEY=value into the
 177         // environment's table
 178         for (int inheritIndex = 0; inheritIndex < inherits.length; inheritIndex++) {
 179             String prefix = "env." + inherits[inheritIndex] + ".";
 180             for (int propIndex = propTables.length - 1; propIndex >= 0; propIndex--) {
 181                 Map propTable = propTables[propIndex];
 182                 for (Iterator i = propTable.keySet().iterator(); i.hasNext(); ) {
 183                     String prop = (String) (i.next());
 184                     if (prop.startsWith(prefix)) {
 185                         String key = prop.substring(prefix.length());
 186                         if (!table.containsKey(key)) {
 187                             Element elem = new Element(key,
 188                                                        (String)(propTable.get(prop)),
 189                                                        inherits[inheritIndex],
 190                                                        propTableNames[propIndex]);
 191                             table.put(key, elem);
 192                         }
 193                     }
 194                 }
 195             }
 196         }
 197 
 198         // finally, add in any top-level names (not beginning with env.)
 199         for (int propIndex = propTables.length - 1; propIndex >= 0; propIndex--) {
 200             Map propTable = propTables[propIndex];
 201             for (Iterator i = propTable.keySet().iterator(); i.hasNext(); ) {
 202                 String key = (String) (i.next());
 203                 if (!key.startsWith("env.")) {
 204                     if (!table.containsKey(key)) {
 205                         Element elem = new Element(key,
 206                                                    (String)(propTable.get(key)),
 207                                                    null,
 208                                                    propTableNames[propIndex]);
 209                         table.put(key, elem);
 210                     }
 211                 }
 212             }
 213         }
 214     }
 215 
 216 
 217     /**
 218      * Create a copy of the current environment.
 219      * @return a copy of the current environment
 220      */
 221     public TestEnvironment copy() {
 222         return new TestEnvironment(this);
 223     }
 224 
 225     /**
 226      * Get the distinguishing name for the properties of this environment.


 541     }
 542 
 543     /**
 544      * This is the name of system property to turn off the bugfix for inline
 545      * comments. You should specify "true" value for this property to enable
 546      * the bugfix, disabling the inline comments.
 547      */
 548     static String DISABLE_INLINE_COMMENTS_PROPERTY = "com.sun.javatest.InlineEnvComments";
 549 
 550     static boolean isInlineCommentsDisabled() {
 551         return Boolean.parseBoolean(System.getProperty(DISABLE_INLINE_COMMENTS_PROPERTY, "false"));
 552     }
 553 
 554     /**
 555      * Check if the environment has any undefined values. These are entries containing
 556      * the text VALUE_NOT_DEFINED.
 557      * @return true if and only if there are any entries containing the text
 558      * VALUE_NOT_DEFINED.
 559      */
 560     public boolean hasUndefinedValues() {
 561         for (Iterator i = elements().iterator(); i.hasNext(); ) {
 562             TestEnvironment.Element entry = (TestEnvironment.Element) (i.next());
 563             if (entry.value.indexOf("VALUE_NOT_DEFINED") >= 0)
 564                 return true;
 565         }
 566         return false;
 567     }
 568 
 569     private void substituteChar(String[] v, char from, char to) {
 570         for (int i = 0; i < v.length; i++)
 571             v[i] = v[i].replace(from, to);
 572     }
 573 
 574     private void substituteMap(String[] v, String[] map) {
 575         if (map == null)
 576             return;
 577 
 578         // this algorithm is directly based on the "map" algorithm in
 579         // Slave.Map, which it supercedes
 580         for (int i = 0; i < v.length; i++) {
 581             String word = v[i];
 582             for (int j = 0; j+1 < map.length; j+=2) {


 608     /**
 609      * Identifies the characters recognized for $ names
 610      */
 611     private static boolean isNameChar(char c) {
 612         return (Character.isUpperCase(c)
 613                 || Character.isLowerCase(c)
 614                 || Character.isDigit(c)
 615                 || (c == '_')
 616                 || (c == '.'));
 617     }
 618 
 619     /**
 620      * Enumerate the keys for this environment, including any inherited keys.
 621      * Use `lookup' to find the values of the individual keys.
 622      *
 623      * @return  An enumeration that yields the various keys, explicit or inherited,
 624      *          that are available in this environment. The keys do <em>not</em>
 625      *          include the `env.<em>environment-name</em>.' prefix of the corresponding
 626      *          property names.
 627      */
 628     public Set keys() {
 629         return table.keySet();
 630     }
 631 
 632     /**
 633      * Get a collection containing those entries in this environment that have been
 634      * referenced, either directly via lookup, or indirectly via the $ syntax in
 635      * other entries.
 636      * @return a collection of those entries in this environment that have been
 637      * referenced.
 638      * @see #resetElementsUsed
 639      */
 640     public Collection elementsUsed() {
 641         return cache.values();
 642     }
 643 
 644     /**
 645      * Reset the record of entries in this environment that have been referenced.
 646      * @see #elementsUsed
 647      */
 648     public void resetElementsUsed() {
 649         cache.clear();
 650     }
 651 
 652     /**
 653      * Enumerate the elements for this environment, including any inherited elements.
 654      *
 655      * @return  An enumeration that yields the various elements, explicit or inherited,
 656      *          that are available in this environment.
 657      */
 658     public Collection elements() {
 659         return table.values();
 660     }
 661 
 662 
 663     protected TestEnvironment(TestEnvironment o) {
 664         name = o.name;
 665         inherits = o.inherits;
 666         table = o.table;
 667         extras = new HashMap<>(o.extras);
 668     }
 669 
 670     /**
 671      * A class representing an entry in a test environment.
 672      */
 673     public class Element {
 674         /**
 675          * Create an entry for a test environment.
 676          * @param key The name of the entry
 677          * @param value The unresolved value of the entry
 678          * @param definedInEnv The name of the environment that defines this entry




 100      * source of the properties can be identified when browing an environment
 101      * @param propTable a table of properties to be included when environments
 102      * are created
 103      * @see #clearDefaultPropTables
 104      * @throws NullPointerException if either name or propTable is null.
 105      */
 106     public static synchronized void addDefaultPropTable(String name, java.util.Properties propTable) {
 107         addDefaultPropTable(name, Properties.convertToStringProps(propTable));
 108     }
 109 
 110     /**
 111      * Remove all previously registered default property tables.
 112      * @see #addDefaultPropTable
 113      */
 114     public static synchronized void clearDefaultPropTables() {
 115         defaultPropTableNames = new String[0];
 116         defaultPropTables = new Map[0];
 117     }
 118 
 119     static String[] defaultPropTableNames = { };
 120     static Map<String, String>[] defaultPropTables = new Map[0];
 121 
 122     /**
 123      * Construct an environment for a named group of properties.
 124      * @param name      The name by which to identify the group of properties
 125      *                  for this environment
 126      * @param propTable Dictionaries containing (but not limited to) the
 127      *                  properties for this environment.
 128      * @param propTableName
 129      *                  The name of the property table, for use in diagnostics etc
 130      * @throws TestEnvironment.Fault if there is an error in the table
 131      *
 132      */
 133     public TestEnvironment(String name, Map<String, String> propTable, String propTableName)
 134                 throws Fault {
 135         this(name, (new Map[] {propTable}), (new String[] {propTableName}));
 136     }
 137 
 138     /**
 139      * Construct an environment for a named group of properties.
 140      * @param name      The name by which to identify the group of properties
 141      *                  for this environment
 142      * @param propTables        Dictionaries containing (but not limited to) the
 143      *                  properties for this environment. They should be ordered
 144      *                  so that values specified in later tables override those
 145      *                  specified in subsequent tables.
 146      * @param propTableNames
 147      *                  The names of the property tables, for use in diagnostics etc
 148      * @throws TestEnvironment.Fault if there is an error in the given tables
 149      *
 150      */
 151     public TestEnvironment(String name, Map[] propTables, String[] propTableNames)
 152         throws Fault
 153     {


 161         Vector<String> v = new Vector<>();
 162         for (String n = name, inherit = null; n != null && n.length() > 0; n = inherit, inherit = null) {
 163             if (v.contains(n))
 164                 throw new Fault(i18n, "env.loop", name);
 165 
 166             v.addElement(n);
 167             String prefix = "env." + n + ".";
 168             for (int i = propTables.length - 1; i >= 0 && inherit == null; i--) {
 169                 inherit = (String)(propTables[i].get("env." + n + ".inherits"));
 170             }
 171         }
 172         inherits = new String[v.size()];
 173         v.copyInto(inherits);
 174 
 175         // for this environment, and its inherited environments, scan for
 176         // properties of the form env.NAME.KEY=value and add KEY=value into the
 177         // environment's table
 178         for (int inheritIndex = 0; inheritIndex < inherits.length; inheritIndex++) {
 179             String prefix = "env." + inherits[inheritIndex] + ".";
 180             for (int propIndex = propTables.length - 1; propIndex >= 0; propIndex--) {
 181                 Map<String, String> propTable = propTables[propIndex];
 182                 for (Iterator<String> i = propTable.keySet().iterator(); i.hasNext(); ) {
 183                     String prop = (i.next());
 184                     if (prop.startsWith(prefix)) {
 185                         String key = prop.substring(prefix.length());
 186                         if (!table.containsKey(key)) {
 187                             Element elem = new Element(key,
 188                                     (propTable.get(prop)),
 189                                                        inherits[inheritIndex],
 190                                                        propTableNames[propIndex]);
 191                             table.put(key, elem);
 192                         }
 193                     }
 194                 }
 195             }
 196         }
 197 
 198         // finally, add in any top-level names (not beginning with env.)
 199         for (int propIndex = propTables.length - 1; propIndex >= 0; propIndex--) {
 200             Map<String, String> propTable = propTables[propIndex];
 201             for (Iterator<String> i = propTable.keySet().iterator(); i.hasNext(); ) {
 202                 String key = (i.next());
 203                 if (!key.startsWith("env.")) {
 204                     if (!table.containsKey(key)) {
 205                         Element elem = new Element(key,
 206                                 (propTable.get(key)),
 207                                                    null,
 208                                                    propTableNames[propIndex]);
 209                         table.put(key, elem);
 210                     }
 211                 }
 212             }
 213         }
 214     }
 215 
 216 
 217     /**
 218      * Create a copy of the current environment.
 219      * @return a copy of the current environment
 220      */
 221     public TestEnvironment copy() {
 222         return new TestEnvironment(this);
 223     }
 224 
 225     /**
 226      * Get the distinguishing name for the properties of this environment.


 541     }
 542 
 543     /**
 544      * This is the name of system property to turn off the bugfix for inline
 545      * comments. You should specify "true" value for this property to enable
 546      * the bugfix, disabling the inline comments.
 547      */
 548     static String DISABLE_INLINE_COMMENTS_PROPERTY = "com.sun.javatest.InlineEnvComments";
 549 
 550     static boolean isInlineCommentsDisabled() {
 551         return Boolean.parseBoolean(System.getProperty(DISABLE_INLINE_COMMENTS_PROPERTY, "false"));
 552     }
 553 
 554     /**
 555      * Check if the environment has any undefined values. These are entries containing
 556      * the text VALUE_NOT_DEFINED.
 557      * @return true if and only if there are any entries containing the text
 558      * VALUE_NOT_DEFINED.
 559      */
 560     public boolean hasUndefinedValues() {
 561         for (Iterator<Element> i = elements().iterator(); i.hasNext(); ) {
 562             Element entry = i.next();
 563             if (entry.value.indexOf("VALUE_NOT_DEFINED") >= 0)
 564                 return true;
 565         }
 566         return false;
 567     }
 568 
 569     private void substituteChar(String[] v, char from, char to) {
 570         for (int i = 0; i < v.length; i++)
 571             v[i] = v[i].replace(from, to);
 572     }
 573 
 574     private void substituteMap(String[] v, String[] map) {
 575         if (map == null)
 576             return;
 577 
 578         // this algorithm is directly based on the "map" algorithm in
 579         // Slave.Map, which it supercedes
 580         for (int i = 0; i < v.length; i++) {
 581             String word = v[i];
 582             for (int j = 0; j+1 < map.length; j+=2) {


 608     /**
 609      * Identifies the characters recognized for $ names
 610      */
 611     private static boolean isNameChar(char c) {
 612         return (Character.isUpperCase(c)
 613                 || Character.isLowerCase(c)
 614                 || Character.isDigit(c)
 615                 || (c == '_')
 616                 || (c == '.'));
 617     }
 618 
 619     /**
 620      * Enumerate the keys for this environment, including any inherited keys.
 621      * Use `lookup' to find the values of the individual keys.
 622      *
 623      * @return  An enumeration that yields the various keys, explicit or inherited,
 624      *          that are available in this environment. The keys do <em>not</em>
 625      *          include the `env.<em>environment-name</em>.' prefix of the corresponding
 626      *          property names.
 627      */
 628     public Set<String> keys() {
 629         return table.keySet();
 630     }
 631 
 632     /**
 633      * Get a collection containing those entries in this environment that have been
 634      * referenced, either directly via lookup, or indirectly via the $ syntax in
 635      * other entries.
 636      * @return a collection of those entries in this environment that have been
 637      * referenced.
 638      * @see #resetElementsUsed
 639      */
 640     public Collection<Element> elementsUsed() {
 641         return cache.values();
 642     }
 643 
 644     /**
 645      * Reset the record of entries in this environment that have been referenced.
 646      * @see #elementsUsed
 647      */
 648     public void resetElementsUsed() {
 649         cache.clear();
 650     }
 651 
 652     /**
 653      * Enumerate the elements for this environment, including any inherited elements.
 654      *
 655      * @return  An enumeration that yields the various elements, explicit or inherited,
 656      *          that are available in this environment.
 657      */
 658     public Collection<Element> elements() {
 659         return table.values();
 660     }
 661 
 662 
 663     protected TestEnvironment(TestEnvironment o) {
 664         name = o.name;
 665         inherits = o.inherits;
 666         table = o.table;
 667         extras = new HashMap<>(o.extras);
 668     }
 669 
 670     /**
 671      * A class representing an entry in a test environment.
 672      */
 673     public class Element {
 674         /**
 675          * Create an entry for a test environment.
 676          * @param key The name of the entry
 677          * @param value The unresolved value of the entry
 678          * @param definedInEnv The name of the environment that defines this entry


< prev index next >