Skip to content

Commit

Permalink
Put module-info into a place required by multi-release jars
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 24, 2018
1 parent 6c2819f commit 199f938
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/tools/BUCK
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# BUILD FILE SYNTAX: SKYLARK

java_library(
name = "package-lib",
srcs = [
Expand Down
32 changes: 29 additions & 3 deletions java/client/src/org/openqa/selenium/tools/ModuleMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.EnumSet;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class ModuleMaker {

Expand Down Expand Up @@ -94,10 +97,30 @@ public static void main(String[] args) throws IOException {
classWriter.visitEnd();

try (OutputStream os = Files.newOutputStream(out);
JarOutputStream jos = new JarOutputStream(os)) {
JarOutputStream jos = new JarOutputStream(os)) {
jos.setLevel(ZipOutputStream.STORED);

ZipEntry dir = new ZipEntry("META-INF/");
dir.setTime(DOS_EPOCH);
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
jos.putNextEntry(dir);

dir = new ZipEntry("META-INF/versions/");
dir.setTime(DOS_EPOCH);
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
jos.putNextEntry(dir);

dir = new ZipEntry("META-INF/versions/9");
dir.setTime(DOS_EPOCH);
dir.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
dir.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
jos.putNextEntry(dir);

byte[] bytes = classWriter.toByteArray();

ZipEntry entry = new ZipEntry("module-info.class");
JarEntry entry = new JarEntry("META-INF/versions/9/module-info.class");
entry.setTime(DOS_EPOCH);
entry.setCreationTime(FileTime.fromMillis(DOS_EPOCH));
entry.setLastModifiedTime(FileTime.fromMillis(DOS_EPOCH));
Expand Down Expand Up @@ -138,7 +161,10 @@ public void visit(ModuleExportsStmt n, Void arg) {
public void visit(ModuleProvidesStmt n, Void arg) {
byteBuddyVisitor.visitProvide(
n.getTypeAsString().replace('.', '/'),
n.getWithTypes().stream().map(type -> type.asString().replace('.', '/')).toArray(String[]::new));
n.getWithTypes().stream()
.map(type -> type.asString()
.replace('.', '/'))
.toArray(String[]::new));
}

@Override
Expand Down

0 comments on commit 199f938

Please sign in to comment.