Skip to content
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

Adding possibility for sputnik to load additional SpotBugs plugins like find-sec-bugs #229

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1a4f193
Publish workflow testing
SpOOnman Jan 8, 2021
3ecbf13
Publish workflow testing - signing
SpOOnman Jan 8, 2021
5738946
Publish workflow testing - signing 2
SpOOnman Jan 8, 2021
8ca43e5
Publish workflow testing - signing 3
SpOOnman Jan 8, 2021
fd550b6
Publish workflow testing - signing 4
SpOOnman Jan 11, 2021
44a165d
Publish workflow testing - signing 5
SpOOnman Jan 11, 2021
5fb31c0
Publish workflow testing - signing 6
SpOOnman Jan 11, 2021
258c78b
Publish workflow testing - signing 7
SpOOnman Jan 11, 2021
f6aabbc
Publish workflow testing - signing 8
SpOOnman Jan 11, 2021
4ce0796
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Jan 11, 2021
26c009f
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Jan 11, 2021
439ae15
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Jan 11, 2021
85dd88f
Merge remote-tracking branch 'origin/master'
Jan 12, 2021
3654b91
Clear imports
fipciu1996 Jan 12, 2021
f0ae5b0
Improving method to get SpotBugs Plugins
fipciu1996 Jan 12, 2021
2b8a950
Improving method to get SpotBugs Plugins
fipciu1996 Jan 12, 2021
5f9d4d7
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Mar 24, 2021
1f26597
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Mar 24, 2021
dc08e71
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Mar 25, 2021
80a134a
Adding possibility for sputnik to load additional SpotBugs plugins li…
fipciu1996 Mar 25, 2021
ce47479
Merge branch 'master' into master
fipciu1996 Mar 25, 2021
ee51538
Reformat build.gradle to us spaces like before
May 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Publish package to the Maven Central Repository
on:
release:
types: [created]
workflow_dispatch:
inputs:
nextVersion:
description: 'Next version number'
required: true
default: '2.3.1'
jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -11,8 +15,16 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Current version
run: ./gradlew currentVersion
- name: Mark next version
run: ./gradlew markNextVersion -Prelease.version=${{ github.event.inputs.nextVersion }}
- name: Release
run: ./gradlew release
- name: Release version
run: ./graldew currentVersion
- name: Publish package
run: gradle publish
run: ./gradlew publish
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pmd.ruleSets=rulesets/java/android.xml,rulesets/java/basic.xml
spotbugs.enabled=true
spotbugs.includeFilter=
spotbugs.excludeFilter=
spotbugs.plugins.location=/opt/sputnik/SpotBugsPlugins
codenarc.enabled=true
codenarc.ruleSets=
codenarc.excludes=**/*.java
Expand Down
Binary file added SpotBugsPlugins/findsecbugs-plugin-1.11.0.jar
Binary file not shown.
22 changes: 17 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ configurations {
}
}

project.version = '2.3.1.1' //scmVersion.version
project.version = scmVersion.version

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -181,6 +181,20 @@ java {
withSourcesJar()
}

distZip {
into(project.name + "-" + project.version) {
from '.'
include 'SpotBugsPlugins/*'
}
}

distTar {
into(project.name + "-" + project.version) {
from '.'
include 'SpotBugsPlugins/*'
}
}

jar {
manifest {
attributes("Specification-Title": "Sputnik",
Expand All @@ -204,7 +218,7 @@ publishing {
pom {
groupId = 'pl.touk'
name = 'Sputnik'
description = 'Static code review for your Gerrit and Stash patchsets. Runs Checkstyle, PMD and SpotBugs for you!'
description = 'Static code review for your Gerrit and Stash patchsets. Runs Checkstyle, PMD and SpotBugs for you!'
url = 'https://github.com/TouK/sputnik/'
scm {
url = 'scm:[email protected]:TouK/sputnik.git'
Expand Down Expand Up @@ -234,8 +248,6 @@ publishing {
}

signing {
def signingKey = System.getenv('SIGNING_KEY')
def signingPassword = System.getenv('SIGNING_PASSWORD')
useInMemoryPgpKeys(signingKey, signingPassword)
useInMemoryPgpKeys(System.getenv('SIGNING_KEY'), System.getenv('SIGNING_PASSWORD'))
sign publishing.publications.mavenJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum GeneralOption implements ConfigurationOption {
SPOTBUGS_ENABLED("spotbugs.enabled", "SpotBugs enabled", "false"),
SPOTBUGS_INCLUDE_FILTER("spotbugs.includeFilter", "SpotBugs include filter file", ""),
SPOTBUGS_EXCLUDE_FILTER("spotbugs.excludeFilter", "SpotBugs exclude filter file", ""),
SPOTBUGS_PLUGINS_LOCATION("spotbugs.plugins.location", "SpotBugs plugins path to jar files", "SpotBugsPlugins"),

SCALASTYLE_ENABLED("scalastyle.enabled", "ScalaStyle enabled", "false"),
SCALASTYLE_CONFIGURATION_FILE("scalastyle.configurationFile", "ScalaStyle configuration file", ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
import edu.umd.cs.findbugs.DetectorFactoryCollection;
import edu.umd.cs.findbugs.FindBugs2;
import edu.umd.cs.findbugs.IClassScreener;
import edu.umd.cs.findbugs.Plugin;
import edu.umd.cs.findbugs.PluginException;
import edu.umd.cs.findbugs.Priorities;
import edu.umd.cs.findbugs.Project;
import edu.umd.cs.findbugs.config.UserPreferences;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,9 +29,11 @@

@Slf4j
public class SpotBugsProcessor implements ReviewProcessor {

private static final String SOURCE_NAME = "SpotBugs";

private final CollectorBugReporter collectorBugReporter;

private final Configuration config;

public SpotBugsProcessor(@NotNull Configuration configuration) {
Expand Down Expand Up @@ -53,6 +61,7 @@ public String getName() {
}

public FindBugs2 createFindBugs2(Review review) {
loadAllSpotbugsPlugins();
FindBugs2 findBugs = new FindBugs2();
findBugs.setProject(createProject(review));
findBugs.setBugReporter(collectorBugReporter);
Expand Down Expand Up @@ -121,4 +130,23 @@ private String getExcludeFilterFilename() {
log.info("Using SpotBugs exclude filter file {}", excludeFilterFilename);
return excludeFilterFilename;
}

private void loadAllSpotbugsPlugins() {
String pluginsLocation = config.getProperty(GeneralOption.SPOTBUGS_PLUGINS_LOCATION);
if (pluginsLocation != null) {
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
File[] pluginsList = new File(pluginsLocation).listFiles();
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
for (File plugin : Objects.requireNonNull(pluginsList)) {
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
if (plugin.getName().contains(".jar")) {
log.info("SpotBugs additional plugin loading: file://{}", plugin);
try {
Plugin.getAllPlugins().add(Plugin.addCustomPlugin(new URI("file://" + plugin.getAbsoluteFile())));
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
} catch (PluginException e) {
log.info("Spotbugs additional plugins not loaded {} plugin not supported", e.getMessage());
} catch (URISyntaxException e) {
log.info("Spotbugs additional plugins not loaded {} check path", e.getMessage());
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pmd.showViolationDetails=true
spotbugs.enabled=true
spotbugs.includeFilter=
spotbugs.excludeFilter=
spotbugs.plugins.location=

scalastyle.enabled=true
scalastyle.configurationFile=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package pl.touk.sputnik.processor.spotbugs;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import edu.umd.cs.findbugs.Plugin;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import pl.touk.sputnik.TestEnvironment;
Expand All @@ -11,9 +12,6 @@
import pl.touk.sputnik.review.ReviewFile;
import pl.touk.sputnik.review.ReviewFormatterFactory;
import pl.touk.sputnik.review.ReviewResult;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class SpotBugsProcessorTest extends TestEnvironment {
Expand Down Expand Up @@ -54,4 +52,10 @@ void shouldReturnEmptyWhenNoFilesToReview() {
assertThat(reviewResult.getViolations()).isEmpty();
}

@Test
void shouldLoadSpotbugsPlugins() {
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
spotBugsProcessor.createFindBugs2(nonExistentReview());
assertThat(Plugin.getAllPlugins()).isNotEmpty();
}

}
1 change: 1 addition & 0 deletions src/test/resources/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pmd.ruleSets=rulesets/java/android.xml,rulesets/java/basic.xml,rulesets/java/bra
spotbugs.enabled=true
spotbugs.includeFilter=
spotbugs.excludeFilter=
spotbugs.plugins.location=SpotBugsPlugins
fipciu1996 marked this conversation as resolved.
Show resolved Hide resolved
jslint.enabled=true
scalastyle.configurationFile=src/test/resources/scalastyle.xml
jshint.enabled=true