-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
177 lines (142 loc) · 5.49 KB
/
build.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
import java.util.stream.Collectors
apply from: "variables.gradle"
def protectedModules = protectedModules
.stream()
.map { new ProtectedModule(project.ext, it[0], it[1], it[2]) }
.collect(Collectors.toList())
def modelDir = "$deploymentDir/$modelDirName"
def debugLevel = "lines,source"
if (generateFullDebugInfo) {
debugLevel = "lines,source,vars"
}
def publicApiJars = publicApiJars
.stream()
.map { "$mendixInstallDir/$it" }
.collect(Collectors.toList())
class ProtectedModule {
org.gradle.api.plugins.ExtraPropertiesExtension ext
String modulePath
List<String> included
List<String> excluded
ProtectedModule(ext, modulePath, included, excluded) {
this.ext = ext
this.modulePath = modulePath
this.included = included
this.excluded = excluded
}
private String root() {
"${ext.mendixProjectDir}/${modulePath}"
}
String userlib() {
"${root()}/${ext.userlibDirName}"
}
String javasource() {
"${root()}/${ext.javaSourceDirName}"
}
String resolveJar(String jar) {
"${userlib()}/$jar"
}
}
tasks.register("checkDependencies") {
description "Check dependencies"
def packagesArg = jvmRemovedPackages.collect { ["-p", it] }.flatten()
def classpath = (publicApiJars + "$mendixProjectDir/$userlibDirName/.*").join(File.pathSeparator)
def buffer = new ByteArrayOutputStream()
exec {
standardOutput = buffer
commandLine = ["java", "-Duser.language=en", "com.sun.tools.jdeps.Main", "-cp", classpath,
"--multi-release", "11", "-verbose:class"] + packagesArg + "$deploymentDir/$runDir"
}
def output = new String(buffer.toByteArray())
def lines = output.split("\\R")
if (lines.any { !it.contains("Warning: ") && it.toLowerCase().contains("not found") }) {
System.err.println output
throw new GradleException("Dependency check failed, most probably some packages and/or classes are not provided.")
}
}
tasks.register('clean', Delete) {
description 'clean the deployment directory'
delete modelDir
delete "$deploymentDir/$runDir"
}
tasks.register('clean-custom-classes', Delete) {
description 'clean the compiled custom java action classes'
delete "$deploymentDir/$compileTargetDir"
}
tasks.register('clean-excluded-jars', Delete) {
description = 'clean the jar files that should be excluded'
(excludedJars + protectedModules.collectMany { it.excluded }).each { delete("$modelDir/$libDirName/$userlibDirName/$it") }
}
tasks.register('copyDeploymentArtifacts', Copy) {
duplicatesStrategy = 'include'
from("$templatesDir/$deploymentDirName") {
excludedRunTemplatesFiles.each { f -> exclude f }
}
into deploymentDir
doNotTrackState("Always copy deployment artifacts")
}
def unzipDataSnapshot = tasks.register('unzipDataSnapshot', Copy) {
if (!file(dataDir).exists()) {
from zipTree(dataSnapshotFile)
into deploymentDir
}
doNotTrackState("Always unzip data snapshot")
}
unzipDataSnapshot.configure {
enabled = extractDataSnapshot
}
tasks.register('copyUserLibs', Copy) {
duplicatesStrategy = 'include'
protectedModules.forEach { module ->
from(module.userlib()) { module.excluded.forEach { exclude(it) } }
}
from("$mendixProjectDir/$userlibDirName") {
excludedJars.each { f -> exclude f }
}
into "$modelDir/$libDirName/$userlibDirName"
}
tasks.register("copyResources", Copy) {
duplicatesStrategy = 'include'
from "$mendixProjectDir/$resourcesDirName"
into "$modelDir/$resourcesDirName"
}
tasks.register("deploy") {
dependsOn("unzipDataSnapshot")
dependsOn("copyDeploymentArtifacts")
dependsOn("copyUserLibs")
dependsOn("copyResources")
}
tasks.register("compile", JavaCompile) {
description "Compile Java Actions"
options.debug = true
options.debugOptions.debugLevel = debugLevel
options.encoding = "UTF-8"
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
def protectedModulesSources = protectedModules.stream().map { fileTree(it.javasource()) }.collect(Collectors.toList())
def publicApiJarFiles = files(publicApiJars)
def protectedModulesJarFiles = files(protectedModules.stream().flatMap { module -> module.included.stream().map { module.resolveJar(it) } }.collect(Collectors.toList()))
def userlibJarFiles = fileTree("$mendixProjectDir/$userlibDirName").matching {
include("*.jar")
excludedJars.forEach { exclude(it) }
}
source = [fileTree("$mendixProjectDir/$javaSourceDirName")] + protectedModulesSources
classpath = project.files((publicApiJarFiles + userlibJarFiles + protectedModulesJarFiles).sort())
destinationDirectory.set(project.file("$deploymentDir/$compileTargetDir"))
}
tasks.register("package", Jar) {
dependsOn("compile")
description = "Generate Jar file"
destinationDirectory.set(project.file("$modelDir/bundles"))
archiveBaseName.set("project")
from("$deploymentDir/$compileTargetDir") { exclude(".keep") }
from("$mendixProjectDir/$userlibDirName") { exclude { it.file.getName().toLowerCase().endsWith(".jar") } }
from("$deploymentDir/$runDir/component.xml") { into("OSGI-INF") }
manifest {
attributes([
"Bundle-Name" : projectSafeName,
"Bundle-SymbolicName": "project",
"Service-Component" : "OSGI-INF/component.xml"
])
}
}