-
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
Conversation
| @@ -0,0 +1,99 @@ | |||
| package com.salesforce.messaging; | |||
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.
| @@ -0,0 +1,59 @@ | |||
| package com.salesforce.messaging; | |||
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/messaging/EventKey.java.
| @@ -0,0 +1,47 @@ | |||
| package com.salesforce.messaging; | |||
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/messaging/Message.java.
| @@ -0,0 +1,47 @@ | |||
| package com.salesforce.messaging; | |||
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/messaging/SfdxScannerException.java.
| @@ -0,0 +1,126 @@ | |||
| package com.salesforce.messaging; | |||
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/test/java/sfdc/sfdx/messaging/EventKeyTest.java.
| cp.stderr.on('data', data => { | ||
| stderr += data; | ||
| }); | ||
| protected abstract handleResults(args: ResultHandlerArgs): void; |
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.
New abstract method for doing any weird stuff that must be done with results.
| rej(stderr); | ||
| } | ||
| }); | ||
| protected defaultResultHandler(args: ResultHandlerArgs): void { |
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.
Default implementation of abstract method. Most of the implementers will just call super.defaultResultHandler().
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.
This feels a little awkward to me since this abstract method's implementations are invoking another protected non-final method, which is at the same level as the abstract method's definition. Could possibly lead to cyclic invocations if defaultResultHandler() is overridden.
A few common patterns we could consider in this case:
- (Composition over inheritance)[https://en.wikipedia.org/wiki/Composition_over_inheritance] - this default implementation could be in a class outside of this hierarchy
- Creating hooks to call additional steps before/after the default steps are done
|
|
||
| try { | ||
| const output = await SfgeWrapper.runSfge(targetPaths, rules, JSON.parse(engineOptions.get(CUSTOM_CONFIG.SfgeConfig)) as SfgeConfig); | ||
| const output = await SfgeWrapper.runSfge(targets, rules, JSON.parse(engineOptions.get(CUSTOM_CONFIG.SfgeConfig)) as SfgeConfig); |
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.
Passing the targets instead of just the path components.
| type: 'INFO', | ||
| handler: 'UX', | ||
| verbose: false, | ||
| messageKey: eventTemplateKey, |
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.
Formatting changes done by IntelliJ without my consent.
| expect(results[0].paths.length).to.equal(2, 'Wrong number of paths matched'); | ||
| }); | ||
|
|
||
| it('Positive method-level targets are properly matched', async () => { |
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.
New unit test for method-level targeting.
| } | ||
|
|
||
| @Test | ||
| public void getTargetMethods_targetMethodInInnerAndOuterClass() { |
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.
Test case: A method that exists in both inner and outer class. QUESTION: The syntax here would be path/to/file.cls#methodName, and it would return both the inner and outer class methods. Are we okay with that? I'm okay with that for now, and we can change it if people complain.
| } | ||
|
|
||
| @Test | ||
| public void getTargetMethods_targetMethodInInnerClass() { |
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.
Test case: Targeting a method in an inner class. As noted below, the syntax would be path/to/file.cls#methodName, without including the inner class.
src/lib/sfge/SfgeWrapper.ts
Outdated
| const classpath = await this.buildClasspath(); | ||
|
|
||
| const targetListFile = await this.createInputFile([this.createTargetJsons()]); | ||
| const sourceListFile = await this.createInputFile(this.projectDirs); |
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.
While QA'g this as an internal implementation, we had a discussion around passing a single file with both target and source instead of separate files but didn't have an iteration to make the changes. Could you address it with these changes? A single input file would help us move towards a configuration of sorts for executing SFGE.
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.
I'll see what I can do.
…e-passing system to allow for proper logging.
…aloger and increase test coverage as necessary.
…etter readability.
d8b895a to
8882d41
Compare
This PR does the following:
scanner:run:dfa's--targetflag. Syntax ispath/to/file.cls#method1;method2.cli-messagingmodule that duplicates the functionality of themessagingpackage inpmd-cataloger.CommandLineSupportand its child classes slightly.OutputProcessor.tsfrompmdtoservices.What it does NOT do:
pmd-cataloger. This will be done in a subsequent pull request. It was omitted this time because it lowers test coverage beyond acceptable minimum.