-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
176 lines (148 loc) · 5.36 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
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
apply plugin: 'java'
apply plugin:'application'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
mainClassName = "foo.Main"
group = "co.paralleluniverse"
version = "0.3.0"
status = "integration"
description = "A demo using Capsule"
repositories {
mavenLocal()
mavenCentral()
}
configurations {
capsule
supercapsule
capsuleUtil
quasar
provided
}
sourceSets {
main.compileClasspath = main.compileClasspath + configurations.provided
test.compileClasspath = test.compileClasspath + configurations.provided
test.runtimeClasspath = test.runtimeClasspath + configurations.provided
}
dependencies {
capsule 'co.paralleluniverse:capsule:1.0'
capsule 'co.paralleluniverse:capsule-maven:1.0'
capsuleUtil 'co.paralleluniverse:capsule-util:1.0'
provided 'co.paralleluniverse:capsule:1.0' // for the MyCapsule caplet
compile ('co.paralleluniverse:quasar-core:0.7.3:jdk8') {
exclude group: 'org.slf4j', module: '*'
exclude group: 'org.apache.logging.log4j', module: '*'
exclude group: 'org.apache.ant', module: '*'
}
compile "co.paralleluniverse:quasar-actors:0.7.3"
quasar "co.paralleluniverse:quasar-core:0.7.3:jdk8@jar"
testCompile group: 'junit', name: 'junit', version: '4.10'
}
tasks.withType(JavaExec) {
standardInput = System.in
jvmArgs '-server'
jvmArgs "-javaagent:${configurations.quasar.iterator().next()}" // =vdmc (verbose, debug, allow monitors, check class)
// systemProperty "co.paralleluniverse.fibers.DefaultFiberPool.parallelism", "4"
systemProperty "co.paralleluniverse.fibers.DefaultFiberPool.monitor", "JMX" // "METRICS" // "NONE" //
systemProperty "co.paralleluniverse.actors.moduleDir", "${rootProject.projectDir}/modules"
// memory
jvmArgs '-Xmx1024m'
}
apply plugin: 'maven'
// converts Gradle dependencies into Capsule dependencies
def getDependencies(config) {
return config.getAllDependencies().collect {
def res = it.group + ':' + it.name + ':' + it.version + (!it.artifacts.isEmpty() ? ':' + it.artifacts.iterator().next().classifier : '')
if(!it.excludeRules.isEmpty()) {
res += "(" + it.excludeRules.collect { it.group + ':' + it.module }.join(',') + ")"
}
return res
}
}
// creates a "thin" capsule, with the dependencies listen in the manifest
task capsule(type: Jar, dependsOn: classes) {
archiveName = "foo.jar"
from sourceSets.main.output // this way we don't need to extract
from { configurations.capsule.collect { zipTree(it) } }
into('capsule') {
from configurations.supercapsule
}
duplicatesStrategy 'exclude'
manifest {
attributes(
'Main-Class' : 'Capsule',
'Premain-Class' : 'Capsule',
'Caplets' : 'MavenCapsule',
'Application-Class' : mainClassName,
'Extract-Capsule' : 'false',
'Min-Java-Version' : '1.8.0',
// 'Args' : 'hello world',
'JVM-Args' : run.jvmArgs.join(' '),
'System-Properties' : run.systemProperties.collect { k,v -> "$k=$v" }.join(' '),
'Java-Agents' : getDependencies(configurations.quasar).iterator().next(),
'Dependencies': getDependencies(configurations.runtime).join(' ')
)
}
}
// creates a "fat" capsule, with all dependencies embedded in the capsule
task fatCapsule(type: Jar, dependsOn: jar) {
archiveName = "foo.jar"
from(configurations.capsule.collect { zipTree(it) }) { include 'Capsule.class' } // we just need the single Capsule class
// from(zipTree(jar.archivePath)) { include 'MyCapsule.class' } // - if we want a custom capsule
from jar // embed our application jar
from { configurations.runtime } // embed dependencies
manifest {
attributes(
'Main-Class' : 'Capsule',
'Premain-Class' : 'Capsule',
'Capsule-Agent' : 'false',
'Application-Class' : mainClassName,
'Min-Java-Version' : '1.8.0',
'JVM-Args' : run.jvmArgs.join(' '),
'System-Properties' : run.systemProperties.collect { k,v -> "$k=$v" }.join(' '),
'Java-Agents' : configurations.quasar.singleFile.getName()
)
}
}
tasks.withType(Jar) {
doLast { task -> reallyExecutable(task) }
}
def reallyExecutable(jar) {
ant.concat(destfile: "tmp.jar", binary: true) {
zipentry(zipfile: configurations.capsuleUtil.first(), name: 'capsule/trampoline-execheader.sh')
fileset(dir: jar.destinationDir) {
include(name: jar.archiveName)
}
}
copy {
from 'tmp.jar'
into jar.destinationDir
rename { jar.archiveName }
}
delete 'tmp.jar'
}
//def reallyExecutable(jar) {
// def srcFile = new File(jar)
// def shortcutFile = new File("${buildDir}/denominator")
// shortcutFile.delete()
// shortcutFile << "#!/usr/bin/env sh\n"
// shortcutFile << 'exec java -jar $0 "$@"' + "\n"
// shortcutFile << srcFile.bytes
// shortcutFile.setExecutable(true, true)
// srcFile.delete()
// srcFile << shortcutFile.bytes
// srcFile.setExecutable(true, true)
//}
//jar {
// manifest {
// attributes(
// 'Main-Class' : mainClassName,
// )
// }
//}
///////// Publish Artifacts
apply plugin: 'maven'
artifacts {
archives capsule
}
assemble.dependsOn capsule