|
| 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