@@ -59,12 +59,42 @@ dependencies { |
59 | 59 | embeddedRuntime("com.google.protobuf:protobuf-javalite:4.33.1") |
60 | 60 | embeddedRuntime("com.google.code.gson:gson:2.14.0") |
61 | 61 | embeddedRuntime("org.openjdk.jmc:flightrecorder.writer:9.1.2") |
| 62 | + embeddedRuntime("info.picocli:picocli:4.7.7") |
62 | 63 | jmcWriterSources("org.openjdk.jmc:flightrecorder.writer:9.1.2:sources@jar") |
63 | 64 | } |
64 | 65 |
|
| 66 | +// The build version and the async-profiler fork commit, for --version. |
| 67 | +val asyncProfilerCommit = |
| 68 | + providers |
| 69 | + .exec { |
| 70 | + // The pinned gitlink, which is what the build embeds whether or not the submodule is checked out. |
| 71 | + commandLine("git", "-C", rootProject.projectDir.absolutePath, "rev-parse", "HEAD:async-profiler") |
| 72 | + isIgnoreExitValue = true |
| 73 | + }.standardOutput.asText |
| 74 | + .map { it.trim().ifEmpty { "unknown" } } |
| 75 | +val generateVersionResource = |
| 76 | + tasks.register("generateVersionResource") { |
| 77 | + val version = project.version.toString() |
| 78 | + val commit = asyncProfilerCommit |
| 79 | + val outputDir = layout.buildDirectory.dir("generated/version-resource") |
| 80 | + inputs.property("version", version) |
| 81 | + inputs.property("asyncProfilerCommit", commit) |
| 82 | + outputs.dir(outputDir) |
| 83 | + doLast { |
| 84 | + val file = |
| 85 | + outputDir |
| 86 | + .get() |
| 87 | + .file("io/github/lhotari/jonoffcpu/offline/version.properties") |
| 88 | + .asFile |
| 89 | + file.parentFile.mkdirs() |
| 90 | + file.writeText("version=$version\nasyncProfilerCommit=${commit.get()}\n") |
| 91 | + } |
| 92 | + } |
| 93 | + |
65 | 94 | sourceSets { |
66 | 95 | main { |
67 | 96 | proto.setSrcDirs(listOf(rootProject.layout.projectDirectory.dir("docs/schema"))) |
| 97 | + resources.srcDir(generateVersionResource) |
68 | 98 | } |
69 | 99 | } |
70 | 100 |
|
@@ -106,6 +136,7 @@ val buildAsyncProfilerConverter = tasks.register<Exec>("buildAsyncProfilerConver |
106 | 136 | val expectedDependencyDigests = mapOf( |
107 | 137 | "protobuf-javalite-4.33.1.jar" to "a1a1cccbcfa861e988b7ccde58dbe95204156906dd6cd42786b9c8f74d5fe34e", |
108 | 138 | "gson-2.14.0.jar" to "2cbd119bf1961c28788310963dc80ba65f58cdeec1dd139c8bdb1240faa2c36f", |
| 139 | + "picocli-4.7.7.jar" to "f86e30fffd10d2b13b8caa8d4b237a7ee61f2ffccf5b1941de718b765d235bf8", |
109 | 140 | "flightrecorder.writer-9.1.2.jar" to |
110 | 141 | "8313e66f798f31de144c65b257a0434afca07b1bce1b59f17e63aed38c0dc9c1", |
111 | 142 | "flightrecorder.writer-9.1.2-sources.jar" to |
@@ -127,7 +158,7 @@ fun sha256File(input: File): String { |
127 | 158 |
|
128 | 159 | val verifyDependencyDigests = tasks.register("verifyDependencyDigests") { |
129 | 160 | group = "verification" |
130 | | - description = "Checks the exact protobuf, Gson and patched JMC writer artifacts before embedding them." |
| 161 | + description = "Checks the exact protobuf, Gson, picocli and patched JMC writer artifacts before embedding them." |
131 | 162 | inputs.files(embeddedRuntime, jmcWriterSources) |
132 | 163 | doLast { |
133 | 164 | (embeddedRuntime.files + jmcWriterSources.files).forEach { artifact -> |
@@ -184,6 +215,7 @@ val jar = tasks.named<ShadowJar>("shadowJar") { |
184 | 215 | relocate("com.google.protobuf", "io.github.lhotari.jonoffcpu.correlator.internal.shaded.protobuf") |
185 | 216 | relocate("com.google.gson", "io.github.lhotari.jonoffcpu.correlator.internal.shaded.gson") |
186 | 217 | relocate("org.openjdk.jmc", "io.github.lhotari.jonoffcpu.correlator.internal.shaded.jmc") |
| 218 | + relocate("picocli", "io.github.lhotari.jonoffcpu.correlator.internal.shaded.picocli") |
187 | 219 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE |
188 | 220 | isPreserveFileTimestamps = false |
189 | 221 | isReproducibleFileOrder = true |
@@ -235,14 +267,16 @@ val verifyRuntimeJar = tasks.register("verifyRuntimeJar") { |
235 | 267 | it.name.startsWith("com/google/gson/") |
236 | 268 | || it.name.startsWith("org/openjdk/jmc/") |
237 | 269 | || it.name.startsWith("com/google/protobuf/") |
| 270 | + || it.name.startsWith("picocli/") |
238 | 271 | }) { |
239 | 272 | throw GradleException("Correlator JAR contains unrelocated dependency packages") |
240 | 273 | } |
241 | 274 | listOf( |
242 | 275 | "io/github/lhotari/jonoffcpu/correlator/internal/shaded/gson/Gson.class", |
243 | 276 | "io/github/lhotari/jonoffcpu/correlator/internal/shaded/protobuf/CodedInputStream.class", |
244 | 277 | "io/github/lhotari/jonoffcpu/correlator/internal/shaded/jmc/flightrecorder/writer/api/Recordings.class", |
245 | | - "io/github/lhotari/jonoffcpu/correlator/internal/shaded/jmc/flightrecorder/writer/ConstantPool.class" |
| 278 | + "io/github/lhotari/jonoffcpu/correlator/internal/shaded/jmc/flightrecorder/writer/ConstantPool.class", |
| 279 | + "io/github/lhotari/jonoffcpu/correlator/internal/shaded/picocli/CommandLine.class" |
246 | 280 | ).forEach { name -> |
247 | 281 | if (zip.getEntry(name) == null) throw GradleException("Correlator JAR is missing relocated class $name") |
248 | 282 | } |
@@ -259,7 +293,8 @@ val fixtureMains = mapOf( |
259 | 293 | "PartialCorrelator" to "io.github.lhotari.jonoffcpu.offline.PartialCorrelatorTest", |
260 | 294 | "PrimitiveStructures" to "io.github.lhotari.jonoffcpu.offline.PrimitiveStructuresTest", |
261 | 295 | "StreamingCorrelator" to "io.github.lhotari.jonoffcpu.offline.StreamingCorrelatorTest", |
262 | | - "StackProfile" to "io.github.lhotari.jonoffcpu.offline.StackProfileTest" |
| 296 | + "StackProfile" to "io.github.lhotari.jonoffcpu.offline.StackProfileTest", |
| 297 | + "CommandLine" to "io.github.lhotari.jonoffcpu.offline.CommandLineTest" |
263 | 298 | ) |
264 | 299 | val fixtureTasks = fixtureMains.map { (taskName, className) -> |
265 | 300 | tasks.register<JavaExec>("test$taskName") { |
@@ -274,6 +309,12 @@ val fixtureTasks = fixtureMains.map { (taskName, className) -> |
274 | 309 |
|
275 | 310 | // Spec acceptance 4: the scale fixture's assertion is the heap cap itself, so it must run under |
276 | 311 | // exactly the bound it proves, not whatever heap the other fixtures happen to get. |
| 312 | +// The README's option tables are checked against the parser, so documentation and help cannot drift. |
| 313 | +tasks.named<JavaExec>("testCommandLine") { |
| 314 | + inputs.file(rootProject.file("README.md")) |
| 315 | + systemProperty("jonoffcpu.readme", rootProject.file("README.md").absolutePath) |
| 316 | +} |
| 317 | + |
277 | 318 | tasks.named<JavaExec>("testStreamingCorrelator") { |
278 | 319 | jvmArgs("-ea", "-Xmx1g") |
279 | 320 | } |
|