Skip to content

Conversation

@jfeingold35
Copy link
Contributor

@jfeingold35 jfeingold35 commented Jun 1, 2022

This PR does the following:

  • Adds method-level targeting to scanner:run:dfa's --target flag. Syntax is path/to/file.cls#method1;method2.
  • Adds a new cli-messaging module that duplicates the functionality of the messaging package in pmd-cataloger.
  • Uses the new module to log messages when a method doesn't exist or has multiple matches.
  • Refactors CommandLineSupport and its child classes slightly.
  • Moves OutputProcessor.ts from pmd to services.

What it does NOT do:

  • Integrate the new module into pmd-cataloger. This will be done in a subsequent pull request. It was omitted this time because it lowers test coverage beyond acceptable minimum.

@@ -0,0 +1,99 @@
package com.salesforce.messaging;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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().

Copy link
Contributor

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:

  1. (Composition over inheritance)[https://en.wikipedia.org/wiki/Composition_over_inheritance] - this default implementation could be in a class outside of this hierarchy
  2. 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);
Copy link
Contributor Author

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,
Copy link
Contributor Author

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 () => {
Copy link
Contributor Author

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.

@jfeingold35 jfeingold35 marked this pull request as ready for review June 1, 2022 20:56
}

@Test
public void getTargetMethods_targetMethodInInnerAndOuterClass() {
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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.

const classpath = await this.buildClasspath();

const targetListFile = await this.createInputFile([this.createTargetJsons()]);
const sourceListFile = await this.createInputFile(this.projectDirs);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jfeingold35 jfeingold35 merged commit 5912f12 into dev-3 Jun 7, 2022
@jfeingold35 jfeingold35 mentioned this pull request Jun 7, 2022
@jfeingold35 jfeingold35 deleted the d/W-10759090-c branch June 23, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants