Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ConfigProperty |
|
| 4.25;4.25 |
1 | /*BEGIN_COPYRIGHT_BLOCK | |
2 | * | |
3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * * Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
14 | * names of its contributors may be used to endorse or promote products | |
15 | * derived from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | * | |
29 | * This software is Open Source Initiative approved Open Source Software. | |
30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
31 | * | |
32 | * This file is part of DrJava. Download the current version of this project | |
33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
34 | * | |
35 | * END_COPYRIGHT_BLOCK*/ | |
36 | ||
37 | package edu.rice.cs.drjava.config; | |
38 | ||
39 | import edu.rice.cs.drjava.DrJava; | |
40 | ||
41 | import java.util.Vector; | |
42 | ||
43 | /** Class representing values from the DrJava configuration file that can be inserted as variables in external processes. | |
44 | * @version $Id: ConfigProperty.java 5175 2010-01-20 08:46:32Z mgricken $ | |
45 | */ | |
46 | public class ConfigProperty extends EagerProperty { | |
47 | /** True if this is a list of values. This allows the sep="..." attribute. */ | |
48 | 1393632830 | protected boolean _isList = false; |
49 | ||
50 | /** Create a configuration property. */ | |
51 | public ConfigProperty(String name) { | |
52 | 1393632830 | super(name, "Help not available."); |
53 | 1393632830 | resetAttributes(); |
54 | 1393632830 | } |
55 | ||
56 | /** Update the property so the value is current. | |
57 | * @param pm PropertyMaps used for substitution when replacing variables */ | |
58 | public void update(PropertyMaps pm) { | |
59 | 4166234 | OptionMap om = DrJava.getConfig().getOptionMap(); |
60 | 37496106 | for (OptionParser<?> op : om.keys()) { |
61 | 33329872 | String key = op.getName(); |
62 | 33329872 | String value = om.getString(op); |
63 | 33329872 | if (_name.equals("config." + key)) { |
64 | 4166234 | if (op instanceof VectorOption<?>) { |
65 | @SuppressWarnings("unchecked") | |
66 | 0 | Vector<?> vec = ((VectorOption)op).parse(value); |
67 | 0 | StringBuilder sb = new StringBuilder(); |
68 | 0 | for(Object o: vec) { |
69 | 0 | sb.append(_attributes.get("sep")); |
70 | 0 | sb.append(o.toString()); |
71 | } | |
72 | 0 | _value = sb.toString(); |
73 | 0 | if (_value.startsWith(_attributes.get("sep"))) { |
74 | 0 | _value= _value.substring(_attributes.get("sep").length()); |
75 | } | |
76 | } | |
77 | 4166234 | else if (_name.equals("config.debug.step.exclude")) { |
78 | 0 | java.util.StringTokenizer tok = new java.util.StringTokenizer(value); |
79 | 0 | StringBuilder sb = new StringBuilder(); |
80 | 0 | while(tok.hasMoreTokens()) { |
81 | 0 | sb.append(_attributes.get("sep")); |
82 | 0 | sb.append(tok.nextToken()); |
83 | } | |
84 | 0 | _value = sb.toString(); |
85 | 0 | if (_value.startsWith(_attributes.get("sep"))) { |
86 | 0 | _value= _value.substring(_attributes.get("sep").length()); |
87 | } | |
88 | } | |
89 | else { | |
90 | 4166234 | _value = value; |
91 | } | |
92 | 4166234 | return; |
93 | } | |
94 | } | |
95 | 0 | _value = "--unknown--"; |
96 | 0 | } |
97 | ||
98 | /** Reset attributes to their defaults. */ | |
99 | public void resetAttributes() { | |
100 | 2787265660 | _attributes.clear(); |
101 | 2787265660 | OptionMap om = DrJava.getConfig().getOptionMap(); |
102 | 471006295560 | for (OptionParser<?> op : om.keys()) { |
103 | 468219029900 | String key = op.getName(); |
104 | 468219029900 | if (_name.equals("config." + key)) { |
105 | 2787265660 | if (op instanceof VectorOption<?>) { |
106 | 1198108224 | _isList = true; |
107 | 1198108224 | _attributes.put("sep", java.io.File.pathSeparator); |
108 | } | |
109 | 1589157436 | else if (_name.equals("config.debug.step.exclude")) { |
110 | 0 | _isList = true; |
111 | 0 | _attributes.put("sep", ","); |
112 | } | |
113 | 1589157436 | else _isList = false; |
114 | 2787265660 | return; |
115 | } | |
116 | } | |
117 | 0 | } |
118 | ||
119 | /** Return the value. */ | |
120 | 4178506 | public String toString() { return _value; } |
121 | } |