Skip to content

Commit

Permalink
Restrict getOutputSourceDirectorySet() to directories only
Browse files Browse the repository at this point in the history
#480 allows `outputPath` to be a zip/jar file, but it's not excluded from the `SourceDirectorySet` in that case. Therefore, when the source set gets evaluated, it leads to this exception in Gradle 7.2:

```
Caused by: org.gradle.api.InvalidUserDataException: Source directory '<redacted>/build/generated-proto/main/cpp.zip' is not a directory.
	at org.gradle.api.internal.file.DefaultSourceDirectorySet.getSourceTrees(DefaultSourceDirectorySet.java:273)
	at org.gradle.api.internal.file.DefaultSourceDirectorySet.getSrcDirTrees(DefaultSourceDirectorySet.java:256)
	at org.gradle.api.internal.file.DefaultSourceDirectorySet.getSrcDirs(DefaultSourceDirectorySet.java:114)
	at jdk.internal.reflect.GeneratedMethodAccessor2253.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at com.google.protobuf.gradle.ProtobufPlugin$_addSourcesToIde_closure31.doCall(ProtobufPlugin.groovy:554)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at com.google.protobuf.gradle.ProtobufPlugin.addSourcesToIde(ProtobufPlugin.groovy:553)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at com.google.protobuf.gradle.ProtobufPlugin$_doApply_closure5.doCall(ProtobufPlugin.groovy:159)
...
```
  • Loading branch information
cilki authored Nov 6, 2021
1 parent fb32f4a commit b92296a
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,16 @@ public abstract class GenerateProtoTask extends DefaultTask {
SourceDirectorySet srcSet
srcSet = objectFactory.sourceDirectorySet(srcSetName, srcSetName)
builtins.each { builtin ->
srcSet.srcDir new File(getOutputDir(builtin))
File dir = new File(getOutputDir(builtin))
if (!dir.name.endsWith(".zip") && !dir.name.endsWith(".jar")) {
srcSet.srcDir dir
}
}
plugins.each { plugin ->
srcSet.srcDir new File(getOutputDir(plugin))
File dir = new File(getOutputDir(plugin))
if (!dir.name.endsWith(".zip") && !dir.name.endsWith(".jar")) {
srcSet.srcDir dir
}
}
return srcSet
}
Expand Down

0 comments on commit b92296a

Please sign in to comment.