Skip to content

don't put signatures in deploy jar #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/java/io/bazel/rulesscala/jar/JarCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ public void execute() throws IOException {
}
}

@Override
protected boolean ignoreFileName(String name) {
/*
* It does not make sense to copy signature files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be wise to rename JarCreator to FatJarCreator / DeployJarCreator / UberJarCreator? Current name made me wonder why the override is like this and the base is just "false". Until I read the comment and remembered

* into a fat jar because the jar signature will
* be broken
*/
return (name.endsWith(".DSA") || name.endsWith(".RSA"));
}

public static void buildJar(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("usage: CreateJar [-m manifest] output [root directories]");
Expand Down
8 changes: 6 additions & 2 deletions src/java/io/bazel/rulesscala/jar/JarHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,21 @@ protected void writeManifestEntry(byte[] content) throws IOException {
}
}

protected boolean ignoreFileName(String name) {
return false;
}

/**
* This copies the contents of jarFile into out
* This is a static method to make it clear what is mutated (and it
* was written by someone who really likes to minimize state changes).
*/
static private void copyJar(JarFile nameJf, Set<String> names, JarOutputStream out) throws IOException {
private void copyJar(JarFile nameJf, Set<String> names, JarOutputStream out) throws IOException {
byte[] buffer = new byte[2048];
for (Enumeration<JarEntry> e = nameJf.entries(); e.hasMoreElements();) {
JarEntry existing = e.nextElement();
String name = existing.getName();
if (!names.contains(name)) {
if (!(ignoreFileName(name) || names.contains(name))) {
JarEntry outEntry = new JarEntry(name);
outEntry.setTime(existing.getTime());
outEntry.setSize(existing.getSize());
Expand Down
24 changes: 24 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,27 @@ scala_library(
srcs = ["src/main/scala/scala/test/utf8/JavaClassWithUtf8.java",
"src/main/scala/scala/test/utf8/ScalaClassWithUtf8.scala"]
)

# make sure making a fat jar strips signatures
java_import(
name = "fakejar",
jars = ["fake_sig.jar"])

scala_binary(
name = "ScalaBinary_with_fake",
srcs = ["ScalaBinary.scala"],
main_class = "scala.test.ScalaBinary",
deps = [":HelloLib", ":MacroTest", ":fakejar"],
)

py_binary(
name = "jar_lister",
srcs = ["jar_lister.py"]
)

sh_test(
name = "no_sig",
srcs = ["no_sigs.sh"],
args = ["$(location //test:jar_lister)", "$(location //test:ScalaBinary_with_fake_deploy.jar)"],
data = [":ScalaBinary_with_fake_deploy.jar", ":jar_lister"],
)
Binary file added test/fake_sig.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions test/jar_lister.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import zipfile
import sys

for n in zipfile.ZipFile(sys.argv[1]).namelist():
print n
13 changes: 13 additions & 0 deletions test/no_sigs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

OUTPUT1=`$1 $2 | grep DSA`
OUTPUT2=`$1 $2 | grep RSA`

if [[ $OUTPUT1 ]]; then
echo $OUTPUT1
exit 1
fi
if [[ $OUTPUT2 ]]; then
echo $OUTPUT2
exit 1
fi