-
Notifications
You must be signed in to change notification settings - Fork 466
/
Copy pathp2-fat-jar-setup.gradle
182 lines (157 loc) · 5.33 KB
/
p2-fat-jar-setup.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
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
apply from: rootProject.file('../gradle/java-setup.gradle')
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.diffplug.gradle:goomph:3.17.4"
}
}
apply plugin: com.diffplug.gradle.p2.AsMavenPlugin
ext {
// P2 Repository URL
if (!project.hasProperty('p2Repository')) {
p2Repository = "p2Repository not defined in project"
}
// P2 dependencies
if (!project.hasProperty('p2Dependencies')) {
p2Dependencies = "p2Dependencies not defined in project"
}
// Some JARs may include JARs themselfs, which shall be unpacked and added to the embedded class folder.
if (!project.hasProperty('internalJars')) {
internalJars = []
}
// Include form the JARs, which goes into a fat-jar with the spottless formatter interface.
if (!project.hasProperty('jarInclude')) {
jarInclude = [
'**/*.class', // Take all classes
'**/*.properties', // Text resources (for messages, etc)
'**/*.xml', // Plugin XML and other resources
'*.html', // License information about the included JARs,
'META-INF/**' // Plugin manifest and addtional information
]
}
// Exclude form the JARs, which goes into a fat-jar with the spottless formatter interface.
if (!project.hasProperty('jarExclude')) {
jarExclude = [
'META-INF/*.RSA', // The eclipse jars are signed, and our fat-jar breaks the signatures
'META-INF/*.SF', // ... so all signatures are filtered
]
}
// Exclude form the JARs, which goes into a fat-jar with the spottless formatter interface.
if (!project.hasProperty('jarExclude')) {
jarExclude = [
'META-INF/*.RSA', // The eclipse jars are signed, and our fat-jar breaks the signatures
'META-INF/*.SF', // ... so all signatures are filtered
]
}
// Map fat-JAR resources path if JAR file name does not correspond to plugin package name (e.g. required for internal plugins)
if (!project.hasProperty('fatJarResourcesMap')) {
fatJarResourcesMap = [:]
}
// The directory contains all external classes for the fat-jar
embeddedClassesDirName = 'build/embeddedClasses'
embeddedClassesDir = project.file(embeddedClassesDirName)
}
// build a maven repo in our build folder containing these artifacts
p2AsMaven {
group 'p2', {
repo project.p2Repository
p2Dependencies.keySet.each { p2.addIU(it) }
p2ant {
/*
Define p2ant proxy settings as a closure. Refer to the API documents for instructions:
https://diffplug.github.io/goomph/javadoc/3.17.4/com/diffplug/gradle/p2/AsMavenPlugin.html
*/
if (project.hasProperty('setP2AntProxy')) {
setP2AntProxy(it)
}
}
}
}
configurations {
embeddedJars // P2 JARs the fat-JAR is based uppon
}
dependencies {
p2Dependencies.each { groupArtifact, version ->
embeddedJars "p2:${groupArtifact}:${version}"
}
// Includes the classes from P2 JARs during compilation
compile files(embeddedClassesDir)
}
jar {
// Add P2 clases to fat-JAR
from embeddedClassesDir
}
//////////////////////////
// Unpack External Deps //
//////////////////////////
import java.io.File
import org.apache.commons.io.filefilter.DirectoryFileFilter
task unjarEmbeddedClasses {
description = "Copies filtered set of embedded classes from the Eclise/GrEclipse dependencies to '${project.relativePath(embeddedClassesDir)}'."
inputs.files(configurations.embeddedJars)
inputs.property('internalJars', internalJars)
inputs.property('jarInclude', jarInclude)
inputs.property('jarExclude', jarExclude)
inputs.property('fatJarResourcesMap', fatJarResourcesMap)
outputs.file(embeddedClassesDir)
doLast {
embeddedClassesDir.deleteDir()
embeddedClassesDir.mkdirs()
configurations.embeddedJars.each {
unjar(it, embeddedClassesDir)
}
// Unpack internal JARs. Maintain the order defined in internalJars
internalJars.each {
fileTree(embeddedClassesDir).include("${it}.jar").each {
unjar(it, embeddedClassesDir)
delete(it)
}
}
}
}
def unjar(File jarFile, File destDir) {
ant.unjar(src: jarFile, dest: destDir) {
patternset {
jarInclude.each {
include(name: "${it}")
}
internalJars.each {
include(name: "**/${it}.jar")
}
jarExclude.each {
exclude(name: "${it}")
}
}
}
// Provide Fat JAR resources (following naming convention of spotless-eclipse-base)
def fat_jar_resource_dir = jarFile.getName().split('-')[0]
fat_jar_resource_dir = fatJarResourcesMap.getOrDefault(fat_jar_resource_dir, fat_jar_resource_dir)
ant.move(todir: "${destDir}/${fat_jar_resource_dir}/META-INF", quiet: 'true', failonerror: 'false') {
fileset(dir: "${destDir}/META-INF")
}
//Keep licenses and other human readable information for transparency
ant.move(todir: "${destDir}/${fat_jar_resource_dir}", quiet: 'true') {
fileset(dir: destDir) {
include(name: '*')
type(type: 'file')
exclude(name: '*jar-*')
exclude(name: '*.jar')
}
}
}
tasks.compileJava.dependsOn(unjarEmbeddedClasses)
/////////
// IDE //
/////////
apply plugin: 'eclipse'
// always create fresh projects
tasks.eclipse.dependsOn(cleanEclipse)
// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line
tasks.eclipseClasspath.dependsOn(unjarEmbeddedClasses)
apply plugin: 'idea'
// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line
tasks.idea.dependsOn(unjarEmbeddedClasses)