-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
270 lines (239 loc) · 10.3 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
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
/*
* Copyright (c) 2018. PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
* Copyright for PTC software products is with PTC Inc. and its subsidiary companies (collectively “PTC”), and their respective licensors. This software is provided under written license agreement, contains valuable trade secrets and proprietary information, and is protected by the copyright laws of the United States and other countries. It may not be copied or distributed in any form or medium, disclosed to third parties, or used in any manner not provided for in the software license agreement except with written prior approval from PTC.
*
*/
import groovy.xml.XmlUtil
import org.apache.http.entity.mime.MultipartEntityBuilder
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.*
group 'com.thingworx.things'
version '6.0-SNAPSHOT'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: 'wrapper'
defaultTasks 'clean', 'build-extension'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.apache.httpcomponents:httpmime:4.5.2'
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.3'
}
}
project.sourceCompatibility = 1.8
project.targetCompatibility = 1.8
// set the properties accordingly
project.ext {
incrementVersionNumber = true
extensionJar = "Kube_Extensions.jar"
baseDir = projectDir
common = 'common'
uiDir = "${baseDir}/ui" // if there are any widgets
localJarDir = "${baseDir}/lib/local" // if you have any jars add them here
srcDir = "${baseDir}/src/main/java" // where are the sources located
buildDir = "${baseDir}/build" // where is the build saved
configDir = "${baseDir}/configfiles" // folder location of the metadata.xml file
zipDir = "${baseDir}/zip" // where to store the generated zip
thingworxSdkDir = "${baseDir}/lib/common" // where the thingworx sdk is located
packageVendor = "ThingWorx EMEA-RO PRESALES IOT"
packageName = "Kube_Extensions"
packageTitle = "Kube Interface"
packageVersion = version
thingworxServerRoot = "http://Administrator:trUf6yuz2?_Gub@localhost:8015"
}
repositories {
mavenCentral()
jcenter()
flatDir {
dirs project.ext.thingworxSdkDir
}
flatDir {
dirs project.ext.localJarDir
}
}
sourceSets {
main {
java {
srcDir project.ext.srcDir
}
}
}
clean.doFirst {
delete project.ext.zipDir
}
configurations {
packageDependencies
compile {
extendsFrom packageDependencies
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
// add all the dependencies for the extension using the packageDependencies configuration. Here only one is added
// the zip version
compile fileTree(dir: project.ext.thingworxSdkDir, include: ['*.jar'])
packageDependencies fileTree(dir: project.ext.localJarDir, include: ['*.jar'])
// https://mvnrepository.com/artifact/io.kubernetes/client-java
packageDependencies group: 'io.kubernetes', name: 'client-java', version: '4.0.0'
// https://mvnrepository.com/artifact/io.fabric8/kubernetes-client
packageDependencies group:'io.fabric8', name: 'kubernetes-client', version: '4.2.0'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
packageDependencies group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
// https://mvnrepository.com/artifact/io.fabric8/kubernetes-api
packageDependencies group: 'io.fabric8', name: 'kubernetes-api', version: '3.0.12'
// https://mvnrepository.com/artifact/io.fabric8/fabric8-utils
packageDependencies group: 'io.fabric8', name: 'fabric8-utils', version: '3.0.12'
// https://mvnrepository.com/artifact/org.springframework/spring-core
packageDependencies group: 'org.springframework', name: 'spring-core', version: '5.1.6.RELEASE'
}
jar {
archiveName = project.ext.extensionJar
manifest {
attributes(["Built-By" : project.ext.packageVendor,
"Build-Date": new Date().format("yyyy-MM-dd HH:mm:ss")])
attributes(["Package-Title" : project.ext.packageTitle,
"Package-Version": project.ext.packageVersion,
"Package-Vendor" : project.ext.packageVendor], project.ext.packageName
)
}
}
def addDependenciesInMetadata() {
def file = "${buildDir}/zip/metadata.xml"
def parser = new XmlParser(false, true)
def xml = parser.parse(file)
xml.ExtensionPackages.ExtensionPackage.JarResources[0]?.appendNode(
"FileResource",
[type: "JAR", file: project.ext.extensionJar]
)
for (File f : configurations.packageDependencies) {
if (f.getName().startsWith("commons-codec") ||
f.getName().startsWith("commons-io") ||
f.getName().startsWith("commons-lang") ||
f.getName().startsWith("commons-logging") ||
f.getName().startsWith("netty") ||
f.getName().startsWith("log4j") ||
f.getName().startsWith("httpclient") ||
f.getName().startsWith("httpcore") ||
f.getName().startsWith("slf4j") ||
f.getName().startsWith("jcip-annotations") ||
f.getName().startsWith("xml-apis") ||
f.getName().startsWith("jsr305") ||
f.getName().startsWith("logback-core") ||
f.getName().startsWith("hk2") ||
f.getName().startsWith("jersey-client") ||
f.getName().startsWith("jackson-annotations") ||
f.getName().startsWith("guava") ||
f.getName().startsWith("jackson-jaxrs") ||
f.getName().startsWith("commons-compress") ||
f.getName().startsWith("joda-time") ||
f.getName().startsWith("jline") ||
f.getName().startsWith("logback-classic") ||
f.getName().startsWith("metrics-core") ||
f.getName().startsWith("metrics-json") ||
f.getName().startsWith("zookeeper") ||
f.getName().startsWith("curator") ||
f.getName().startsWith("jsr311") ||
f.getName().startsWith("spring-jcl") ||
f.getName().startsWith("spring-core") ||
f.getName().startsWith("httpmime") ||
f.getName().startsWith("jcl-over-slf4j") ||
f.getName().startsWith("jackson-module") ||
f.getName().startsWith("checker-qual") ||
f.getName().startsWith("bcprov-jdk") ||
f.getName().startsWith("protobuf-java") ||
f.getName().startsWith("jul-to-slf4j") ||
f.getName().startsWith("jackson-databind") ||
f.getName().startsWith("jackson-core") ||
f.getName().startsWith("validation-api") ||
f.getName().startsWith("json-2016") ||
f.getName().startsWith("javax.el") ||
f.getName().startsWith("javax.inject")
) {
continue
}
xml.ExtensionPackages.ExtensionPackage.JarResources[0]?.appendNode(
"FileResource",
[type: "JAR", file: f.getName()]
)
}
PrintWriter pw = new PrintWriter(new File(file))
pw.write(XmlUtil.serialize(xml))
pw.close()
}
task prepPackage(dependsOn: jar) {
if (project.ext.incrementVersionNumber)
increaseVersionNumber()
doLast {
delete project.ext.zipDir
delete "${buildDir}/zip/"
// add here all the jars from the packageDependencies configuration
copy {
from configurations.packageDependencies
into "${buildDir}/zip/lib/common/"
}
// add the configuration
copy {
from "${project.ext.configDir}"
into "${buildDir}/zip/"
}
addDependenciesInMetadata()
// add the extension jar itself
copy {
from "${buildDir}/libs/${project.ext.extensionJar}"
into "${buildDir}/zip/lib/common/"
}
// add the ui files
copy {
from uiDir
into "${buildDir}/zip/ui/"
}
}
}
task packageExtension(type: Zip, dependsOn: prepPackage, overwrite: true) {
archiveName = "${project.name}.zip"
destinationDir = new File(project.ext.zipDir)
from "${buildDir}/zip/"
}
def increaseVersionNumber() {
def file = "${configDir}/metadata.xml"
def parser = new XmlParser(false, true)
def xml = parser.parse(file)
def currentVersion = xml.ExtensionPackages.ExtensionPackage.@packageVersion[0]
def versionComponents = currentVersion.split('\\.')
def minorVersion = ++Integer.parseInt(versionComponents[versionComponents.length - 1])
versionComponents[versionComponents.length - 1] = String.valueOf(minorVersion)
xml.ExtensionPackages.ExtensionPackage.@packageVersion = String.join('.', versionComponents)
// xml.ExtensionPackages.ExtensionPackage.get(0).attributes().put('packageVersion', String.join(',', versionComponents));
println 'Updated to version ' + String.join('.', versionComponents)
println xml.ExtensionPackages.ExtensionPackage.@packageVersion[0]
PrintWriter pw = new PrintWriter(new File(file))
pw.write(XmlUtil.serialize(xml))
pw.close()
}
task upload(dependsOn: packageExtension) {
doLast {
def http = new HTTPBuilder("${thingworxServerRoot}/Thingworx/")
def extZip = file("${baseDir}/zip/${project.name}.zip")
http.request(POST) { req ->
uri.path = 'ExtensionPackageUploader'
uri.query = ['purpose': 'import']
headers."X-XSRF-TOKEN" = "TWX-XSRF-TOKEN-VALUE"
requestContentType = 'multipart/form-data'
MultipartEntityBuilder entity = MultipartEntityBuilder.create().setLaxMode()
entity.addBinaryBody('file', extZip)
req.setEntity(entity.build())
response.success = { resp ->
println("Upload successful!")
}
response.failure = { resp ->
println(resp.statusLine)
throw new StopExecutionException("Thingworx upload failed! See server response above")
}
}
}
}