Skip to content

Commit 7557fe4

Browse files
committed
Cleanup Codenarc violations (#351)
1 parent 79a2f52 commit 7557fe4

26 files changed

+155
-237
lines changed

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.jrubygradle
22

33
import com.github.jrubygradle.testhelper.IntegrationSpecification
44
import org.gradle.testkit.runner.BuildResult
5-
import spock.lang.Shared
65

76
/**
87
* @author Schalk W. Cronjé
@@ -19,7 +18,6 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
1918
script 'src/${HELLO_WORLD}'
2019
"""
2120

22-
2321
when: "I call jrubyexec with only a script name"
2422
BuildResult result = build()
2523

@@ -136,10 +134,12 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
136134
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
137135
}
138136

137+
@SuppressWarnings('BuilderMethodWithSideEffects')
139138
private void createJRubyExecProject(String jrubyexecConfig) {
140139
createJRubyExecProject('', jrubyexecConfig)
141140
}
142141

142+
@SuppressWarnings('BuilderMethodWithSideEffects')
143143
private void createJRubyExecProject(String preamble, String jrubyexecConfig) {
144144
buildFile.text = """
145145
${projectWithLocalRepo}
@@ -157,7 +157,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
157157
}
158158

159159
private String withJarToUse(String jarFormat) {
160-
String dependencies = """
160+
"""
161161
dependencies {
162162
jrubyExec ${jarFormat}
163163
}
@@ -171,6 +171,4 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
171171
private String getBcprovVer() {
172172
testProperties.bcprovVersion
173173
}
174-
175-
176174
}

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyGenerateGradleRbIntegrationSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class JRubyGenerateGradleRbIntegrationSpec extends IntegrationSpecification {
3434
String content = expected.text
3535

3636
then: "The GEM_HOME to include gemInstallDir"
37-
expected.text.contains "export GEM_HOME=\"${new File(projectDir, 'build/gems').absolutePath}"
37+
content.contains "export GEM_HOME=\"${new File(projectDir, 'build/gems').absolutePath}"
3838

3939
and: "The JARS_HOME is set"
40-
expected.text.contains('export JARS_HOME=')
40+
content.contains('export JARS_HOME=')
4141

4242
and: "The java command invoked with the -cp flag"
4343
// with this test setup it is just jrubyExec.asPath
44-
expected.text.contains "-cp ${flatRepoLocation.absolutePath}"
44+
content.contains "-cp ${flatRepoLocation.absolutePath}"
4545
}
4646
}

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyPrepareJarsIntegrationSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.jrubygradle
22

3-
import com.github.jrubygradle.testhelper.BasicProjectBuilder
43
import com.github.jrubygradle.testhelper.IntegrationSpecification
54

65
/**

base-plugin/src/integTest/groovy/com/github/jrubygradle/testhelper/BasicProjectBuilder.groovy

Lines changed: 0 additions & 45 deletions
This file was deleted.

base-plugin/src/integTest/groovy/com/github/jrubygradle/testhelper/IntegrationSpecification.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import org.junit.rules.TemporaryFolder
66
import spock.lang.Shared
77
import spock.lang.Specification
88

9-
109
class IntegrationSpecification extends Specification {
1110

1211
static final boolean OFFLINE = System.getProperty('TESTS_ARE_OFFLINE')
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package com.github.jrubygradle.testhelper
22

3-
import groovy.transform.CompileStatic
4-
53
import java.util.regex.Pattern
64

75
/**
86
* @author Schalk W. Cronjé.
97
*/
108
class VersionFinder {
11-
static String find( final File repoDir, final String artifact, final String extension ) {
9+
@SuppressWarnings(['NoDef'])
10+
static String find(final File repoDir, final String artifact, final String extension) {
1211
Pattern pat = ~/^${artifact}-(.+)\.${extension}/
13-
def files = repoDir.list([ accept : { File dir,String name ->
12+
def files = repoDir.list([ accept: { File dir, String name ->
1413
name ==~ pat
15-
}] as FilenameFilter)
14+
} ] as FilenameFilter)
1615

1716
if (files.size()) {
1817
def matcher = files[0] =~ pat
@@ -22,7 +21,7 @@ class VersionFinder {
2221
}
2322
}
2423

25-
static findDependency( final File repoDir, final String organisation, final String artifact, final String extension ) {
26-
"${organisation}:${artifact}:${find(repoDir,artifact,extension)}@${extension}"
24+
static String findDependency(final File repoDir, final String organisation, final String artifact, final String extension) {
25+
"${organisation}:${artifact}:${find(repoDir, artifact, extension)}@${extension}"
2726
}
2827
}

base-plugin/src/main/groovy/com/github/jrubygradle/JRubyPlugin.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.jrubygradle
22

3-
import com.github.jrubygradle.internal.JRubyExecDelegate
43
import com.github.jrubygradle.internal.GemVersionResolver
4+
import com.github.jrubygradle.internal.JRubyExecDelegate
55
import com.github.jrubygradle.internal.JRubyExecUtils
66
import com.github.jrubygradle.internal.RubygemsServlet
77
import org.gradle.api.Plugin
@@ -65,7 +65,7 @@ class JRubyPlugin implements Plugin<Project> {
6565
// can not cast
6666
Object embedded = embeddedServer()
6767
String path = embedded.addRepository(localUrl)
68-
project.logger.info( 'Adding remote rubygems repo: {}', localUrl)
68+
project.logger.info('Adding remote rubygems repo: {}', localUrl)
6969
maven {
7070
url {
7171
startEmbeddedServer(project)
@@ -87,6 +87,7 @@ class JRubyPlugin implements Plugin<Project> {
8787

8888
// can not cast same object from different classloaders
8989
private Object server
90+
9091
private Object embeddedServer() {
9192
if (server == null) {
9293
// TODO maybe things will work now without cloning
@@ -97,7 +98,7 @@ class JRubyPlugin implements Plugin<Project> {
9798
List<URL> urls = [] as Queue
9899
URL warFileURL
99100
RubygemsServlet.classLoader.URLs.each {
100-
if (it.file.endsWith('.war') ) {
101+
if (it.file.endsWith('.war')) {
101102
warFileURL = it
102103
}
103104
// for integTest we need to filter some jars here
@@ -115,6 +116,7 @@ class JRubyPlugin implements Plugin<Project> {
115116
}
116117

117118
private boolean serverStarted = false
119+
118120
private void startEmbeddedServer(Project project) {
119121
if (server != null && !serverStarted) {
120122
// we need to set the current thread context class loader

base-plugin/src/main/groovy/com/github/jrubygradle/internal/JRubyExecUtils.groovy

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class JRubyExecUtils {
5757
* @param jar JRuby Jar
5858
* @return Version string map [major,minor,patchlevel] or null
5959
*
60-
* @since 0.1.16
61-
* @deprecated This method is no longer used and will be removed in a later
60+
* @since 0.1.16* @deprecated This method is no longer used and will be removed in a later
6261
* version
6362
*/
6463
@CompileDynamic
@@ -76,9 +75,9 @@ class JRubyExecUtils {
7675
}
7776

7877
return [
79-
major : matches[0][1].toInteger(),
80-
minor : matches[0][2].toInteger(),
81-
patchlevel : matches[0][3].toInteger()
78+
major : matches[0][1].toInteger(),
79+
minor : matches[0][2].toInteger(),
80+
patchlevel: matches[0][3].toInteger()
8281
]
8382
}
8483

@@ -105,9 +104,9 @@ class JRubyExecUtils {
105104
* @return sequential list of arguments to pass jruby-complete.jar
106105
*/
107106
static List<String> buildArgs(List<Object> extra,
108-
List<Object> jrubyArgs,
109-
File script,
110-
List<Object> scriptArgs) {
107+
List<Object> jrubyArgs,
108+
File script,
109+
List<Object> scriptArgs) {
111110
List<Object> cmdArgs = extra
112111
// load Jars.lock on startup
113112
cmdArgs.add('-rjars/setup')
@@ -129,8 +128,7 @@ class JRubyExecUtils {
129128
throw new InvalidUserDataException("${script} does not exist")
130129
}
131130
cmdArgs.add(script.toString())
132-
}
133-
else if (script == null) {
131+
} else if (script == null) {
134132
if (useBinPath && (jrubyArgs.size() <= 1)) {
135133
throw new InvalidUserDataException('No `script` property defined and no inline script provided')
136134
}

base-plugin/src/test/groovy/com/github/jrubygradle/GemUtilsSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.gradle.api.file.DuplicateFileCopyingException
55
import org.gradle.testfixtures.ProjectBuilder
66
import spock.lang.Specification
77

8-
98
/**
109
* @author Schalk W. Cronjé
1110
*/

base-plugin/src/test/groovy/com/github/jrubygradle/JRubyExecSpec.groovy

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.jrubygradle
22

3-
43
import org.gradle.api.InvalidUserDataException
54
import org.gradle.api.Project
65
import org.gradle.api.ProjectConfigurationException
@@ -67,9 +66,6 @@ class JRubyExecSpec extends Specification {
6766
}
6867

6968
void "Check jruby defaults when jruby.execVersion is changed after the task is created"() {
70-
given:
71-
final String initialVersion = project.jruby.execVersion
72-
7369
when: "ExecVersion is changed later on, and JRubyExec.jrubyVersion was not called"
7470
project.jruby.execVersion = '1.5.0'
7571

@@ -169,10 +165,10 @@ class JRubyExecSpec extends Specification {
169165
}
170166

171167
then:
172-
execTask.getArgs() == ['-I', testJarDependencies, '-rjars/setup',
173-
'-j1', '-j2', '-j3', '-S',
174-
SCRIPT_NAME,
175-
'-s1', '-s2', '-s3']
168+
execTask.args == ['-I', testJarDependencies, '-rjars/setup',
169+
'-j1', '-j2', '-j3', '-S',
170+
SCRIPT_NAME,
171+
'-s1', '-s2', '-s3']
176172
}
177173

178174
void "Properly handle the lack of a `script` argument"() {
@@ -182,13 +178,12 @@ class JRubyExecSpec extends Specification {
182178
}
183179

184180
then:
185-
execTask.getArgs() == ['-I', testJarDependencies, '-rjars/setup', '-S', 'rspec']
181+
execTask.args == ['-I', testJarDependencies, '-rjars/setup', '-S', 'rspec']
186182
}
187183

188184
void "Error when `script` is empty and there is no `jrubyArgs`"() {
189185
when:
190-
project.configure(execTask) {}
191-
execTask.getArgs()
186+
execTask.args
192187

193188
then: "An exception should be thrown"
194189
thrown(InvalidUserDataException)

0 commit comments

Comments
 (0)