-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
142 lines (117 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
138
139
140
141
142
plugins {
id 'biz.aQute.bnd.builder' version '3.3.0'
}
sourceCompatibility = '1.8'
version = '20.12'
repositories {
maven { url "https://repo.dotcms.com/artifactory/libs-release" }
}
configurations {
osgiLibs
}
dependencies {
compile ('com.dotcms:dotcms:20.11.1')
compile ('org.scribe:scribe:1.3.7')
osgiLibs ('org.scribe:scribe:1.3.7')
testCompile 'junit:junit:4.12'
}
import java.util.jar.*
/////////////////////////
//Plugin jar
/////////////////////////
jar {
manifest {
attributes (
'Bundle-Vendor': 'dotCMS',
'Bundle-Description': 'dotCMS - OAuth / OIDC ',
'Bundle-DocURL': 'https://dotcms.com/',
'Bundle-Activator': 'com.dotcms.osgi.oauth.Activator',
'Bundle-ClassPath' : "${classPathLibraries()}",
'Import-Package': '*;version=0'
)
}
}
task cleanLibFiles(type: Delete) {
delete fileTree("src/main/resources/libs").matching {
include "**/*"
}
}
task copyToLib(type: Copy) {
from configurations.osgiLibs
into "src/main/resources/libs"
}
compileJava.dependsOn copyToLib
jar.finalizedBy 'fragmentJar'
def classPathLibraries() {
def bundleClassPath = "";
fileTree("src/main/resources/libs").filter { it.isFile() }.each { bundleClassPath += "libs/" + it.name + "," }
if (bundleClassPath != "") {
bundleClassPath = '.,' + bundleClassPath
}
return bundleClassPath
}
/////////////////////////
//Fragment jar
/////////////////////////
ext {
bundleName = "OAuth fragment"
bundleDescription = "dotCMS - OAuth fragment"
fragmentHost = "system.bundle; extension:=framework"
bundleSymbolicName = "" //Auto generated based on the plugin jar
bundleVersion = "" //Auto generated based on the plugin jar
importPackage = "" //Auto generated based on the plugin jar
bundleManifestVersion = "" //Auto generated based on the plugin jar
bundleDocURL = "" //Auto generated based on the plugin jar
bundleVendor = "" //Auto generated based on the plugin jar
}
/**
* The import generates versions like this: version="[1.8,2)"
* That format does not work for the export, so we need to replace it
* to: version=0
*/
ext.fixVersionNumber = {importValue ->
return importValue.replaceAll("\"\\[[0-9.,]+\\)\"", "0")
}
/**
* Reads the Manifest file of the just created plugin jar in order to get the required info
* to automatically create the fragment jar.
*/
task readManifesttAttributes {
doFirst {
File file = configurations.baseline.singleFile
JarFile jar = new JarFile(file)
Attributes manifest = jar.getManifest().getMainAttributes()
bundleSymbolicName = "${manifest.getValue('Bundle-SymbolicName')}"
bundleVersion = "${manifest.getValue('Bundle-Version')}"
importPackage = "${manifest.getValue('Import-Package')}"
bundleManifestVersion = "${manifest.getValue('Bundle-ManifestVersion')}"
bundleDocURL = "${manifest.getValue('Bundle-DocURL')}"
bundleVendor = "${manifest.getValue('Bundle-Vendor')}"
}
}
task fragmentJar(type: Jar) {
doFirst {
//Setting the fragment jar name
baseName = project.name
archiveName = "${baseName}.fragment-${version}.jar"
importPackage = fixVersionNumber(importPackage)
manifest {
attributes (
'Bundle-Name': "${bundleName}",
'Bundle-Description': "${bundleDescription}",
'Bundle-Vendor': "${bundleVendor}",
'Bundle-Version': "${version}",
'Bundle-SymbolicName': "${baseName}.fragment",
'Bundle-ManifestVersion': "${bundleManifestVersion}",
'Bundle-DocURL': "${bundleDocURL}",
'Fragment-Host': "${fragmentHost}",
'Export-Package': "${importPackage}"
)
}
}
}
fragmentJar.dependsOn 'readManifesttAttributes'
tasks.copyToLib.execute()
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
}