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