Skip to content

Commit 8d09927

Browse files
author
mgricken
committed
Committed new stream tokenizer that balances quotes/braces.
Allowed attributes in variables for external processes. Many properties still missing; Windows support still lacking. git-svn-id: file:///tmp/test-svn/trunk@4360 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent e02b291 commit 8d09927

13 files changed

+1382
-160
lines changed

drjava/src/edu/rice/cs/drjava/config/ConfigProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class ConfigProperty extends EagerProperty {
4848
/** Create a configuration property. */
4949
public ConfigProperty(String name) {
5050
super(name);
51+
resetAttributes();
5152
}
5253

5354
/** Update the property so the value is current. */
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2008, 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+
import java.util.HashSet;
41+
import java.util.Iterator;
42+
43+
/** Class representing values that are constant and that
44+
* can be inserted as variables in external processes.
45+
*
46+
* @version $Id$
47+
*/
48+
public class ConstantProperty extends DrJavaProperty {
49+
/** Create a constant property. */
50+
public ConstantProperty(String name, String value) {
51+
super(name);
52+
if (value==null) { throw new IllegalArgumentException("DrJavaProperty value is null"); }
53+
_value = value;
54+
_isCurrent = true;
55+
resetAttributes();
56+
}
57+
58+
/** Update the property so the value is current. */
59+
public void update() { }
60+
61+
62+
/** Return the value of the property. If it is not current, update first. */
63+
public String getCurrent() {
64+
return _value;
65+
}
66+
67+
/** Return the value. */
68+
public String toString() {
69+
return getCurrent();
70+
}
71+
72+
/** Return true if the value is current. */
73+
public boolean isCurrent() { return true; }
74+
75+
/** Mark the value as stale. */
76+
public void invalidate() {
77+
// nothing to do, but tell those who are listening
78+
invalidateOthers(new HashSet<DrJavaProperty>());
79+
}
80+
81+
/** @return true if the specified property is equal to this one. */
82+
public boolean equals(Object other) {
83+
if (other == null || other.getClass() != this.getClass()) return false;
84+
EagerProperty o = (EagerProperty)other;
85+
return _name.equals(o._name) && (_isCurrent == o._isCurrent) && _value.equals(o._value);
86+
}
87+
88+
/** @return the hash code. */
89+
public int hashCode() {
90+
int result;
91+
result = _name.hashCode();
92+
result = 31 * result + (_value.hashCode());
93+
result = 31 * result + (_isCurrent?1:0);
94+
return result;
95+
}
96+
}

drjava/src/edu/rice/cs/drjava/config/DrJavaProperty.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.util.Set;
4040
import java.util.HashSet;
41+
import java.util.HashMap;
4142
import java.util.Iterator;
4243

4344
/** Class representing values that can be inserted as variables in external processes.
@@ -54,6 +55,8 @@ public abstract class DrJavaProperty implements Comparable<DrJavaProperty> {
5455
protected String _value = "--uninitialized--";
5556
/** Is the value current? */
5657
protected boolean _isCurrent = false;
58+
/** Map of attributes. */
59+
protected HashMap<String,String> _attributes = new HashMap<String,String>();
5760
/** Set of other properties that are listening to this property, i.e.
5861
* when this property is invalidated, the other properties are too. */
5962
protected Set<DrJavaProperty> _listening = new HashSet<DrJavaProperty>();
@@ -62,6 +65,7 @@ public abstract class DrJavaProperty implements Comparable<DrJavaProperty> {
6265
public DrJavaProperty(String name) {
6366
if (name==null) { throw new IllegalArgumentException("DrJavaProperty name is null"); }
6467
_name = name;
68+
resetAttributes();
6569
}
6670

6771
/** Create a property. */
@@ -88,6 +92,34 @@ public String getCurrent() {
8892
/** Update the property so the value is current. */
8993
public abstract void update();
9094

95+
/** Reset attributes to their defaults. Should be overridden by properties that use attributes. */
96+
public void resetAttributes() {
97+
_attributes.clear();
98+
}
99+
100+
/** Set an attribute's value. The attribute must already exist in the table.
101+
* @param key name of the attribute
102+
* @param value new value of the attribute
103+
* @throws IllegalArgumentException if attribute with specified key does not already exist in table
104+
*/
105+
public void setAttribute(String key, String value) {
106+
if (!_attributes.containsKey(key)) {
107+
throw new IllegalArgumentException("Attribute "+key+" not known to property "+_name);
108+
}
109+
_attributes.put(key, value);
110+
}
111+
112+
/** Return an attribute's value.
113+
* @param key name of the attribute
114+
* @throws IllegalArgumentException if attribute with specified key does not already exist in table
115+
*/
116+
public String getAttribute(String key) {
117+
if (!_attributes.containsKey(key)) {
118+
throw new IllegalArgumentException("Attribute "+key+" not known to property "+_name);
119+
}
120+
return _attributes.get(key);
121+
}
122+
91123
/** Return the value, which might be stale. */
92124
public String toString() {
93125
return _value;

drjava/src/edu/rice/cs/drjava/config/EagerFileListProperty.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838

3939
import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
4040
import edu.rice.cs.drjava.DrJava;
41+
import edu.rice.cs.util.FileOps;
4142
import java.util.HashSet;
4243
import java.util.Iterator;
4344
import java.util.List;
45+
import java.io.File;
46+
import java.io.IOException;
4447

4548
/** Class representing values that are always up-to-date and that
4649
* can be inserted as variables in external processes.
@@ -50,10 +53,14 @@
5053
public abstract class EagerFileListProperty extends EagerProperty {
5154
/** Separating string. */
5255
protected String _sep;
56+
/** Relative directory. */
57+
protected String _dir;
5358
/** Create an eager property. */
54-
public EagerFileListProperty(String name, String sep) {
59+
public EagerFileListProperty(String name, String sep, String dir) {
5560
super(name);
5661
_sep = sep;
62+
_dir = dir;
63+
resetAttributes();
5764
}
5865

5966
/** Return the value of the property. If it is not current, update first. */
@@ -87,12 +94,24 @@ public void update() {
8794
if (l.size()==0) { _value = ""; return; }
8895
StringBuilder sb = new StringBuilder();
8996
for(OpenDefinitionsDocument odd: l) {
90-
sb.append(_sep);
91-
String f = edu.rice.cs.util.StringOps.escapeSpacesWith1bHex(odd.getRawFile().toString());
92-
sb.append(f);
97+
sb.append(_attributes.get("sep"));
98+
try {
99+
File f = FileOps.makeRelativeTo(odd.getRawFile(), new File(_attributes.get("dir")));
100+
String s = edu.rice.cs.util.StringOps.escapeSpacesWith1bHex(f.toString());
101+
sb.append(s);
102+
}
103+
catch(IOException e) { /* ignore */ }
104+
catch(SecurityException e) { /* ignore */ }
93105
}
94106
_value = sb.toString().substring(_sep.length());
95107
}
108+
109+
/** Reset the attributes. */
110+
public void resetAttributes() {
111+
_attributes.clear();
112+
_attributes.put("sep", _sep);
113+
_attributes.put("dir", _dir);
114+
}
96115

97116
/** @return true if the specified property is equal to this one. */
98117
public boolean equals(Object other) {

drjava/src/edu/rice/cs/drjava/config/EagerProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class EagerProperty extends DrJavaProperty {
4949
/** Create an eager property. */
5050
public EagerProperty(String name) {
5151
super(name);
52+
resetAttributes();
5253
}
5354

5455
/** Return the value of the property. If it is not current, update first. */

drjava/src/edu/rice/cs/drjava/config/JavaSystemProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class JavaSystemProperty extends EagerProperty {
4545
/** Create a Java system property. */
4646
public JavaSystemProperty(String name) {
4747
super(name);
48+
resetAttributes();
4849
}
4950

5051
/** Update the property so the value is current. */

0 commit comments

Comments
 (0)