Skip to content

Commit

Permalink
Bump to Gradle 4.8 and fix codenarc lints (google#239)
Browse files Browse the repository at this point in the history
For unknown reasons, the unit tests hang for Gradle 4.3 on this PR on Travis:
google#237

I have confirmed that the code works fine on 4.8.
  • Loading branch information
zpencer authored and zhangkun83 committed Nov 7, 2018
1 parent d929ac5 commit 13dd596
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
7 changes: 6 additions & 1 deletion config/codenarc/codenarc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<ruleset-ref path='rulesets/design.xml'>
<exclude name="Instanceof"/>
<exclude name="ImplementationAsType"/>
<exclude name="BuilderMethodWithSideEffects"/>
</ruleset-ref>
<ruleset-ref path='rulesets/dry.xml'>
<exclude name="DuplicateStringLiteral"/>
<exclude name="DuplicateNumberLiteral"/>
</ruleset-ref>
<ruleset-ref path='rulesets/exceptions.xml'/>
<ruleset-ref path='rulesets/formatting.xml'/>
<ruleset-ref path='rulesets/formatting.xml'>
<exclude name="Indentation"/>
</ruleset-ref>
<ruleset-ref path='rulesets/generic.xml'/>
<ruleset-ref path='rulesets/grails.xml'/>
<ruleset-ref path='rulesets/groovyism.xml'/>
Expand All @@ -69,12 +72,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<exclude name="CrapMetric"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="NestedBlockDepth"/>
<exclude name="MethodCount"/>
</ruleset-ref>
<ruleset-ref path='rulesets/unused.xml'/>
<ruleset-ref path='rulesets/unnecessary.xml'>
<exclude name="UnnecessaryCollectCall"/>
<exclude name="UnnecessaryGetter"/>
<exclude name="UnnecessaryGString"/>
<exclude name="UnnecessarySetter"/>
<exclude name="UnnecessaryPublicModifier"/>
<exclude name="UnnecessaryReturnKeyword"/>
</ruleset-ref>
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ import org.gradle.api.Named
* configured, the plugin should try to run the executable from system search
* path.
*/
public class ExecutableLocator implements Named {
class ExecutableLocator implements Named {

private final String name

private String artifact
private String path

public ExecutableLocator(String name) {
ExecutableLocator(String name) {
this.name = name
}

@Override
public String getName() {
String getName() {
return name
}

/**
* Specifies an artifact spec for downloading the executable from
* repositories. spec format: '<groupId>:<artifactId>:<version>'
*/
public setArtifact(String spec) {
void setArtifact(String spec) {
this.artifact = spec
this.path = null
}

/**
* Specifies a local path.
*/
public setPath(String path) {
void setPath(String path) {
this.path = path
this.artifact = null
}

public String getArtifact() {
String getArtifact() {
return artifact
}

public String getPath() {
String getPath() {
return path
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ package com.google.protobuf.gradle

import com.google.common.base.Preconditions
import com.google.common.collect.ImmutableList
import com.google.common.primitives.Ints

import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
Expand Down Expand Up @@ -297,9 +296,8 @@ public class GenerateProtoTask extends DefaultTask {
public boolean getIsTest() {
if (Utils.isAndroidProject(project)) {
return isTestVariant
} else {
return Utils.isTest(sourceSet.name)
}
return Utils.isTest(sourceSet.name)
}

/**
Expand Down Expand Up @@ -337,7 +335,7 @@ public class GenerateProtoTask extends DefaultTask {
/**
* Set the output directory for this plugin, relative to {@link GenerateProtoTask#outputBaseDir}.
*/
public setOutputSubDir(String outputSubDir) {
void setOutputSubDir(String outputSubDir) {
this.outputSubDir = outputSubDir
}

Expand Down Expand Up @@ -476,7 +474,7 @@ public class GenerateProtoTask extends DefaultTask {
List<List<String>> cmds = []
if (!protoFiles.isEmpty()) {
int baseCmdLength = baseCmd.sum { it.length() + CMD_ARGUMENT_EXTRA_LENGTH }
List<String> currentArgs = new ArrayList<String>()
List<String> currentArgs = []
int currentArgsLength = 0
for (File proto: protoFiles) {
String protoFileName = proto
Expand Down
17 changes: 8 additions & 9 deletions src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class ProtobufPlugin implements Plugin<Project> {
if (wasApplied) {
project.logger.warn('The com.google.protobuf plugin was already applied to the project: ' + project.path
+ ' and will not be applied again after plugin: ' + prerequisitePlugin.id)

} else {
wasApplied = true

Expand Down Expand Up @@ -152,7 +151,7 @@ class ProtobufPlugin implements Plugin<Project> {
* Creates a configuration if necessary for a source set so that the build
* author can configure dependencies for it.
*/
private createConfiguration(String sourceSetName) {
private void createConfiguration(String sourceSetName) {
String configName = Utils.getConfigName(sourceSetName, 'protobuf')
if (project.configurations.findByName(configName) == null) {
project.configurations.create(configName) {
Expand All @@ -167,7 +166,7 @@ class ProtobufPlugin implements Plugin<Project> {
* Adds the proto extension to all SourceSets, e.g., it creates
* sourceSets.main.proto and sourceSets.test.proto.
*/
private addSourceSetExtensions() {
private void addSourceSetExtensions() {
getSourceSets().all { sourceSet ->
sourceSet.extensions.create('proto', ProtobufSourceDirectorySet, sourceSet.name, fileResolver)
}
Expand All @@ -191,7 +190,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Adds Protobuf-related tasks to the project.
*/
private addProtoTasks() {
private void addProtoTasks() {
if (Utils.isAndroidProject(project)) {
getNonTestVariants().each { variant ->
addTasksForVariant(variant, false)
Expand All @@ -209,7 +208,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Creates Protobuf tasks for a sourceSet in a Java project.
*/
private addTasksForSourceSet(final SourceSet sourceSet) {
private void addTasksForSourceSet(final SourceSet sourceSet) {
Task generateProtoTask = addGenerateProtoTask(sourceSet.name, [sourceSet])
generateProtoTask.sourceSet = sourceSet
generateProtoTask.doneInitializing()
Expand All @@ -235,7 +234,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Creates Protobuf tasks for a variant in an Android project.
*/
private addTasksForVariant(final Object variant, boolean isTestVariant) {
private void addTasksForVariant(final Object variant, boolean isTestVariant) {
Task generateProtoTask = addGenerateProtoTask(variant.name, variant.sourceSets)
generateProtoTask.setVariant(variant, isTestVariant)
generateProtoTask.flavors = ImmutableList.copyOf(variant.productFlavors.collect { it.name } )
Expand Down Expand Up @@ -398,12 +397,12 @@ class ProtobufPlugin implements Plugin<Project> {
}
}

private static linkGenerateProtoTasksToTask(Task task, GenerateProtoTask genProtoTask) {
private static void linkGenerateProtoTasksToTask(Task task, GenerateProtoTask genProtoTask) {
task.dependsOn(genProtoTask)
task.source genProtoTask.getOutputSourceDirectorySet()
}

private linkGenerateProtoTasksToTaskName(String compileTaskName, GenerateProtoTask genProtoTask) {
private void linkGenerateProtoTasksToTaskName(String compileTaskName, GenerateProtoTask genProtoTask) {
Task compileTask = project.tasks.findByName(compileTaskName)
if (compileTask != null) {
linkGenerateProtoTasksToTask(compileTask, genProtoTask)
Expand All @@ -418,7 +417,7 @@ class ProtobufPlugin implements Plugin<Project> {
}
}

private linkGenerateProtoTasksToSourceCompile() {
private void linkGenerateProtoTasksToSourceCompile() {
if (Utils.isAndroidProject(project)) {
(getNonTestVariants() + project.android.testVariants).each { variant ->
project.protobuf.generateProtoTasks.ofVariant(variant.name).each { GenerateProtoTask genProtoTask ->
Expand Down

0 comments on commit 13dd596

Please sign in to comment.