Skip to content

Commit

Permalink
fix sonarlint and checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas3oo committed Dec 26, 2023
1 parent 42650b7 commit 73730df
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .settings/org.sonarlint.eclipse.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
autoEnabled=true
bindingSuggestionsDisabled=true
eclipse.preferences.version=1
3 changes: 3 additions & 0 deletions .theia/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Apply the plugin to your project.

```groovy
plugins {
id 'se.solrike.sonarlint' version '1.0.0-beta.15'
id 'se.solrike.sonarlint' version '1.0.0-beta.16'
}
```

Expand Down Expand Up @@ -166,7 +166,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 '1.0.0-beta.15'
id 'se.solrike.sonarlint' version '1.0.0-beta.16'
}
repositories {
mavenCentral()
Expand Down Expand Up @@ -213,7 +213,7 @@ Typical `gradle.build.kts`:
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 "1.0.0-beta.15"
id("se.solrike.sonarlint") version "1.0.0-beta.16"
}

repositories {
Expand Down Expand Up @@ -255,7 +255,7 @@ and `org.sonarsource.slang:sonar-scala-plugin:1.11.0.3905` and any additionally
```groovy
plugins {
id 'scala'
id 'se.solrike.sonarlint' version '1.0.0-beta.15'
id 'se.solrike.sonarlint' version '1.0.0-beta.16'
}
repositories {
Expand Down Expand Up @@ -293,7 +293,7 @@ Instead it has to be defined explicitly in the `build.gradle`.
```groovy
plugins {
id 'base'
id 'se.solrike.sonarlint' version '1.0.0-beta.15'
id 'se.solrike.sonarlint' version '1.0.0-beta.16'
}
repositories {
mavenCentral()
Expand Down Expand Up @@ -335,7 +335,7 @@ To list all the rules in your configured plugins you will have to create the tas

```groovy
plugins {
id 'se.solrike.sonarlint' version '1.0.0-beta.15'
id 'se.solrike.sonarlint' version '1.0.0-beta.16'
id 'com.github.node-gradle.node' version '5.0.0'
}
repositories {
Expand Down Expand Up @@ -590,6 +590,11 @@ You must install "SARIF SAST Scans Tab" from the marketplace into the Azure DevO
## Release notes
### 1.0.0-beta.16
Support for Gradle configuration cache <https://docs.gradle.org/current/userguide/configuration_cache.html>.
Contributed by <https://github.com/lukasgraef>.
### 1.0.0-beta.15
Fix bug in detecting CPU architecture for selecting correct node binaries.
Expand Down
68 changes: 9 additions & 59 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ plugins {
id 'groovy'
// Apply the Plugin Publish Plugin to make plugin publication possible
id 'com.gradle.plugin-publish' version '1.0.0'
id 'com.github.spotbugs' version '5.0.13'
id 'se.solrike.sonarlint' version '1.0.0-beta.14'
//id 'codenarc'
id 'se.solrike.conventions.java-conventions' version '1.0.0-beta.5'
}

repositories {
Expand All @@ -19,8 +17,6 @@ dependencies {
implementation('org.apache.commons:commons-text:1.10.0')
implementation('org.sonarsource.sonarlint.core:sonarlint-core:8.0.2.42487')

sonarlintPlugins 'org.sonarsource.java:sonar-java-plugin:7.17.0.31219'

testImplementation('org.mockito:mockito-core:3.7.7')
testImplementation('org.mockito:mockito-junit-jupiter:3.7.7')

Expand All @@ -31,14 +27,6 @@ dependencies {

group = 'se.solrike.sonarlint'
version = '1.0.0-beta.16'
sourceCompatibility = '11'
targetCompatibility = '11'

tasks.withType(GroovyCompile).configureEach {
configure(options) {
options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
}
}

sourceSets {
main {
Expand All @@ -61,64 +49,26 @@ groovydoc {
enabled = false
}

// folder names that ends with 'nosync' will not be synced to iCloud drive.
eclipse {
classpath {
def mainOutputDir = 'bin.nosync/main'
defaultOutputDir = file(mainOutputDir)
file {
whenMerged {
entries.findAll({it.kind == 'src'}).each {
if (it.path.contains('main') || it.path == '.apt_generated') {
it.output = mainOutputDir
}
else if (it.path.contains('test')) {
it.output = 'bin.nosync/test'
}
}
}
}
}
}

test {
useJUnitPlatform()
}

// Spotbugs
spotbugsMain {
effort = 'less' // 'default', 'less' or 'max'
excludeFilter = file('./plugin-config/spotbugs/exclude.xml')
ignoreFailures = true
showStackTraces = false
dependencies {
// http://find-sec-bugs.github.io
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.4.7'
spotbugs 'com.github.spotbugs:spotbugs:4.7.1'
}
reports {
html.enabled = true
sarif.enabled = true
}
}
spotbugsTest {
enabled = false
}

sonarlintMain {
reports {
html.enabled = true
sarif.enabled = true
}
ignoreFailures = true
ignoreFailures = false
}
sonarlintTest {
reports {
sarif.enabled = true
}
ignoreFailures = false
}

spotbugsMain {
ignoreFailures = true
}
spotbugsTest {
enabled = false
}


// publish the plugin like: ./gradlew publishPlugins
Expand Down
49 changes: 0 additions & 49 deletions plugin-config/spotbugs/exclude.xml

This file was deleted.

30 changes: 20 additions & 10 deletions src/main/java/se/solrike/sonarlint/Sonarlint.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.gradle.api.GradleException;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
Expand All @@ -14,7 +16,11 @@
import org.gradle.api.file.FileTree;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.logging.Logger;
import org.gradle.api.provider.*;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.Input;
Expand All @@ -30,8 +36,6 @@
import se.solrike.sonarlint.impl.ReportAction;
import se.solrike.sonarlint.impl.SonarlintAction;

import javax.inject.Inject;

/**
* Gradle task to execute sonarlint stand alone code analysis.
*
Expand All @@ -41,6 +45,7 @@ public abstract class Sonarlint extends SourceTask {

private FileCollection mCompileClasspath;
private FileCollection mClassFiles;
private final SonarlintAction mAction;

/**
* List of rules to exclude from the analysis. E.g 'java:S1186'.
Expand Down Expand Up @@ -156,21 +161,23 @@ public FileTree getSource() {
@Internal
protected abstract SetProperty<File> getSonarlintConfiguration();

@SuppressWarnings("java:S5993")
public Sonarlint() {
action = new SonarlintAction(this);
Provider<Set<ResolvedArtifactResult>> artifactProvider = getProject().getConfigurations().named(SonarlintPlugin.PLUGINS_CONFIG_NAME).flatMap(c -> c.getIncoming().getArtifacts().getResolvedArtifacts());
getSonarlintConfiguration().set(artifactProvider.map(p -> p.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toSet())));
mAction = new SonarlintAction(this);
Provider<Set<ResolvedArtifactResult>> artifactProvider = getProject().getConfigurations()
.named(SonarlintPlugin.PLUGINS_CONFIG_NAME)
.flatMap(c -> c.getIncoming().getArtifacts().getResolvedArtifacts());
getSonarlintConfiguration()
.set(artifactProvider.map(p -> p.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toSet())));
}

private final SonarlintAction action;

@TaskAction
public void run() {
Logger logger = getLogger();

logTaskParameters();

List<IssueEx> issues = action.run(this, getSonarlintConfiguration(), getProjectLayout());
List<IssueEx> issues = mAction.run(this, getSonarlintConfiguration(), getProjectLayout());

String resultMessage = String.format("%d SonarLint issue(s) were found. Max issue(s) allowed: %d.", issues.size(),
getMaxIssues().getOrElse(0));
Expand Down Expand Up @@ -206,7 +213,10 @@ private void logTaskParameters() {
getLogger().debug("Source: {}", getSource().getAsPath());
getLogger().debug("Source files: {}", getSource().getAsFileTree().getFiles());
getLogger().debug("IsTestSource: {}", getIsTestSource().getOrElse(Boolean.FALSE));
String sonarlintPlugins = getSonarlintConfiguration().get().stream().map(File::getName).reduce("", (p1, p2) -> p1 + ", " + p2 );
String sonarlintPlugins = getSonarlintConfiguration().get()
.stream()
.map(File::getName)
.reduce("", (p1, p2) -> p1 + ", " + p2);
getLogger().debug("Plugins: {}", sonarlintPlugins);
getLogger().debug("<<< SonarLint task " + getName());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/se/solrike/sonarlint/SonarlintListRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int compare(StandaloneRuleDetails rule1, StandaloneRuleDetails rule2) {

// if the key is like java:S1176 then it has a numeric "id" in it that we can sort on.
boolean keyHasId(String key) {
return key.matches(".*:S[0-9]+");
return key.matches(".*:S\\d+");
}

// must be on form similar to java:S1176
Expand Down
Loading

0 comments on commit 73730df

Please sign in to comment.