Skip to content

Commit 7a11398

Browse files
chore: update README and add .javawhitelistignore and allowlist.txt that ci uses
1 parent addfeb8 commit 7a11398

5 files changed

Lines changed: 179 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ jobs:
2828
run: |
2929
curl -L https://github.com/gituser12981u2/javaWhitelist/releases/latest/download/javaWhitelist.jar -o javaWhitelist.jar
3030
31-
- name: Run whitelist checker
31+
- name: Run whitelist checker
3232
run: |
33-
java -jar javaWhitelist.jar src/main/java
33+
set -euo pipefail
34+
SRC_DIRS=$(find . -type d -path '*/src/main/java' | sort)
35+
if [ -z "$SRC_DIRS" ]; then
36+
echo "No src/main/java directories found; skipping."
37+
exit 0
38+
fi
39+
while IFS= read -r d; do
40+
echo "javaWhitelist $d"
41+
java -jar javaWhitelist.jar --allowlist allowlist.txt "$d"
42+
done <<< "$SRC_DIRS"
3443
3544
- name: Verify (format check + checkstyle + compile)
3645
run: mvn -B -ntp verify

.javawhitelistignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/src/main/java/Picture.java
2+
**/src/main/java/Tweet.java

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,42 @@ Example
1818
make run module=c99-example-project
1919
```
2020

21-
## Adding a new project
21+
### Usage of .javawhitelistignore
2222

23-
Make a new directory per project with internal structure src/main/java.
24-
Place a pom.xml at root of the new directory and copy and paste the pom.xml
25-
from c99-example-project and change `artifactId` and `mainClass` only.
23+
`javaWhitelist` is a program which disallows forbidden methods from code.
2624

27-
Note: `mainClass` points to the file which contains the java main class.
25+
The `.javawhitelistignore` file contains the paths from CWD (current working directory)
26+
of the files that `javaWhitelist` should not parse and throw errors for. This is helpful
27+
for provided Java files which do not follow the code quality policy of the class.
28+
29+
Note: current `.javawhitelistignore` may not be complete for all classes, but is complete for CSE122.
30+
31+
### Usage of allowlist.txt
32+
33+
`allowlist.txt` is a file for `javaWhitelist` which tells `javaWhitelist` which methods
34+
are allowed, i.e. not forbidden. Any method added there becomes an allowed one.
35+
36+
Note: current `allowlist.txt` setup may be wrong or not complete for some classes, but is complete for CSE122.
37+
38+
### Usage of checkstyle
39+
40+
The `checkstyle.xml` and `checkstyle-suppressions.xml` file are setup for all CSE 12X classes.
41+
42+
Certain methods included in files which are not ignored in `checkstyle-supressions.xml`, since they
43+
contain both user code and provided code, may need to be manually flagged as ignored for checkstyle
44+
to correctly check only user code.
45+
46+
Use these suppression warnings on methods of this type:
47+
48+
- For Java methods with a missing JavaDoc:
49+
```java
50+
@SuppressWarnings("checkstyle:MissingJavadocMethod")
51+
```
52+
53+
- For Java methods with a JavaDoc that is incomplete
54+
```java
55+
@SuppressWarnings("checkstyle:JavadocMethod")
56+
```
2857

2958
## Setup Pre-commit
3059

@@ -34,3 +63,13 @@ Setup pre-commit hook
3463
ln -s ../../scripts/pre-commit.sh .git/hooks/pre-commit
3564
chmod +x scripts/pre-commit.sh
3665
```
66+
67+
## Adding a new project
68+
69+
Make a new directory per project with internal structure src/main/java.
70+
Place a pom.xml at root of the new directory and copy and paste the pom.xml
71+
from c99-example-project and change `artifactId` and `mainClass` only.
72+
73+
Note: `mainClass` points to the file which contains the java main class.
74+
75+

allowlist.txt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
@ENFORCE_PREFIXES=java.,javax.
2+
3+
@DISALLOW_NULL_LITERAL=false
4+
@DISALLOW_RETURN_FROM_VOID=true
5+
@DISALLOW_BREAK=true
6+
@DISALLOW_CONTINUE=true
7+
@DISALLOW_SWITCH=true
8+
@DISALLOW_TRY=true
9+
@DISALLOW_ENHANCED_FORLOOP_OVER_STACK_OR_QUEUE=true
10+
@REQUIRE_WILDCARD_IMPORTS=true
11+
12+
# For class initialization
13+
java.lang.Object#<init>
14+
15+
java.lang.String#equals
16+
java.lang.String#equalsIgnoreCase
17+
java.lang.String#length
18+
java.lang.String#charAt
19+
java.lang.String#contains
20+
java.lang.String#valueOf
21+
java.lang.String#indexOf
22+
java.lang.String#substring
23+
java.lang.String#toUpperCase
24+
java.lang.String#toLowerCase
25+
java.lang.String#toString
26+
27+
java.lang.Integer#parseInt
28+
java.lang.Double#parseDouble
29+
java.lang.Double#toString
30+
31+
java.util.Scanner#<init>
32+
java.util.Scanner#next
33+
java.util.Scanner#nextInt
34+
java.util.Scanner#nextDouble
35+
java.util.Scanner#nextLine
36+
java.util.Scanner#hasNext
37+
java.util.Scanner#hasNextInt
38+
java.util.Scanner#hasNextDouble
39+
java.util.Scanner#hasNextLine
40+
java.util.Scanner#close
41+
42+
java.io.PrintStream#<init>
43+
java.io.PrintStream#print
44+
java.io.PrintStream#println
45+
java.io.PrintStream#close
46+
47+
java.io.File#<init>
48+
49+
java.lang.System#out
50+
java.lang.System#in
51+
52+
java.util.List#add
53+
java.util.List#remove
54+
java.util.List#get
55+
java.util.List#size
56+
java.util.List#isEmpty
57+
java.util.List#clear
58+
59+
java.util.ArrayList#<init>
60+
java.util.ArrayList#add
61+
java.util.ArrayList#remove
62+
java.util.ArrayList#get
63+
java.util.ArrayList#size
64+
java.util.ArrayList#isEmpty
65+
java.util.ArrayList#clear
66+
67+
java.util.Queue#add
68+
java.util.Queue#remove
69+
java.util.Queue#peek
70+
java.util.Queue#size
71+
java.util.Queue#isEmpty
72+
java.util.Queue#clear
73+
74+
java.util.Stack#<init>
75+
java.util.Stack#push
76+
java.util.Stack#pop
77+
java.util.Stack#peek
78+
java.util.Stack#size
79+
java.util.Stack#isEmpty
80+
java.util.Stack#clear
81+
82+
java.util.Set#<init>
83+
java.util.TreeSet#<init>
84+
java.util.HashSet#<init>
85+
java.util.Set#add
86+
java.util.Set#remove
87+
java.util.Set#size
88+
java.util.Set#contains
89+
java.util.Set#isEmpty
90+
java.util.Set#clear
91+
92+
java.util.Map#<init>
93+
java.util.HashMap#<init>
94+
java.util.TreeMap#<init>
95+
java.util.Map#put
96+
java.util.Map#get
97+
java.util.Map#containsKey
98+
java.util.Map#remove
99+
java.util.Map#clear
100+
java.util.Map#size
101+
java.util.Map#isEmpty
102+
java.util.Map#toString
103+
java.util.Map#keySet
104+
java.util.Map#values
105+
java.util.Map#putAll
106+
java.util.Map#equals
107+
108+
java.util.LinkedList#<init>
109+
java.lang.IllegalStateException#<init>
110+
java.lang.IllegalArgumentException#<init>
111+
112+
java.lang.Math#abs
113+
java.lang.Math#pow
114+
java.lang.Math#exp
115+
java.lang.Math#PI
116+
java.lang.Math#e
117+
java.lang.Math#log

checkstyle.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
<module name="SuppressionFilter">
99
<property name="file" value="checkstyle-suppressions.xml"/>
10-
</module>
10+
</module>
11+
12+
<module name="SuppressWarningsFilter"/>
1113

1214
<!-- Make messages show file/line/col -->
1315
<module name="SeverityMatchFilter"/>
@@ -28,6 +30,8 @@
2830

2931
<module name="TreeWalker">
3032

33+
<module name="SuppressWarningsHolder"/>
34+
3135
<!-- =========================================
3236
MEMBER ORDERING
3337
========================================= -->

0 commit comments

Comments
 (0)