From f501e6c073da1e938bfdbceaf966839bef1a8b40 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 13 Jul 2018 00:39:21 -0700 Subject: [PATCH] Added spotbugs settings & annotations. --- build.gradle | 74 +++++++------------ config/spotbugs/excludefilter.xml | 14 ++++ .../net/thauvin/erik/mobibot/Mobibot.java | 10 ++- .../thauvin/erik/mobibot/TwitterOAuth.java | 4 +- .../mobibot/modules/CurrencyConverter.java | 2 + 5 files changed, 54 insertions(+), 50 deletions(-) create mode 100644 config/spotbugs/excludefilter.xml diff --git a/build.gradle b/build.gradle index 2fbd869..ebf7053 100644 --- a/build.gradle +++ b/build.gradle @@ -1,48 +1,28 @@ plugins { - id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.4" + id 'java' + id 'idea' + id 'application' id "com.github.ben-manes.versions" version "0.20.0" - id "org.owasp.dependencycheck" version "3.2.1" + id "org.owasp.dependencycheck" version "3.2.1" + id "net.thauvin.erik.gradle.semver" version "0.9.6-beta" + id "com.github.spotbugs" version "1.6.2" } -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'application' + +import com.github.spotbugs.SpotBugsTask defaultTasks 'deploy' final def packageName = 'net.thauvin.erik.mobibot' final def deployDir = 'deploy' def isRelease = 'release' in gradle.startParameter.taskNames -final def semverJar = 'net.thauvin.erik:semver:1.0.1' - -def getVersion(isIncrement = false) { - final def propsFile = 'version.properties' - final def majorKey = 'version.major' - final def minorKey = 'version.minor' - final def patchKey = 'version.patch' - final def metaKey = 'version.buildmeta' - final def preKey = 'version.prerelease' - if (isIncrement) { - ant.propertyfile(file: propsFile) { - entry(key: patchKey, - type: 'int', - default: '-1', - operation: '+') - } - } - def p = new Properties() - file(propsFile).withInputStream { final stream -> p.load(stream) } - final def metadata = p.getProperty(metaKey, '') - final def prerelease = p.getProperty(preKey, '') - return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + - (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) -} - -version = getVersion() +final def semverProcessor = "net.thauvin.erik:semver:1.1.0-beta" mainClassName = packageName + '.Mobibot' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated") + repositories { mavenLocal() mavenCentral() @@ -50,6 +30,9 @@ repositories { } dependencies { + annotationProcessor semverProcessor + compileOnly semverProcessor + compile 'pircbot:pircbot:1.5.0' compileOnly 'pircbot:pircbot:1.5.0:sources' @@ -62,7 +45,7 @@ dependencies { compile 'commons-net:commons-net:3.6' compile 'com.squareup.okhttp3:okhttp:3.10.0' - compile 'com.rometools:rome:1.10.0' + compile 'com.rometools:rome:1.11.0' compile 'org.json:json:20180130' compile 'org.ostermiller:utils:1.07.00' @@ -75,24 +58,27 @@ dependencies { // https://bitbucket.org/akapribot/owm-japis compile files('lib/owm-japis-2.5.0.5.jar') - compileOnly semverJar - testCompile 'org.testng:testng:6.14.3' testCompile 'org.assertj:assertj-core:3.10.0' + + spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.8.0' + compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.5' } test { useTestNG() } -annotationProcessor { - project.version = getVersion(isRelease) - library semverJar - processor 'net.thauvin.erik.semver.VersionProcessor' +tasks.withType(SpotBugsTask) { + reports { + xml.enabled = false + html.enabled = true + } + excludeFilter = file("$projectDir/config/spotbugs/excludeFilter.xml") } compileJava { - options.compilerArgs << '-proc:none' << '-Xlint:unchecked' << '-Xlint:deprecation' + options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' } javadoc { @@ -139,11 +125,7 @@ task deploy(dependsOn: ['build']) { mustRunAfter clean } - task release(dependsOn: ['wrapper', 'clean', 'deploy']) { - doLast { - group = 'Publishing' - description = 'Releases new version.' - isRelease = true - } -} \ No newline at end of file + group = 'Publishing' + description = 'Releases new version.' +} diff --git a/config/spotbugs/excludefilter.xml b/config/spotbugs/excludefilter.xml new file mode 100644 index 0000000..f7e9cce --- /dev/null +++ b/config/spotbugs/excludefilter.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index f26cb20..c1e6d01 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -32,6 +32,7 @@ package net.thauvin.erik.mobibot; import com.rometools.rome.io.FeedException; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.modules.*; import net.thauvin.erik.semver.Version; import org.apache.commons.cli.*; @@ -294,15 +295,16 @@ public class Mobibot extends PircBot { * * @param args The command line arguments. */ + @SuppressFBWarnings(value = {"INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE", "DM_DEFAULT_ENCODING"}) public static void main(final String[] args) { // Setup the command line options final Options options = new Options(); options.addOption(Commands.HELP_ARG.substring(0, 1), Commands.HELP_ARG, false, "print this help message"); options.addOption(Commands.DEBUG_ARG.substring(0, 1), Commands.DEBUG_ARG, false, - "print debug & logging data directly to the console"); + "print debug & logging data directly to the console"); options.addOption(Option.builder( - Commands.PROPS_ARG.substring(0, 1)).hasArg().argName("file").desc("use " + "alternate properties file") - .longOpt(Commands.PROPS_ARG).build()); + Commands.PROPS_ARG.substring(0, 1)).hasArg().argName("file").desc("use " + "alternate properties file") + .longOpt(Commands.PROPS_ARG).build()); options.addOption(Commands.VERSION_ARG.substring(0, 1), Commands.VERSION_ARG, false, "print version info"); // Parse the command line @@ -418,6 +420,7 @@ public class Mobibot extends PircBot { /** * Connects to the server and joins the channel. */ + @SuppressFBWarnings(value = {"DM_EXIT", "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE"}) public final void connect() { try { connect(ircServer, ircPort); @@ -1287,6 +1290,7 @@ public class Mobibot extends PircBot { /** * {@inheritDoc} */ + @SuppressFBWarnings(value = "DM_EXIT", justification = "Yes, we want to bail out.") @Override protected final void onPrivateMessage(final String sender, final String login, diff --git a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java index 71e2e26..7796453 100644 --- a/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java +++ b/src/main/java/net/thauvin/erik/mobibot/TwitterOAuth.java @@ -1,5 +1,6 @@ package net.thauvin.erik.mobibot; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.auth.AccessToken; @@ -27,8 +28,9 @@ import java.io.InputStreamReader; * @since 1.0 */ public final class TwitterOAuth { + @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING") public static void main(final String[] args) - throws Exception { + throws Exception { if (args.length == 2) { final twitter4j.Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(args[0], args[1]); diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.java b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.java index b6a2f60..2cb3a5e 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.java @@ -31,6 +31,7 @@ */ package net.thauvin.erik.mobibot.modules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.Utils; import org.jdom2.Document; @@ -114,6 +115,7 @@ final public class CurrencyConverter extends AbstractModule { /** * Converts the specified currencies. */ + @SuppressFBWarnings(value = "REDOS") private void run(final Mobibot bot, final String sender, final String query) { if (Utils.isValidString(sender)) { if (EXCHANGE_RATES.isEmpty()) {