Skip to content

Commit 156d32d

Browse files
committed
resolved conflicts with main
2 parents 963a89e + d60e698 commit 156d32d

File tree

477 files changed

+8339
-2820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

477 files changed

+8339
-2820
lines changed

benchmarks/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import org.elasticsearch.gradle.internal.info.BuildParams
1010

1111
apply plugin: 'elasticsearch.java'
1212
apply plugin: 'application'
13-
mainClassName = 'org.openjdk.jmh.Main'
13+
14+
application {
15+
mainClass = 'org.openjdk.jmh.Main'
16+
}
1417

1518
tasks.named("assemble").configure { enabled = false }
16-
archivesBaseName = 'elasticsearch-benchmarks'
19+
base {
20+
archivesName = 'elasticsearch-benchmarks'
21+
}
1722

1823
tasks.named("test").configure { enabled = false }
1924

build-conventions/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ plugins {
1717
group = "org.elasticsearch"
1818

1919
// This project contains Checkstyle rule implementations used by IDEs which use a Java 11 runtime
20-
targetCompatibility = 11
21-
sourceCompatibility = 11
20+
java {
21+
targetCompatibility = 11
22+
sourceCompatibility = 11
23+
}
2224

2325
gradlePlugin {
2426
// We already configure publication and we don't need or want the one that comes

build-tools-internal/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ gradlePlugin {
155155
id = 'elasticsearch.standalone-test'
156156
implementationClass = 'org.elasticsearch.gradle.internal.test.StandaloneTestPlugin'
157157
}
158+
stringTemplate {
159+
id = 'elasticsearch.string-templates'
160+
implementationClass = 'org.elasticsearch.gradle.internal.StringTemplatePlugin'
161+
}
158162
testFixtures {
159163
id = 'elasticsearch.test.fixtures'
160164
implementationClass = 'org.elasticsearch.gradle.internal.testfixtures.TestFixturesPlugin'
@@ -199,8 +203,10 @@ gradlePlugin {
199203
*****************************************************************************/
200204

201205
def minCompilerJava = versions.get("minimumCompilerJava")
202-
targetCompatibility = minCompilerJava
203-
sourceCompatibility = minCompilerJava
206+
java {
207+
targetCompatibility = minCompilerJava
208+
sourceCompatibility = minCompilerJava
209+
}
204210

205211
if (JavaVersion.current() < JavaVersion.toVersion(minCompilerJava)) {
206212
throw new GradleException("Java ${minCompilerJava} is required to build Elasticsearch but current Java is version ${JavaVersion.current()}.")
@@ -269,6 +275,7 @@ dependencies {
269275
// needs to match the jackson minor version in use
270276
api buildLibs.json.schema.validator
271277
api buildLibs.jackson.dataformat.yaml
278+
api buildLibs.antlrst4
272279
api buildLibs.asm
273280
api buildLibs.asm.tree
274281
api buildLibs.httpclient
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=5625a0ae20fe000d9225d000b36909c7a0e0e8dda61c19b12da769add847c975
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
3+
distributionSha256Sum=5022b0b25fe182b0e50867e77f484501dba44feeea88f5c1f13b6b4660463640
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
55
networkTimeout=10000
6+
validateDistributionUrl=true
67
zipStoreBase=GRADLE_USER_HOME
78
zipStorePath=wrapper/dists
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal;
10+
11+
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest;
12+
import org.gradle.testkit.runner.TaskOutcome;
13+
14+
class StringTemplatePluginTest extends AbstractGradleFuncTest {
15+
16+
def "test substitution"() {
17+
given:
18+
internalBuild()
19+
file('src/main/p/X-Box.java.st') << """
20+
public class \$Type\$Box {
21+
final \$type\$ value;
22+
public \$Type\$Box(\$type\$ value) {
23+
this.value = value;
24+
}
25+
}
26+
""".stripIndent().stripTrailing()
27+
file('src/main/generated-src/someFile.txt') << """
28+
Just some random data
29+
"""
30+
31+
buildFile << """
32+
apply plugin: 'elasticsearch.build'
33+
apply plugin: 'elasticsearch.string-templates'
34+
35+
tasks.named("stringTemplates").configure {
36+
template {
37+
it.properties = ["Type" : "Int", "type" : "int"]
38+
it.inputFile = new File("${projectDir}/src/main/p/X-Box.java.st")
39+
it.outputFile = "p/IntBox.java"
40+
}
41+
template {
42+
it.properties = ["Type" : "Long", "type" : "long"]
43+
it.inputFile = new File("${projectDir}/src/main/p/X-Box.java.st")
44+
it.outputFile = "p/LongBox.java"
45+
}
46+
}
47+
"""
48+
49+
when:
50+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
51+
52+
then:
53+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
54+
file("src/main/generated-src/someFile.txt").exists() == false
55+
file("src/main/generated-src/p/IntBox.java").exists()
56+
file("src/main/generated-src/p/LongBox.java").exists()
57+
58+
//assert output
59+
normalized(file("src/main/generated-src/p/IntBox.java").text) == """
60+
public class IntBox {
61+
final int value;
62+
public IntBox(int value) {
63+
this.value = value;
64+
}
65+
}
66+
""".stripIndent().stripTrailing()
67+
normalized(file("src/main/generated-src/p/LongBox.java").text) == """
68+
public class LongBox {
69+
final long value;
70+
public LongBox(long value) {
71+
this.value = value;
72+
}
73+
}
74+
""".stripIndent().stripTrailing()
75+
}
76+
77+
def "test basic conditional"() {
78+
given:
79+
internalBuild()
80+
file('src/main/Color.txt.st') << """
81+
\$if(Red)\$1 Red\$endif\$
82+
\$if(Blue)\$2 Blue\$endif\$
83+
\$if(Green)\$3 Green\$endif\$
84+
""".stripIndent().stripTrailing()
85+
86+
buildFile << """
87+
apply plugin: 'elasticsearch.build'
88+
apply plugin: 'elasticsearch.string-templates'
89+
90+
tasks.named("stringTemplates").configure {
91+
template {
92+
it.properties = ["Red" : "true", "Blue" : "", "Green" : "true"]
93+
it.inputFile = new File("${projectDir}/src/main/Color.txt.st")
94+
it.outputFile = "Color.txt"
95+
}
96+
}
97+
"""
98+
99+
when:
100+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
101+
102+
then:
103+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
104+
file("src/main/generated-src/Color.txt").exists()
105+
//assert output
106+
normalized(file("src/main/generated-src/Color.txt").text) == """
107+
1 Red
108+
3 Green
109+
""".stripIndent().stripTrailing()
110+
}
111+
112+
def "test if then else"() {
113+
given:
114+
internalBuild()
115+
file('src/main/Token.txt.st') << """
116+
\$if(Foo)\$1 Foo
117+
\$elseif(Bar)\$2 Bar
118+
\$else\$3 Baz
119+
\$endif\$
120+
""".stripIndent().stripTrailing()
121+
122+
buildFile << """
123+
apply plugin: 'elasticsearch.build'
124+
apply plugin: 'elasticsearch.string-templates'
125+
126+
tasks.named("stringTemplates").configure {
127+
template {
128+
it.properties = [:] // no properties
129+
it.inputFile = new File("${projectDir}/src/main/Token.txt.st")
130+
it.outputFile = "Token.txt"
131+
}
132+
}
133+
"""
134+
135+
when:
136+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
137+
138+
then:
139+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
140+
file("src/main/generated-src/Token.txt").exists()
141+
//assert output
142+
normalized(file("src/main/generated-src/Token.txt").text) == """
143+
3 Baz
144+
""".stripIndent().stripTrailing()
145+
}
146+
147+
def "output file already present and up to date"() {
148+
given:
149+
internalBuild()
150+
file('src/main/UpToDate.txt.st') << """
151+
Hello World!
152+
""".stripIndent().stripTrailing()
153+
// the output file is already created and up to date (content wise)
154+
file('src/main/generated-src/UpToDate.txt') << """
155+
Hello World!
156+
""".stripIndent().stripTrailing()
157+
158+
buildFile << """
159+
apply plugin: 'elasticsearch.build'
160+
apply plugin: 'elasticsearch.string-templates'
161+
162+
tasks.named("stringTemplates").configure {
163+
template {
164+
it.properties = [:] // no properties
165+
it.inputFile = new File("${projectDir}/src/main/UpToDate.txt.st")
166+
it.outputFile = "UpToDate.txt"
167+
}
168+
}
169+
"""
170+
171+
when:
172+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
173+
174+
then:
175+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
176+
file("src/main/generated-src/UpToDate.txt").exists()
177+
//assert output - expect the original output
178+
normalized(file("src/main/generated-src/UpToDate.txt").text) == """
179+
Hello World!
180+
""".stripIndent().stripTrailing()
181+
}
182+
183+
def "output file already present but not up to date"() {
184+
given:
185+
internalBuild()
186+
file('src/main/Message.txt.st') << """
187+
Hello World!
188+
""".stripIndent().stripTrailing()
189+
// the output file is already created, but not up to date (content wise)
190+
file('src/main/generated-src/Message.txt') << """
191+
Hello Chris xx
192+
""".stripIndent().stripTrailing()
193+
194+
buildFile << """
195+
apply plugin: 'elasticsearch.build'
196+
apply plugin: 'elasticsearch.string-templates'
197+
198+
tasks.named("stringTemplates").configure {
199+
template {
200+
it.properties = [:] // no properties
201+
it.inputFile = new File("${projectDir}/src/main/Message.txt.st")
202+
it.outputFile = "Message.txt"
203+
}
204+
}
205+
"""
206+
207+
when:
208+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
209+
210+
then:
211+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
212+
file("src/main/generated-src/Message.txt").exists()
213+
//assert output - expect the updated message output
214+
normalized(file("src/main/generated-src/Message.txt").text) == """
215+
Hello World!
216+
""".stripIndent().stripTrailing()
217+
}
218+
219+
def "cleanup delete files"() {
220+
given:
221+
internalBuild()
222+
file('src/main/generated-src/someFile.txt') << """
223+
Just some random data
224+
"""
225+
226+
buildFile << """
227+
apply plugin: 'elasticsearch.build'
228+
apply plugin: 'elasticsearch.string-templates'
229+
230+
tasks.named("stringTemplates").configure {
231+
// no templates
232+
}
233+
"""
234+
235+
when:
236+
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()
237+
238+
then:
239+
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
240+
file("src/main/generated-src/someFile.txt").exists() == false
241+
file("src/main/generated-src").exists() == true
242+
}
243+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal;
10+
11+
import org.gradle.api.Plugin;
12+
import org.gradle.api.Project;
13+
import org.gradle.api.plugins.JavaPlugin;
14+
import org.gradle.api.plugins.JavaPluginExtension;
15+
import org.gradle.api.tasks.SourceSet;
16+
import org.gradle.api.tasks.SourceSetContainer;
17+
import org.gradle.api.tasks.TaskProvider;
18+
19+
import java.io.File;
20+
21+
public class StringTemplatePlugin implements Plugin<Project> {
22+
@Override
23+
public void apply(Project project) {
24+
File outputDir = project.file("src/main/generated-src/");
25+
26+
TaskProvider<StringTemplateTask> generateSourceTask = project.getTasks().register("stringTemplates", StringTemplateTask.class);
27+
generateSourceTask.configure(stringTemplateTask -> stringTemplateTask.getOutputFolder().set(outputDir));
28+
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
29+
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
30+
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
31+
mainSourceSet.getJava().srcDir(generateSourceTask);
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)