-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
350 lines (294 loc) · 11.9 KB
/
Copy pathbuild.gradle
File metadata and controls
350 lines (294 loc) · 11.9 KB
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
import java.nio.file.FileSystems
import java.nio.file.Files
plugins {
id "biz.aQute.bnd" version "6.1.0" apply false
}
allprojects {
group = 'com.botts'
}
apply from: 'readmes.gradle'
if (!System.getenv("OSH_CORE_VERSION"))
throw new Exception("OSH_CORE_VERSION not set")
ext {
oshCoreVersion = System.getenv("OSH_CORE_VERSION")
}
description = 'NoCode Add-ons'
/* -----------------------------------------------------------
BUNDLE HARVESTING + INDEX
----------------------------------------------------------- */
tasks.register("harvestBundles", Copy) {
group = 'bundles'
description = 'Collects OSGi bundle outputs from all subprojects'
destinationDir = layout.buildDirectory.dir("osgi/bundles").get().asFile
subprojects.each { subproj ->
if (!subproj.name.contains("v4l")) {
def osgiOutputs = subproj.osgi?.outputs
if (osgiOutputs) from osgiOutputs
}
}
}
tasks.register("genOSGiIndex", aQute.bnd.gradle.Index) {
group = 'bundles'
dependsOn harvestBundles
destinationDirectory = file(layout.buildDirectory.dir("osgi/bundles"))
gzip = false
bundles = fileTree(destinationDirectory) {
include "**/*-bundle.jar"
builtBy tasks.withType(Jar)
}
}
tasks.register("bundlesDistZip", Zip) {
group = 'bundles'
dependsOn genOSGiIndex
destinationDirectory = file(layout.buildDirectory.dir("osgi"))
from layout.buildDirectory.dir("osgi/bundles")
archiveFileName = "${rootProject.name}-osgi-bundles.zip"
}
tasks.register("cleanBundles") {
group = 'bundles'
doLast {
delete layout.buildDirectory.dir("osgi")
}
}
/* -----------------------------------------------------------
SUBPROJECT CONFIG
----------------------------------------------------------- */
subprojects {
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
if (project.findProperty("snapshot") == "true") {
version = "${version}-SNAPSHOT"
}
ext.pom = {} // pom data that subprojects can append to
// -----------------------------------------------------------
// Prevent test fixtures from being published to Maven
// -----------------------------------------------------------
components.java.withVariantsFromConfiguration(
configurations.testFixturesApiElements
) { skip() }
components.java.withVariantsFromConfiguration(
configurations.testFixturesRuntimeElements
) { skip() }
sourceCompatibility = 17
targetCompatibility = 17
repositories {
mavenCentral()
maven {
name = 'nexus'
url = uri(System.getenv("NEXUS_REPO_URL"))
credentials {
username = System.getenv("NEXUS_ACTOR")
password = System.getenv("NEXUS_TOKEN")
}
}
}
dependencies {
testImplementation "junit:junit:4.13.1"
}
tasks.register("printVersion") {
doLast {
println("${project.name} version = ${project.version}")
}
}
/* -----------------------------------------------------------
EMBEDDED CONFIG MODEL
----------------------------------------------------------- */
configurations {
embeddedApi
embeddedImpl
embedded.extendsFrom(embeddedApi, embeddedImpl)
api.extendsFrom(embeddedApi)
implementation.extendsFrom(embeddedImpl)
}
/* -----------------------------------------------------------
OSGI BUNDLE TASK
----------------------------------------------------------- */
task osgi(type: aQute.bnd.gradle.Bundle) {
from sourceSets.main.output
archiveClassifier = 'bundle'
bundle {
classpath = sourceSets.main.compileClasspath
}
into('lib') {
from configurations.embedded
}
// helper methods preserved exactly
ext.getPackagesFromJar = { jarFile, packageSet ->
FileSystems.newFileSystem(jarFile.toPath(), ClassLoader.getSystemClassLoader()).withCloseable { fs ->
def rootDir = fs.getPath('/')
getPackagesFromDir(rootDir, packageSet)
}
}
ext.getPackagesFromDir = { rootDir, packageSet ->
rootDir.eachDirRecurse { dir ->
if (dir.toString().startsWith(File.separator + 'META-INF')) return
Files.list(dir)
.filter { it.toString().endsWith('.class') }
.findAny()
.ifPresent {
def rel = rootDir.relativize(dir).toString()
packageSet.add(rel.replace('\\', '.').replace('/', '.') + '.*')
}
}
}
ext.findActivator = {
for (def classDir : sourceSets.main.output.classesDirs) {
def rootDir = classDir.toPath()
def activatorClass = Files.walk(rootDir)
.filter { it.toString().endsWith('Activator.class') }
.map {
rootDir.relativize(it).toString()
.replace(File.separatorChar, (char) '.')
.replaceAll('.class$', '')
}
.findAny()
.orElse(null)
if (activatorClass) return activatorClass
}
}
doFirst {
manifest {
attributes '-fixupmessages': 'Classes found in the wrong directory; is:=ignore,' +
'Unused Import-Package instructions; is:=ignore,' +
'The default package \'.\' is not permitted; is:=ignore,' +
'Unused Export-Package instructions; is:=ignore,'
if (!attributes['-dsannotations'])
attributes '-dsannotations': '!*'
if (!attributes['Bundle-Activator']) {
def activatorClass = findActivator()
if (activatorClass)
attributes 'Bundle-Activator': activatorClass
}
def embeddedJars = configurations.embedded
def depJars = configurations.compileClasspath.minus(embeddedJars)
def apiJars = configurations.embeddedApi
def importedPackages = [] as Set
depJars.each { getPackagesFromJar(it, importedPackages) }
if (!attributes['Import-Package'])
attributes 'Import-Package': importedPackages.join(',')
def exportedPackages = [] as Set
sourceSets.main.output.classesDirs.each {
getPackagesFromDir(it.toPath(), exportedPackages)
}
apiJars.each { getPackagesFromJar(it, exportedPackages) }
if (!attributes['-exportcontents'])
attributes '-exportcontents': exportedPackages.join(',')
def runtimeDeps = configurations.runtimeClasspath.collect { it.name }
def embeddedClasspath = ''
configurations.embedded.each {
if (runtimeDeps.contains(it.name)) {
embeddedClasspath += "lib/${it.name},"
}
}
attributes 'Bundle-ClassPath': embeddedClasspath + '.'
attributes 'OSH-Core-Version': oshCoreVersion
}
}
}
/* -----------------------------------------------------------
BUILD MANIFESTS
----------------------------------------------------------- */
afterEvaluate { p ->
rootProject.dependencies {
def dep = p.version.endsWith('SNAPSHOT') ? dev(p) : stable(p)
dep.exclude group: 'org.sensorhub'
dep.exclude group: 'org.vast.opengis'
}
if (p.name != "sensorhub-test") {
p.osgi {
manifest {
// main info
attributes 'Bundle-SymbolicName': p.group + '.' + p.name
if (p.description != null && !attributes['Bundle-Name'])
attributes 'Bundle-Name': p.description
if (p.details != null && !attributes['Bundle-Description'])
attributes 'Bundle-Description': p.details
attributes 'Bundle-Version': p.version
if (p.hasProperty('buildNumber') && p.buildNumber != null && !p.buildNumber.isEmpty())
attributes 'Bundle-BuildNumber': p.buildNumber
if (!attributes['Bundle-License'])
attributes 'Bundle-License': 'Proprietary – All rights reserved. No redistribution or modification permitted.'
if (!attributes['Bundle-Copyright'] && attributes['Bundle-Vendor'])
attributes 'Bundle-Copyright': 'Copyright (c) ' + attributes['Bundle-Vendor'] + '. All Rights Reserved'
}
}
// also use osgi headers in JAR manifest
p.jar {
manifest {
from p.osgi.manifest
attributes 'OSH-Core-Version': oshCoreVersion
}
}
}
}
/* -----------------------------------------------------------
PUBLISHING (CLEAN + DEV FLAG SUPPORT)
----------------------------------------------------------- */
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact(tasks.osgi) {
classifier = 'bundle'
}
pom {
name = project.description
description = project.hasProperty('details') && project.details ? project.details : project.description
url = 'https://georobotix.us'
licenses {
license {
name = 'Proprietary – All rights reserved'
url = 'https://georobotix.us/legal'
distribution = 'repo'
}
}
scm {
url = 'https://github.com/Botts-Innovative-Research/osh-no-code'
connection = 'scm:git:git://github.com/Botts-Innovative-Research/osh-no-code.git'
}
issueManagement {
url = 'https://github.com/Botts-Innovative-Research/osh-no-code/issues'
system = 'GitHub Issues'
}
properties.put("coreVersion", oshCoreVersion)
}
}
}
repositories {
maven {
name = "Nexus"
if (project.version.toString().endsWith("SNAPSHOT")) {
url = System.getenv("NEXUS_REPO_SNAPSHOT")
} else {
url = System.getenv("NEXUS_REPO_RELEASE")
}
credentials {
username = System.getenv("NEXUS_ACTOR")
password = System.getenv("NEXUS_TOKEN")
}
}
}
}
/* -----------------------------------------------------------
SAFETY CHECKS
----------------------------------------------------------- */
tasks.named("generateMetadataFileForMavenJavaPublication") {
doFirst {
if (!System.getenv("NEXUS_ACTOR"))
throw new Exception("NEXUS_ACTOR not set")
if (!System.getenv("NEXUS_TOKEN"))
throw new Exception("NEXUS_TOKEN not set")
}
}
jar.dependsOn(copyReadmes)
clean.dependsOn(cleanReadmes, cleanBundles)
}
/* -----------------------------------------------------------
DISTRIBUTION CONFIGS
----------------------------------------------------------- */
configurations {
stable
dev
}