Skip to content

Commit 910d746

Browse files
author
mgricken
committed
Changed keyboard shortcut for Debug mode to MASK + D, instead of just
D. Added DrJavaProperties and PropertyMaps instead of a Map of Properties. These DrJavaProperties can be lazy and delay computationally intensive tasks like that of finding all compiled class files until actually necessary. In the "Preview", they may display stale values. Two basic categories existed before, "Java" with the System.getProperties, and "Config" with the values of the DrJava configuration. The "Config" category was previously named "DrJava", but I thought "Config" was a better name. All the entries in "Config" start with "config.". The entries in "Java" have the names as specified by Sun. A new category has been added, "DrJava", with just a few sample variables. One of them is "drjava.current.time.millis", which contains the current time in milliseconds since the beginning of the epoche -- useless, but a good first test. "drjava.current.file" contains the currently open document as an absolute path. "drjava.all.files" contains all open files, separated by File.pathSeparator. "drjava.project.files", "drjava.included.files" and "drjava.external.files" do the same for project files, external files that are saved with the project, and files that are open but not part of the project. The same "drjava.*.files" properties exist as "drjava.*.files.spaces", but here, a space is used to separate the files. Properties can listen to each other to find out when their values have been invalidated. There is a debug mechanism in place that prevents infinite loops. These are only some very basic sample properties, and we need lots more, and we need to make sure that we invalidate the values of the properties in all the right places, but it's a good start. On a Linux system, for example, try opening a project and then run an external process with the command line: tar cfvz test.tar.gz ${drjava.all.files.spaces} It will create a tar file with all the source files currently open. Not bad, eh? Please help me figure out what other properties are needed, and how we can easily make them relative to other directories, etc. This is a massive commit, with far-reaching changes. Please update your working copy of DrJava to the newest revision and test the changes, the new features, and also the old ones to make sure I haven't broken anything. Thanks! M src/edu/rice/cs/drjava/config/OptionConstants.java A src/edu/rice/cs/drjava/config/DrJavaProperty.java A src/edu/rice/cs/drjava/config/JavaSystemProperty.java A src/edu/rice/cs/drjava/config/PropertyMaps.java A src/edu/rice/cs/drjava/config/ConfigProperty.java A src/edu/rice/cs/drjava/config/EagerProperty.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/drjava/ui/InsertVariableDialog.java M src/edu/rice/cs/drjava/ui/ExecuteExternalDialog.java M src/edu/rice/cs/util/JVMProcessCreator.java M src/edu/rice/cs/util/StringOps.java M src/edu/rice/cs/util/StringOpsTest.java M src/edu/rice/cs/util/ProcessCreator.java git-svn-id: file:///tmp/test-svn/trunk@4353 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 2e0841e commit 910d746

13 files changed

+1001
-204
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.Iterator;
41+
42+
/** Class representing values from the DrJava configuration file that
43+
* can be inserted as variables in external processes.
44+
*
45+
* @version $Id$
46+
*/
47+
public class ConfigProperty extends EagerProperty {
48+
/** Create a configuration property. */
49+
public ConfigProperty(String name) {
50+
super(name);
51+
}
52+
53+
/** Update the property so the value is current. */
54+
public void update() {
55+
OptionMap om = DrJava.getConfig().getOptionMap();
56+
Iterator<OptionParser<?>> it = om.keys();
57+
while(it.hasNext()) {
58+
OptionParser<?> op = it.next();
59+
String key = op.getName();
60+
String value = om.getString(op);
61+
if (_name.equals("config."+key)) { _value = value; return; }
62+
}
63+
_value = "--unknown--";
64+
}
65+
66+
/** Return the value. */
67+
public String toString() {
68+
return getCurrent();
69+
}
70+
71+
/** @return true if the specified property is equal to this one. */
72+
public boolean equals(Object other) {
73+
if (other == null || other.getClass() != this.getClass()) return false;
74+
ConfigProperty o = (ConfigProperty)other;
75+
return _name.equals(o._name) && (_isCurrent == o._isCurrent) && _value.equals(o._value);
76+
}
77+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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 java.util.Set;
40+
import java.util.HashSet;
41+
import java.util.Iterator;
42+
43+
/** Class representing values that can be inserted as variables in external processes.
44+
*
45+
* @version $Id$
46+
*/
47+
public abstract class DrJavaProperty implements Comparable<DrJavaProperty> {
48+
/** Whether the invalidation listening mechanism has been deactivated due to an error. */
49+
public volatile boolean DEACTIVATED_DUE_TO_ERROR = false;
50+
51+
/** Name of the property. Must be unique. */
52+
protected String _name;
53+
/** Value of the property. */
54+
protected String _value = "--uninitialized--";
55+
/** Is the value current? */
56+
protected boolean _isCurrent = false;
57+
/** Set of other properties that are listening to this property, i.e.
58+
* when this property is invalidated, the other properties are too. */
59+
protected Set<DrJavaProperty> _listening = new HashSet<DrJavaProperty>();
60+
61+
/** Create a property. */
62+
public DrJavaProperty(String name) {
63+
if (name==null) { throw new IllegalArgumentException("DrJavaProperty name is null"); }
64+
_name = name;
65+
}
66+
67+
/** Create a property. */
68+
public DrJavaProperty(String name, String value) {
69+
this(name);
70+
if (value==null) { throw new IllegalArgumentException("DrJavaProperty value is null"); }
71+
_value = value;
72+
_isCurrent = true;
73+
}
74+
75+
/** Return the name of the property. */
76+
public String getName() { return _name; }
77+
78+
/** Return the value of the property. If it is not current, update first. */
79+
public String getCurrent() {
80+
if (!_isCurrent) {
81+
update();
82+
if (_value==null) { throw new IllegalArgumentException("DrJavaProperty value is null"); }
83+
_isCurrent = true;
84+
}
85+
return _value;
86+
}
87+
88+
/** Update the property so the value is current. */
89+
public abstract void update();
90+
91+
/** Return the value, which might be stale. */
92+
public String toString() {
93+
return _value;
94+
}
95+
96+
/** Return true if the value is current. */
97+
public boolean isCurrent() { return _isCurrent; }
98+
99+
/** Mark the value as stale and invalidate other properties that are listening. */
100+
public void invalidate() {
101+
_invalidate();
102+
invalidateOthers(new HashSet<DrJavaProperty>());
103+
}
104+
105+
/** Just invalidate. */
106+
protected void _invalidate() { _isCurrent = false; }
107+
108+
public DrJavaProperty listenToInvalidatesOf(DrJavaProperty other) {
109+
if (other==this) {
110+
DEACTIVATED_DUE_TO_ERROR = true;
111+
RuntimeException e = new IllegalArgumentException("Property cannot listen for invalidation of itself. "+
112+
"Variables for external processes will not function correctly anymore. "+
113+
"This is a SERIOUS programming error. Please notify the DrJava team.");
114+
edu.rice.cs.drjava.ui.DrJavaErrorHandler.record(e);
115+
throw e;
116+
}
117+
other._listening.add(this);
118+
return this;
119+
}
120+
121+
/** Compare two properties. */
122+
public int compareTo(DrJavaProperty o) {
123+
return _name.compareTo(o._name);
124+
}
125+
126+
/** @return true if the specified property is equal to this one. */
127+
public boolean equals(Object other) {
128+
if (other == null || other.getClass() != this.getClass()) return false;
129+
DrJavaProperty o = (DrJavaProperty)other;
130+
return _name.equals(o._name) && (_isCurrent == o._isCurrent) && _value.equals(o._value);
131+
}
132+
133+
/** @return the hash code. */
134+
public int hashCode() {
135+
int result;
136+
result = _name.hashCode();
137+
result = 31 * result + (_value.hashCode());
138+
result = 31 * result + (_isCurrent?1:0);
139+
return result;
140+
}
141+
142+
/** Invalidate those properties that are listening to this property.
143+
* @param alreadyVisited set of properties already visited, to avoid cycles. */
144+
protected void invalidateOthers(Set<DrJavaProperty> alreadyVisited) {
145+
if (DEACTIVATED_DUE_TO_ERROR) { return; }
146+
if (alreadyVisited.contains(this)) {
147+
Iterator<DrJavaProperty> it = alreadyVisited.iterator();
148+
StringBuilder sb = new StringBuilder("Invalidating ");
149+
sb.append(getName());
150+
sb.append(" after already having invalidated ");
151+
boolean first = true;
152+
while(it.hasNext()) {
153+
if (first) { first = false; }
154+
else { sb.append(", "); }
155+
sb.append(it.next().getName());
156+
}
157+
sb.append(". Variables for external processes will not function correctly anymore. "+
158+
"This is a SERIOUS programming error. Please notify the DrJava team.");
159+
DEACTIVATED_DUE_TO_ERROR = true;
160+
RuntimeException e = new InfiniteLoopException(sb.toString());
161+
edu.rice.cs.drjava.ui.DrJavaErrorHandler.record(e);
162+
throw e;
163+
}
164+
alreadyVisited.add(this);
165+
Iterator<DrJavaProperty> it = _listening.iterator();
166+
while(it.hasNext()) {
167+
DrJavaProperty prop = it.next();
168+
prop._invalidate();
169+
prop.invalidateOthers(alreadyVisited);
170+
}
171+
}
172+
173+
/** Exception thrown if an infinite loop of invalidation listening is detected. */
174+
public static class InfiniteLoopException extends RuntimeException {
175+
public InfiniteLoopException(String s) { super(s); }
176+
}
177+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 always up-to-date and that
44+
* can be inserted as variables in external processes.
45+
*
46+
* @version $Id$
47+
*/
48+
public abstract class EagerProperty extends DrJavaProperty {
49+
/** Create an eager property. */
50+
public EagerProperty(String name) {
51+
super(name);
52+
}
53+
54+
/** Return the value of the property. If it is not current, update first. */
55+
public String getCurrent() {
56+
update();
57+
if (_value==null) { throw new IllegalArgumentException("DrJavaProperty value is null"); }
58+
_isCurrent = true;
59+
return _value;
60+
}
61+
62+
/** Return the value. */
63+
public String toString() {
64+
return getCurrent();
65+
}
66+
67+
/** Return true if the value is current. */
68+
public boolean isCurrent() { return true; }
69+
70+
/** Mark the value as stale. */
71+
public void invalidate() {
72+
// nothing to do, but tell those who are listening
73+
invalidateOthers(new HashSet<DrJavaProperty>());
74+
}
75+
76+
/** @return true if the specified property is equal to this one. */
77+
public boolean equals(Object other) {
78+
if (other == null || other.getClass() != this.getClass()) return false;
79+
EagerProperty o = (EagerProperty)other;
80+
return _name.equals(o._name) && (_isCurrent == o._isCurrent) && _value.equals(o._value);
81+
}
82+
83+
/** @return the hash code. */
84+
public int hashCode() {
85+
int result;
86+
result = _name.hashCode();
87+
result = 31 * result + (_value.hashCode());
88+
result = 31 * result + (_isCurrent?1:0);
89+
return result;
90+
}
91+
}

0 commit comments

Comments
 (0)