forked from openremote/openremote
-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.gradle
322 lines (283 loc) · 11.4 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
// Common configuration applied to all projects
import java.nio.file.*
import java.nio.file.attribute.*
import java.util.Set
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
// Configure versions in gradle.properties (putting a gradle.properties file
// in a subproject only overrides root properties of same name for the actual
// subproject, not for its children!)
version = hasProperty("openremoteVersion") ? openremoteVersion : "0.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 = (isCustomProject() ? project(":openremote").projectDir.toString() : projectDir.toString())
}
defaults(Application) {
mainClass = 'org.openremote.manager.Main'
shortenCommandLine = MANIFEST
workingDirectory = (isCustomProject() ? project(":openremote").projectDir.toString() : projectDir.toString())
}
"Demo Setup"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.setup.demo" : ".setup.demo")
envs = [
OR_SETUP_TYPE: "demo"
]
}
"Demo Setup with Proxy"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.setup.demo" : ".setup.demo")
envs = [
OR_SETUP_TYPE: "demo",
OR_WEBSERVER_LISTEN_HOST: "0.0.0.0",
OR_SSL_PORT: "-1"
]
}
"Test Setup"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.setup.integration" : ".setup.integration")
}
"Test Setup with Proxy"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.setup.integration" : ".setup.integration")
envs = [
OR_WEBSERVER_LISTEN_HOST: "0.0.0.0",
OR_SSL_PORT: "-1"
]
}
"Empty"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.manager.main" : ".manager.main")
}
"Empty with Proxy"(Application) {
moduleName = getProject().idea.module.name + (isCustomProject() ? ".openremote.manager.main" : ".manager.main")
envs = [
OR_WEBSERVER_LISTEN_HOST: "0.0.0.0",
OR_SSL_PORT: "-1"
]
}
}
}
if (isCustomProject()) {
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 {
maven {
url = "https://repo.osgeo.org/repository/release/"
}
mavenCentral()
maven {
url "https://pkgs.dev.azure.com/OpenRemote/OpenRemote/_packaging/OpenRemote/maven/v1"
}
}
// 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")
}
}
// Helper functions for project/task resolution when the main
// repo is checked out as a git submodule and therefore a subproject
def isCustomProject() {
findProject(":openremote") != null
}
def resolvePath(String path) {
isCustomProject() ? ":openremote" + path : path
}
def resolveProject(String path) {
project(resolvePath(path))
}
def resolveTask(String path) {
tasks.getByPath(resolvePath(path))
}
def getYarnInstallTask() {
if (isCustomProject()) {
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")
}
} else {
// Just use openremote repo yarn install
resolveTask(":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 []
}
// Get all dependencies that are already part of the openremote manager and exclude these from the libs dir
// otherwise they will appear on the classpath twice (once in manager app dir and then again in extensions)
def excludeDependencies = resolveProject(":manager").configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts
return project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.findAll {
dep -> excludeDependencies.find { it == dep } == null && dep.name != "openremote-manager" }.collect {
println "CopyLibs Artifact: ${it.file.path}"
return it.file
}
}
ext {
resolvePath = this.&resolvePath
resolveProject = this.&resolveProject
resolveTask = this.&resolveTask
isCustomProject = this.&isCustomProject
getYarnInstallTask = this.&getYarnInstallTask
getDeploymentJars = this.&getDeploymentJars
}
// Add UI tasks
ext.npmCommand = {
cmd ->
isFamily(FAMILY_WINDOWS) ? "${cmd}.cmd" : cmd
}
// Add yarn tasks
task yarnInstall(type: Exec){
commandLine npmCommand("yarn"), "install"
}
task yarnInstallForce(type: Exec){
commandLine npmCommand("yarn"), "install", "--force"
}
task npmClean(type: Exec){
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "clean"
}
task npmBuild(type: Exec){
mustRunAfter npmClean
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "build"
}
task npmTest(type: Exec){
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "test"
}
task npmServe(type: Exec){
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "serve"
}
task npmPrepare(type: Exec){
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "prepublishOnly"
}
task npmPublish(type: Exec){
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "publish"
}
task npmServeProduction(type: Exec) {
dependsOn getYarnInstallTask()
commandLine npmCommand("yarn"), "run", "serveProduction"
}
// Add typescript tasks
task tscWatch(type: 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'
}
// JAR/ZIP base name is the fully qualified subproject name
archivesBaseName = "${rootProject.name}${path.replaceAll(":", "-")}"
}
// POM generator