Skip to content

Commit

Permalink
Add more attributes to the classpath entries
Browse files Browse the repository at this point in the history
Signed-off-by: sheche <[email protected]>
  • Loading branch information
jdneo authored and rougsig committed Aug 21, 2022
1 parent 5e5b913 commit 53c1d08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/groovy/com/google/protobuf/gradle/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ class Utils {
SourceFolder entry = new SourceFolder(relativePath, getOutputPath(cp, sourceSetName))
entry.entryAttributes.put("optional", "true")
entry.entryAttributes.put("ignore_optional_problems", "true")

entry.entryAttributes.put("gradle_scope", isTest ? "test" : "main")
entry.entryAttributes.put("gradle_used_by_scope", isTest ? "test" : "main,test")

// this attribute is optional, but it could be useful for IDEs to recognize that it is
// generated source folder from protobuf, thus providing some support for that.
// e.g. Hint user to run generate tasks if the folder is empty or does not exist.
entry.entryAttributes.put("protobuf_generated_source", "true")

// check if output is not null here because test source folder
// must have a separate output folder in Eclipse
if (entry.output != null && isTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,16 @@ class ProtobufJavaPluginTest extends Specification {
Set<String> sourceDir = [] as Set
srcEntries.each {
sourceDir.add(it.@path)
String path = it.@path
sourceDir.add(path)
if (path.startsWith("build/generated/source/proto")) {
if (path.contains("test")) {
// test source path has one more attribute: ["test"="true"]
assert it.attributes.attribute.size() == 6
} else {
assert it.attributes.attribute.size() == 5
}
}
}
Set<String> expectedSourceDir = ImmutableSet.builder()
Expand Down

0 comments on commit 53c1d08

Please sign in to comment.