-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
137 lines (122 loc) · 4.02 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
group 'com.thingworx.extensions'
version '1.0-SNAPSHOT'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
defaultTasks 'clean', 'build-extension'
project.sourceCompatibility = 1.8
project.targetCompatibility = 1.8
// set the properties accordingly
project.ext {
extensionJar = "thingworx-ssh-extension.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" // 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 Customer Service"
packageName = "SshExtension"
packageTitle = "SshExtension"
packageVersion = version
}
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
}
thingworxsdk
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
// add all the dependencies for the extension using the packageDependencies configuration. Here only one is added
packageDependencies 'com.jcraft:jsch:0.1.54'
// the zip version
// thingworxsdk group: 'com.thingworx', name: 'Thingworx-Extension-SDK', version: '6.5.2-b463', ext: 'zip'
compile fileTree(dir: project.ext.thingworxSdkDir, include: ['*.jar'])
packageDependencies fileTree(dir: project.ext.localJarDir, include: ['*.jar'])
}
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 groovy.util.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) {
xml.ExtensionPackages.ExtensionPackage.JarResources[0]?.appendNode(
"FileResource",
[type: "JAR", file: f.getName()]
)
}
PrintWriter pw = new PrintWriter(new File(file))
pw.write(groovy.xml.XmlUtil.serialize(xml))
pw.close()
}
task prepPackage(dependsOn: jar) {
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/"
}