Skip to content

Commit

Permalink
finally fix reports config on sonarlint extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas3oo committed Aug 17, 2024
1 parent 8874b12 commit bb124ed
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 54 deletions.
97 changes: 97 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,18 +1,115 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=javax.annotation.Nonnull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=javax.annotation.ParametersAreNonnullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.notowning=org.eclipse.jdt.annotation.NotOwning
org.eclipse.jdt.core.compiler.annotation.nullable=javax.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.annotation.owning=org.eclipse.jdt.annotation.Owning
org.eclipse.jdt.core.compiler.annotation.resourceanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompatibleOwningContract=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.insufficientResourceAnalysis=warning
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=ignore
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=11
56 changes: 40 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Apply the plugin to your project.

```gradle
plugins {
id 'se.solrike.sonarlint' version '2.0.0'
id 'se.solrike.sonarlint' version '2.1.0'
}
```

Gradle 7.0 or later must be used.
Gradle **7.5** or later must be used.


### Tasks in this plugin
Expand Down Expand Up @@ -104,16 +104,22 @@ dependencies {
}
```

To enable reports you currently have to enable that per task. E.g.
To enable reports you can configure the extension and/or individual tasks. E.g.

Groovy DSL:

```gradle
sonarlintMain {
sonarlint {
reports {
sarif.enabled = true // default false
}
}
sonarlintMain {
reports {
xml.enabled = true // default false
}
}
```


Expand Down Expand Up @@ -170,7 +176,7 @@ Kotlin DSL:
```Gradle Kotlin DSL
tasks.sonarlintMain {
reports {
reports.create("html") {
create("html") {
enabled.set(true)
}
}
Expand All @@ -197,7 +203,7 @@ This example has TypeScript code under `projects/` and `src/`
plugins {
id 'base'
id 'com.github.node-gradle.node' version '5.0.0'
id 'se.solrike.sonarlint' version '2.0.0'
id 'se.solrike.sonarlint' version '2.1.0'
}
repositories {
mavenCentral()
Expand Down Expand Up @@ -246,7 +252,7 @@ import se.solrike.sonarlint.*
plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.7.21"
id("se.solrike.sonarlint") version "2.0.0"
id("se.solrike.sonarlint") version "2.0.1-beta.1"
}
repositories {
Expand All @@ -270,6 +276,11 @@ dependencies {
sonarlint {
maxIssues.set(1)
reports {
create("sarif") {
enabled.set(true)
}
}
}
```
Expand All @@ -287,7 +298,7 @@ and `org.sonarsource.slang:sonar-scala-plugin:1.11.0.3905` and any additionally
```gradle
plugins {
id 'scala'
id 'se.solrike.sonarlint' version '2.0.0'
id 'se.solrike.sonarlint' version '2.1.0'
}
repositories {
Expand Down Expand Up @@ -325,7 +336,7 @@ Instead it has to be defined explicitly in the `build.gradle`.
```gradle
plugins {
id 'base'
id 'se.solrike.sonarlint' version '2.0.0'
id 'se.solrike.sonarlint' version '2.1.0'
}
repositories {
mavenCentral()
Expand All @@ -351,10 +362,11 @@ By default, this Gradle Plugin uses the [sonarlint core](https://github.com/Sona



|Gradle Plugin|sonarlint|
|-----:|-----:|
| 1.0.0| 8.0.2.42487|
| 2.0.0| 9.6.1.76766|
|Gradle Plugin|sonarlint|Gradle|
|-----:|-----:|-----:|
| 1.0.0| 8.0.2.42487|7.0|
| 2.0.0| 9.6.1.76766|7.0|
| 2.1.0| 9.6.1.76766|7.5|


## sonarlint rules
Expand All @@ -368,7 +380,7 @@ To list all the rules in your configured plugins you will have to create the tas

```gradle
plugins {
id 'se.solrike.sonarlint' version '2.0.0'
id 'se.solrike.sonarlint' version '2.1.0'
id 'com.github.node-gradle.node' version '5.0.0'
}
repositories {
Expand Down Expand Up @@ -623,7 +635,19 @@ You must install "SARIF SAST Scans Tab" from the marketplace into the Azure DevO
## Release notes
### 2.0.1 - unreleased
### 2.1.0
Minimum Gradle version is now 7.5.
It is now possible to enable reports using the sonarlint extension:
```gradle
sonarlint {
reports {
sarif.enabled = true // default false
}
}
```

Fix for issue https://github.com/Lucas3oo/sonarlint-gradle-plugin/issues/7. Contributed by [scscgit](https://github.com/scscgit). Correct samples for Kotlin DSL.

Fix for issue https://github.com/Lucas3oo/sonarlint-gradle-plugin/issues/9. Contributed by [Chris Ribble](https://github.com/chrisribble). Java sourceCompatibility property is now correctly read.
Expand Down Expand Up @@ -708,7 +732,7 @@ SARIF
A set of strings used to track the unique identity of the result. Code scanning uses partialFingerprints to accurately identify which results are the same across commits and branches.
Note: Code scanning only uses the primaryLocationLineHash.

"partialFingerprints": {
"partialFingerprints": {
"primaryLocationLineHash": "39fa2ee980eb94b0:1"
}

8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'eclipse'
id 'groovy'
// Apply the Plugin Publish Plugin to make plugin publication possible
id 'com.gradle.plugin-publish' version '1.0.0'
id 'com.gradle.plugin-publish' version '1.2.1'
id 'se.solrike.conventions.java-conventions' version '1.0.0-beta.7'
}

Expand All @@ -26,7 +26,7 @@ dependencies {
}

group = 'se.solrike.sonarlint'
version = '2.0.1-beta1'
version = '2.1.0'

sourceSets {
main {
Expand Down Expand Up @@ -85,7 +85,7 @@ gradlePlugin {
'The plugin supports Gradle configuration cache.\n' +
'The plugin can produce Spotbugs compatible XML reports and also SARIF which can be used by Github actions, Jenkins, ' +
'AWS CodeCatalyst and Azure DevOps.\n' +
'Min Gradle version 7.0.'
'Min Gradle version 7.5.'
}
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ pluginBundle {

// to upgrade the metainfo about which gradle version we shall use. Run ./gradlew wrapper after you have updated the version. The commit the new wrapper files except the gradlew.bat
wrapper {
gradleVersion = '7.5.1'
gradleVersion = '7.5'
}


Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/se/solrike/sonarlint/Sonarlint.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public abstract class Sonarlint extends SourceTask {
*
* @return the reports
*/
// if annotated with @Input then Gradle tries to fingerprint the reports and
// serialise it which will not work if you specify outputLocation which is a File object.
@Internal
public abstract NamedDomainObjectContainer<SonarlintReport> getReports();

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/se/solrike/sonarlint/SonarlintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class SonarlintPlugin implements Plugin<Project> {

private static final Logger sLogger = LoggerFactory.getLogger(SonarlintPlugin.class);
private static final GradleVersion SUPPORTED_VERSION = GradleVersion.version("7.0");
private static final GradleVersion SUPPORTED_VERSION = GradleVersion.version("7.5");

public static final String CONFIG_NAME = "sonarlint";
public static final String PLUGINS_CONFIG_NAME = "sonarlintPlugins";
Expand Down Expand Up @@ -123,8 +123,7 @@ protected TaskProvider<Sonarlint> createTask(Project project, SonarlintExtension
task.getRuleParameters().set(extension.getRuleParameters());
task.getShowIssues().set(extension.getShowIssues());
task.getReportsDir().set(extension.getReportsDir());
// below doesn't seesm to work
task.getReports().addAll(extension.getReports().getAsMap().values());
extension.getReports().whenObjectAdded(report -> task.getReports().add(report));
});

// let "check" task depend on sonarlint so it gets run automatically
Expand Down
Loading

0 comments on commit bb124ed

Please sign in to comment.