@@ -2,6 +2,7 @@ package com.worksap.nlp.tools
2
2
3
3
import org.gradle.api.Plugin
4
4
import org.gradle.api.Project
5
+ import org.gradle.api.Action
5
6
import org.gradle.api.Task
6
7
import org.gradle.api.Transformer
7
8
import org.gradle.api.model.ObjectFactory
@@ -49,67 +50,6 @@ class PluginDescriptor {
49
50
}
50
51
}
51
52
52
- class StringProvider implements Provider<String > , Serializable {
53
- private static final long serialVersionUID = 42L
54
- String value
55
-
56
- @Override
57
- String get () {
58
- return value
59
- }
60
-
61
- @Override
62
- String getOrNull () {
63
- return value
64
- }
65
-
66
- @Override
67
- String getOrElse (String defaultValue ) {
68
- if (value == null ) return defaultValue else return value
69
- }
70
-
71
- @Override
72
- def <S> Provider<S> map (Transformer<? extends S, ? super String > transformer ) {
73
- throw new IllegalStateException (" not implemented" )
74
- }
75
-
76
- @Override
77
- def <S> Provider<S> flatMap (Transformer<? extends Provider<? extends S> , ? super String > transformer ) {
78
- throw new IllegalStateException (" not implemented" )
79
- }
80
-
81
- @Override
82
- boolean isPresent () {
83
- return value != null
84
- }
85
-
86
- @Override
87
- Provider<String > orElse (String value ) {
88
- return this
89
- }
90
-
91
- @Override
92
- Provider<String > orElse (Provider<? extends String > provider ) {
93
- if (value == null ) return provider else return this
94
- }
95
-
96
- @Override
97
- Provider<String > forUseAtConfigurationTime () {
98
- return this
99
- }
100
-
101
- @Override
102
- def <U, R> Provider<R> zip (Provider<U> right , BiFunction<? super String , ? super U, ? extends R> combiner ) {
103
- throw new IllegalStateException (" not implemented" )
104
- }
105
-
106
-
107
- @Override
108
- String toString () {
109
- return value;
110
- }
111
- }
112
-
113
53
class EsTestEnvPlugin implements Plugin<Project > {
114
54
115
55
private final ObjectFactory objectFactory
@@ -124,14 +64,28 @@ class EsTestEnvPlugin implements Plugin<Project> {
124
64
EsTestEnvExtension ext = new EsTestEnvExtension ()
125
65
target. extensions. add(EsTestEnvExtension . class, " esTestEnv" , ext)
126
66
target. tasks. named(" test" ). configure { Test task ->
127
- Provider<String > envRoot = new StringProvider ()
67
+ // Determine the final, unique path for this test run during the configuration phase.
68
+ // This is required because the test JVM is forked before the task's actions run,
69
+ // and it needs java.io.tmpdir to exist on startup. A newer/faster JDK can expose
70
+ // this timing issue.
71
+ def formatter = DateTimeFormatter . ofPattern(" yyyyMMdd-HH-mm-ss-SSS" , Locale . ROOT )
72
+ def now = Instant . now(). atZone(ZoneId . of(" UTC" ))
73
+ def timepart = formatter. format(now)
128
74
Path esHomePath = target. buildDir. toPath(). resolve(" es-env" )
129
- envRoot. setValue(esHomePath. toString())
130
- task. systemProperty(" sudachi.es.root" , envRoot)
75
+ Path finalEnvRootPath = esHomePath. resolve(timepart)
76
+
77
+ // Create the directory during configuration. This is generally an anti-pattern,
78
+ // but necessary to prevent the "java.io.tmpdir directory does not exist" warning from the forked JVM.
79
+ Files . createDirectories(finalEnvRootPath)
80
+
81
+ task. systemProperty(" sudachi.es.root" , finalEnvRootPath. toString())
82
+ task. systemProperty(" java.io.tmpdir" , finalEnvRootPath. toString())
83
+
131
84
task. doFirst {
132
- envRoot. setValue(prepareEnvironment(target, task, esHomePath, ext). toString())
85
+ // The root directory is already created, just populate it with files.
86
+ populateEnvironment(target, task, finalEnvRootPath, ext)
133
87
}
134
- task. doLast { cleanupEnvironment(esHomePath) }
88
+ task. doLast { cleanupEnvironment(target, esHomePath) }
135
89
ext. additionalPlugins. forEach {
136
90
if (it. value instanceof TaskProvider || it. value instanceof Task ) {
137
91
dependsOn(it. value)
@@ -147,7 +101,18 @@ class EsTestEnvPlugin implements Plugin<Project> {
147
101
task. systemProperty(" tests.task" , task. getPath())
148
102
task. systemProperty(" gradle.dist.lib" , gradleRtDir. resolve(" lib" ). toString())
149
103
task. systemProperty(" gradle.worker.jar" , gradleCacheDir. resolve(" workerMain/gradle-worker.jar" ). toString())
150
- task. systemProperty(" java.io.tmpdir" , envRoot)
104
+
105
+ // OpenSearch test framework requires reflective access to JDK internals, which is restricted on Java 17+.
106
+ // It also uses a Security Manager, which is disabled by default in Java 17+.
107
+ // We need to add JVM arguments to re-enable these features for the tests to run.
108
+ def esExtension = target. extensions. findByName(" sudachiEs" )
109
+ if (esExtension != null && esExtension. kind. get(). engine == EngineType.OpenSearch ) {
110
+ task. jvmArgs(
111
+ ' --add-opens=java.base/java.lang=ALL-UNNAMED'
112
+ )
113
+ // Allow the test framework to set a Security Manager
114
+ task. systemProperty(" java.security.manager" , " allow" )
115
+ }
151
116
}
152
117
153
118
target. gradle. taskGraph. whenReady {
@@ -172,12 +137,8 @@ class EsTestEnvPlugin implements Plugin<Project> {
172
137
}
173
138
}
174
139
175
- private Path prepareEnvironment (Project project , Test testTask , Path basePath , EsTestEnvExtension ext ) {
176
- def formatter = DateTimeFormatter . ofPattern(" yyyyMMdd-HH-mm-ss" , Locale . ROOT )
177
- def now = Instant . now(). atZone(ZoneId . of(" UTC" ))
178
- def timepart = formatter. format(now)
179
- def rootPath = basePath. resolve(timepart)
180
-
140
+ /* * Populates the pre-created environment directory with necessary files for the test run. */
141
+ private void populateEnvironment (Project project , Test testTask , Path rootPath , EsTestEnvExtension ext ) {
181
142
def pluginDir = rootPath. resolve(" plugins" )
182
143
def configPath = rootPath. resolve(" config" )
183
144
@@ -204,12 +165,10 @@ class EsTestEnvPlugin implements Plugin<Project> {
204
165
Files . createDirectories(sudachiConfigDir)
205
166
Files . copy(ext. systemDic, sudachiConfigDir. resolve(" system_core.dic" ))
206
167
Files . copy(ext. configFile, sudachiConfigDir. resolve(" sudachi.json" ))
207
-
208
- return rootPath
209
168
}
210
169
211
- private void cleanupEnvironment (Path envPath ) {
212
-
170
+ private void cleanupEnvironment (Project project , Path envPath ) {
171
+ // project.delete(envPath)
213
172
}
214
173
215
174
@@ -273,5 +232,3 @@ class EsTestEnvPlugin implements Plugin<Project> {
273
232
.writeTo(outputStream. newWriter(' utf-8' ))
274
233
}
275
234
}
276
-
277
-
0 commit comments