This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
141 lines (122 loc) · 4.29 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
apply plugin: 'maven-publish'
group = 'org.elasticsearch'
String upstreamVersion = '5.10.0'
// Rarely, modifications may need to be made to the jna jar that
// aren't reflected in the upstream. A suffix can be supplied to bump
// the local version. See readme for details.
String versionSuffix = System.getProperty("version.suffix", "")
version = "${upstreamVersion}${versionSuffix}"
String jnaDir = 'build/jna'
String jarDir = 'build/jar'
String pkgDir = 'com/sun/jna'
/** A better exec task which captures output and only prints it on failure. */
class LoggedExec extends Exec {
protected ByteArrayOutputStream output = new ByteArrayOutputStream()
LoggedExec() {
if (logger.isInfoEnabled() == false) {
standardOutput = output
errorOutput = output
ignoreExitValue = true
doLast {
if (execResult.exitValue != 0) {
output.toString('UTF-8').eachLine { line -> logger.error(line) }
throw new GradleException("Process '${executable} ${args.join(' ')}' finished with non-zero exit value ${execResult.exitValue}")
}
}
}
}
}
/***********************************************************
* RELEASE TASKS *
***********************************************************/
/** Pull in the existing release of jna */
repositories {
mavenCentral()
}
configurations {
jna
}
dependencies {
jna "net.java.dev.jna:jna:${upstreamVersion}"
}
task clean(type: Delete) {
delete buildDir
}
/** Copy the existing files from the release. */
task extractRelease(type: Copy) {
dependsOn clean
into jarDir
from { zipTree(configurations.jna.singleFile) }
}
/** Remove native libs for platforms we do not support */
task removeUnsupported(type: Delete) {
dependsOn extractRelease
List<String> inclusions = ['darwin', 'linux-aarch64', 'linux-x86-64', 'win32-x86-64']
for (File arch : file("${jarDir}/${pkgDir}/").listFiles()) {
// skip non-directories
if (arch.isDirectory() == false) {
continue
}
// skip directories that do not contain native libraries
if (new File(arch, 'jnidispatch.dll').exists() == false &&
new File(arch, 'libjnidispatch.a').exists() == false &&
new File(arch, 'libjnidispatch.jnilib').exists() == false &&
new File(arch, 'libjnidispatch.so').exists() == false) {
continue
}
// skip inclusions
if (inclusions.contains(arch.getName())) {
continue
}
delete arch
}
}
/** Checkout the jna project, so that native libs can be built. */
task checkoutJna(type: LoggedExec) {
doFirst {
file(jnaDir).parentFile.mkdirs()
}
commandLine 'git', 'clone', '-b', upstreamVersion, 'https://github.com/java-native-access/jna', jnaDir
}
/** Repackage the jar now that it is fixed up with proper native libs. */
task buildJar(type: Zip) {
dependsOn removeUnsupported
from jarDir
destinationDir = file('build/distributions')
version = project.version
baseName 'jna'
extension = 'jar'
}
task assemble {
dependsOn buildJar
}
project.tasks.withType(GenerateMavenPom.class) { GenerateMavenPom t ->
// place the pom next to the jar it is for
t.destination = new File(project.buildDir, "distributions/jna-${project.version}.pom")
// build poms with assemble
project.assemble.dependsOn(t)
}
publishing {
publications {
jna(MavenPublication) {
artifactId = 'jna'
artifact buildJar
pom.withXml { XmlProvider xml ->
Node node = xml.asNode()
node.appendNode('name', 'Elastic JNA Distribution')
node.appendNode('description',
'A build of jna which supports all platforms supported by Elasticsearch')
node.appendNode('url', 'https://github.com/java-native-access/jna')
Node license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', 'Apache License, Version 2.0')
license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
license.appendNode('distribution', 'repo')
Node developer = node.appendNode('developers').appendNode('developer')
developer.appendNode('name', 'JNA Developers')
developer.appendNode('url', 'https://github.com/java-native-access/jna')
Node scm = node.appendNode('scm')
scm.appendNode('url', 'https://github.com/java-native-access/jna')
}
}
}
}