Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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: 7 additions & 3 deletions test/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_java//java:defs.bzl", "java_binary", "java_import", "java_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load(
"//scala:scala.bzl",
"scala_binary",
Expand Down Expand Up @@ -616,9 +616,13 @@ scala_library(
)

# make sure making a fat jar strips signatures
java_import(
java_library(
name = "fakejar",
jars = ["fake_sig.jar"],
resources = [
"//test/src/main/resources/META-INF:FAKE.DSA",
"//test/src/main/resources/META-INF:FAKE.RSA",
],
visibility = ["//visibility:public"],
)

scala_binary(
Expand Down
14 changes: 7 additions & 7 deletions test/example_jars/BUILD
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
load("@rules_java//java:defs.bzl", "java_import")
load("@rules_java//java:defs.bzl", "java_library")

java_import(
java_library(
name = "example_jar1",
jars = [
"example_jar1.jar",
resources = [
"//test/src/main/resources/META-INF/services:org.apache.beam.sdk.io.FileSystemRegistrar",
],
visibility = ["//visibility:public"],
)

java_import(
java_library(
name = "example_jar2",
jars = [
"example_jar2.jar",
resources = [
"//test/src/main/resources/META-INF/services:org.apache.beam.sdk.io.FileSystemRegistrar",
],
visibility = ["//visibility:public"],
)
Binary file removed test/example_jars/example_jar1.jar
Binary file not shown.
Binary file removed test/example_jars/example_jar2.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion test/example_jars/expected_service_manifest.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar
org.apache.beam.sdk.io.LocalFileSystemRegistrar
org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar
Binary file removed test/fake_sig.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions test/src/main/resources/META-INF/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports_files([
"FAKE.DSA",
"FAKE.RSA",
])
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/src/main/resources/META-INF/services/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports_files([
"org.apache.beam.sdk.io.FileSystemRegistrar",
])
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.beam.sdk.extensions.gcp.storage.GcsFileSystemRegistrar
4 changes: 3 additions & 1 deletion test/src/main/resources/scalarules/test/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
exports_files([
"byes",
"hellos",
"hellos-and-byes.jar",
"more-byes",
"more-hellos",
"Foo.thrift",
"Bar.thrift",
"Baz.thrift",
])

genrule(
Expand Down
5 changes: 5 additions & 0 deletions test/src/main/resources/scalarules/test/Bar.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Bar {
1: optional string Bar
}
5 changes: 5 additions & 0 deletions test/src/main/resources/scalarules/test/Baz.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Baz {
1: optional string Baz
}
5 changes: 5 additions & 0 deletions test/src/main/resources/scalarules/test/Foo.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Foo {
1: optional string foo
}
Binary file not shown.
14 changes: 13 additions & 1 deletion test/src/main/scala/scalarules/test/resource_jars/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//scala:scala.bzl", "scala_test")

java_library(
name = "jarWithResources",
resources = [
"//test/src/main/resources/scalarules/test:byes",
"//test/src/main/resources/scalarules/test:hellos",
"//test/src/main/resources/scalarules/test:more-byes",
"//test/src/main/resources/scalarules/test:more-hellos",
],
visibility = ["//visibility:public"],
)

scala_test(
name = "resource_jars",
srcs = ["TestResourceJars.scala"],
resource_jars = ["//test/src/main/resources/scalarules/test:hellos-and-byes.jar"],
resource_jars = [":jarWithResources"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestResourceJars extends AnyFlatSpec {
)
expectedSubstrings.foreach {
case (resource_name, substring) => {
val stream = getClass.getResourceAsStream("/" + resource_name)
val stream = getClass.getResourceAsStream("/scalarules/test/" + resource_name)
assert(stream != null, s"failed to find resource $resource_name")
val content = Source.fromInputStream(stream).getLines().mkString("\n")
assert(content.contains(substring), s"resource $resource_name did not contain substring $substring")
Expand Down
20 changes: 13 additions & 7 deletions test/src/main/scala/scalarules/test/scala_import/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ scala_import(
],
)

# Jars as files
scala_library(
name = "generic_scalalib",
testonly = True,
srcs = ["generic/Generic.scala"],
visibility = ["//visibility:private"],
)

scala_import(
name = "relate",
name = "imported_genericlib_jar",
jars = [
"relate_2.11-2.1.1.jar",
":generic_scalalib.jar",
],
)

Expand All @@ -41,7 +47,7 @@ scala_specs2_junit_test(
size = "small",
srcs = ["ScalaImportExposesFileJarsTest.scala"],
suffixes = ["Test"],
deps = [":relate"],
deps = [":imported_genericlib_jar"],
)

scala_library(
Expand Down Expand Up @@ -123,15 +129,15 @@ scala_specs2_junit_test(
# https://github.com/bazelbuild/rules_scala/issues/1188
scala_import(
name = "stamping_first_time",
jars = ["relate_2.11-2.1.1.jar"],
jars = ["//test/src/main/scala/scalarules/test/scala_import/nl:ScalaImportNeverLink"],
)

scala_import(
name = "stamping_second_time",
jars = ["relate_2.11-2.1.1.jar"],
jars = ["//test/src/main/scala/scalarules/test/scala_import/nl:ScalaImportNeverLink"],
)

scala_import_stamping_test_suite(
name = "stamping_tests",
jar = "relate_2.11-2.1.1.jar",
jar = "//test/src/main/scala/scalarules/test/scala_import/nl:ScalaImportNeverLink",
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package scalarules.test.scala_import

import scalarules.test.scala_import.generic.Generic

import org.specs2.mutable.SpecificationWithJUnit
import com.lucidchart.relate.SqlRow

class ScalaImportExposesJarsTest extends SpecificationWithJUnit {

"scala_import" >> {
"enable importing jars from files" in {
println(classOf[SqlRow])
assert(Generic.foo == "bar")
success
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scalarules.test.scala_import.generic

object Generic {
val foo = "bar"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
load("//scala:scala.bzl", "scala_specs2_junit_test")
load("//scala:scala_import.bzl", "scala_import")
load("@rules_java//java:defs.bzl", "java_library")

java_library(
name = "ScalaImportNeverLink",
srcs = ["ScalaImportNeverLink.java"],
visibility = ["//visibility:public"],
)

scala_import(
name = "scala_import_never_link",
jars = [
"scala_import_never_link.jar",
":ScalaImportNeverLink",
],
neverlink = 1,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
package scalarules.test.scala_import.nl;

/**
* This class is packaged in scala_import_never_link.jar
*
* <p>The jar file was created with the following steps:
*
* <p>- javac ScalaImportNeverLink.java - makdir -p scalarules/test/scala_import/nl - mv
* ScalaImportNeverLink.class scalarules/test/scala_import/nl - jar cf scala_import_never_link.jar
* scalarules - rm -fr scalarules ScalaImportNeverLink.class
*
* <p>To stage the updated jar: git add -f scala_import_never_link.jar
*/
public class ScalaImportNeverLink {}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
load("@rules_java//java:defs.bzl", "java_import")
load("//thrift:thrift.bzl", "thrift_library")

java_import(
name = "barejar",
jars = ["bare-thrift.jar"],
visibility = ["//visibility:public"],
)

thrift_library(
name = "bare_jar_thrifts",
external_jars = [
":barejar",
],
srcs = ["//test/src/main/resources/scalarules/test:Foo.thrift"],
visibility = ["//visibility:public"],
deps = [
"//test/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("//thrift:thrift.bzl", "thrift_library")

thrift_library(
name = "bare_jar_1",
external_jars = [
"bare-thrift-1.jar",
],
srcs = ["//test/src/main/resources/scalarules/test:Bar.thrift"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above. Do you know why the second test is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now I reference .jar directly
the second test is meant for test_version.sh, apparently every test running against various versions has its copy there

visibility = ["//visibility:public"],
)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("//thrift:thrift.bzl", "thrift_library")

thrift_library(
name = "bare_jar_2",
external_jars = [
"bare-thrift-2.jar",
],
srcs = ["//test/src/main/resources/scalarules/test:Baz.thrift"],
visibility = ["//visibility:public"],
)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ thrift_library(

scrooge_scala_import(
name = "thrift3_import",
scala_jars = ["thrift3_scrooge.jar"],
scala_jars = ["//test/src/main/scala/scalarules/test/twitter_scrooge:scrooge3"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like a comment (in the code) here about what's going on. Just by looking at the test is very hard to understand what's going on and how is it being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kk, hope the comment I added is useful
thx for your patience too ;D

thrift_jars = ["libthrift3.jar"],
visibility = ["//visibility:public"],
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports_files([
"Foo.thrift",
"Bar.thrift",
"Baz.thrift",
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Bar {
1: optional string Bar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Baz {
1: optional string Baz
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace java com.foo.bar.baz

struct Foo {
1: optional string foo
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
load("@rules_java//java:defs.bzl", "java_import")
load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library")

java_import(
name = "barejar",
jars = ["bare-thrift.jar"],
visibility = ["//visibility:public"],
)

thrift_library(
name = "bare_jar_thrifts",
external_jars = [
":barejar",
],
srcs = ["//src/main/resources/scalarules/test:Foo.thrift"],
visibility = ["//visibility:public"],
deps = [
"//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library")

thrift_library(
name = "bare_jar_1",
external_jars = [
"bare-thrift-1.jar",
],
srcs = ["//src/main/resources/scalarules/test:Bar.thrift"],
visibility = ["//visibility:public"],
)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library")

thrift_library(
name = "bare_jar_2",
external_jars = [
"bare-thrift-2.jar",
],
srcs = ["//src/main/resources/scalarules/test:Baz.thrift"],
visibility = ["//visibility:public"],
)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ thrift_library(

scrooge_scala_import(
name = "thrift3_import",
scala_jars = ["thrift3_scrooge.jar"],
scala_jars = ["//src/main/scala/scalarules/test/twitter_scrooge:scrooge3"],
thrift_jars = ["libthrift3.jar"],
visibility = ["//visibility:public"],
)
Binary file not shown.