-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
119 lines (101 loc) · 3.69 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
apply from: rootProject.file("${bnd_cnf_shared}/master.gradle")
import aQute.bnd.deployer.repository.*
import java.io.*
import java.util.zip.*
/* Add bnd as a script dependency */
buildscript {
dependencies {
classpath files(bndURI, bndRepoURI)
}
}
// Reconfigure the Javadoc classes
generateJavadoc.source = fileTree('.') {
include 'flexiblepower.ral*/**/*.java'
include 'flexiblepower.runtime/src/org/flexiblepower/simulation/api/*.java'
include 'flexiblepower.ui/src/org/flexiblepower/ui/*.java'
exclude '*.test/*'
exclude '**/*Test.java'
}
generateJavadoc.enabled = true
// These methods are used to generate a deployment zip file
def zipDir(ZipOutputStream zos, File dir) {
def topDirLength = dir.absolutePath.length() + 1
dir.eachFileRecurse { file ->
def relative = file.absolutePath.substring(topDirLength).replaceAll('\\\\', '/')
if ( file.isDirectory() && !relative.endsWith('/')){
relative += "/"
}
ZipEntry entry = new ZipEntry(relative)
entry.time = file.lastModified()
zos.putNextEntry(entry)
if(file.isFile()) {
zos << new FileInputStream(file)
}
}
}
def zipFiles(ZipOutputStream zos, Iterable files, String baseDir) {
return files.collect { file ->
def name = "${baseDir}/${file.name}"
zos.putNextEntry(new ZipEntry(name))
zos << new FileInputStream(file)
return name
}
}
def downloadRepo(ZipOutputStream zos, String url) {
def repo = new FixedIndexedRepo()
repo.setProperties(["locations": url])
zipFiles(zos,
repo.list(null).collect {
bsn -> repo.get(bsn, repo.versions(bsn).last().toString())
}.flatten(),
"bundles/ext");
}
def copyRelease(ZipOutputStream zos) {
zipFiles(zos,
fileTree("${deploymentDir.absolutePath}/repo").include("**/*.jar").exclude("**/*.test/**").getFiles(),
"bundles/fpai-core")
}
def generateProperties(ZipOutputStream zos, Iterable dependancyFiles, Iterable fpaiFiles) {
zos.putNextEntry(new ZipEntry("etc/config.properties"));
new OutputStreamWriter(zos).withPrintWriter { w ->
w.println("org.osgi.framework.storage.clean=onFirstInit");
w.println()
w.println("felix.startlevel.framework=1");
w.println("felix.startlevel.bundle=3");
w.println("org.osgi.framework.startlevel.beginning=3");
w.println()
// First all the framework stuff
w.println("felix.auto.start.1=\\");
for (String name : dependancyFiles) {
w.println("\tfile:./${name} \\")
}
w.println()
// Then add the fpai bundles
w.println("felix.auto.start.2=\\");
for (String name : fpaiFiles) {
w.println("\tfile:./${name} \\");
}
w.println()
w.println("felix.auto.deploy.dir=bundles/fpai-apps");
w.println("felix.auto.deploy.action=install,update,start");
w.println("#org.osgi.framework.security=osgi");
}
}
task(generateDeploymentZip, dependsOn: [cleanDeployment, releaseBundles]) {
def deployDir = file("${cnf.projectDir}/deployment")
ext.dependancies = 'https://raw.githubusercontent.com/flexiblepower/bundle-hub/split-repos/run/index.xml'
if(deployDir.exists() && deployDir.isDirectory()) {
doFirst {
def zipfile = file("${deploymentDir.absolutePath}/${project.name}-runtime-${qualifier}.zip")
logger.info("Generating ZIP file: ${zipfile.absolutePath}")
def zos = new ZipOutputStream(new FileOutputStream(zipfile))
zipDir(zos, deployDir)
def dependancyFiles = downloadRepo(zos, dependancies)
def fpaiFiles = copyRelease(zos)
zos.putNextEntry(new ZipEntry("bundles/fpai-apps/"))
generateProperties(zos, dependancyFiles, fpaiFiles)
zos.close();
}
}
}
distribute.dependsOn generateDeploymentZip