Skip to content

Commit

Permalink
Follow latest version automatically (spotbugs#195)
Browse files Browse the repository at this point in the history
* upgrade Gradle to use WriteProperties task

* use resource to follow the latest release automatically

* fix test for classes built by Java7
  • Loading branch information
KengoTODA authored and henrik242 committed Jun 8, 2017
1 parent ad4399b commit 6084506
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ subprojects {
}

wrapper {
gradleVersion = '3.2.1'
gradleVersion = '3.5'
distributionType = Wrapper.DistributionType.ALL
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
1 change: 1 addition & 0 deletions gradlePlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/main/resources/spotbugs-gradle-plugin.properties
7 changes: 7 additions & 0 deletions gradlePlugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ pluginBundle {
}
}
}

task processVersionFile(type: WriteProperties) {
outputFile file('src/main/resources/spotbugs-gradle-plugin.properties')

property 'spotbugs-version', project(':spotbugs').version
}
tasks.processResources.dependsOn processVersionFile
22 changes: 20 additions & 2 deletions gradlePlugin/src/main/java/com/github/spotbugs/SpotBugsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.github.spotbugs;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collection;
import java.util.Properties;
import java.util.concurrent.Callable;

import org.gradle.api.Action;
Expand All @@ -15,6 +20,8 @@
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.SourceSet;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.io.Resources;
import com.google.common.util.concurrent.Callables;

/**
Expand All @@ -33,7 +40,6 @@
*/
public class SpotBugsPlugin extends AbstractCodeQualityPlugin<SpotBugsTask> {

public static final String DEFAULT_FINDBUGS_VERSION = "3.1.0-RC2";
private FindBugsExtension extension;

@Override
Expand Down Expand Up @@ -61,10 +67,22 @@ private void configureFindBugsConfigurations() {
@Override
protected CodeQualityExtension createExtension() {
extension = project.getExtensions().create("spotbugs", FindBugsExtension.class, project);
extension.setToolVersion(DEFAULT_FINDBUGS_VERSION);
extension.setToolVersion(loadToolVersion());
return extension;
}

@VisibleForTesting
String loadToolVersion() {
URL url = Resources.getResource("spotbugs-gradle-plugin.properties");
try (InputStream input = url.openStream()) {
Properties prop = new Properties();
prop.load(input);
return prop.getProperty("spotbugs-version");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override
protected void configureTaskDefaults(SpotBugsTask task, String baseName) {
task.setPluginClasspath(project.getConfigurations().getAt("findbugsPlugins"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.github.spotbugs;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;

import java.io.File;
import java.util.Arrays;

Expand Down Expand Up @@ -40,4 +43,10 @@ public void TestFindBugsTasksExist() throws Exception{
assertTrue(result.getOutput().contains("findbugsMain"));
assertTrue(result.getOutput().contains("findbugsTest"));
}

@Test
public void testLoadToolVersion() {
SpotBugsPlugin plugin = new SpotBugsPlugin();
assertThat(plugin.loadToolVersion(), is(notNullValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FindUnsatisfiedObligationTest {
*/
@Test
public void testIssue60() {
BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/main/Issue60.class"));
BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/main/lambdas/Issue60.class"));
assertThat(bugCollection, is(emptyIterable()));
}
}
3 changes: 3 additions & 0 deletions spotbugsTestCases/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ tasks.withType(JavaCompile).all {

task classesJava7(type:JavaCompile) {
exclude '**/*jdk8.java'
exclude '**/lambdas/**'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
destinationDir = file("$buildDir/classes-jdk7")
classpath = sourceSets.main.compileClasspath
source = sourceSets.main.java
}

tasks['build'].dependsOn classesJava7
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package lambdas;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
Expand Down

0 comments on commit 6084506

Please sign in to comment.