-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathproject.gradle
402 lines (359 loc) · 14.8 KB
/
project.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// Common configuration applied to all projects
import java.nio.file.*
import java.nio.file.attribute.*
import java.util.stream.Collectors
import java.util.stream.Stream
import java.util.stream.StreamSupport
import static org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS
import static org.apache.tools.ant.taskdefs.condition.Os.isFamily
import static org.jetbrains.gradle.ext.ShortenCommandLine.MANIFEST
import org.jetbrains.gradle.ext.Application
import org.jetbrains.gradle.ext.JUnit
configurations.all {
resolutionStrategy {
// check for changing (i.e. SNAPSHOT) updates every build
cacheChangingModulesFor 0, 'seconds'
//failOnVersionConflict()
// This has been replaced with eclipse angus implementation
exclude group: "com.sun.activation", module: "jakarta.activation"
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.eclipse.angus' && details.requested.name == 'angus-activation' && details.requested.version == '1.0.0') {
details.useVersion '2.0.0'
}
}
}
}
// Ensure git hook creation task is executed
if (project == rootProject) {
project.afterEvaluate {
if (rootProject.hasProperty("gradleFileEncrypt")) {
println("File encryption plugin config found, configuring git pre commit hook and decrypt task dependency")
try {
// Write git hook for encryption plugin checks before any commit
def path = Paths.get(rootProject.projectDir.path, ".git/hooks/pre-commit")
def f = path.toFile()
f.text = """#!/bin/sh
echo "***** Running gradle encryption plugin checkFilesGitIgnored task ******"
./gradlew checkFilesGitIgnoredNew
status=\$?
if [ \$status != 0 ]; then
echo "***** One or more encrypted files are not listed in a .gitignore - please add to prevent unencrypted version of file(s) from being committed *****"
fi
exit \$status
"""
Set<PosixFilePermission> perms = Files.readAttributes(path, PosixFileAttributes.class).permissions()
perms.add(PosixFilePermission.OWNER_WRITE)
perms.add(PosixFilePermission.OWNER_READ)
perms.add(PosixFilePermission.OWNER_EXECUTE)
perms.add(PosixFilePermission.GROUP_WRITE)
perms.add(PosixFilePermission.GROUP_READ)
perms.add(PosixFilePermission.GROUP_EXECUTE)
perms.add(PosixFilePermission.OTHERS_READ)
perms.add(PosixFilePermission.OTHERS_EXECUTE)
Files.setPosixFilePermissions(path, perms)
} catch (Exception ignored) {}
// Add dependency on decrypt task for deployment installDist only if GFE_PASSWORD defined
def password = System.env.GFE_PASSWORD
if (password != null) {
Task decryptTask = getTasksByName("decryptFiles", false)[0]
try {
def installDist = tasks.getByPath(":deployment:installDist")
installDist.dependsOn decryptTask
installDist.mustRunAfter(decryptTask)
} catch (Exception ex) {
println("Failed to add decryptFiles task dependency: " + ex)
}
}
} else {
// Remove git hook
try {
Files.delete(Paths.get(rootProject.projectDir.path, ".git/hooks/pre-commit"))
} catch (Exception ignored) {
}
}
}
}
// Configure Conditional plugins
if (project == rootProject) {
apply plugin: "org.jetbrains.gradle.plugin.idea-ext"
// Configure IDEA
if (project.hasProperty("idea") && idea.project) {
// IDEA settings
idea.project.settings {
compiler {
javac {
javacAdditionalOptions "-parameters"
}
}
runConfigurations {
defaults(JUnit) {
shortenCommandLine = MANIFEST
workingDirectory = projectDir.toString()
}
defaults(Application) {
mainClass = 'org.openremote.manager.Main'
shortenCommandLine = MANIFEST
workingDirectory = projectDir.toString()
}
"Empty"(Application) {
moduleName = getProject().idea.module.name + ".openremote.manager.main"
}
}
}
idea.project.settings.runConfigurations {
"Custom Deployment"(Application) {
moduleName = "${getProject().idea.module.name}.setup.main"
envs = [
OR_MAP_SETTINGS_PATH: "deployment/map/mapsettings.json",
OR_MAP_TILES_PATH: "deployment/map/mapdata.mbtiles",
OR_CUSTOM_APP_DOCROOT: "deployment/manager/app",
OR_CONSOLE_APP_CONFIG_DOCROOT: "deployment/manager/consoleappconfig"
]
}
}
}
}
// Give test projects more memory (Gradle 5 reduced this to 512MB)
subprojects {
tasks.withType(Test) {
maxHeapSize = "2g"
}
}
// Default repositories for dependency resolution
repositories {
mavenLocal()
maven {
url = "https://repo.osgeo.org/repository/release/"
}
mavenCentral()
maven {
url "https://pkgs.dev.azure.com/OpenRemote/OpenRemote/_packaging/OpenRemote/maven/v1"
}
maven {
url "https://s01.oss.sonatype.org/content/repositories/snapshots"
}
}
// Eclipse needs help
apply plugin: "eclipse"
// Intellij needs help
apply plugin: 'idea'
// Use the same output directories in IDE as in gradle
idea {
module {
outputDir file('build/classes/main')
testOutputDir file('build/classes/test')
excludeDirs += file(".node")
excludeDirs += file("node_modules")
excludeDirs += file("dist")
excludeDirs += file("lib")
excludeDirs += file("build")
}
}
/**
* This defines reusable config for the typescript generator plugin
*/
def createTSGeneratorConfigForModel(String outputFileName, Project...customProjectsToScan) {
def config = createTSGeneratorConfig(false, outputFileName, customProjectsToScan) <<
{
extensions = [
"org.openremote.model.util.AssetModelInfoExtension",
"CustomExtension",
"JsonSerializeExtension"
]
customTypeMappings = [
"com.fasterxml.jackson.databind.node.ObjectNode:{ [id: string]: any }",
"java.lang.Class<T>:string",
"org.openremote.model.attribute.MetaItem<T>:any"
]
customTypeProcessor = "CustomTypeProcessor"
generateInfoJson = true
}
return config
}
def createTSGeneratorConfigForClient(String outputFileName, File modelInfoJson, Project...customProjectsToScan) {
def config = createTSGeneratorConfig(true, outputFileName, customProjectsToScan) <<
{
extensions = [
"CustomExtension",
"JsonSerializeExtension",
"CustomAggregatedApiClient",
"cz.habarta.typescript.generator.ext.AxiosClientExtension"
]
customTypeMappings = [
"com.fasterxml.jackson.databind.node.ObjectNode:{ [id: string]: any }",
"java.lang.Class<T>:string",
"org.openremote.model.attribute.MetaItem<T>:any",
"org.openremote.model.asset.Asset<T>:Model.Asset",
"org.openremote.model.asset.AssetDescriptor<T>:Model.AssetDescriptor",
"org.openremote.model.asset.agent.Agent<T,U,V>:Model.Agent",
"org.openremote.model.asset.agent.AgentDescriptor<T,U,V>:Model.AgentDescriptor",
"org.openremote.model.value.MetaItemDescriptor<T>:Model.MetaItemDescriptor",
"org.openremote.model.value.ValueDescriptor<T>:Model.ValueDescriptor"
]
moduleDependencies = [
cz.habarta.typescript.generator.ModuleDependency.module(
"model",
"Model",
modelInfoJson,
(String) null,
(String) null
)
]
restNamespacing = "perResource"
}
return config
}
def createTSGeneratorConfig(boolean outputAPIClient, String outputFileName, Project...customProjectsToScan) {
def classPatternGlobs = Arrays.stream(customProjectsToScan).flatMap { project ->
return project.sourceSets.findByName('main').java.srcDirs.stream().map {
def srcPath = it
def isPackageDir = true
while (srcPath != null && isPackageDir) {
def files = srcPath.listFiles()
isPackageDir = files != null && files.length == 1 && files[0].isDirectory()
if (isPackageDir) {
srcPath = files[0]
}
}
Path packagePath = it.toPath().relativize(srcPath.toPath())
return StreamSupport
.stream(packagePath.spliterator(), false)
.map(Path::toString)
.collect(Collectors.joining(".")) + (outputAPIClient ? ".**Resource" : ".**")
}
}.toList()
def baseClassPattern = outputAPIClient
? customProjectsToScan.length == 0 ? [ "org.openremote.model.**Resource" ] : []
: [ "org.openremote.model.**" ]
return {
jsonLibrary = "jackson2"
classPatterns = baseClassPattern + classPatternGlobs
customTypeNamingFunction = "function(name, simpleName) { if (name.indexOf(\"\$\") > 0) return name.substr(name.lastIndexOf(\".\")+1).replace(\"\$\",\"\"); }"
excludeClassPatterns = [
"org.openremote.model.event.shared.*Filter**",
"org.openremote.model.util.**",
"org.openremote.model.flow.**",
"java.io.**",
"java.lang.**",
"org.hibernate.**",
"jakarta.**"
]
mapEnum = cz.habarta.typescript.generator.EnumMapping.asEnum
mapDate = cz.habarta.typescript.generator.DateMapping.asNumber
optionalProperties = "all" // TODO: cleanup model to be more explicit about optional params
outputFileType = "implementationFile"
outputKind = "module"
outputFile = outputFileName
jackson2Configuration = [
fieldVisibility: "ANY",
creatorVisibility: "ANY",
getterVisibility: "NONE",
isGetterVisibility: "NONE",
setterVisibility: "NONE"
]
jackson2Modules = [
"com.fasterxml.jackson.datatype.jdk8.Jdk8Module",
"com.fasterxml.jackson.datatype.jsr310.JavaTimeModule",
"com.fasterxml.jackson.module.paramnames.ParameterNamesModule"
]
}
}
def resolveTask(String path) {
tasks.getByPath(path)
}
def getYarnInstallTask() {
def customPackageJsonFile = Paths.get(rootProject.projectDir.path, "package.json").toFile()
if (!customPackageJsonFile.exists()) {
// No custom project yarn package.json so use standard openremote repo package.json
return resolveTask(":yarnInstall")
} else {
return tasks.getByPath(":yarnInstall")
}
}
// Gets the list of runtime JAR dependencies; can be used in custom project deployment installDist task to populate
// extensions directory
def getDeploymentJars(Project project = project) {
if (project.configurations.find { it.name == "runtimeClasspath" } == null) {
return []
}
// Dependencies already part of the manager are excluded so they do not appear on the classpath twice
return project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts
.findAll { !it.file.path.contains(".gradle") && !it.file.path.contains(".m2") }
.collect {
println "CopyLibs Artifact: ${it.file.path}"
return it.file
}
}
ext {
resolveTask = this.&resolveTask
getYarnInstallTask = this.&getYarnInstallTask
getDeploymentJars = this.&getDeploymentJars
createTSGeneratorConfigForClient = this.&createTSGeneratorConfigForClient
createTSGeneratorConfigForModel = this.&createTSGeneratorConfigForModel
}
// Add UI tasks
ext.npmCommand = {
cmd ->
isFamily(FAMILY_WINDOWS) ? "${cmd}.cmd" : cmd
}
// Add yarn tasks
tasks.register('yarnInstall', Exec) {
commandLine npmCommand("yarn"), "install"
}
tasks.register('yarnInstallForce', Exec) {
commandLine npmCommand("yarn"), "install", "--force"
}
tasks.register('npmClean', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "clean"
}
tasks.register('npmBuild', Exec) {
mustRunAfter npmClean
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "build"
}
tasks.register('npmTest', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "test"
}
tasks.register('npmServe', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "serve"
}
tasks.register('npmPrepare', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "prepublishOnly"
}
tasks.register('npmPublish', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "publish"
}
tasks.register('npmServeProduction', Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "serveProduction"
}
// Add typescript tasks
tasks.register('tscWatch', Exec) {
commandLine npmCommand("npx"), "tsc", "-b", "--watch"
}
// Configure Java build
plugins.withType(JavaPlugin).whenPluginAdded {
// Use Java 17
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
def warnLogFile = file("$buildDir/${name}Warnings.log")
logging.addStandardErrorListener(new StandardOutputListener() {
void onOutput(CharSequence output) {
warnLogFile << output
}
})
options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
options.encoding = 'UTF-8'
}
// Allow dependencyInsight checks across all projects
tasks.register('allDependencyInsight', DependencyInsightReportTask) {}
// JAR/ZIP base name is the fully qualified subproject name
archivesBaseName = "${rootProject.name}${path.replaceAll(":", "-")}"
}
// POM generator