Skip to content

Commit c45b29a

Browse files
authored
Merge pull request #188 from CROSSINGTUD/conditional-events
Add conditional events to predicates
2 parents ee6524c + 749196a commit c45b29a

File tree

3 files changed

+80
-30
lines changed

3 files changed

+80
-30
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy CrySL
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy-and-release:
8+
runs-on: ubuntu-latest
9+
name: Deploy CrySL (Release)
10+
environment: Deploy
11+
12+
steps:
13+
- name: Checkout source code
14+
uses: actions/checkout@v4
15+
16+
- name: Deploy release version
17+
uses: secure-software-engineering/actions/deployment/maven-deployment@develop
18+
with:
19+
java-distribution: adopt
20+
java-version: 17
21+
server-id: central
22+
server-username: ${{ secrets.SONATYPE_USER }}
23+
server-password: ${{ secrets.SONATYPE_PW }}
24+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
25+
gpg-passphrase: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
26+
mvn-cli-args: '-DskipTests -Pdeployment'
27+
deploy-mode: release
28+
29+
- name: Bump to next SNAPSHOT version
30+
uses: secure-software-engineering/actions/deployment/update-snapshot-version@develop
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
source-branch: master
34+
target-branch: master
35+
snapshot-branch: snapshot-update
36+
37+
# Steps for GitHub release based on latest tag
38+
- name: Get latest tag
39+
run: echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
40+
- name: Create GitHub release
41+
run: |
42+
gh release create ${{ env.tag }} --title ${{ env.tag }} --generate-notes
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CrySLParser/src/main/java/crysl/parsing/CrySLModelReader.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ public static Collection<CrySLVulnerabilityEntry> toVulnerabilityEntries(EList<S
222222
return cves.stream().map(CrySLCveEntry::new).collect(Collectors.toList());
223223
}
224224

225-
// private static int parseIntUnderscore(String s) {
226-
// return Integer.parseInt(s.replace("_", "").trim());
227-
// }
228-
229225
public static List<Integer> expandPageRange(PageList list) {
230226
List<Integer> result = new ArrayList<>();
231227

@@ -237,15 +233,13 @@ public static List<Integer> expandPageRange(PageList list) {
237233
int start = r.getStart();
238234
if (start <= 0) continue;
239235

240-
try {
241-
int end = r.getEnd();
242-
if (end <= 0) {
243-
result.add(start);
244-
} else if (end >= start) {
245-
for (int i = start; i <= end; i++) result.add(i);
236+
int end = r.getEnd();
237+
if (end <= 0) {
238+
result.add(start);
239+
} else if (end >= start) {
240+
for (int i = start; i <= end; i++) {
241+
result.add(i);
246242
}
247-
} catch (NumberFormatException e) {
248-
// ignore or log invalid INTs, consistent with your current code
249243
}
250244
}
251245
return result;
@@ -397,11 +391,12 @@ private Collection<CrySLPredicate> getTimedPredicates(
397391
if (timed.getAfter() == null) {
398392
predicates.add(new CrySLPredicate(null, name, parameters, negate, constraint));
399393
} else {
400-
Collection<StateNode> nodes =
401-
getStatesForMethods(
402-
CrySLReaderUtils.resolveEventToCryslMethods(timed.getAfter()));
394+
Collection<CrySLMethod> afterEvents =
395+
CrySLReaderUtils.resolveEventToCryslMethods(timed.getAfter());
396+
Collection<StateNode> nodes = getStatesForMethods(afterEvents);
403397
predicates.add(
404-
new CrySLCondPredicate(null, name, parameters, negate, nodes, constraint));
398+
new CrySLCondPredicate(
399+
null, name, parameters, negate, afterEvents, nodes, constraint));
405400
}
406401
}
407402
return predicates;

CrySLParser/src/main/java/crysl/rule/CrySLCondPredicate.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,62 @@
22

33
import java.util.Collection;
44
import java.util.List;
5+
import java.util.Objects;
56

67
public class CrySLCondPredicate extends CrySLPredicate {
78

9+
private final Collection<CrySLMethod> conditionalEvents;
810
private final Collection<StateNode> conditionalNodes;
911

1012
public CrySLCondPredicate(
1113
ICrySLPredicateParameter baseObj,
1214
String name,
1315
List<ICrySLPredicateParameter> parameters,
1416
Boolean negated,
17+
Collection<CrySLMethod> conditionalEvents,
1518
Collection<StateNode> nodes) {
16-
this(baseObj, name, parameters, negated, nodes, null);
19+
this(baseObj, name, parameters, negated, conditionalEvents, nodes, null);
1720
}
1821

1922
public CrySLCondPredicate(
2023
ICrySLPredicateParameter baseObj,
2124
String name,
2225
List<ICrySLPredicateParameter> parameters,
2326
Boolean negated,
27+
Collection<CrySLMethod> conditionalEvents,
2428
Collection<StateNode> nodes,
2529
ISLConstraint constraint) {
2630
super(baseObj, name, parameters, negated, constraint);
31+
32+
this.conditionalEvents = conditionalEvents;
2733
this.conditionalNodes = nodes;
2834
}
2935

30-
/**
31-
* @return the conditionalMethods
32-
*/
33-
public Collection<StateNode> getConditionalMethods() {
36+
public Collection<CrySLMethod> getConditionalEvents() {
37+
return conditionalEvents;
38+
}
39+
40+
public Collection<StateNode> getConditionalNodes() {
3441
return conditionalNodes;
3542
}
3643

3744
@Override
38-
public boolean equals(Object obj) {
39-
if (!super.equals(obj)) return false;
40-
41-
if (!(obj instanceof CrySLCondPredicate)) return false;
42-
43-
CrySLCondPredicate other = (CrySLCondPredicate) obj;
44-
if (!getConditionalMethods().equals(other.getConditionalMethods())) return false;
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
if (!super.equals(o)) return false;
49+
CrySLCondPredicate that = (CrySLCondPredicate) o;
50+
return Objects.equals(conditionalEvents, that.conditionalEvents)
51+
&& Objects.equals(conditionalNodes, that.conditionalNodes);
52+
}
4553

46-
return true;
54+
@Override
55+
public int hashCode() {
56+
return Objects.hash(super.hashCode(), conditionalEvents, conditionalNodes);
4757
}
4858

59+
@Override
4960
public String toString() {
50-
return super.toString() + " after " + conditionalNodes;
61+
return super.toString() + " after " + conditionalEvents + " (" + conditionalNodes + ")";
5162
}
5263
}

0 commit comments

Comments
 (0)