blob: 135694644137205a9bf8462df75712e586a97257 [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001apply plugin: 'maven-publish'
2
3def baseArtifactId = 'SysId'
4def artifactGroupId = 'edu.wpi.first.tools'
5def zipBaseName = '_GROUP_edu_wpi_first_tools_ID_SysId_CLS'
6
7def outputsFolder = file("$project.buildDir/outputs")
8
9model {
10 tasks {
11 // Create the run task.
12 $.components.sysid.binaries.each { bin ->
13 if (bin.buildable && bin.name.toLowerCase().contains("debug") && nativeUtils.isNativeDesktopPlatform(bin.targetPlatform)) {
14 Task run = project.tasks.create("run", Exec) {
15 commandLine bin.tasks.install.runScriptFile.get().asFile.toString()
16 }
17 run.dependsOn bin.tasks.install
18 }
19 }
20 }
21 publishing {
22 def sysIdTaskList = []
23 $.components.each { component ->
24 component.binaries.each { binary ->
25 if (binary in NativeExecutableBinarySpec && binary.component.name.contains("sysid")) {
26 if (binary.buildable && (binary.name.contains('Release') || binary.name.contains('release'))) {
27 // We are now in the binary that we want.
28 // This is the default application path for the ZIP task.
29 def applicationPath = binary.executable.file
30 def icon = file("$project.projectDir/src/main/native/mac/ov.icns")
31
32 // Create the macOS bundle.
33 def bundleTask = project.tasks.create("bundleSysIdOsxApp" + binary.targetPlatform.architecture.name, Copy) {
34 description("Creates a macOS application bundle for SysId")
35 from(file("$project.projectDir/Info.plist"))
36 into(file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/SysId.app/Contents"))
37 into("MacOS") {
38 with copySpec {
39 from binary.executable.file
40 }
41 }
42 into("Resources") {
43 with copySpec {
44 from icon
45 }
46 }
47
48 inputs.property "HasDeveloperId", project.hasProperty("developerID")
49
50 doLast {
51 if (project.hasProperty("developerID")) {
52 // Get path to binary.
53 exec {
54 workingDir rootDir
55 def args = [
56 "sh",
57 "-c",
58 "codesign --force --strict --deep " +
59 "--timestamp --options=runtime " +
60 "--verbose -s ${project.findProperty("developerID")} " +
61 "$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/SysId.app/"
62 ]
63 commandLine args
64 }
65 }
66 }
67 }
68
69 // Reset the application path if we are creating a bundle.
70 if (binary.targetPlatform.operatingSystem.isMacOsX()) {
71 applicationPath = file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name")
72 project.build.dependsOn bundleTask
73 }
74
75 // Create the ZIP.
76 def task = project.tasks.create("copySysIdExecutable" + binary.targetPlatform.architecture.name, Zip) {
77 description("Copies the SysId executable to the outputs directory.")
78 destinationDirectory = outputsFolder
79
80 archiveBaseName = '_M_' + zipBaseName
81 duplicatesStrategy = 'exclude'
82 archiveClassifier = nativeUtils.getPublishClassifier(binary)
83
84 from(licenseFile) {
85 into '/'
86 }
87
88 from(applicationPath)
89
90 if (binary.targetPlatform.operatingSystem.isWindows()) {
91 def exePath = binary.executable.file.absolutePath
92 exePath = exePath.substring(0, exePath.length() - 4)
93 def pdbPath = new File(exePath + '.pdb')
94 from(pdbPath)
95 }
96
97 into(nativeUtils.getPlatformPath(binary))
98 }
99
100 if (binary.targetPlatform.operatingSystem.isMacOsX()) {
101 bundleTask.dependsOn binary.tasks.link
102 task.dependsOn(bundleTask)
103 }
104
105 task.dependsOn binary.tasks.link
106 sysIdTaskList.add(task)
107 project.build.dependsOn task
108 project.artifacts { task }
109 addTaskToCopyAllOutputs(task)
110 }
111 }
112 }
113 }
114
115 publications {
116 sysId(MavenPublication) {
117 sysIdTaskList.each { artifact it }
118
119 artifactId = baseArtifactId
120 groupId = artifactGroupId
121 version wpilibVersioning.version.get()
122 }
123 }
124 }
125}