Skip to content

Commit 7a39e4c

Browse files
author
Mithilesh Pawar
authored
Code linter (#125)
1 parent 1b21324 commit 7a39e4c

File tree

5 files changed

+62
-23
lines changed

5 files changed

+62
-23
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ jobs:
88
steps:
99
- name: Checkout
1010
uses: actions/checkout@v3
11-
12-
- name: Set up JDK 8
13-
uses: actions/[email protected]
1411
with:
15-
distribution: 'temurin'
16-
java-version: 8
12+
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
1713

1814
- name: Cache local Maven repository
1915
uses: actions/cache@v3
@@ -23,12 +19,36 @@ jobs:
2319
restore-keys: |
2420
${{ runner.os }}-maven-
2521
22+
- name: Set up JDK 11
23+
uses: actions/[email protected]
24+
with:
25+
distribution: 'temurin'
26+
java-version: '11'
27+
server-id: ossrh
28+
server-username: MAVEN_USERNAME
29+
server-password: MAVEN_PASSWORD
30+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
31+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
32+
2633
- name: Run tests with Maven
34+
run: mvn -B test --file pom.xml
2735
env:
2836
CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID}}
2937
CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}}
3038
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
3139
CX_TENANT: ${{ secrets.CX_TENANT }}
3240
CX_SCAN_ID: ${{ secrets.CX_SCAN_ID }}
3341
CX_APIKEY: ${{ secrets.CX_APIKEY }}
34-
run: mvn -B test --file pom.xml
42+
43+
44+
- name: Build with Maven
45+
run: mvn -B verify -DskipTests --file pom.xml
46+
env:
47+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
48+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
49+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
50+
51+
- name: Run SpotBugs Analysis
52+
uses: jwgmeligmeyling/spotbugs-github-action@master
53+
with:
54+
path: '**/spotbugsXml.xml'

pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<packaging>jar</packaging>
1010

1111
<name>Checkmarx AST Client</name>
12-
<description>Checkmarx AST ClI SDK</description>
12+
<description>Checkmarx AST CLI SDK</description>
1313
<url>https://www.checkmarx.com</url>
1414

1515
<properties>
@@ -60,6 +60,24 @@
6060

6161
<build>
6262
<plugins>
63+
<plugin>
64+
<groupId>com.github.spotbugs</groupId>
65+
<artifactId>spotbugs-maven-plugin</artifactId>
66+
<version>4.7.0.0</version>
67+
<configuration>
68+
<effort>Max</effort>
69+
<threshold>High</threshold>
70+
<xmlOutput>true</xmlOutput>
71+
<failOnError>false</failOnError>
72+
</configuration>
73+
<executions>
74+
<execution>
75+
<goals>
76+
<goal>check</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
</plugin>
6381
<plugin>
6482
<groupId>org.apache.maven.plugins</groupId>
6583
<artifactId>maven-surefire-plugin</artifactId>

src/main/java/com/checkmarx/ast/results/result/Node.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.fasterxml.jackson.databind.type.TypeFactory;
1010
import lombok.Value;
1111
import org.apache.commons.lang3.StringUtils;
12-
1312
import java.io.IOException;
1413
import java.util.List;
1514
import java.util.Objects;
@@ -103,14 +102,18 @@ public boolean equals(Object obj) {
103102
}
104103
Node node = (Node) obj;
105104
return line == node.line &&
106-
column == node.column &&
107-
length == node.length &&
108-
Objects.equals(name, node.name) &&
109-
Objects.equals(method, node.method) &&
110-
Objects.equals(domType, node.domType) &&
111-
Objects.equals(fileName, node.fileName) &&
112-
Objects.equals(fullName, node.fullName) &&
113-
Objects.equals(methodLine, node.methodLine);
105+
column == node.column &&
106+
length == node.length &&
107+
Objects.equals(name, node.name) &&
108+
Objects.equals(method, node.method) &&
109+
Objects.equals(domType, node.domType) &&
110+
Objects.equals(fileName, node.fileName) &&
111+
Objects.equals(fullName, node.fullName) &&
112+
Objects.equals(methodLine, node.methodLine);
114113
}
115114

115+
@Override
116+
public int hashCode() {
117+
return id.hashCode();
118+
}
116119
}

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.apache.commons.lang3.StringUtils;
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
18-
1918
import java.io.IOException;
2019
import java.nio.file.Files;
2120
import java.util.ArrayList;
@@ -35,7 +34,7 @@ public class CxWrapper {
3534
@NonNull
3635
private final String executable;
3736

38-
public CxWrapper(@NonNull CxConfig cxConfig)
37+
public CxWrapper(CxConfig cxConfig)
3938
throws CxConfig.InvalidCLIConfigException, IOException {
4039
this(cxConfig, LoggerFactory.getLogger(CxWrapper.class));
4140
}

src/main/java/com/checkmarx/ast/wrapper/Execution.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.checkmarx.ast.wrapper;
22

33
import org.slf4j.Logger;
4-
54
import java.io.*;
65
import java.net.URL;
76
import java.nio.charset.StandardCharsets;
@@ -83,7 +82,7 @@ static String executeCommand(List<String> arguments,
8382
File outputFile = new File(directory, file);
8483

8584
return new String(Files.readAllBytes(Paths.get(outputFile.getAbsolutePath())),
86-
StandardCharsets.UTF_8);
85+
StandardCharsets.UTF_8);
8786
}
8887

8988
static String getTempBinary() throws IOException {
@@ -98,7 +97,7 @@ static String getTempBinary() throws IOException {
9897
}
9998
File tempExecutable = new File(TEMP_DIR, fileName);
10099
if (!tempExecutable.exists() || !compareChecksum(resource.openStream(),
101-
new FileInputStream(tempExecutable))) {
100+
new FileInputStream(tempExecutable))) {
102101
copyURLToFile(resource, tempExecutable);
103102
}
104103
if (!tempExecutable.canExecute() && !tempExecutable.setExecutable(true)) {
@@ -111,7 +110,7 @@ static String getTempBinary() throws IOException {
111110

112111
private static BufferedReader getReader(Process process) {
113112
InputStream is = process.getInputStream();
114-
InputStreamReader isr = new InputStreamReader(is);
113+
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
115114
return new BufferedReader(isr);
116115
}
117116

@@ -167,7 +166,7 @@ private static String md5(InputStream a) {
167166
while ((i = a.read(buf)) != -1) {
168167
md.update(buf, 0, i);
169168
}
170-
md5 = new String(md.digest());
169+
md5 = new String(md.digest(), StandardCharsets.UTF_8);
171170
} catch (NoSuchAlgorithmException | IOException e) {
172171
// ignore
173172
}

0 commit comments

Comments
 (0)