John Park | 7eb9042 | 2018-01-27 12:04:57 -0800 | [diff] [blame] | 1 | apply plugin: 'maven-publish' |
| 2 | apply plugin: 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' |
| 3 | |
| 4 | def getVersion = { |
| 5 | if (WPILibVersion.version.contains('-')) |
| 6 | return WPILibVersion.version.substring(WPILibVersion.version.indexOf('-')) |
| 7 | else |
| 8 | return "" |
| 9 | } |
| 10 | |
| 11 | if (!hasProperty('releaseType')) { |
| 12 | WPILibVersion { |
| 13 | releaseType = 'dev' |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | def pubVersion |
| 18 | if (project.hasProperty("publishVersion")) { |
| 19 | pubVersion = project.publishVersion |
| 20 | } else { |
| 21 | pubVersion = WPILibVersion.version |
| 22 | } |
| 23 | |
| 24 | def outputsFolder = file("$buildDir/outputs") |
| 25 | |
| 26 | def versionFile = file("$outputsFolder/version.txt") |
| 27 | |
| 28 | task outputVersions() { |
| 29 | description = 'Prints the versions of wpiutil to a file for use by the downstream packaging project' |
| 30 | group = 'Build' |
| 31 | outputs.files(versionFile) |
| 32 | |
| 33 | doFirst { |
| 34 | outputsFolder.mkdir() |
| 35 | } |
| 36 | |
| 37 | doLast { |
| 38 | versionFile.write pubVersion |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | build.dependsOn outputVersions |
| 43 | |
| 44 | def baseArtifactId = 'wpiutil' |
| 45 | def artifactGroupId = 'edu.wpi.first.wpiutil' |
| 46 | |
| 47 | def licenseFile = file("$rootDir/license.txt") |
| 48 | |
| 49 | task cppSourcesZip(type: Zip) { |
| 50 | destinationDir = outputsFolder |
| 51 | classifier = "sources" |
| 52 | |
| 53 | from(licenseFile) { |
| 54 | into '/' |
| 55 | } |
| 56 | |
| 57 | from('src/main/native/cpp') { |
| 58 | into '/' |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | task cppHeadersZip(type: Zip) { |
| 63 | destinationDir = outputsFolder |
| 64 | classifier = "headers" |
| 65 | |
| 66 | from(licenseFile) { |
| 67 | into '/' |
| 68 | } |
| 69 | |
| 70 | from('src/main/native/include') { |
| 71 | into '/' |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | task sourcesJar(type: Jar, dependsOn: classes) { |
| 76 | classifier = 'sources' |
| 77 | from sourceSets.main.allSource |
| 78 | } |
| 79 | |
| 80 | task javadocJar(type: Jar, dependsOn: javadoc) { |
| 81 | classifier = 'javadoc' |
| 82 | from javadoc.destinationDir |
| 83 | } |
| 84 | |
| 85 | if (project.hasProperty('jenkinsBuild')) { |
| 86 | jar { |
| 87 | classifier = 'javaArtifact' |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | artifacts { |
| 92 | archives sourcesJar |
| 93 | archives javadocJar |
| 94 | archives cppHeadersZip |
| 95 | archives cppSourcesZip |
| 96 | outputVersions.outputs.files.each { |
| 97 | archives it |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | def createComponentZipTasks = { components, name, base, type, project, func -> |
| 102 | def configMap = [:] |
| 103 | components.each { |
| 104 | if (it in NativeLibrarySpec && it.name == name) { |
| 105 | it.binaries.each { |
| 106 | def target = getClassifier(it) |
| 107 | if (configMap.containsKey(target)) { |
| 108 | configMap.get(target).add(it) |
| 109 | } else { |
| 110 | configMap.put(target, []) |
| 111 | configMap.get(target).add(it) |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | def taskList = [] |
| 117 | configMap.each { key, value -> |
| 118 | def baseN = base + name |
| 119 | def task = project.tasks.create(baseN + "-${key}", type) { |
| 120 | description = 'Creates component archive for platform ' + key |
| 121 | destinationDir = outputsFolder |
| 122 | classifier = key |
| 123 | baseName = baseN + '-classifier' |
| 124 | duplicatesStrategy = 'exclude' |
| 125 | |
| 126 | from(licenseFile) { |
| 127 | into '/' |
| 128 | } |
| 129 | |
| 130 | func(it, value) |
| 131 | } |
| 132 | taskList.add(task) |
| 133 | |
| 134 | project.build.dependsOn task |
| 135 | |
| 136 | project.artifacts { |
| 137 | archives task |
| 138 | } |
| 139 | } |
| 140 | return taskList |
| 141 | } |
| 142 | |
| 143 | model { |
| 144 | publishing { |
| 145 | def wpiutilTaskList = createComponentZipTasks($.components, 'wpiutil', 'zipcppwpiutil', Zip, project, { task, value -> |
| 146 | value.each { binary-> |
| 147 | if (binary.buildable) { |
| 148 | if (binary instanceof SharedLibraryBinarySpec) { |
| 149 | task.dependsOn binary.buildTask |
| 150 | task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) { |
| 151 | into getPlatformPath(binary) + '/shared' |
| 152 | } |
| 153 | task.from (binary.sharedLibraryFile) { |
| 154 | into getPlatformPath(binary) + '/shared' |
| 155 | } |
| 156 | task.from (binary.sharedLibraryLinkFile) { |
| 157 | into getPlatformPath(binary) + '/shared' |
| 158 | } |
| 159 | } else if (binary instanceof StaticLibraryBinarySpec) { |
| 160 | task.dependsOn binary.buildTask |
| 161 | task.from (binary.staticLibraryFile) { |
| 162 | into getPlatformPath(binary) + '/static' |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | }) |
| 168 | |
| 169 | def allCppTask |
| 170 | if (!project.hasProperty('jenkinsBuild')) { |
| 171 | allCppTask = project.tasks.create("wpiutilAllZip", Zip) { |
| 172 | description = 'Creates a zip with all Cpp artifacts' |
| 173 | classifier = 'all' |
| 174 | baseName = 'zipcppwpiutilwpiutil' |
| 175 | destinationDir = outputsFolder |
| 176 | duplicatesStrategy = 'exclude' |
| 177 | |
| 178 | wpiutilTaskList.each { |
| 179 | it.outputs.files.each { |
| 180 | from project.zipTree(it) |
| 181 | } |
| 182 | dependsOn it |
| 183 | } |
| 184 | } |
| 185 | project.build.dependsOn allCppTask |
| 186 | } |
| 187 | |
| 188 | publications { |
| 189 | cpp(MavenPublication) { |
| 190 | wpiutilTaskList.each { |
| 191 | artifact it |
| 192 | } |
| 193 | artifact cppHeadersZip |
| 194 | artifact cppSourcesZip |
| 195 | |
| 196 | if (!project.hasProperty('jenkinsBuild')) { |
| 197 | artifact allCppTask |
| 198 | } |
| 199 | |
| 200 | artifactId = "${baseArtifactId}-cpp" |
| 201 | groupId artifactGroupId |
| 202 | version pubVersion |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | publishing { |
| 209 | publications { |
| 210 | |
| 211 | java(MavenPublication) { |
| 212 | artifact jar |
| 213 | artifact sourcesJar |
| 214 | artifact javadocJar |
| 215 | |
| 216 | artifactId = "${baseArtifactId}-java" |
| 217 | groupId artifactGroupId |
| 218 | version pubVersion |
| 219 | } |
| 220 | } |
| 221 | } |