-
Notifications
You must be signed in to change notification settings - Fork 54
@W-10759090@: Implemented method-level targeting for SFGE, and message-passing system to allow for proper logging. #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a0c065
f526cb5
6980d4b
9735b1d
539e265
8882d41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| plugins { | ||
| java | ||
| } | ||
|
|
||
| version = "1.0" | ||
| java.sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| group = "com.salesforce.messaging" | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation ("com.googlecode.json-simple:json-simple:1.1.1") { | ||
| exclude("junit") | ||
| } | ||
| implementation("com.google.code.gson:gson:2.3") | ||
| testImplementation("junit", "junit", "4.12") | ||
| implementation("com.google.guava:guava:28.0-jre") | ||
| testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") | ||
| testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") | ||
| } | ||
|
|
||
| tasks.getByName<Test>("test") { | ||
| useJUnitPlatform() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rootProject.name = "cli-messaging" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| package sfdc.sfdx.scanner.messaging; | ||
| import static sfdc.sfdx.scanner.messaging.SfdxMessager.*; | ||
| package com.salesforce.messaging; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically a copy of |
||
| import static com.salesforce.messaging.Message.*; | ||
|
|
||
| public enum EventKey { | ||
| // MAKE SURE messageKey OF EVERY VALUE ADDED HERE HAS AN ENTRY IN 'messages/EventKeyTemplates.js'! | ||
| // MAKE SURE `messageKey` OF EVERY VALUE ADDED HERE HAS AN ENTRY IN 'messages/EventKeyTemplates.js'! | ||
| INFO_GENERAL_INTERNAL_LOG("info.generalInternalLog", 1, MessageType.INFO, MessageHandler.INTERNAL, true), | ||
| WARNING_INVALID_CAT_SKIPPED("warning.invalidCategorySkipped", 1, MessageType.WARNING, MessageHandler.UX, true), | ||
| WARNING_INVALID_RULESET_SKIPPED("warning.invalidRulesetSkipped", 1, MessageType.WARNING, MessageHandler.UX, true), | ||
|
|
@@ -19,13 +19,15 @@ public enum EventKey { | |
| ERROR_EXTERNAL_MULTIPLE_RULE_DESC("error.external.multipleRuleDesc", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| ERROR_EXTERNAL_RECURSION_LIMIT("error.external.recursionLimitReached", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| ERROR_EXTERNAL_XML_NOT_READABLE("error.external.xmlNotReadable", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| ERROR_EXTERNAL_XML_NOT_PARSABLE("error.external.xmlNotParsable", 2, MessageType.ERROR, MessageHandler.UX, false); | ||
|
|
||
| String messageKey; | ||
| int argCount; | ||
| MessageType messageType; | ||
| MessageHandler messageHandler; | ||
| boolean verbose;//true: only when verbose is true, false: ignores verbose flag and always prints | ||
| ERROR_EXTERNAL_XML_NOT_PARSABLE("error.external.xmlNotParsable", 2, MessageType.ERROR, MessageHandler.UX, false), | ||
| WARNING_MULTIPLE_METHOD_TARGET_MATCHES("warning.multipleMethodTargetMatches", 3, MessageType.WARNING, MessageHandler.UX, true), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created both new messages as warnings. The "multiple matches found" is verbose-only, the "no matches found" is always. |
||
| WARNING_NO_METHOD_TARGET_MATCHES("warning.noMethodTargetMatches", 2, MessageType.WARNING, MessageHandler.UX, false); | ||
|
|
||
| final String messageKey; | ||
| final int argCount; | ||
| final MessageType messageType; | ||
| final MessageHandler messageHandler; | ||
| final boolean verbose;//true: only when verbose is true, false: ignores verbose flag and always prints | ||
|
|
||
| EventKey(String messageKey, int argCount, MessageType messageType, MessageHandler messageHandler, boolean verbose) { | ||
| this.messageKey = messageKey; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,25 @@ | ||
| package sfdc.sfdx.scanner.messaging; | ||
| package com.salesforce.messaging; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically a copy of |
||
|
|
||
| import com.google.gson.Gson; | ||
| import static sfdc.sfdx.scanner.messaging.SfdxMessager.*; | ||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| public class Message { | ||
| private String messageKey; | ||
| private List<String> args; | ||
| private String internalLog; | ||
| private MessageType type; | ||
| private MessageHandler handler; | ||
| private boolean verbose; | ||
| private long time; | ||
| final private String messageKey; | ||
| final private List<String> args; | ||
| final private String internalLog; | ||
| final private MessageType type; | ||
| final private MessageHandler handler; | ||
| final private boolean verbose; | ||
| final private long time; | ||
|
|
||
| Message(String messageKey, List<String> args, String internalLog, MessageType type, MessageHandler handler, boolean verbose) { | ||
| this.messageKey = messageKey; | ||
| this.args = args; | ||
| this.internalLog = internalLog; | ||
| this.type = type; | ||
| this.handler = handler; | ||
| this.time = Instant.now().toEpochMilli(); | ||
| this.verbose = verbose; | ||
| } | ||
|
|
||
| String toJson() { | ||
| return new Gson().toJson(this); | ||
| this.time = Instant.now().toEpochMilli(); | ||
| } | ||
|
|
||
| public String getMessageKey() { | ||
|
|
@@ -40,4 +34,14 @@ public String getInternalLog() { | |
| return internalLog; | ||
| } | ||
|
|
||
| enum MessageHandler { | ||
| UX, | ||
| INTERNAL | ||
| } | ||
|
|
||
| enum MessageType { | ||
| INFO, | ||
| WARNING, | ||
| ERROR | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,24 @@ | ||
| package sfdc.sfdx.scanner.messaging; | ||
| package com.salesforce.messaging; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically a copy of |
||
|
|
||
| import com.google.common.base.Throwables; | ||
| import sfdc.sfdx.scanner.messaging.EventKey; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Internal exception representation. | ||
| * Extends RuntimeException to avoid declaring everywhere | ||
| * Handles capability to plug into SfdxMessager | ||
| * Handles capability to plug into CliMessager | ||
| */ | ||
| public class SfdxScannerException extends RuntimeException { | ||
| public class MessagePassableException extends RuntimeException { | ||
|
|
||
| private final EventKey eventKey; | ||
| private final String[] args; | ||
|
|
||
| public SfdxScannerException(EventKey eventKey, String... args) { | ||
| public MessagePassableException(EventKey eventKey, String... args) { | ||
| this(eventKey, null, args); | ||
| } | ||
|
|
||
| public SfdxScannerException(EventKey eventKey, Throwable throwable, String... args) { | ||
| public MessagePassableException(EventKey eventKey, Throwable throwable, String... args) { | ||
| super(throwable); | ||
|
|
||
| this.eventKey = eventKey; | ||
|
|
@@ -40,7 +39,7 @@ public String getFullStacktrace() { | |
|
|
||
| @Override | ||
| public String toString() { | ||
| return "SfdxScannerException{" + | ||
| return "MessagePassableException{" + | ||
| "eventKey=" + eventKey + | ||
| ", args=" + Arrays.toString(args) + | ||
| '}'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package sfdc.sfdx.scanner.messaging; | ||
| package com.salesforce.messaging; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically a copy of |
||
|
|
||
| import org.json.simple.JSONObject; | ||
| import org.json.simple.parser.JSONParser; | ||
|
|
@@ -12,7 +12,7 @@ | |
| import org.junit.runners.Parameterized; | ||
| import org.junit.runners.Parameterized.Parameters; | ||
|
|
||
| import static sfdc.sfdx.scanner.messaging.SfdxMessager.*; | ||
| import static com.salesforce.messaging.Message.*; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ module.exports = { | |
| "pmdSkippedFile": "PMD failed to evaluate against file '%s'. Message: %s", | ||
| "pmdSuppressedViolation": "PMD suppressed violation against file '%s'. Message: %s. Suppression Type: %s. User Message: %s", | ||
| "unexpectedPmdNodeType": "Encountered unexpected PMD node of type '%s'", | ||
| "multipleMethodTargetMatches": "Total of %s methods in file %s matched name #%s", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New messages. |
||
| "noMethodTargetMatches": "No methods in file %s matched name #%s()", | ||
| "pmdConfigError": "PMD failed to evaluate rule '%s'. Message: %s" | ||
| }, | ||
| "error": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,11 @@ module.exports = { | |
| "sevthresholdDescription": "throws an error when violations of specific severity (or more severe) are detected, invokes --normalize-severity", | ||
| "sevthresholdDescriptionLong": "Throws an error if violations are found with equal or greater severity than provided value. Values are 1 (high), 2 (moderate), and 3 (low). Exit code is the most severe violation. Using this flag also invokes the --normalize-severity flag", | ||
| "targetDescription": "location of source code", | ||
| "targetDescriptionLong": "Source code location. May use glob patterns. Multiple values can be specified as a comma-separated list" | ||
| "targetDescriptionLong": "Source code location. May use glob patterns, or specify individual methods with #-syntax. Multiple values can be specified as a comma-separated list" | ||
| }, | ||
| "validations": { | ||
| "methodLevelTargetCannotBeGlob": "Method-level targets supplied to --target cannot be globs", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New messages for validations of flags. |
||
| "methodLevelTargetMustBeRealFile": "Method-level target %s must be a real file", | ||
| "projectdirCannotBeGlob": "--projectdir cannot specify globs", | ||
| "projectdirMustBeDir": "--projectdir must specify directories", | ||
| "projectdirMustExist": "--projectdir must specify existing paths" | ||
|
|
@@ -37,6 +39,9 @@ module.exports = { | |
| Unix example: $ sfdx scanner:run:dfa --target './**/*.cls,!./**/IgnoreMe.cls' ... | ||
| Windows example: > sfdx scanner:run:dfa --target ".\\**\\*.cls,!.\\**\\IgnoreMe.cls" ... | ||
| Evaluate rules against all .cls files below the current directory, except for IgnoreMe.cls. | ||
| Individual methods within a file may be targeted by suffixing the file's path with a hash (#), and a semi-colon-delimited list of method names. This syntax is incompatible with globs and directories. | ||
| E.g., $ sfdx scanner:run:dfa --target "./File1.cls#Method1;Method2,./File2.cls#Method3" ... | ||
| Evaluates rules against ALL methods named Method1 or Method2 in File1.cls, and ALL methods named Method3 in File2.cls. | ||
| Use --normalize-severity to output a normalized (across all engines) severity (1 [high], 2 [moderate], and 3 [low]) in addition to the engine specific severity (when shown). | ||
| E.g., $ sfdx scanner:run:dfa --target "/some-project/" --projectdir "/some-project/" --format csv --normalize-severity | ||
| Use --severity-threshold to throw a non-zero exit code when rule violations of a specific normalized severity (or greater) are found. For this example, if there are any rule violations with a severity of 2 or more (which includes 1-high and 2-moderate), the exit code will be equal to the severity of the most severe violation. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically a copy of
pmd-cataloger/src/main/java/sfdc/sfdx/scanner/messaging/SfdxMessager.java.