Skip to content

Commit 7e94988

Browse files
committed
v0.1.3-beta
fix typos update to JDK 19 update README add support for @literal tag-value mappings improve stability of node auto-reset feature
1 parent b47eac2 commit 7e94988

File tree

8 files changed

+106
-14
lines changed

8 files changed

+106
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Another possible use for this add-on is advanced reporting with automatic data c
3030
4. Click the *Upload Script* button and select your script. An error will be thrown if any compilation/loading errors occur. For debugging purposes, the stack trace of any error is recorded in the *Error Log*.
3131
5. Click *Semantic Mappings* and then *New Mapping* in order to select which parts of the WebCTRL system are accessible to the script.
3232
6. Click *Add Group* and then *Add Equipment* to select which control programs should be tested.
33-
7. Enter in a few semantic tags and mapping expressions to be referenced by the script. The *Examine* button on each control program can help to determine the expression to use for mapping a given semantic tag. Note that each tag mapping is actually a [regular expression](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/regex/Pattern.html).
33+
7. Enter in a few semantic tags and mapping expressions to be referenced by the script. The *Examine* button on each control program can help to determine the expression to use for mapping a given semantic tag. Note that each tag mapping is actually a [regular expression](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/regex/Pattern.html). Expressions prefixed with `@` are interpreted literally as opposed to a node mapping pattern (e.g, the node mapped with `@3.14159` will always return a value of *3.14159*).
3434
8. Press the *Save Changes* button as the last step to create your mapping. Note that all groups and mappings should be named.
3535
9. The *Preview Mapping Resolution* button should be used to determine whether each tag mapping is resolved correctly.
3636
10. Navigate back to the *Scripts* page.
@@ -52,7 +52,7 @@ However, it is recommended that scripts are compiled and packaged into *.jar* ar
5252

5353
Be mindful to compile your script with a version of Java compatible with the target WebCTRL version of your server. For instance, you should use the build flag `--release 8` if you intend the script to run on WebCTRL7.0, and `--release 11` for WebCTRL8.0. See https://jdk.java.net/ to download the latest version of the java development kit.
5454

55-
To ease the development process, it is suggested to use an IDE (e.g, [Visual Studio Code](https://code.visualstudio.com/)), and then add the following dependencies: [CommissioningScripts-0.1.2.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.2-beta/CommissioningScripts-0.1.2.jar) and [CommissioningScripts-0.1.2-sources.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.2-beta/CommissioningScripts-0.1.2-sources.jar). These dependencies will provide you with intellisense and Javadocs for script development. You are also welcome to reference any other dependencies provided by WebCTRL at runtime (e.g, the add-on API, or `javax.servlet`).
55+
To ease the development process, it is suggested to use an IDE (e.g, [Visual Studio Code](https://code.visualstudio.com/)), and then add the following dependencies: [CommissioningScripts-0.1.3.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.3-beta/CommissioningScripts-0.1.3.jar) and [CommissioningScripts-0.1.3-sources.jar](https://github.com/automatic-controls/commissioning-scripts/releases/download/v0.1.3-beta/CommissioningScripts-0.1.3-sources.jar). These dependencies will provide you with intellisense and Javadocs for script development. You are also welcome to reference any other dependencies provided by WebCTRL at runtime (e.g, the add-on API, or `javax.servlet`).
5656

5757
This add-on does not enforce any security restrictions on what scripts can do. Scripts are executed with the same privilege set as the add-on. As such, you must be careful to **use scripts at your own risk.** Note that only WebCTRL server administrators are allowed to manage scripts.
5858

config/BUILD_DETAILS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
JDK Version:
2-
openjdk 18.0.2.1 2022-08-18
3-
OpenJDK Runtime Environment (build 18.0.2.1+1-1)
4-
OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)
2+
openjdk 19.0.1 2022-10-18
3+
OpenJDK Runtime Environment (build 19.0.1+10-21)
4+
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)
55

66
Compilation Flags:
77
--release 8

root/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<extension version="1">
22
<name>CommissioningScripts</name>
33
<description>Executes scripts concurrently on groups of equipment to evaluate performance and detect faults.</description>
4-
<version>0.1.2</version>
4+
<version>0.1.3</version>
55
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
66
</extension>

src/aces/webctrl/scripts/commissioning/core/Initializer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.concurrent.*;
77
import java.nio.file.*;
88
public class Initializer implements ServletContextListener {
9-
/** Contains basic informatin about this addon. */
9+
/** Contains basic information about this addon. */
1010
public volatile static AddOnInfo info = null;
1111
/** The name of this addon */
1212
private volatile static String name;
@@ -177,16 +177,16 @@ public void execute(WritableSystemAccess sys){
177177
*/
178178
@Override public void contextDestroyed(ServletContextEvent sce){
179179
try{
180-
kill = true;
181-
dataQueryThread.interrupt();
182180
Collection<Test> tests = Test.instances.values();
183181
for (Test t:tests){
184182
t.kill();
185183
}
186-
dataQueryThread.join();
187184
for (Test t:tests){
188185
t.waitForDeath();
189186
}
187+
kill = true;
188+
dataQueryThread.interrupt();
189+
dataQueryThread.join();
190190
ArchivedTest.saveAll();
191191
Mapping.saveAll();
192192
ScheduledTest.saveAll();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package aces.webctrl.scripts.commissioning.core;
2+
import com.controlj.green.addonsupport.access.*;
3+
import com.controlj.green.addonsupport.access.node.*;
4+
import java.util.*;
5+
public class LiteralNode implements Node {
6+
private volatile String value;
7+
public LiteralNode(String value){
8+
this.value = value;
9+
}
10+
@Override public String eval(String arg0){
11+
return null;
12+
}
13+
@Override public Node evalToNode(String arg0){
14+
return null;
15+
}
16+
@Override public List<Node> getChildren(){
17+
return null;
18+
}
19+
@Override public String getDisplayName(){
20+
return null;
21+
}
22+
@Override public String getDisplayName(Locale arg0){
23+
return null;
24+
}
25+
@Override public String getDisplayValue(){
26+
return value;
27+
}
28+
@Override public Node getParent(){
29+
return null;
30+
}
31+
@Override public String getReferenceName(){
32+
return null;
33+
}
34+
@Override public String getRelativeReferencePath(Node arg0){
35+
return null;
36+
}
37+
@Override public String getValue(){
38+
return value;
39+
}
40+
@Override public boolean hasParent(){
41+
return false;
42+
}
43+
@Override public Location resolveToLocation(Tree arg0){
44+
return null;
45+
}
46+
@Override public void setDisplayValue(String arg0){
47+
value = arg0;
48+
}
49+
@Override public void setValue(String arg0){
50+
value = arg0;
51+
}
52+
}

src/aces/webctrl/scripts/commissioning/core/ResolvedTestingUnit.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public ResolvedTestingUnit(TestingUnit tu, Tree tree, Collection<SemanticTag> ta
5555
node = loc.toNode();
5656
group = tu.getGroup();
5757
Node n;
58+
String expr;
5859
for (SemanticTag st:tagMappings){
59-
n = st.resolve(node);
60+
if (st.isLiteral() && (expr=st.getExpression()).charAt(0)=='@'){
61+
n = new LiteralNode(expr.substring(1));
62+
}else{
63+
n = st.resolve(node);
64+
}
6065
if (n!=null){
6166
tags.put(st.getTag(), n);
6267
}
@@ -120,6 +125,10 @@ public static boolean setValue(final Node n, final Object value, final int tries
120125
return false;
121126
}
122127
final String str = String.valueOf(value);
128+
if (n instanceof LiteralNode){
129+
((LiteralNode)n).setValue(str);
130+
return true;
131+
}
123132
final Result<Boolean> ret = new Result<Boolean>();
124133
for (int i=0;i<tries;++i){
125134
if (i!=0){
@@ -153,6 +162,13 @@ public String markAndSetValue(final String tag, final Object value) throws Inter
153162
return null;
154163
}
155164
final String str = String.valueOf(value);
165+
if (n instanceof LiteralNode){
166+
final LiteralNode nn = (LiteralNode)n;
167+
final String prev = nn.getValue();
168+
nn.setValue(str);
169+
marks.put(tag,prev);
170+
return prev;
171+
}
156172
final Result<String> ret = new Result<String>();
157173
final Container<String> val = new Container<String>(null);
158174
String s;
@@ -219,6 +235,8 @@ public String getValue(String tag) throws InterruptedException {
219235
public static String getValue(Node n, final int tries, final long failedAttemptTimeout) throws InterruptedException {
220236
if (n==null){
221237
return null;
238+
}else if (n instanceof LiteralNode){
239+
return ((LiteralNode)n).getValue();
222240
}
223241
final Result<String> ret = new Result<String>();
224242
String s;
@@ -254,6 +272,8 @@ public String getDisplayValue(String tag) throws InterruptedException {
254272
public static String getDisplayValue(Node n, final int tries, final long failedAttemptTimeout) throws InterruptedException {
255273
if (n==null){
256274
return null;
275+
}else if (n instanceof LiteralNode){
276+
return ((LiteralNode)n).getDisplayValue();
257277
}
258278
final Result<String> ret = new Result<String>();
259279
String s;
@@ -301,6 +321,11 @@ public boolean reset(String tag) throws InterruptedException {
301321
final String value = marks.get(str);
302322
if (value!=null){
303323
final Node n = entry.getValue();
324+
if (n instanceof LiteralNode){
325+
((LiteralNode)n).setValue(value);
326+
marks.remove(str);
327+
continue;
328+
}
304329
final Result<Boolean> ret = new Result<Boolean>();
305330
rets.add(ret);
306331
Initializer.enqueue(new WriteAction(){

src/aces/webctrl/scripts/commissioning/core/SemanticTag.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class SemanticTag {
99
private volatile String expr;
1010
private volatile String tag;
1111
private volatile Pattern pattern = null;
12+
private volatile boolean literal;
1213
public void serialize(ByteBuilder b){
1314
b.write(tag);
1415
b.write(expr);
@@ -30,8 +31,11 @@ public SemanticTag(String tag, String expr) throws PatternSyntaxException {
3031
public void setExpression(String expr) throws PatternSyntaxException {
3132
expr = Utility.V_SPACE.matcher(expr).replaceAll("");
3233
this.expr = expr;
34+
literal = expr.charAt(0)=='@';
3335
pattern = null;
34-
pattern = Pattern.compile(expr);
36+
if (!literal){
37+
pattern = Pattern.compile(expr);
38+
}
3539
}
3640
/**
3741
* @return the expression used to match nodes against this semantic tag.
@@ -45,6 +49,12 @@ public String getExpression(){
4549
public String getTag(){
4650
return tag;
4751
}
52+
/**
53+
* @return whether the expression should be interpreted as a literal value instead of a node mapping.
54+
*/
55+
public boolean isLiteral(){
56+
return literal;
57+
}
4858
/**
4959
* Attempts to resolve this semantic tag against the provided node.
5060
* @return the resolved node which corresponds to this semantic tag, or {@code null} if no matches are found.

src/aces/webctrl/scripts/commissioning/core/Test.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean isRunning(){
162162
*/
163163
public void waitForDeath() throws InterruptedException {
164164
while (running.get()){
165-
Thread.sleep(1000L);
165+
Thread.sleep(500L);
166166
}
167167
}
168168
/**
@@ -353,7 +353,12 @@ public void run(){
353353
Initializer.log(t);
354354
}
355355
if (autoReset.x){
356-
rtu.reset(null);
356+
while (true){
357+
try{
358+
rtu.reset(null);
359+
break;
360+
}catch(InterruptedException e){}
361+
}
357362
}
358363
rtu.complete();
359364
groups[i].complete();

0 commit comments

Comments
 (0)