blob: 765302a086aa29c40c1c72e0c1082f6279d5d6b5 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import java.security.MessageDigest
2apply plugin: 'maven-publish'
3
4def outputsFolder = file("$buildDir/outputs")
5
6def baseArtifactId = nativeName
7def artifactGroupId = "edu.wpi.first.${nativeName}"
8def zipBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-cpp_CLS"
9def jniBaseName = "_GROUP_edu_wpi_first_${nativeName}_ID_${nativeName}-jni_CLS"
10
11def licenseFile = file("$rootDir/license.txt")
12
13task cppSourcesZip(type: Zip) {
14 destinationDirectory = outputsFolder
15 archiveBaseName = zipBaseName
16 classifier = "sources"
17 duplicatesStrategy = 'exclude'
18
19 from(licenseFile) {
20 into '/'
21 }
22
23 from('src/main/native/cpp') {
24 into '/'
25 }
26
27 model {
28 components {
29 it.all {
30 if (it in getJniSpecClass()) {
31 it.jniHeaderLocations.each {
32 dependsOn it.key
33 from(it.value) {
34 into '/jni'
35 }
36 }
37 }
38 }
39 }
40 }
41}
42
43task cppHeadersZip(type: Zip) {
44 destinationDirectory = outputsFolder
45 archiveBaseName = zipBaseName
46 classifier = "headers"
47
48 from(licenseFile) {
49 into '/'
50 }
51
52 from('src/main/native/include') {
53 into '/'
54 }
55}
56
57artifacts {
58 archives cppHeadersZip
59 archives cppSourcesZip
60}
61
62addTaskToCopyAllOutputs(cppSourcesZip)
63addTaskToCopyAllOutputs(cppHeadersZip)
64
65model {
66 publishing {
67 def taskList = createComponentZipTasks($.components, [nativeName, "${nativeName}JNIShared"], zipBaseName, Zip, project, includeStandardZipFormat)
68
69 def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
70 value.each { binary ->
71 if (binary.buildable) {
72 if (binary instanceof SharedLibraryBinarySpec) {
73 task.dependsOn binary.tasks.link
74 def hashFile = new File(binary.sharedLibraryFile.parentFile.absolutePath, "${binary.component.baseName}.hash")
75 task.outputs.file(hashFile)
76 task.inputs.file(binary.sharedLibraryFile)
77 task.from(hashFile) {
78 into nativeUtils.getPlatformPath(binary)
79 }
80 task.doFirst {
81 hashFile.text = MessageDigest.getInstance("MD5").digest(binary.sharedLibraryFile.bytes).encodeHex().toString()
82 }
83 task.from(binary.sharedLibraryFile) {
84 into nativeUtils.getPlatformPath(binary)
85 }
86 }
87 }
88 }
89 })
90
91 publications {
92 cpp(MavenPublication) {
93 taskList.each {
94 artifact it
95 }
96 artifact cppHeadersZip
97 artifact cppSourcesZip
98
99 artifactId = "${baseArtifactId}-cpp"
100 groupId artifactGroupId
101 version wpilibVersioning.version.get()
102 }
103 jni(MavenPublication) {
104 jniTaskList.each {
105 artifact it
106 }
107
108 artifactId = "${baseArtifactId}-jni"
109 groupId artifactGroupId
110 version wpilibVersioning.version.get()
111 }
112 }
113 }
114}