Skip to content

Commit

Permalink
Use jar --date to set ZIP entry timestamps rather than repackaging
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Feb 25, 2024
1 parent 932b188 commit ad82d2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 61 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ package junitbuild.java

import org.gradle.api.Action
import org.gradle.api.Task
import org.gradle.api.internal.file.archive.ZipCopyAction
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.process.ExecOperations
import java.time.Instant
import javax.inject.Inject

abstract class ExecJarAction @Inject constructor(private val operations: ExecOperations): Action<Task> {
abstract class UpdateJarAction @Inject constructor(private val operations: ExecOperations): Action<Task> {

abstract val javaLauncher: Property<JavaLauncher>

abstract val args: ListProperty<String>

init {
args.addAll(
"--update",
"--date=${Instant.ofEpochMilli(ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES)}",
)
}

override fun execute(t: Task) {
operations.exec {
executable = javaLauncher.get()
.metadata.installationPath.file("bin/jar").asFile.absolutePath
args = this@ExecJarAction.args.get()
args = this@UpdateJarAction.args.get()
}
}
}
6 changes: 2 additions & 4 deletions junit-platform-commons/junit-platform-commons.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import junitbuild.java.ExecJarAction
import junitbuild.java.UpdateJarAction

plugins {
id("junitbuild.java-library-conventions")
id("junitbuild.java-multi-release-sources")
id("junitbuild.java-repackage-jars")
`java-test-fixtures`
}

Expand All @@ -18,10 +17,9 @@ dependencies {
tasks.jar {
val release9ClassesDir = sourceSets.mainRelease9.get().output.classesDirs.singleFile
inputs.dir(release9ClassesDir).withPathSensitivity(PathSensitivity.RELATIVE)
doLast(objects.newInstance(ExecJarAction::class).apply {
doLast(objects.newInstance(UpdateJarAction::class).apply {
javaLauncher = javaToolchains.launcherFor(java.toolchain)
args.addAll(
"--update",
"--file", archiveFile.get().asFile.absolutePath,
"--release", "9",
"-C", release9ClassesDir.absolutePath, "."
Expand Down
6 changes: 3 additions & 3 deletions junit-platform-console/junit-platform-console.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import junitbuild.java.UpdateJarAction

plugins {
id("junitbuild.java-library-conventions")
id("junitbuild.shadow-conventions")
id("junitbuild.java-multi-release-sources")
id("junitbuild.java-repackage-jars")
}

description = "JUnit Platform Console"
Expand Down Expand Up @@ -40,10 +41,9 @@ tasks {
into("META-INF")
}
from(sourceSets.mainRelease9.get().output.classesDirs)
doLast(objects.newInstance(junitbuild.java.ExecJarAction::class).apply {
doLast(objects.newInstance(UpdateJarAction::class).apply {
javaLauncher = project.javaToolchains.launcherFor(java.toolchain)
args.addAll(
"--update",
"--file", archiveFile.get().asFile.absolutePath,
"--main-class", "org.junit.platform.console.ConsoleLauncher",
"--release", "17",
Expand Down

0 comments on commit ad82d2a

Please sign in to comment.