Skip to content

Commit f12facd

Browse files
anfelbarjayconrod
andauthored
Added Scala language support and hello world example (#37)
* Added Scala language supoort and hello world example * Small fixes * Updated ubuntu iso version for genrules examples * Update WORKSPACE Co-authored-by: Jay Conrod <[email protected]> * Update scala/BUILD Co-authored-by: Jay Conrod <[email protected]> * Re organized scala example with test case (same as java) * Fixed ubuntu name * rules_scala_version in uppercase Co-authored-by: Jay Conrod <[email protected]>
1 parent 1e0dd59 commit f12facd

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

WORKSPACE

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
workspace(name = "example")
2+
13
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
24
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
35
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
@@ -14,10 +16,10 @@ http_file(
1416

1517
http_file(
1618
name = "ubuntu_20.04_1.3GB",
17-
sha256 = "28ccdb56450e643bad03bb7bcf7507ce3d8d90e8bf09e38f6bd9ac298a98eaad",
19+
sha256 = "5035be37a7e9abbdc09f0d257f3e33416c1a0fb322ba860d42d74aa75c3468d4",
1820
urls = [
19-
"https://mirror.math.princeton.edu/pub/ubuntu-iso/focal/ubuntu-20.04.4-live-server-amd64.iso",
20-
"https://mirror.pit.teraswitch.com/ubuntu-releases/focal/ubuntu-20.04.4-live-server-amd64.iso",
21+
"https://mirror.math.princeton.edu/pub/ubuntu-iso/focal/ubuntu-20.04.5-live-server-amd64.iso",
22+
"https://mirror.pit.teraswitch.com/ubuntu-releases/focal/ubuntu-20.04.5-live-server-amd64.iso",
2123
],
2224
)
2325

@@ -122,3 +124,30 @@ maven_install(
122124
load("@maven//:compat.bzl", "compat_repositories")
123125

124126
compat_repositories()
127+
128+
129+
RULES_SCALA_VERSION = "20220201"
130+
131+
http_archive(
132+
name = "io_bazel_rules_scala",
133+
sha256 = "77a3b9308a8780fff3f10cdbbe36d55164b85a48123033f5e970fdae262e8eb2",
134+
strip_prefix = "rules_scala-%s" % RULES_SCALA_VERSION,
135+
type = "zip",
136+
url = "https://github.com/bazelbuild/rules_scala/archive/%s.zip" % RULES_SCALA_VERSION,
137+
)
138+
139+
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
140+
141+
scala_config()
142+
143+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
144+
145+
scala_repositories()
146+
147+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
148+
149+
scala_register_toolchains()
150+
151+
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
152+
scalatest_repositories()
153+
scalatest_toolchain()

scala/com/engflow/example/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library", "scala_test")
2+
3+
scala_library(
4+
name = "exampleScala",
5+
srcs = ["ScalaExample.scala"],
6+
#main_class = "com.engflow.example.ScalaExample",
7+
)
8+
9+
scala_test(
10+
name = "exampleScalaTest",
11+
srcs = ["ScalaExampleTest.scala"],
12+
deps = [":exampleScala"],
13+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.engflow.example;
2+
3+
object ScalaExample {
4+
def fizzbuzz(i: Int): String = {
5+
if (i % 3 == 0){
6+
if (i % 5 == 0){
7+
return "FizzBuzz";
8+
}
9+
return "Fizz";
10+
} else if (i % 5 == 0){
11+
return "Buzz";
12+
} else {
13+
return Integer.toString(i);
14+
}
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.engflow.example
2+
import org.scalatest.FunSuite
3+
4+
class ScalaExampleTest extends FunSuite {
5+
test ("engflow scala tests") {
6+
assert("1" == ScalaExample.fizzbuzz(1))
7+
assert("2" == ScalaExample.fizzbuzz(2))
8+
assert("Fizz" == ScalaExample.fizzbuzz(3))
9+
assert("4" == ScalaExample.fizzbuzz(4))
10+
assert("Buzz" == ScalaExample.fizzbuzz(5))
11+
assert("FizzBuzz" == ScalaExample.fizzbuzz(15))
12+
}
13+
}

0 commit comments

Comments
 (0)