Skip to content

Introduce tooling api module #2861

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

Merged
merged 69 commits into from
Jul 15, 2020
Merged

Introduce tooling api module #2861

merged 69 commits into from
Jul 15, 2020

Conversation

arturbosch
Copy link
Member

@arturbosch arturbosch commented Jul 12, 2020

Sorry for the huge PR upfront. Please review this commit by commit.

I want to make this right without a breaking change and an API which will work for the gradle, sonar, maven, bazel, intellij and cli integrations of the core module.

Why an extra tooling api?

  • All mentioned integrations use core directly via the horrible ProcessingSettings class.
  • cli is/(was) more core than core
  • Introduce tooling-api #2860

Notable additional changes in this PR:

  • Running a specified single rule is supported by the tooling api. Cli's SingleRunner implementation was removed.
  • KtFileModifier is now just an extension and has no special treatment in the core classes.
  • ProcessingSettings is still public but only used internally in core. We can better refactor/remove this class in the future. Edit: I've refactored the class.
  • core decides when to fail the build via a MaxIssuePolicy sealed class.
  • UnstableApi annotation now has a reason property.
  • createRunner test helper which uses NullPrintStream by default.
  • formatting module does not depend on core anymore!

Usages:

@codecov
Copy link

codecov bot commented Jul 12, 2020

Codecov Report

Merging #2861 into master will decrease coverage by 0.49%.
The diff coverage is 80.51%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2861      +/-   ##
============================================
- Coverage     80.78%   80.28%   -0.50%     
- Complexity     2346     2417      +71     
============================================
  Files           388      421      +33     
  Lines          7050     7359     +309     
  Branches       1288     1346      +58     
============================================
+ Hits           5695     5908     +213     
- Misses          709      756      +47     
- Partials        646      695      +49     
Impacted Files Coverage Δ Complexity Δ
...n/io/gitlab/arturbosch/detekt/api/ConsoleReport.kt 100.00% <ø> (ø) 5.00 <0.00> (ø)
.../kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt 100.00% <ø> (ø) 3.00 <0.00> (-5.00)
.../io/gitlab/arturbosch/detekt/cli/Configurations.kt 0.00% <0.00%> (-84.62%) 0.00 <0.00> (ø)
...in/kotlin/io/gitlab/arturbosch/detekt/core/Junk.kt 60.00% <ø> (+16.25%) 0.00 <0.00> (ø)
...io/gitlab/arturbosch/detekt/core/KtFileModifier.kt 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...arturbosch/detekt/core/baseline/BaselineHandler.kt 72.22% <ø> (ø) 15.00 <0.00> (ø)
...kt/core/config/DefaultPropertiesConfigValidator.kt 100.00% <ø> (ø) 1.00 <0.00> (ø)
...itlab/arturbosch/detekt/core/extensions/Loading.kt 66.66% <ø> (+66.66%) 0.00 <0.00> (ø)
...tlab/arturbosch/detekt/core/reporting/Colorizer.kt 76.92% <0.00%> (ø) 0.00 <0.00> (ø)
...otlin/io/gitlab/arturbosch/detekt/cli/CliRunner.kt 7.14% <7.14%> (ø) 1.00 <1.00> (?)
... and 129 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 265b217...ffcde93. Read the comment docs.

@BraisGabin BraisGabin self-requested a review July 12, 2020 11:50
Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't continue with the review right now. I leave the current comments and I'll try to finish the review this nigh or tomorrow.

I really like this refecator. Great job!

@arturbosch
Copy link
Member Author

I'm not sure why jacoco fails on detekt-core with Java8 but I can reproduce this locally...

@arturbosch
Copy link
Member Author

arturbosch commented Jul 12, 2020

I'm not sure why jacoco fails on detekt-core with Java8 but I can reproduce this locally...

This is a really strange one!
The stacktrace on the console is:

2020-07-12-214325_1302x228_scrot

But taking a look at the gradle test report I get:

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 15.
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/commons/util/BlacklistedExceptions
	at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:187)
	at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:168)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	... 25 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.BlacklistedExceptions
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 32 more

So Gradle can't find org.junit.platform.commons.util.BlacklistedExceptions at runtime.

Now I stumbled upon this issue junit-team/junit5#2322 ....

@BraisGabin BraisGabin mentioned this pull request Jul 12, 2020
Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Huge, but really good. ProcessingSettings is kind of a god class but I think that we can think about it later.

@@ -14,7 +14,7 @@ private data class Color(private val value: Byte) {
get() = "$ESC[${value}m"
}

private val isColoredOutputSupported: Boolean = !IS_WINDOWS
private val isColoredOutputSupported: Boolean = !SystemInfo.isWindows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@arturbosch arturbosch marked this pull request as ready for review July 14, 2020 12:57
@arturbosch
Copy link
Member Author

arturbosch commented Jul 14, 2020

I've fixed the build/classloader issue.
The PR is ready.
I will try to increase the code coverage now.

Edit: the code coverage changes on rules modules are buggy in this PR and should not decrease on master.

@arturbosch arturbosch added this to the 1.11.0 milestone Jul 14, 2020
@BraisGabin
Copy link
Member

Should we deprecate Main.buildRunner() from :detekt-cli?

@arturbosch
Copy link
Member Author

Should we deprecate Main.buildRunner() from :detekt-cli?

Already done :)

@NotApiButProbablyUsedByUsers
@Deprecated(
"Don't build a runner yourself.",
ReplaceWith(
"DetektCli.load().run(args, outputPrinter, errorPrinter)",
"io.github.detekt.tooling.api.DetektCli"
)
)
fun buildRunner(

@BraisGabin
Copy link
Member

Should we deprecate Main.buildRunner() from :detekt-cli?

Already done :)

@NotApiButProbablyUsedByUsers
@Deprecated(
"Don't build a runner yourself.",
ReplaceWith(
"DetektCli.load().run(args, outputPrinter, errorPrinter)",
"io.github.detekt.tooling.api.DetektCli"
)
)
fun buildRunner(

ups! my bad. I had this as an annotation in my note book from when I did the code review and I forgot to comment it at that moment and then I didn't recheck.

@arturbosch arturbosch merged commit 5a0fe62 into master Jul 15, 2020
@arturbosch arturbosch deleted the tooling-api branch July 15, 2020 17:55
@arturbosch arturbosch modified the milestones: 1.11.0, 1.10.1 Aug 2, 2020
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.

2 participants