Skip to content

Commit

Permalink
Not all systems have zip, so use a simple java utility to strip
Browse files Browse the repository at this point in the history
META-INF/services from the repackaged jetty jar.
  • Loading branch information
jleyba committed May 2, 2019
1 parent 44af705 commit fb2b085
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions java/client/src/org/openqa/selenium/tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
java_binary(
name = "DeleteFromZip",
srcs = ["DeleteFromZip.java"],
main_class = "org.openqa.selenium.tools.DeleteFromZip",
visibility = ["//third_party/java/jetty:__pkg__"],
deps = ["//third_party/java/guava"],
)
40 changes: 40 additions & 0 deletions java/client/src/org/openqa/selenium/tools/DeleteFromZip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.openqa.selenium.tools;

import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

final class DeleteFromZip {
public static void main(String[] args) throws IOException {
if (args.length < 2) {
throw new RuntimeException("usage: [zip file] [paths to delete...]");
}

Map<String, String> properties = new HashMap<>();
properties.put("create", "false");

Path zip = Paths.get(args[0]).toAbsolutePath();
URI uri = URI.create("jar:file:" + zip);
try (FileSystem zipfs = FileSystems.newFileSystem(uri, properties)) {
System.out.println("Opened " + args[0]);
for (int i = 1; i < args.length; i++) {
Path path = zipfs.getPath(args[i]);
if (Files.isDirectory(path)) {
MoreFiles.deleteRecursively(path, RecursiveDeleteOption.ALLOW_INSECURE);
System.out.println("Deleted directory " + args[i]);
} else if (Files.exists(path)) {
Files.delete(path);
System.out.println("Deleted file " + args[i]);
}
}
}
}
}
3 changes: 2 additions & 1 deletion third_party/java/jetty/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ genrule(
name = "strip-services",
srcs = [":bundle-jars_deploy.jar"],
outs = ["stripped-bundle.jar"],
cmd = "cp $< $@ && chmod +w $@ && zip -d $@ META-INF/services/*",
tools = ["//java/client/src/org/openqa/selenium/tools:DeleteFromZip"],
cmd = "cp $< $@ && chmod +w $@ && $(location //java/client/src/org/openqa/selenium/tools:DeleteFromZip) $@ META-INF/services",
visibility = ["//visibility:private"],
)

Expand Down

0 comments on commit fb2b085

Please sign in to comment.