Skip to content

Commit 038c81c

Browse files
committed
Fix proto with proto-libraries, refactor errorprone
Refactor errorprone Fix building protos in Gradle commit_hash:54d1cdf9df00e7ab30b991ddf1f534ab5992ef3c
1 parent 5fb7f5f commit 038c81c

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

build/export_generators/ide-gradle/build.gradle.kts.jinja

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ subprojects {
3838
{%- endif %}
3939

4040
plugins {
41-
{#- some plugins configuration -#}
42-
{%- for library in target.consumer if library.classpath -%}
43-
{#- error prone plugin configuration -#}
44-
{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations/" in library.jar -%}
45-
46-
id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}"
47-
48-
{%- endif -%}
49-
{%- endfor -%}
50-
51-
{#- lombok configuration -#}
52-
{#- TODO remove usings annotation_processors semantic -#}
53-
{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %}
54-
id("io.freefair.lombok") version "8.6"
55-
{%- endif -%}
5641
{%- if mainClass %}
5742
`application`
5843
{%- else %}
@@ -76,6 +61,17 @@ plugins {
7661
{%- if target.with_kotlinc_plugin_serialization|length %}
7762
kotlin("plugin.serialization") version "{{ kotlin_version }}"
7863
{% endif -%}
64+
{%- endif -%}
65+
66+
{#- errorprone plugin configuration -#}
67+
{%- if target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length %}
68+
id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}"
69+
{%- endif -%}
70+
71+
{#- lombok plugin configuration -#}
72+
{#- TODO remove usings annotation_processors semantic -#}
73+
{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %}
74+
id("io.freefair.lombok") version "8.6"
7975
{%- endif %}
8076
}
8177

@@ -272,6 +268,7 @@ sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
272268
{%- endfor -%}
273269

274270
sourceSets {
271+
{%- if target.runs|length %}
275272
main {
276273
{#-
277274
Default by Gradle:
@@ -280,13 +277,11 @@ sourceSets {
280277
resources.srcDir("src/main/resources")
281278
282279
#}
283-
{%- if target.runs|length -%}
284280
{%- for run in target.runs -%}
285281
{{ OutDirs(run, ' java.srcDir("', '")') }}
286-
{%- endfor -%}
287-
{%- endif %}
282+
{%- endfor %}
288283
}
289-
284+
{%- endif %}
290285
test {
291286
{#-
292287
Default by Gradle:
@@ -315,11 +310,9 @@ sourceSets {
315310

316311
dependencies {
317312
{%- for library in target.consumer if library.classpath -%}
318-
{# error prone plugin configuration #}
319-
{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations" in library.jar -%}
320-
{% set errorprone_version = library.jar -%}
321-
{% set errorprone_parts = errorprone_version|replace("contrib/java/com/google/errorprone/error_prone_annotations/") -%}
322-
{% set errorprone_parts = split(errorprone_parts, '/') %}
313+
{%- if library.prebuilt and (library.type != "contrib" or build_contribs) and ("contrib/java/com/google/errorprone/error_prone_annotations" in library.jar) -%}
314+
{%- set errorprone_version = library.jar|replace("contrib/java/com/google/errorprone/error_prone_annotations/", "") -%}
315+
{%- set errorprone_parts = split(errorprone_version, '/', 2) %}
323316
errorprone("com.google.errorprone:error_prone_core:{{ errorprone_parts[0] }}")
324317
{%- endif -%}
325318

build/export_generators/ide-gradle/build.gradle.kts.proto.jinja

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- set publish = target.publish -%}
2+
{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%}
3+
24
import com.google.protobuf.gradle.*
35

46
val baseBuildDir = "{{ export_root }}/gradle.build/"
@@ -7,6 +9,11 @@ subprojects {
79
buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
810
}
911

12+
val mainProtosDir = File(buildDir, "main_protos")
13+
{%- if libraries|length %}
14+
val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main")
15+
{%- endif %}
16+
1017
plugins {
1118
id("java-library")
1219
id("com.google.protobuf") version "0.8.19"
@@ -99,8 +106,13 @@ dependencies {
99106
}
100107
{%- endif -%}
101108
{%- endif -%}
102-
{%- endfor %}
103-
protobuf(files("$projectDir"))
109+
{%- endfor -%}
110+
111+
{%- if target.proto_namespace %}
112+
protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}")))
113+
{%- else %}
114+
protobuf(files(mainProtosDir))
115+
{%- endif %}
104116
}
105117

106118
protobuf {
@@ -141,6 +153,36 @@ protobuf {
141153
{%- endif %}
142154
}
143155

156+
val prepareMainProtos = tasks.register<Copy>("prepareMainProtos") {
157+
from("$project_root") {
158+
{#- list of all current project proto files -#}
159+
{%- for proto in target.proto_files %}
160+
include("{{ proto }}")
161+
{%- endfor %}
162+
}
163+
into(mainProtosDir)
164+
}
165+
166+
{% if libraries|length -%}
167+
val extractMainLibrariesProtos = tasks.register<Copy>("extractMainLibrariesProtos") {
168+
from("$project_root") {
169+
{#- list of all library directories -#}
170+
{%- for library in libraries -%}
171+
{%- set path_and_jar = rsplit(library.jar, '/', 2) %}
172+
include("{{ path_and_jar[0] }}/**/*.proto")
173+
{%- endfor %}
174+
}
175+
into(mainExtractedIncludeProtosDir)
176+
}
177+
178+
{% endif -%}
179+
afterEvaluate {
180+
tasks.getByName("extractProto").dependsOn(prepareMainProtos)
181+
{%- if libraries|length %}
182+
tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos)
183+
{%- endif %}
184+
}
185+
144186
{# To avoid problems when build project with proto #}
145187
tasks.getByName("sourcesJar").dependsOn("generateProto")
146188

0 commit comments

Comments
 (0)