-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
102 lines (88 loc) · 2.97 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
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream
group 'Kliket'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'net.sf.jopt-simple:jopt-simple:6.0-alpha-1'
}
task("assembleExecutableJar",type: Jar){
dependsOn "copyGeneratedJar"
archiveName "${name}.jar"
manifest {
attributes['Main-Class']="com.nao20010128nao.Kliket.KliketLauncher"
}
from zipTree(new File(buildDir,"tmp/$name-${version}.jar"))
}
task("copyGeneratedJar",type: Copy){
dependsOn "gatherClasses"
def gathered=jar.archivePath
def tmp=new File(buildDir,"tmp")
into tmp
from(gathered.parentFile) {
include '*.jar'
}
}
task("gatherClasses"){
dependsOn "assemble"
doLast {
def exclude="^META-INF/.*\\.(SF|RSA|DSA|MF)\$"
def archive = jar.archivePath
def backup = new File("${archive.absolutePath}.bak")
backup.delete()
archive.renameTo(backup)
new ZipOutputStream(new BufferedOutputStream(archive.newOutputStream())).with { zos ->
zos.method = DEFLATED
//Merge libraries
project.configurations.compile*.toURI().each { singleJar ->
new ZipInputStream(new File(singleJar).newInputStream()).with { zis ->
ZipEntry entry = null
while ((entry = zis.nextEntry) != null) {
if (entry.name.matches(exclude))
continue
try {
zos.putNextEntry(new ZipEntry(entry.name))
zos.write new UnclosableInputStreamWrapper(zis).bytes
//System.console().readLine()
} catch (e) {
e.printStackTrace()
}
}
}
}
//Merge my code
new ZipInputStream(backup.newInputStream()).with { zis ->
ZipEntry entry = null
while ((entry = zis.nextEntry) != null) {
if (entry.name.matches(exclude))
continue
try {
zos.putNextEntry(new ZipEntry(entry.name))
zos.write new UnclosableInputStreamWrapper(zis).bytes
//System.console().readLine()
} catch (e) {
e.printStackTrace()
}
}
}
zos.finish()
zos.close()
}
}
}
class UnclosableInputStreamWrapper extends FilterInputStream{
UnclosableInputStreamWrapper(InputStream inputStream) {
super(inputStream)
}
@Override
void close() throws IOException {
}
}