-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
205 lines (169 loc) · 6.59 KB
/
build.gradle
File metadata and controls
205 lines (169 loc) · 6.59 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
plugins {
id 'biz.aQute.bnd.builder' version '3.5.0'
}
//apply plugin: 'application'
//apply plugin: 'war'
//apply plugin: 'idea'
sourceCompatibility = JavaVersion.VERSION_11
version = '0.5.0'
repositories {
maven { url "https://repo.dotcms.com/artifactory/libs-release" }
}
configurations {
osgiLibs
}
dependencies {
compileOnly('com.dotcms:dotcms:23.01.10') { transitive = true }
implementation (group: 'com.google.analytics', name: 'google-analytics-data', version: '0.48.0')
osgiLibs (group: 'com.google.analytics', name: 'google-analytics-data', version: '0.48.0')
//compile group: 'com.google.apis', name: 'google-api-services-analyticsreporting', version: 'v4-rev174-1.25.0'
//osgiLibs group: 'com.google.apis', name: 'google-api-services-analyticsreporting', version: 'v4-rev174-1.25.0'
implementation "commons-io:commons-io:2.11.0"
// implementation "com.google.code.gson:gson:2.8.6"
//compileOnly('org.apache.logging.log4j:log4j-api:2.17.2')
compileOnly('org.apache.logging.log4j:log4j-core:2.20.0')
compileOnly('org.apache.felix:org.apache.felix.framework:7.0.5')
//compileOnly('org.apache.httpcomponents:httpclient:4.5.9')
// https://mvnrepository.com/artifact/javax.servlet/servlet-api
compileOnly group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
}
/////////////////////////
//Plugin jar
/////////////////////////
import java.util.jar.*
//import java.util.jar.Attributes
//import java.util.jar.JarFile
//jar.baseName = 'com.dotcms.google.analytics'
jar {
manifest {
attributes (
'Bundle-Vendor': 'DotCMS',
'Bundle-Description': 'dotCMS - GA Reporting',
'Bundle-DocURL': 'https://dotcms.com/',
'Bundle-Activator': 'com.dotcms.google.analytics.osgi.Activator',
'Bundle-ClassPath' : "${classPathLibraries()}",
'Import-Package': '''
!com.google.*,
!com.aayushatharva.*,
!com.github.luben.*,
!com.jcraft.*,
!com.ning.*,
!io.netty.*,
!io.grpc.*,
!io.perfmark.*,
!io.opencensus.*,
!org.conscrypt.*,
!org.codehaus.*,
!org.checkerframework.*,
!org.threeten.*,
javax.*,
org.osgi.*,
org.apache.commons.io.*,
org.apache.felix.*,
org.apache.logging.log4j.*,
org.apache.velocity.*,
com.dotcms.*,
com.dotmarketing.*,
com.liferay.*
'''
)
}
println 'Jar done'
}
task cleanLibFiles(type: Delete) {
delete fileTree("src/main/resources/libs").matching {
include "**/*"
}
}
task copyToLib(type: Copy) {
into "src/main/resources/libs"
from configurations.osgiLibs
}
copyToLib.dependsOn cleanLibFiles
compileJava.dependsOn copyToLib
jar.finalizedBy 'fragmentJar'
/**
* Searches for jars inside the src/main/resources/libs folder, the returned list is used for the
* Bundle-ClassPath attribute.
* @return String with the list of jars inside the src/main/resources/libs folder or empty if the
* folder does not exist or it is empty.
*/
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 = "dotCMS GA Reporting fragment"
bundleDescription = "dotCMS - GA Reporting 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 {
println 'starting readManifesttAttributes'
File file = //configurations.baseline.singleFile
file("${buildDir}/tmp/jar/${jar.baseName}-${jar.version}.jar")
println 'readManifesttAttributes, file:::: ' + file
JarFile jar = new JarFile(file)
println 'jar::::' + jar
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')}"
println 'end manifest::::'
}
}
task fragmentJar(type: Jar) {
doFirst {
//Setting the fragment jar name
baseName = project.name
archiveName = "${baseName}.fragment-${version}.jar"
importPackage = fixVersionNumber(importPackage)
println 'Jar fragmentJar, archiveName = ' + archiveName
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'
task wrapper(type: Wrapper) {
gradleVersion = '4.10.2'
}