1
+ import java.nio.file.Paths
2
+ import kotlin.io.path.pathString
3
+
4
+ /*
5
+ External Configuration Properties
6
+ =================================
7
+ Below values can be overridden when invoking gradle build using property arguments, for example:
8
+
9
+ ./gradlew build -Pversion=2.0
10
+
11
+ group => The group ID
12
+ version => The version
13
+ nuixEngineDir => Overrides value to engine release otherwise pulled from ENV var NUIX_ENGINE_DIR
14
+ tempDir => Used to override temp directory for testing which would otherwise default to dir in localappdata
15
+ testDataDir => Directory tests can load test data they depend on from
16
+ testOutputDirectory => Root directory where tests may write data while running. Each test run will create a timestamp subdirectory
17
+ nuixUsername => Username used to authenticate with CLS (Cloud License Server).
18
+ Otherwise, would be pulled from ENV var NUIX_USERNAME
19
+ nuixPassword => Password used to authenticate with CLS (Cloud License Server).
20
+ Otherwise, would be pulled from ENV var NUIX_PASSWORD
21
+ gpr.user => GitHub username for retrieving engine wrapper package used in tests.
22
+ Otherwise, would be pulled from ENV var GITHUB_USERNAME
23
+ gpr.key => GitHub classic token for retrieving engine wrapper package used in tests, needs at least "read:packages" permission.
24
+ Otherwise, would be pulled from ENV var GITHUB_TOKEN
25
+ */
26
+
27
+ plugins {
28
+ id(" java" )
29
+ }
30
+
31
+ // So we don't get "unmappable character for encoding windows-1252" errors on a Windows machine
32
+ tasks.compileJava.get().options.encoding = " UTF-8"
33
+ tasks.compileTestJava.get().options.encoding = " UTF-8"
34
+
35
+ group = findProperty(" group" ) ? : " com.nuix.innovation"
36
+ version = findProperty(" version" ) ? : " 1.23.0"
37
+
38
+ project.extra[" nuixEngineDirectory" ] = findProperty(" nuixEngineDirectory" ) ? : System .getenv(" NUIX_ENGINE_DIR" )
39
+ if (project.extra[" nuixEngineDirectory" ].toString().isBlank()) {
40
+ throw InvalidUserDataException (" Please populate the environment variable 'NUIX_ENGINE_DIR' with directory containing a Nuix Engine release" )
41
+ }
42
+ System .out .println (" Resolved 'nuixEngineDirectory': " + project.extra[" nuixEngineDirectory" ].toString())
43
+
44
+ // Determines where Nuix dependencies can be found and where JARs will be copied to for tasks:
45
+ // - copyDependencyJarsToEngine
46
+ // - copyJarToEngine
47
+ // - copyJarsToEngine (test execution invokes this)
48
+ project.extra[" engineLibDir" ] = Paths .get(project.extra[" nuixEngineDirectory" ].toString(), " lib" ).pathString
49
+
50
+ // Necessary to be on PATH when test is ran which makes use of Nuix engine
51
+ project.extra[" engineBinDir" ] = Paths .get(project.extra[" nuixEngineDirectory" ].toString(), " bin" ).pathString
52
+ project.extra[" engineBinX86Dir" ] = Paths .get(project.extra[" nuixEngineDirectory" ].toString(), " bin" , " x86" ).pathString
53
+
54
+ // Determines destination for tasks:
55
+ // - copyDependencyJarsToApp
56
+ // - copyJarToApp
57
+ // - copyJarsToApp
58
+ project.extra[" nuixAppLibDir" ] = findProperty(" nuixAppLibDir" )
59
+
60
+ // Configures temp directory used in several places during test execution:
61
+ // - System property 'java.io.tmpdir'
62
+ // - ENV variable 'TEMP'
63
+ // - ENV variable 'TMP'
64
+ project.extra[" nuixTempDirectory" ] = findProperty(" tempDir" )
65
+ ? : Paths .get(System .getenv(" LOCALAPPDATA" ), " Temp" , " Nuix" ).pathString
66
+
67
+ // Directory used to store data a test may rely on (like sample data)
68
+ project.extra[" testDataDirectory" ] = findProperty(" testDataDirectory" )
69
+ ? : Paths .get(" ${projectDir} " , " .." , " .." , " TestData" ).pathString
70
+
71
+ // Directory that tests may write data to, unique to each test invocation
72
+ project.extra[" testOutputDirectory" ] = findProperty(" testOutputDirectory" )
73
+ ? : Paths .get(" ${projectDir} " , " .." , " .." , " TestOutput" , " ${System .currentTimeMillis()} " )
74
+
75
+ repositories {
76
+ mavenCentral()
77
+
78
+ val github_username = project.findProperty(" gpr.user" ) as String? ? : System .getenv(" GITHUB_USERNAME" )
79
+ val github_token = project.findProperty(" gpr.key" ) as String? ? : System .getenv(" GITHUB_TOKEN" )
80
+
81
+ maven {
82
+ url = uri(" https://maven.pkg.github.com/nuix/nuix-java-engine-baseline" )
83
+ credentials {
84
+ username = github_username
85
+ password = github_token
86
+ }
87
+ }
88
+ }
89
+
90
+ // Dependencies referenced using this configuration will be copied as part these tasks:
91
+ // - CopyDependencyJarsToApp
92
+ // - CopyDependencyJarsToEngine
93
+ // - copyJarsToApp
94
+ // - copyJarsToEngine (Note this is used to get JARs in place before test run)
95
+ val deployedDependency: Configuration by configurations.creating {
96
+ isTransitive = true
97
+ }
98
+
99
+ dependencies {
100
+ implementation(" org.jetbrains.kotlin:kotlin-stdlib:+" )
101
+ implementation(" org.jetbrains:annotations:24.0.1" )
102
+ compileOnly(" org.projectlombok:lombok:1.18.26" )
103
+ annotationProcessor(" org.projectlombok:lombok:1.18.26" )
104
+ testCompileOnly(" org.projectlombok:lombok:1.18.26" )
105
+ testAnnotationProcessor(" org.projectlombok:lombok:1.18.26" )
106
+ testImplementation(" org.junit.jupiter:junit-jupiter-api:5.9.2" )
107
+ testRuntimeOnly(" org.junit.jupiter:junit-jupiter-engine:5.9.2" )
108
+
109
+ // Wrapper class for running tests in engine, pulled from public facing GitHub repository
110
+ testImplementation(" com.nuix.innovation:enginewrapper:Nuix9.10-v1.1.4" )
111
+
112
+ // Used to extract test data
113
+ testImplementation(" net.lingala.zip4j:zip4j:2.11.5" )
114
+
115
+ // Dependencies from engine lib referenced during compile time
116
+
117
+ val compileDependencies = arrayOf(
118
+ " *joda*.jar" ,
119
+ " nuix-api*.jar" ,
120
+ " nuix-util-*.jar" ,
121
+ " nuix-data-*.jar" ,
122
+ " nuix-scripting-*.jar" ,
123
+ " aspose-cells-*.jar" ,
124
+ " aspose-pdf-*.jar" ,
125
+ " *slf4j*.jar" ,
126
+ " *log4j*.jar" ,
127
+ " *commons-io*.jar" ,
128
+ " *commons-csv*.jar" ,
129
+ " *commons-math*.jar" ,
130
+ " *commons-lang*.jar" ,
131
+ " *commons-text*.jar" ,
132
+ " *commons-compress*.jar" ,
133
+ " RoaringBitmap-*.jar" ,
134
+ " sqlite*.jar" ,
135
+ " guava*.jar" ,
136
+ " gson*.jar" ,
137
+ " jruby*.jar" ,
138
+ " flying-saucer*.jar" ,
139
+ " jaxb*.jar" ,
140
+ " lucene*.jar" ,
141
+ " jsoup*.jar" ,
142
+ " itext*.jar" ,
143
+ " sevenzip*.jar"
144
+ )
145
+ val lib = project.extra[" engineLibDir" ].toString()
146
+ compileOnly(fileTree(baseDir = lib) { include(* compileDependencies) })
147
+ testCompileOnly(fileTree(baseDir = lib) { include(* compileDependencies) })
148
+
149
+ // When tests run which make use of NuixEngine wrapper class, it will need to have the
150
+ // Nuix Engine dependencies in the lib folder present on the class path
151
+ testRuntimeOnly(fileTree(baseDir = project.extra[" engineLibDir" ].toString()) {
152
+ include(" *.jar" )
153
+ })
154
+ }
155
+
156
+ java {
157
+ toolchain {
158
+ languageVersion.set(JavaLanguageVersion .of(11 ))
159
+ }
160
+ }
161
+
162
+ fun configureTestEnvironment (test : Test ) {
163
+ // Args passed to JVM running tests
164
+ test.jvmArgs(
165
+ " --add-exports=java.base/jdk.internal.loader=ALL-UNNAMED" , // Engine 9.6(?) and later require this
166
+ " -Xmx4G" ,
167
+ " -Djava.io.tmpdir=\" ${project.extra[" nuixTempDirectory" ]} \" " ,
168
+ // "-verbose:class" // Can help troubleshoot weird dependency issues
169
+ )
170
+
171
+ // Configure ENV vars for JVM tests run in
172
+ test.setEnvironment(
173
+ // Add our engine release's bin and bin/x86 to PATH env var of test JVM process
174
+ Pair (" PATH" , " ${System .getenv(" PATH" )} ;${project.extra[" engineBinDir" ]} ;${project.extra[" engineBinX86Dir" ]} " ),
175
+
176
+ // Define where tests can place re-usable test data
177
+ Pair (" TEST_DATA_DIRECTORY" , project.extra[" testDataDirectory" ]),
178
+
179
+ // Define where tests can write output produce for later review
180
+ Pair (" TEST_OUTPUT_DIRECTORY" , project.extra[" testOutputDirectory" ]),
181
+
182
+ // Forward ENV username and password
183
+ Pair (" NUIX_USERNAME" , System .getenv(" NUIX_USERNAME" )),
184
+ Pair (" NUIX_PASSWORD" , System .getenv(" NUIX_PASSWORD" )),
185
+
186
+ // Forward LOCALAPPDATA and APPDATA
187
+ Pair (" LOCALAPPDATA" , System .getenv(" LOCALAPPDATA" )),
188
+ Pair (" APPDATA" , System .getenv(" APPDATA" )),
189
+ Pair (" PROGRAMDATA" , System .getenv(" PROGRAMDATA" )),
190
+
191
+ // Important to have in some instances, otherwise some code may resolve a local
192
+ // path in project tree rather than actual system drive
193
+ Pair (" SYSTEMDRIVE" , System .getenv(" SYSTEMDRIVE" )),
194
+
195
+ // We need to make sure we set these so workers will properly resolve temp dir
196
+ // (when using a worker based operation via EngineWrapper).
197
+ Pair (" TEMP" , project.extra[" nuixTempDirectory" ]),
198
+ Pair (" TMP" , project.extra[" nuixTempDirectory" ]),
199
+
200
+ Pair (" NUIX_ENGINE_DIR" , project.extra[" nuixEngineDirectory" ])
201
+ )
202
+ }
203
+
204
+ // Copies compiled JAR to engine lib directory
205
+ tasks.register<Copy >(" copyJarToEngine" ) {
206
+ dependsOn(tasks.jar)
207
+ // You will receive implicit dependency errors without this
208
+ mustRunAfter(tasks.compileJava, tasks.compileTestJava)
209
+ val jarName = " ${rootProject.name} .jar"
210
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
211
+ from(tasks.jar)
212
+ into(Paths .get(project.extra[" engineLibDir" ].toString()).toFile())
213
+ rename(" .*\\ .jar" , jarName)
214
+ }
215
+
216
+ // Copies 'deployedDependency' JARs and their transitive JARs to engine lib directory
217
+ tasks.register<Copy >(" copyDependencyJarsToEngine" ) {
218
+ // You will receive implicit dependency errors without this
219
+ mustRunAfter(tasks.compileJava, tasks.compileTestJava)
220
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
221
+ from(configurations.findByName(" deployedDependency" ))
222
+ into(Paths .get(project.extra[" engineLibDir" ].toString()).toFile())
223
+ rename(" (.*)\\ .jar" , " ${rootProject.name} -Dependency-$1.jar" )
224
+ }
225
+
226
+ // Copies JAR and 'deployedDependency' JARs to engine lib directory
227
+ // Invoked before tests are ran
228
+ tasks.register(" copyJarsToEngine" ) {
229
+ println (" Copying files to engine lib dir..." )
230
+ dependsOn(" copyJarToEngine" )
231
+ dependsOn(" copyDependencyJarsToEngine" )
232
+ }
233
+
234
+ // Copies compiled JAR to Nuix Workstation lib directory
235
+ // as defined by project.extra["nuixAppLibDir"]
236
+ tasks.register<Copy >(" copyJarToApp" ) {
237
+ dependsOn(tasks.jar)
238
+ val jarName = " ${rootProject.name} .jar"
239
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
240
+ from(tasks.jar)
241
+ into(Paths .get(project.extra[" nuixAppLibDir" ].toString()).toFile())
242
+ rename(" .*\\ .jar" , jarName)
243
+ }
244
+
245
+ // Copies 'deployedDependency' JARs and their transitive JARs to Nuix Workstation lib directory
246
+ // as defined by project.extra["nuixAppLibDir"]
247
+ tasks.register<Copy >(" copyDependencyJarsToApp" ) {
248
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
249
+ from(configurations.findByName(" deployedDependency" ))
250
+ into(Paths .get(project.extra[" nuixAppLibDir" ].toString()).toFile())
251
+ rename(" (.*)\\ .jar" , " ${rootProject.name} -Dependency-$1.jar" )
252
+ }
253
+
254
+ // Copies JAR and 'deployedDependency' JARs to Nuix Workstation lib directory
255
+ // as defined by project.extra["nuixAppLibDir"]
256
+ tasks.register(" copyJarsToApp" ) {
257
+ println (" Copying files to app lib dir..." )
258
+ dependsOn(" copyinJarToApp" )
259
+ dependsOn(" copyDependencyJarsToApp" )
260
+ }
261
+
262
+ // Before tests are ran we need to make sure a few things are done:
263
+ // - JAR and 'deployedDependency' JARs have been copied to engine lib dir
264
+ // - IDE executes our test using JUnit
265
+ // - Environment configuration is performed which sets up ENV vars, properties, etc
266
+ tasks.test {
267
+ dependsOn(tasks.findByName(" copyJarsToEngine" ))
268
+ mustRunAfter(" copyDependencyJarsToEngine" , " copyJarToEngine" )
269
+ useJUnitPlatform()
270
+ configureTestEnvironment(this )
271
+ }
272
+
273
+ // Customize where Javadoc output is written to
274
+ tasks.getByName<Javadoc >(" javadoc" ) {
275
+ options.encoding = " UTF-8"
276
+ setDestinationDir(Paths .get(" $projectDir " , " .." , " .." , " docs" ).toFile())
277
+ }
0 commit comments