-
Notifications
You must be signed in to change notification settings - Fork 2
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
NEW(cpd): @W-16866836@: Add java_command and rule_langage configurability to cpd engine #123
Conversation
|
||
// Instead of throwing exceptions and causing the entire run to fail, instead we report exceptions as | ||
// if they are processing errors so that they can better be handled on the typescript side | ||
for (Exception ex : errorListener.exceptionsCaught) { |
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 noticed a bug in CPD and so I created pmd/pmd#5322. This bug actually prevented the engine from finishing across all languages since we just had java throw an exception which causes the engine to report the exception as a unexpected exception based violation.
But to improve the experience, so that CPD errors don't prevent us from finishing with other languages, I went ahead here and made the exceptions (messages + stack traces) show up as a special kind of processing error which then appears an ErrorEvent back to the CLI so that things continue and the error still gets reported.
This was a fix as you go item as I was self-QAing my own changes here.
|
||
export const PMD_ENGINE_CONFIG_DESCRIPTION: ConfigDescription = { | ||
overview: getMessage('PmdConfigOverview'), | ||
fieldDescriptions: { | ||
java_command: getMessage('PmdConfigFieldDescription_java_command'), | ||
rule_languages: getMessage('PmdConfigFieldDescription_rule_languages', PMD_AVAILABLE_LANGUAGES_TEXT), | ||
java_command: getMessage('SharedConfigFieldDescription_java_command', PMD_ENGINE_NAME), |
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 first tried to use PmdEngine.NAME and CpdEngine.NAME but the compiler had issues with the order of things being loaded (since then config.ts would depend on pmd-engine.ts and vice versa).
So to fix this, I just moved the names of these engines into the constants.ts file.
@@ -98,11 +138,56 @@ class PmdConfigValueExtractor { | |||
return javaCommand; | |||
} | |||
|
|||
private async attemptToAutoDetectJavaCommand(): Promise<string> { |
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.
Nothing new here... just moved this to a shared abstract class so that it could be reused for both cpd and pmd.
@@ -124,7 +126,7 @@ function createRuleForLanguage(languageId: LanguageId): RuleDescription { | |||
name: getRuleNameFromLanguage(languageId), | |||
severityLevel: SeverityLevel.Info, | |||
type: RuleType.MultiLocation, | |||
tags: [`${languageId}Language`], | |||
tags: ['Recommended', `${languageId}Language`], |
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.
Note: that we'll confirm this with John before going GA... but I am leaning towards Josh's preference here to just make these turned on by default with the 'Recommended' flag. Makes sense to me.
@@ -76,10 +87,10 @@ describe('Tests for the PmdCpdEnginesPlugin', () => { | |||
} | |||
}); | |||
|
|||
it(`When createEngineConfig for 'pmd' is given an empty raw config and if our attempt to look-up java on the users machine produces old java version, then error`, async () => { | |||
it.each(['cpd','pmd'])(`When createEngineConfig for '%s' is given an empty raw config and if our attempt to look-up java on the users machine produces old java version, then error`, async (engineName) => { |
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.
Reusing many tests using it.each - since it is the Abstract class that has most of the logic behind what is being tested with the java_command and rule_languages fields for both pmd and cpd.
"htmlLanguage" | ||
], | ||
"description": "Identify duplicate code blocks within your workspace files associated with the 'html' language.", | ||
"resourceUrls": [ | ||
"https://docs.pmd-code.org/latest/pmd_userdocs_cpd.html#refactoring-duplicates" | ||
] | ||
}, | ||
{ | ||
"name": "DetectCopyPasteForJava", |
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.
We might remove java support alltogether (still waiting to confirm with John). But for now, although still available, it isn't one of the default languages anymore.
171c18f
to
2b4a3e7
Compare
f75efb4
to
6969924
Compare
6969924
to
8b44b93
Compare
In this review: