Skip to content

Commit 0c46d16

Browse files
Merge pull request #765 from forcedotcom/dev-3
@W-11445992@ Merging dev-3 to release-3
2 parents 89c8c00 + cb9aacb commit 0c46d16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2358
-404
lines changed

.circleci/config.yml

Lines changed: 102 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ commands:
8080
- gradle/collect_test_results:
8181
reports_path: pmd-cataloger/build/reports/
8282
test_results_path: pmd-cataloger/build/test-results/
83+
- gradle/collect_test_results:
84+
reports_path: sfge/build/reports/
85+
test_results_path: sfge/build/test-results/
8386
- store_test_results:
8487
path: test-results
8588
- store_artifacts: # upload nyc test coverage as artifact.
@@ -218,12 +221,21 @@ jobs:
218221

219222
# Purpose: Runs the unit tests in a Windows environment.
220223
windows-unit-tests:
224+
# `parallelism` indicates how many simultaneous executors should be run, allowing us to split
225+
# long-running tasks across multiple executors.
226+
parallelism: 4 # larger values didn't seem to affect performance greatly
221227
executor:
222228
name: win/default # executor type
223-
size: "medium"
229+
size: "large"
224230
shell: bash.exe
225231
parameters:
226232
node-version: *node_version_param
233+
# Specify a subset of unit tests to be run, instead of the whole suite.
234+
# This allows us to work around the suboptimal performance of the Windows executor by running
235+
# multiple executors in parallel where different unit tests are ran in each.
236+
test-type:
237+
type: string
238+
default: all
227239
working_directory: C:\repo
228240
steps:
229241
- attach_workspace:
@@ -259,12 +271,90 @@ jobs:
259271
- run: mkdir test-results
260272

261273
# Unit tests
262-
- run:
263-
name: test
264-
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
265-
shell: bash.exe
266-
command: yarn test --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
267-
when: always
274+
- when:
275+
condition:
276+
equal: [ all, << parameters.test-type >> ]
277+
steps:
278+
- run:
279+
name: test
280+
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
281+
shell: bash.exe
282+
command: yarn test --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
283+
when: always
284+
285+
- when:
286+
condition:
287+
equal: [ sfge, << parameters.test-type >> ]
288+
steps:
289+
- run:
290+
name: test-sfge
291+
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
292+
shell: bash.exe
293+
# Identify all the test files and allocate them between parallelized executors by timing data.
294+
# Then turn the array of tests into something that gradle can accept, and run the tests.
295+
command: |
296+
TESTGLOB=$(circleci tests glob "sfge/src/test/**/*Test.java" | circleci tests split --split-by=timings)
297+
echo $TESTGLOB
298+
TESTARRAY=($TESTGLOB)
299+
TESTARG=""
300+
for element in "${TESTARRAY[@]}"
301+
do
302+
TESTARG="$TESTARG --tests `basename $element .java`"
303+
done
304+
echo $TESTARG
305+
yarn test-sfge $TESTARG
306+
when: always
307+
308+
- when:
309+
condition:
310+
equal: [ cli-messaging, << parameters.test-type >> ]
311+
steps:
312+
- run:
313+
name: test-cli-messaging
314+
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
315+
shell: bash.exe
316+
# This unit test suite is fast, so we have the first parallel executor run the tests, and all others exit early.
317+
command: |
318+
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
319+
then
320+
exit 0
321+
fi
322+
yarn test-cli-messaging
323+
when: always
324+
325+
- when:
326+
condition:
327+
equal: [ pmd-cataloger, << parameters.test-type >> ]
328+
steps:
329+
- run:
330+
name: test-pmd-cataloger
331+
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
332+
shell: bash.exe
333+
# This unit test suite is fast, so we have the first parallel executor run the tests, and all others exit early.
334+
command: |
335+
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
336+
then
337+
exit 0
338+
fi
339+
yarn test-pmd-cataloger
340+
when: always
341+
342+
- when:
343+
condition:
344+
equal: [ ts, << parameters.test-type >> ]
345+
steps:
346+
- run:
347+
name: test-ts
348+
# Explicitly using bash, for simplicity of required shell script.
349+
shell: bash.exe
350+
# This unit test suite is relatively fast, so we have the first parallel executor run the tests, and all others exit early.
351+
command: |
352+
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
353+
then
354+
exit 0
355+
fi
356+
yarn test-ts --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
357+
when: always
268358

269359
# Linting
270360
- run:
@@ -510,6 +600,11 @@ workflows:
510600
<<: *testing_filters
511601
requires:
512602
- setup
603+
matrix:
604+
parameters:
605+
# The values of the parameters will be appended to the jobs they create.
606+
# So we'll get "windows-unit-tests-pmd-cataloger", "windows-unit-tests-ts", etc.
607+
test-type: [pmd-cataloger, cli-messaging, ts, sfge]
513608
- linux-tarball-test:
514609
filters:
515610
<<: *testing_filters

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10+
[*.java]
11+
indent_style = space
12+
indent_size = 4
13+
1014
[*.md]
1115
trim_trailing_whitespace = false
1216

messages/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
FEEDBACK_SURVEY_BANNER: `We're constantly improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA.`
3+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/sfdx-scanner",
33
"description": "Static code scanner that applies quality and security rules to Apex code, and provides feedback.",
4-
"version": "3.2.0",
4+
"version": "3.3.0",
55
"author": "ISV SWAT",
66
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
77
"dependencies": {
@@ -133,6 +133,10 @@
133133
"postpack": "rm -f oclif.manifest.json",
134134
"lint": "eslint ./src --ext .ts",
135135
"test": "./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
136+
"test-cli-messaging": "./gradlew cli-messaging:test",
137+
"test-pmd-cataloger": "./gradlew pmd-cataloger:test",
138+
"test-sfge": "./gradlew sfge:test",
139+
"test-ts": "nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
136140
"coverage": "nyc report --reporter text",
137141
"version": "oclif-dev readme && git add README.md"
138142
}

pmd-cataloger/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ group = "sfdx"
99
version = "1.0"
1010

1111
val distDir = "$buildDir/../../dist"
12-
val pmdVersion = "6.45.0"
12+
val pmdVersion = "6.47.0"
1313
val pmdFile = "pmd-bin-$pmdVersion.zip"
1414
val pmdUrl = "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${pmdVersion}/${pmdFile}"
1515
val skippableJarRegexes = setOf("""^common_[\d\.-]*\.jar""".toRegex(),

sfge/.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ trim_trailing_whitespace = true
99
insert_final_newline = true
1010

1111
[*.java]
12-
indent_style = tab
12+
indent_style = space
1313
indent_size = 4

sfge/src/main/java/com/salesforce/Main.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.salesforce.cli.OutputFormatter;
55
import com.salesforce.exception.SfgeException;
66
import com.salesforce.exception.SfgeRuntimeException;
7+
import com.salesforce.exception.UnexpectedException;
78
import com.salesforce.graph.ops.GraphUtil;
89
import com.salesforce.messaging.CliMessager;
910
import com.salesforce.metainfo.MetaInfoCollector;
@@ -88,7 +89,7 @@ private int catalog() {
8889
LOGGER.info("Invoked CATALOG flow");
8990
List<AbstractRule> rules;
9091
try {
91-
rules = RuleUtil.getAllRules();
92+
rules = RuleUtil.getEnabledRules();
9293
} catch (SfgeException | SfgeRuntimeException ex) {
9394
System.err.println(ex.getMessage());
9495
return INTERNAL_ERROR;
@@ -129,6 +130,11 @@ private int execute(String... args) {
129130
LOGGER.error("Error while loading graph", ex);
130131
System.err.println(formatError(ex));
131132
return INTERNAL_ERROR;
133+
} catch (UnexpectedException ex) {
134+
LOGGER.error("Unexpected exception while loading graph", ex);
135+
System.err.println(
136+
"Unexpected exception while loading graph. See logs for more information.");
137+
return INTERNAL_ERROR;
132138
}
133139

134140
// Run all of the rules.

sfge/src/main/java/com/salesforce/apex/jorje/ModifierNodeWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ protected void fillProperties(Map<String, Object> properties) {
2323
properties.put(Schema.ABSTRACT, Modifier.isAbstract(javaModifiers));
2424
properties.put(Schema.STATIC, Modifier.isStatic(javaModifiers));
2525
properties.put(Schema.GLOBAL, getNode().getModifiers().has(ModifierTypeInfos.GLOBAL));
26+
properties.put(Schema.VIRTUAL, getNode().getModifiers().has(ModifierTypeInfos.VIRTUAL));
27+
properties.put(Schema.OVERRIDE, getNode().getModifiers().has(ModifierTypeInfos.OVERRIDE));
2628
}
2729
}

sfge/src/main/java/com/salesforce/cli/CliArgParser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,13 @@ private List<String> readFile(String fileName) throws IOException {
126126

127127
private void identifyRules(List<String> rulesToRun) {
128128
try {
129-
for (String ruleName : rulesToRun) {
130-
AbstractRule rule = RuleUtil.getRule(ruleName);
131-
selectedRules.add(rule);
129+
if (rulesToRun.isEmpty()) {
130+
selectedRules.addAll(RuleUtil.getEnabledRules());
131+
} else {
132+
for (String ruleName : rulesToRun) {
133+
AbstractRule rule = RuleUtil.getRule(ruleName);
134+
selectedRules.add(rule);
135+
}
132136
}
133137
} catch (RuleUtil.RuleNotFoundException ex) {
134138
throw new InvocationException(ex.getMessage(), ex);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.salesforce.config;
2+
3+
/**
4+
* Contains error message constants that will be displayed to users. TODO: move all other
5+
* user-facing messages here.
6+
*/
7+
public final class UserFacingErrorMessages {
8+
9+
/** UserActionException * */
10+
11+
// format: filename,defined type, line number
12+
public static final String UNREACHABLE_CODE =
13+
"Please remove unreachable code to proceed with analysis: %s,%s:%d";
14+
}

0 commit comments

Comments
 (0)