Skip to content

Commit dc3e624

Browse files
committed
Refactor ide-gradle templates
Refactor ide-gradle templates commit_hash:58147076392cab3f86ba196c01f437e39173e48e
1 parent eebc72e commit dc3e624

24 files changed

+311
-312
lines changed

build/export_generators/gradle/build.gradle.kts.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{%- set publish = target.publish -%}
22
{%- set mainClass = target.app_main_class -%}
3-
{%- set hasJunit5Test = extra_targets|selectattr('junit5_test') -%}
3+
{%- set has_junit5_test = extra_targets|selectattr('junit5_test') -%}
44
plugins {
55
{% if mainClass -%}
66
`application`
@@ -34,7 +34,7 @@ java {
3434
}
3535

3636
dependencies {
37-
{% if hasJunit5Test -%}
37+
{% if has_junit5_test -%}
3838
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
3939
api("org.apache.commons:commons-math3:3.6.1")
4040
api("com.google.guava:guava:31.0.1-jre")
@@ -71,7 +71,7 @@ dependencies {
7171
{% endfor -%}
7272
}
7373

74-
{% if hasJunit5Test -%}
74+
{% if has_junit5_test -%}
7575
tasks.named<Test>("test") {
7676
useJUnitPlatform()
7777
}
Lines changed: 16 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,21 @@
1-
{%- set has_errorprone = target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length -%}
2-
{%- if has_errorprone -%}
3-
import net.ltgt.gradle.errorprone.CheckSeverity
4-
import net.ltgt.gradle.errorprone.errorprone
5-
6-
{% endif -%}
7-
8-
{%- include "[generator]/builddir.jinja" %}
9-
10-
{%- macro OutDirs(runs, prefix, suffix) -%}
11-
{%- if run.args|length and run.out_dir|length -%}
12-
{%- for out_dir in run.out_dir -%}
13-
{#- search all run arguments ended by /<out_dir> -#}
14-
{%- set out_dirs = select_by_ends(run.args, "/" + out_dir) -%}
15-
{%- if out_dirs|length %}
16-
{{ prefix }}{{ out_dirs|first }}{{ suffix }}
17-
{%- endif -%}
18-
{%- endfor -%}
19-
{%- endif -%}
20-
{%- endmacro %}
21-
22-
{%- set mainClass = target.app_main_class -%}
23-
{%- set publish = target.publish -%}
24-
{%- set with_kotlin = target.with_kotlin -%}
25-
{%- set kotlin_version = target.kotlin_version -%}
26-
{%- set hasJunit5Test = extra_targets|selectattr('junit5_test') -%}
27-
28-
{%- if not target.required_jdk -%}
29-
{%- set has_required_jdk = false -%}
30-
{#- If no required JDK, set default JDK for Kotlin parts -#}
31-
{%- set required_jdk = '17' -%}
32-
{%- else -%}
33-
{%- set has_required_jdk = true -%}
34-
{%- set required_jdk = target.required_jdk -%}
35-
{%- endif %}
36-
37-
{% include "[generator]/plugins.jinja" -%}
1+
{%- include "[generator]/vars.jinja" -%}
2+
{%- include "[generator]/import.jinja" -%}
3+
{%- include "[generator]/repositories.jinja" -%}
4+
{%- include "[generator]/builddir.jinja" -%}
5+
{%- include "[generator]/plugins.jinja" -%}
386
{%- include "[generator]/kotlin_plugins.jinja" -%}
397
{%- include "[generator]/publish.jinja" -%}
408
{%- include "[generator]/preview.jinja" -%}
41-
42-
{#- javac flags -#}
43-
{%- if target.javac.flags|length -%}
44-
{#- skip errorprone options -#}
45-
{%- set javac_flags = target.javac.flags|reject('startsWith', '-Xep:')|reject('startsWith', '-XepOpt:') -%}
46-
{%- if javac_flags|length and javac_flags != ['-parameters'] %}
47-
48-
tasks.withType<JavaCompile> {
49-
{%- for javac_flag in javac_flags %}
50-
options.compilerArgs.add("{{ javac_flag }}")
51-
{%- endfor %}
52-
}
53-
{% endif -%}
54-
{%- endif -%}
55-
56-
{%- include "[generator]/errorprone.jinja" %}
57-
{% include "[generator]/bucket.jinja" %}
58-
val project_root = "{{ arcadia_root }}"
59-
60-
{% if mainClass -%}
61-
application {
62-
mainClass.set("{{ mainClass }}")
63-
}
64-
65-
{% endif -%}
66-
java {
67-
withSourcesJar()
68-
withJavadocJar()
69-
}
70-
71-
configurations.api {
72-
isTransitive = false
73-
}
74-
75-
configurations.implementation {
76-
isTransitive = false
77-
}
78-
79-
configurations.testImplementation {
80-
isTransitive = false
81-
}
82-
83-
{%- if has_test %}
84-
85-
val testsJar by tasks.registering(Jar::class) {
86-
dependsOn(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
87-
archiveClassifier.set("tests")
88-
from(sourceSets["test"].output)
89-
}
90-
91-
artifacts.add(configurations.create("testArtifacts").name, testsJar)
92-
93-
tasks.test {
94-
testLogging {
95-
showStandardStreams = true
96-
events("passed", "skipped", "failed")
97-
}
98-
}
99-
{% endif -%}
100-
101-
{%- include "[generator]/source_sets.jinja" %}
102-
103-
{% include "[generator]/dependencies.jinja" -%}
104-
105-
{%- if hasJunit5Test %}
106-
107-
tasks.named<Test>("test") {
108-
useJUnitPlatform()
109-
}
110-
{% endif -%}
111-
9+
{%- include "[generator]/configuration.jinja" -%}
10+
{%- include "[generator]/javac_flags.jinja" -%}
11+
{%- include "[generator]/errorprone.jinja" -%}
12+
{%- include "[generator]/source_sets.jinja" -%}
13+
{%- include "[generator]/test.jinja" -%}
14+
{%- include "[generator]/javadoc.jinja" -%}
11215
{%- include "[generator]/run_java_program.jinja" -%}
113-
114-
{% include "extra-tests.gradle.kts" ignore missing %}
115-
{% if publish -%}
116-
{% include 'publish.gradle.kts' ignore missing -%}
117-
{% endif -%}
118-
{#- To disable redundant javadoc (it may fail the build) #}
119-
120-
tasks.withType<Javadoc>().configureEach {
121-
isEnabled = false
122-
}
123-
16+
{%- include "[generator]/dependencies.jinja" -%}
17+
{%- include "extra-tests.gradle.kts" ignore missing -%}
18+
{%- if publish -%}
19+
{%- include 'publish.gradle.kts' ignore missing -%}
20+
{%- endif -%}
12421
{%- include "[generator]/debug.jinja" ignore missing -%}
Lines changed: 12 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,13 @@
1-
{%- set publish = target.publish -%}
2-
{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%}
3-
import com.google.protobuf.gradle.*
4-
5-
{% include "[generator]/builddir.jinja" %}
6-
7-
val mainProtosDir = File(buildDir, "main_protos")
8-
{%- if libraries|length %}
9-
val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main")
10-
{%- endif %}
11-
12-
plugins {
13-
id("java-library")
14-
id("com.google.protobuf") version "0.8.19"
15-
{%- if publish %}
16-
`maven-publish`
17-
`signing`
18-
{%- endif %}
19-
}
20-
{%- include "[generator]/publish.jinja" %}
21-
22-
{% include "[generator]/bucket.jinja" %}
23-
val project_root = "{{ arcadia_root }}"
24-
25-
sourceSets {
26-
main {
27-
java.srcDir("$buildDir/generated/sources/proto/main/java")
28-
{%- if target.proto_grpc %}
29-
java.srcDir("$buildDir/generated/sources/proto/main/grpc")
30-
{%- endif %}
31-
}
32-
test {
33-
java.srcDir("$buildDir/generated/sources/proto/test/java")
34-
{%- if target.proto_grpc %}
35-
java.srcDir("$buildDir/generated/sources/proto/test/grpc")
36-
{%- endif %}
37-
}
38-
}
39-
40-
java {
41-
withSourcesJar()
42-
withJavadocJar()
43-
}
44-
45-
configurations.api {
46-
isTransitive = false
47-
}
48-
49-
configurations.implementation {
50-
isTransitive = false
51-
}
52-
53-
configurations.testImplementation {
54-
isTransitive = false
55-
}
56-
57-
{%- if target.jar_source_set is defined -%}
58-
{%- for source_set in target.jar_source_set -%}
59-
{%- set srcdir_glob = split(source_set, ':') %}
60-
sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}"
61-
{% endfor -%}
62-
{%- endif %}
63-
64-
dependencies {
65-
{%- for library in target.consumer if library.classpath -%}
66-
{%- if library.prebuilt and library.jar and (library.type != "contrib" or target.handler.build_contribs) %}
67-
implementation(files("$project_root/{{ library.jar }}"))
68-
{%- else -%}
69-
{%- set classpath = library.classpath -%}
70-
{%- if classpath|replace('"','') == classpath -%}
71-
{%- set classpath = '"' + classpath + '"' -%}
72-
{%- endif %}
73-
{%- if library.type != "contrib" %}
74-
implementation
75-
{%- else %}
76-
api
77-
{%- endif -%}({{ classpath }})
78-
{%- if library.excludes.consumer is defined %} {
79-
{% for exclude in library.excludes.consumer -%}
80-
{% set classpath = exclude.classpath|replace('"','') -%}
81-
{% set classpath_parts = split(classpath, ':') -%}
82-
exclude(group = "{{ classpath_parts[0] }}", module = "{{ classpath_parts[1] }}")
83-
{% endfor -%}
84-
}
85-
{%- endif -%}
86-
{%- endif -%}
87-
{%- endfor -%}
88-
89-
{%- if target.proto_namespace %}
90-
protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}")))
91-
{%- else %}
92-
protobuf(files(mainProtosDir))
93-
{%- endif %}
94-
}
95-
96-
protobuf {
97-
generatedFilesBaseDir = "$buildDir/generated/sources/proto"
98-
99-
protoc {
100-
// Download from repositories
101-
artifact = "com.google.protobuf:protoc:{%- if target.proto_compiler_version -%}{{ target.proto_compiler_version }}{%- else -%}3.22.5{%- endif -%}"
102-
}
103-
{%- if target.proto_grpc %}
104-
105-
plugins {
106-
id("grpc") {
107-
artifact = "io.grpc:protoc-gen-grpc-java:{%- if target.proto_grpc_version -%}{{ target.proto_grpc_version }}{%- else -%}1.45.0{%- endif -%}"
108-
}
109-
{%- if target.proto_kotlin_grpc %}
110-
id("grpckt") {
111-
artifact = "io.grpc:protoc-gen-grpc-kotlin:{%- if target.proto_kotlin_grpc_version -%}{{ target.proto_kotlin_grpc_version }}{%- else -%}1.3.1{%- endif -%}:jdk8@jar"
112-
}
113-
{%- endif %}
114-
}
115-
116-
generateProtoTasks {
117-
all().forEach {
118-
it.plugins {
119-
id("grpc")
120-
{%- if target.proto_kotlin_grpc %}
121-
id("grpckt")
122-
{%- endif %}
123-
}
124-
{%- if target.proto_kotlin_grpc %}
125-
it.builtins {
126-
create("kotlin")
127-
}
128-
{%- endif %}
129-
}
130-
}
131-
{%- endif %}
132-
}
133-
134-
val prepareMainProtos = tasks.register<Copy>("prepareMainProtos") {
135-
from("$project_root") {
136-
{#- list of all current project proto files -#}
137-
{%- for proto in target.proto_files %}
138-
include("{{ proto }}")
139-
{%- endfor %}
140-
}
141-
into(mainProtosDir)
142-
}
143-
144-
{% if libraries|length -%}
145-
val extractMainLibrariesProtos = tasks.register<Copy>("extractMainLibrariesProtos") {
146-
from("$project_root") {
147-
{#- list of all library directories -#}
148-
{%- for library in libraries -%}
149-
{%- set path_and_jar = rsplit(library.jar, '/', 2) %}
150-
include("{{ path_and_jar[0] }}/**/*.proto")
151-
{%- endfor %}
152-
}
153-
into(mainExtractedIncludeProtosDir)
154-
}
155-
156-
{% endif -%}
157-
afterEvaluate {
158-
tasks.getByName("extractProto").dependsOn(prepareMainProtos)
159-
{%- if libraries|length %}
160-
tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos)
161-
{%- endif %}
162-
}
163-
164-
{# To avoid problems when build project with proto #}
165-
tasks.getByName("sourcesJar").dependsOn("generateProto")
166-
167-
{# To disable redundant javadoc (it may fail the build) #}
168-
tasks.withType<Javadoc>().configureEach {
169-
isEnabled = false
170-
}
171-
1+
{%- include "[generator]/proto_vars.jinja" -%}
2+
{%- include "[generator]/proto_import.jinja" -%}
3+
{%- include "[generator]/repositories.jinja" -%}
4+
{%- include "[generator]/proto_builddir.jinja" -%}
5+
{%- include "[generator]/proto_plugins.jinja" -%}
6+
{%- include "[generator]/publish.jinja" -%}
7+
{%- include "[generator]/proto_configuration.jinja" -%}
8+
{%- include "[generator]/proto_source_sets.jinja" -%}
9+
{%- include "[generator]/protobuf.jinja" -%}
10+
{%- include "[generator]/proto_prepare.jinja" -%}
11+
{%- include "[generator]/javadoc.jinja" -%}
12+
{%- include "[generator]/proto_dependencies.jinja" -%}
17213
{%- include "[generator]/debug.jinja" ignore missing -%}

build/export_generators/ide-gradle/builddir.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{#- empty string #}
12
val baseBuildDir = "{{ export_root }}/gradle.build/"
23
buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", "."))
34
subprojects {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{#- empty string #}
2+
val project_root = "{{ arcadia_root }}"
3+
4+
{% if mainClass -%}
5+
application {
6+
mainClass.set("{{ mainClass }}")
7+
}
8+
9+
{% endif -%}
10+
java {
11+
withSourcesJar()
12+
withJavadocJar()
13+
}
14+
15+
configurations.api {
16+
isTransitive = false
17+
}
18+
19+
configurations.implementation {
20+
isTransitive = false
21+
}
22+
23+
configurations.testImplementation {
24+
isTransitive = false
25+
}

build/export_generators/ide-gradle/dependencies.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{#- empty string #}
12
dependencies {
23
{%- for library in target.consumer if library.classpath -%}
34
{%- if has_errorprone -%}

build/export_generators/ide-gradle/errorprone.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{%- if has_errorprone -%}
22
{%- set ep_flags = target.javac.flags|select('startsWith', '-Xep:') -%}
33
{%- if ep_flags|length or ep_opts|length %}
4-
54
tasks.withType<JavaCompile> {
65
{%- if ep_flags|length %}
76
options.errorprone.checks.set(

0 commit comments

Comments
 (0)