Skip to content

Commit aee696c

Browse files
committed
Fix codenarc problems
1 parent 4981ea1 commit aee696c

File tree

2 files changed

+2
-127
lines changed

2 files changed

+2
-127
lines changed

src/main/groovy/com/google/protobuf/gradle/Utils.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class Utils {
151151
String relativePath = projectDir.toURI().relativize(f.toURI()).getPath()
152152
// remove trailing slash
153153
if (relativePath.endsWith("/")) {
154-
relativePath = relativePath.substring(0, relativePath.length() - 1);
154+
relativePath = relativePath[0..(relativePath.length() - 1)]
155155
}
156156
SourceFolder entry = new SourceFolder(relativePath, getOutputPath(cp, sourceSetName))
157157
entry.entryAttributes.put("optional", "true")
@@ -190,7 +190,7 @@ class Utils {
190190
* See: org.eclipse.jdt.internal.core.ClasspathEntry#validateClasspath()
191191
*/
192192
private static boolean isValidOutput(Classpath classpath, String path) {
193-
Set<String> outputs = new HashSet<>()
193+
Set<String> outputs = []
194194
for (ClasspathEntry cpe : classpath.getEntries()) {
195195
if (cpe instanceof SourceFolder) {
196196
outputs.add(((SourceFolder) cpe).getOutput())

src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy

-125
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.google.protobuf.gradle
22

3-
import com.google.common.collect.ImmutableSet
43
import groovy.transform.CompileDynamic
54
import org.gradle.api.Project
65
import org.gradle.testfixtures.ProjectBuilder
@@ -339,130 +338,6 @@ class ProtobufJavaPluginTest extends Specification {
339338
gradleVersion << GRADLE_VERSIONS
340339
}
341340
342-
@Unroll
343-
void "testProject proto and generated output directories should be added to intellij [gradle #gradleVersion]"() {
344-
given: "project from testProject"
345-
File projectDir = ProtobufPluginTestHelper.projectBuilder('testIdea')
346-
.copyDirs('testProjectBase', 'testProject')
347-
.build()
348-
349-
when: "idea is invoked"
350-
BuildResult result = GradleRunner.create()
351-
.withProjectDir(projectDir)
352-
.withArguments('idea')
353-
.withPluginClasspath()
354-
.withGradleVersion(gradleVersion)
355-
.build()
356-
357-
then: "it succeed"
358-
result.task(":idea").outcome == TaskOutcome.SUCCESS
359-
Node imlRoot = new XmlParser().parse(projectDir.toPath().resolve("testProject.iml").toFile())
360-
Collection rootMgr = imlRoot.component.findAll { it.'@name' == 'NewModuleRootManager' }
361-
assert rootMgr.size() == 1
362-
assert rootMgr.content.sourceFolder.size() == 1
363-
364-
Set<String> sourceDir = [] as Set
365-
Set<String> testSourceDir = [] as Set
366-
Set<String> generatedDirs = [] as Set
367-
rootMgr.content.sourceFolder[0].each {
368-
if (Boolean.parseBoolean(it.@isTestSource)) {
369-
testSourceDir.add(it.@url)
370-
} else {
371-
sourceDir.add(it.@url)
372-
}
373-
if (Boolean.parseBoolean(it.@generated)) {
374-
generatedDirs.add(it.@url)
375-
}
376-
}
377-
378-
Set<String> expectedSourceDir = ImmutableSet.builder()
379-
.add('file://$MODULE_DIR$/src/main/java')
380-
.add('file://$MODULE_DIR$/src/grpc/proto')
381-
.add('file://$MODULE_DIR$/src/main/proto')
382-
.add('file://$MODULE_DIR$/build/extracted-include-protos/grpc')
383-
.add('file://$MODULE_DIR$/build/extracted-protos/main')
384-
.add('file://$MODULE_DIR$/build/extracted-include-protos/main')
385-
.add('file://$MODULE_DIR$/build/extracted-protos/grpc')
386-
.add('file://$MODULE_DIR$/build/generated/source/proto/grpc/java')
387-
.add('file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output')
388-
.add('file://$MODULE_DIR$/build/generated/source/proto/main/java')
389-
.build()
390-
Set<String> expectedTestSourceDir = ImmutableSet.builder()
391-
.add('file://$MODULE_DIR$/src/test/java')
392-
.add('file://$MODULE_DIR$/src/test/proto')
393-
.add('file://$MODULE_DIR$/build/extracted-protos/test')
394-
.add('file://$MODULE_DIR$/build/extracted-include-protos/test')
395-
.add('file://$MODULE_DIR$/build/generated/source/proto/test/java')
396-
.build()
397-
Set<String> expectedGeneratedDirs = [
398-
'file://$MODULE_DIR$/build/extracted-include-protos/grpc',
399-
'file://$MODULE_DIR$/build/extracted-protos/main',
400-
'file://$MODULE_DIR$/build/extracted-include-protos/main',
401-
'file://$MODULE_DIR$/build/extracted-protos/grpc',
402-
'file://$MODULE_DIR$/build/generated/source/proto/grpc/java',
403-
'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output',
404-
'file://$MODULE_DIR$/build/generated/source/proto/main/java',
405-
'file://$MODULE_DIR$/build/extracted-protos/test',
406-
'file://$MODULE_DIR$/build/extracted-include-protos/test',
407-
'file://$MODULE_DIR$/build/generated/source/proto/test/java',
408-
]
409-
assert Objects.equals(expectedSourceDir, sourceDir)
410-
assert Objects.equals(expectedTestSourceDir, testSourceDir)
411-
Objects.equals(expectedGeneratedDirs, generatedDirs)
412-
413-
where:
414-
gradleVersion << GRADLE_VERSIONS
415-
}
416-
417-
@Unroll
418-
void "testProject proto and generated output directories should be added to Eclipse [gradle #gradleVersion]"() {
419-
given: "project from testProject"
420-
File projectDir = ProtobufPluginTestHelper.projectBuilder('testEclipse')
421-
.copyDirs('testProjectBase', 'testProject')
422-
.build()
423-
424-
when: "eclipse is invoked"
425-
BuildResult result = GradleRunner.create()
426-
.withProjectDir(projectDir)
427-
.withArguments('eclipse')
428-
.withPluginClasspath()
429-
.withGradleVersion(gradleVersion)
430-
.build()
431-
432-
then: "it succeed"
433-
result.task(":eclipse").outcome == TaskOutcome.SUCCESS
434-
Node classpathFile = new XmlParser().parse(projectDir.toPath().resolve(".classpath").toFile())
435-
Collection srcEntries = classpathFile.classpathentry.findAll {it.'@kind' == 'src'}
436-
assert srcEntries.size() == 6
437-
438-
Set<String> sourceDir = [] as Set
439-
srcEntries.each {
440-
String path = it.@path
441-
sourceDir.add(path)
442-
if (path.startsWith("build/generated/source/proto")) {
443-
if (path.contains("test")) {
444-
// test source path has one more attribute: ["test"="true"]
445-
assert it.attributes.attribute.size() == 4
446-
} else {
447-
assert it.attributes.attribute.size() == 3
448-
}
449-
}
450-
}
451-
452-
Set<String> expectedSourceDir = ImmutableSet.builder()
453-
.add('src/main/java')
454-
.add('src/test/java')
455-
.add('build/generated/source/proto/grpc/java')
456-
.add('build/generated/source/proto/grpc/grpc_output')
457-
.add('build/generated/source/proto/main/java')
458-
.add('build/generated/source/proto/test/java')
459-
.build()
460-
assert Objects.equals(expectedSourceDir, sourceDir)
461-
462-
where:
463-
gradleVersion << GRADLE_VERSIONS
464-
}
465-
466341
@Unroll
467342
void "test proto generation is not up-to-date on dependency changes [gradle #gradleVersion]"() {
468343
given: "project from testProject"

0 commit comments

Comments
 (0)