Skip to content

Commit f77b937

Browse files
committed
[bazel] Generate stable, repeatable zip files
1 parent fbb253f commit f77b937

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed

java/client/src/org/openqa/selenium/tools/javadoc/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ java_binary(
22
name = "javadoc",
33
main_class = "org.openqa.selenium.tools.javadoc.JavadocJarMaker",
44
srcs = glob(["*.java"]),
5-
deps = [],
5+
deps = [
6+
"//java/client/src/org/openqa/selenium/tools/zip",
7+
],
68
visibility = [
79
"//visibility:public",
810
]

java/client/src/org/openqa/selenium/tools/javadoc/JavadocJarMaker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.openqa.selenium.tools.javadoc;
22

3+
import org.openqa.selenium.tools.zip.StableZipEntry;
4+
35
import javax.tools.DocumentationTool;
46
import javax.tools.JavaFileObject;
57
import javax.tools.StandardJavaFileManager;
@@ -76,8 +78,7 @@ public static void main(String[] args) throws IOException {
7678
tempDirs.add(unpackTo);
7779
Set<String> fileNames = new HashSet<>();
7880
readSourceFiles(unpackTo, fileManager, sourceJars, sources, topLevelPackages, fileNames);
79-
List<String> options = new ArrayList<>();
80-
options.addAll(List.of("-html5", "-notimestamp", "-use", "-quiet", "-Xdoclint:-missing", "-encoding", "UTF8"));
81+
List<String> options = new ArrayList<>(List.of("-html5", "-notimestamp", "-use", "-quiet", "-Xdoclint:-missing", "-encoding", "UTF8"));
8182
if (!classpath.isEmpty()) {
8283
options.add("-cp");
8384
options.add(classpath.stream().map(Path::toAbsolutePath).map(String::valueOf).collect(Collectors.joining(File.pathSeparator)));
@@ -110,12 +111,12 @@ public static void main(String[] args) throws IOException {
110111
try {
111112
if (Files.isDirectory(path)) {
112113
String name = outputTo.relativize(path) + "/";
113-
ZipEntry entry = new ZipEntry(name);
114+
ZipEntry entry = new StableZipEntry(name);
114115
zos.putNextEntry(entry);
115116
zos.closeEntry();
116117
} else {
117118
String name = outputTo.relativize(path).toString();
118-
ZipEntry entry = new ZipEntry(name);
119+
ZipEntry entry = new StableZipEntry(name);
119120
zos.putNextEntry(entry);
120121
try (InputStream is = Files.newInputStream(path)) {
121122
is.transferTo(zos);

java/client/src/org/openqa/selenium/tools/modules/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ java_binary(
1212
main_class = "org.openqa.selenium.tools.modules.ModuleGenerator",
1313
visibility = ["//visibility:public"],
1414
deps = [
15+
"//java/client/src/org/openqa/selenium/tools/zip",
1516
artifact("net.bytebuddy:byte-buddy"),
1617
artifact("com.github.javaparser:javaparser-core"),
1718
],

java/client/src/org/openqa/selenium/tools/modules/ModuleGenerator.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
3636
import net.bytebuddy.jar.asm.ClassWriter;
3737
import net.bytebuddy.jar.asm.ModuleVisitor;
38+
import org.openqa.selenium.tools.zip.StableZipEntry;
3839

3940
import java.io.ByteArrayOutputStream;
4041
import java.io.File;
@@ -82,10 +83,7 @@
8283
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
8384

8485
public class ModuleGenerator {
85-
86-
// Starts at 1980-01-01. We'll match what buck uses
87-
private static final long DOS_EPOCH = Instant.parse("1985-02-01T00:00:00.00Z").toEpochMilli();
88-
86+
8987
public static void main(String[] args) throws IOException {
9088
Path outJar = null;
9189
Path inJar = null;
@@ -292,30 +290,18 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
292290
JarOutputStream jos = new JarOutputStream(os, manifest)) {
293291
jos.setLevel(ZipOutputStream.STORED);
294292

295-
ZipEntry dir = new ZipEntry("META-INF/");
296-
dir.setTime(DOS_EPOCH);
297-
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
298-
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
293+
ZipEntry dir = new StableZipEntry("META-INF/");
299294
jos.putNextEntry(dir);
300295

301-
dir = new ZipEntry("META-INF/versions/");
302-
dir.setTime(DOS_EPOCH);
303-
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
304-
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
296+
dir = new StableZipEntry("META-INF/versions/");
305297
jos.putNextEntry(dir);
306298

307-
dir = new ZipEntry("META-INF/versions/9/");
308-
dir.setTime(DOS_EPOCH);
309-
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
310-
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
299+
dir = new StableZipEntry("META-INF/versions/9/");
311300
jos.putNextEntry(dir);
312301

313302
byte[] bytes = classWriter.toByteArray();
314303

315-
JarEntry entry = new JarEntry("META-INF/versions/9/module-info.class");
316-
entry.setTime(DOS_EPOCH);
317-
entry.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
318-
entry.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
304+
ZipEntry entry = new StableZipEntry("META-INF/versions/9/module-info.class");
319305
entry.setSize(bytes.length);
320306

321307
jos.putNextEntry(entry);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
java_library(
2+
name = "zip",
3+
srcs = glob(["*.java"]),
4+
visibility = [
5+
"//java/client/src/org/openqa/selenium/tools:__subpackages__",
6+
],
7+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.openqa.selenium.tools.zip;
2+
3+
import java.nio.file.attribute.FileTime;
4+
import java.time.Instant;
5+
import java.util.zip.ZipEntry;
6+
7+
public class StableZipEntry extends ZipEntry {
8+
9+
// Starts at 1980-01-01. We'll match what buck uses
10+
private static final long DOS_EPOCH = Instant.parse("1985-02-01T00:00:00.00Z").toEpochMilli();
11+
12+
public StableZipEntry(String name) {
13+
super(name);
14+
15+
setTime(DOS_EPOCH);
16+
setCreationTime(FileTime.fromMillis(DOS_EPOCH));
17+
setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
18+
}
19+
}

0 commit comments

Comments
 (0)