Skip to content

Commit 01323f0

Browse files
committed
feat: Add scala-cli script generator to verify jdk classes
1 parent d55350e commit 01323f0

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Verify JDK9 classes
19+
20+
on:
21+
pull_request:
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
verify-jdk9-classes-check:
28+
name: Verify JDK9 classes
29+
runs-on: ubuntu-20.04
30+
if: github.repository == 'apache/incubator-pekko'
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
fetch-tags: true
37+
38+
- name: Setup Java 11
39+
uses: actions/setup-java@v4
40+
with:
41+
distribution: temurin
42+
java-version: 11
43+
44+
- name: Cache Coursier cache
45+
uses: coursier/cache-action@v6
46+
47+
- name: Publish Stream module local
48+
run: sbt ";stream / publishLocal ;"
49+
50+
- uses: VirtusLab/[email protected]
51+
- name: Use Scala-CLI to check
52+
run: |-
53+
scala-cli --version
54+
scala-cli stream/target/scala-cli/VerifyJDK9Classes.sc || (
55+
echo "Error when VerifyJDK9Classes"
56+
exit 1
57+
)
58+

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ lazy val stream = pekkoModule("stream")
434434
.settings(AutomaticModuleName.settings("pekko.stream"))
435435
.settings(OSGi.stream)
436436
.settings(Protobuf.settings)
437+
.settings(VerifyJDK9Classes.settings)
437438
.enablePlugins(BoilerplatePlugin, Jdk9)
438439

439440
lazy val streamTestkit = pekkoModule("stream-testkit")

project/VerifyJDK9Classes.scala

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
object VerifyJDK9Classes {
19+
import sbt.*
20+
import sbt.Keys.*
21+
22+
lazy val settings: Seq[Setting[_]] = inConfig(Compile) {
23+
Seq {
24+
sourceGenerators += {
25+
generateAndWriteScalaCLIScript(
26+
target,
27+
_ / "scala-cli" / "VerifyJDK9Classes.sc")
28+
}
29+
}
30+
}
31+
32+
def generateAndWriteScalaCLIScript(dir: SettingKey[File], locate: File => File): Def.Initialize[Task[Seq[sbt.File]]] =
33+
Def.task[Seq[File]] {
34+
val script = generateScalaCLIScript(version.value)
35+
val file = locate(dir.value)
36+
val content = script.stripMargin.format(version.value)
37+
if (!file.exists || IO.read(file) != content) IO.write(file, content)
38+
// the generated file is not used.
39+
Nil
40+
}
41+
42+
private def generateScalaCLIScript(version: String): String =
43+
s"""
44+
|/*
45+
| * Licensed to the Apache Software Foundation (ASF) under one or more
46+
| * contributor license agreements. See the NOTICE file distributed with
47+
| * this work for additional information regarding copyright ownership.
48+
| * The ASF licenses this file to You under the Apache License, Version 2.0
49+
| * (the "License"); you may not use this file except in compliance with
50+
| * the License. You may obtain a copy of the License at
51+
| *
52+
| * http://www.apache.org/licenses/LICENSE-2.0
53+
| *
54+
| * Unless required by applicable law or agreed to in writing, software
55+
| * distributed under the License is distributed on an "AS IS" BASIS,
56+
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57+
| * See the License for the specific language governing permissions and
58+
| * limitations under the License.
59+
| */
60+
|//> using dep "org.apache.pekko::pekko-stream:${version}"
61+
|////> using jvm 11
62+
|object VerifyJDK9Classes {
63+
| def main(args: Array[String]): Unit = {
64+
| import org.apache.pekko.actor.ActorSystem
65+
| import org.apache.pekko.stream.scaladsl.{ JavaFlowSupport, Source }
66+
|
67+
| import java.lang.System.exit
68+
| import scala.concurrent.Await
69+
| import scala.concurrent.duration.DurationInt
70+
| implicit val system: ActorSystem = ActorSystem.create("test")
71+
| val future = Source(1 to 3).runWith(
72+
| JavaFlowSupport.Sink.asPublisher[Int](fanout = false).mapMaterializedValue { p =>
73+
| JavaFlowSupport.Source.fromPublisher(p).runFold(0)(_ + _)
74+
| })
75+
|
76+
| val result = Await.result(future, 3.seconds)
77+
| println(s"Result:" + result)
78+
| system.terminate()
79+
| exit(if (result == 6) 0 else 1)
80+
| }
81+
|}
82+
|
83+
|""".stripMargin
84+
}

0 commit comments

Comments
 (0)