-
Notifications
You must be signed in to change notification settings - Fork 11
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
Use Gradle's Worker API #32
Conversation
@larsgrefer very cool :-) Can you agree to the terms of the Gradle CPD plugin Contributor License Agreement, also for this PR? I will review it asap. |
@aaschmid Some of the Tests in |
@larsgrefer hm ... yes I am aware of that change - seems that Gradle does not like unit tests ... However, another way is to get the actions of the task and execute these actions. Do you want to try? |
@larsgrefer Thanks for the work. It looks very well, already. Please don't be angry / afraid about all the review comments, I am happy to discuss them or even implement them myself if you prefer :-) |
Some of the tests (mostly the ones testing successful cases) could be refactored to directly use the new |
languageProperties, | ||
isSkipLexicalErrors(), | ||
isSkipDuplicateFiles(), | ||
new HashSet<>(getSource().getFiles()), |
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.
Would it be possible to hand over an Collections.unmodifiableSet
?
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.
It would be possible, but what would be the benefit?
IMHO an unmodifiable set is only interesting for sets which are used for a long time and which are accessed/shared by multiple components.
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.
Hm ... I thought more about the performance as copying the set is more expensive, even more on hugh projects ...
isSkipLexicalErrors(), | ||
isSkipDuplicateFiles(), | ||
new HashSet<>(getSource().getFiles()), | ||
new ArrayList(enabledReports), |
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.
Some here ...
reporter.generate(matches) | ||
logResult(matches) | ||
} | ||
if (isIgnoreLiterals()) { |
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.
Can these be always set using Boolean.toString
as for Tokenizer.OPTION_SKIP_BLOCKS
?
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'm not sure, I've just took the logic from here:
gradle-cpd-plugin/src/main/groovy/de/aaschmid/gradle/plugins/cpd/internal/CpdExecutor.groovy
Lines 100 to 110 in 17e3652
if (task.getIgnoreLiterals()) { | |
p.setProperty(Tokenizer.IGNORE_LITERALS, "true"); | |
} | |
if (task.getIgnoreIdentifiers()) { | |
p.setProperty(Tokenizer.IGNORE_IDENTIFIERS, "true"); | |
} | |
if (task.getIgnoreAnnotations()) { | |
p.setProperty(Tokenizer.IGNORE_ANNOTATIONS, "true"); | |
} | |
p.setProperty(Tokenizer.OPTION_SKIP_BLOCKS, Boolean.toString(task.getSkipBlocks())); | |
p.setProperty(Tokenizer.OPTION_SKIP_BLOCKS_PATTERN, task.getSkipBlocksPattern()); |
} else { | ||
throw new GradleException(message); | ||
} | ||
if (enabledReports.isEmpty()) { |
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.
hm ... we assume that it is no use case to only have a console output without details in a report, don't we?
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 test "wants" the task to throw an exception in this case, thats why I built it that way.
gradle-cpd-plugin/src/test/groovy/de/aaschmid/gradle/plugins/cpd/test/CpdAcceptanceTest.groovy
Lines 111 to 131 in 17e3652
def "executing 'Cpd' task throws wrapped 'InvalidUserDataException' if no report is enabled"() { | |
given: | |
project.cpdCheck{ | |
reports{ | |
csv.enabled = false | |
text.enabled = false | |
xml.enabled = false | |
} | |
source = testFile('.') | |
} | |
when: | |
project.tasks.getByName('cpdCheck').execute() | |
then: | |
!project.file('build/reports/cpdCheck.csv').exists() | |
def e = thrown(TaskExecutionException) | |
e.cause instanceof InvalidUserDataException | |
e.cause.message == '''Task 'cpdCheck' requires exactly one report to be enabled but was: [].''' | |
} |
} | ||
else { | ||
String message = "CPD found duplicate code."; | ||
SingleFileReport report = reports.get(0); |
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.
Should always return a report with the check and throw in Cpd
.
String message = "CPD found duplicate code."; | ||
SingleFileReport report = reports.get(0); | ||
if (report != null) { | ||
String reportUrl = report.getDestination().toString(); |
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.
What about the clickabeFileUrl
?
@@ -130,28 +130,6 @@ class CpdAcceptanceTest extends BaseSpec { | |||
e.cause.message == '''Task 'cpdCheck' requires exactly one report to be enabled but was: [].''' | |||
} | |||
|
|||
def "executing 'Cpd' task throws wrapped 'InvalidUserDataException' if more than one report is enabled"() { |
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.
Would it make sense to replace with an (integration-)test which enables two outputs and verify this?
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.
Thanks for the PR @larsgrefer. Would you mind to discuss my comments or change the code?
After merging the code, tests fail with an exception like the following. I will investigate further ...
|
Problem is that properties of |
Problem is that properties of Now a
|
* use-worker-api: add JDKs 10 and 11 for travis-ci test minimal possible toolVersion and fallback language remove deprecated API adjust minimal required PMD version create executor configuration and move to dedicated package (#38) add check methods for state of task before actually execute anything use serializable report configuration for CpdAction (#38) remove no longer required excludes remove unnecessary loggers for report implementations Use Gradle's Worker API (#32) use 'getByName' consistent to other test cases remove @optional for non-optional properties add integration test which really executes CPD add both test sourceSets to gradlePlugin
This removes the need for the classloading hack mentioned here:
gradle-cpd-plugin/src/main/groovy/de/aaschmid/gradle/plugins/cpd/Cpd.groovy
Line 183 in ed44ed7
As addition, the task can now run parallel to other tasks, and multiple reports can be generated at once.
See also: https://guides.gradle.org/using-the-worker-api/