Skip to content

Commit 1819491

Browse files
author
Alex Zolotko
authored
Merge pull request #17 from IHomer/master
make it build and run on JDK 13
2 parents 56b52b7 + 313a50f commit 1819491

File tree

9 files changed

+95
-6
lines changed

9 files changed

+95
-6
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,18 @@ The important take-aways here are:
189189
* Typically, DSL operations will block until the user input or Central System
190190
response has come, and will return this result as from the function call
191191

192-
### Expectations
192+
### Writing scripts with autocomplete in your favourite IDE
193+
194+
I admit it's quite inconvenient that in the script files you have the full power of Scala, but you don't have IDE support to help you suggest methods to call or highlight mistakes. So I've added a project in which you can edit your docile-charge-point script with IDE support.
195+
196+
How does that work? Well, docile-charge-point actually loads its script files by adding a bunch of imports and other boilerplate before and after the script file contents before the code is compiled. So you would have IDE support if you would be editing the file with the boilerplate in place. I don't want to make it the standard way of working to add this boilerplate in the scripts though, because that would make it harder to read the scripts for outsiders and it would lead to more version compatibility troubles between versions of docile-charge-point.
197+
198+
To still allow you to have your autocomplete, there is a special template project in which you can edit a script with the boilerplate included and also execute it. In that project, docile is loaded as a library so that it is possible to run the interpreter on your compiled code without running the script file loader that adds the boilerplate.
199+
200+
To use it, open the template project in the [autocomplete-template-project](autocomplete-template-project/) directory. The project already has an sbt file setting up the library dependencies
201+
on the docile-charge-point DSL core. IntelliJ IDEA will import this project just fine. You'll then find a file [TestScript.scala](autocomplete-template-project/src/main/scala/TestScript.scala) that contains all the boilerplate and a comment that says `// INSERT SCRIPT HERE`. If you start editing at the place where that comment is, you can type anything that you can also type in a script file without the boilerplate. IDEA will offer you all its suggestion magic. To run your code, just execute `TestScript` as a main class in IDEA. To distribute your code as a reusable docile-charge-point script, just copy the part you added out of the surrounding boilerplate and put it in a file of its own.
202+
203+
### Scripts with expectations
193204

194205
The semi-final line is interesting: `fail("Not authorized")`.
195206

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project is a small sbt project that gives you an opportunity to write [docile-charge-point](https://github.com/NewMotion/docile-charge-point) scripts with autocomplete in IntelliJ IDEA.
2+
3+
Just open [TestScript.scala](src/main/scala/TestScript.scala) and start editing where it says `// INSERT SCRIPT HERE`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name := "docile-examples"
2+
3+
version := "0.1"
4+
5+
scalaVersion := "2.12.8"
6+
7+
resolvers += "TNM" at "https://nexus.thenewmotion.com/content/groups/public"
8+
9+
libraryDependencies += "com.newmotion" %% "docile-charge-point" % "0.5.1"
10+
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0"
11+
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.3.13
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.net.URI
2+
3+
import com.thenewmotion.ocpp.messages.v1x._
4+
5+
import scala.language.postfixOps
6+
import scala.concurrent.duration._
7+
import scala.concurrent.ExecutionContext
8+
import scala.util.Random
9+
import java.time._
10+
11+
import com.typesafe.scalalogging.Logger
12+
import org.slf4j.LoggerFactory
13+
import chargepoint.docile.dsl.{AwaitTimeout, AwaitTimeoutInMillis}
14+
import chargepoint.docile.dsl.Randomized._
15+
import chargepoint.docile.test.{RunOnce, Runner, RunnerConfig, TestCase}
16+
import com.thenewmotion.ocpp.Version
17+
import javax.net.ssl.SSLContext
18+
19+
object Main extends App {
20+
val test = new chargepoint.docile.dsl.Ocpp1XTest with chargepoint.docile.dsl.Ocpp1XTest.V1XOps {
21+
22+
implicit val executionContext: ExecutionContext = ExecutionContext.global
23+
implicit val csmsMessageTypes = com.thenewmotion.ocpp.VersionFamily.V1XCentralSystemMessages
24+
implicit val csMessageTypes = com.thenewmotion.ocpp.VersionFamily.V1XChargePointMessages
25+
26+
private implicit val rand: Random = new Random()
27+
28+
def run(defaultAwaitTimeout: AwaitTimeout) {
29+
implicit val awaitTimeout: AwaitTimeout = defaultAwaitTimeout;
30+
31+
// INSERT SCRIPT HERE
32+
33+
// for example:
34+
//
35+
// say("going to send heartbeat...")
36+
// heartbeat()
37+
// say("heartbeat request sent and response received!")
38+
}
39+
}
40+
41+
val testCase = TestCase("the single autocomplete test", () => test)
42+
val runner = new Runner(Seq(testCase))
43+
44+
runner.run(RunnerConfig(
45+
number = 1,
46+
chargePointId = "reintest01",
47+
uri = new URI("ws://compliancy.ihomer.nl:9090"),
48+
ocppVersion = Version.V16,
49+
authKey = None,
50+
repeat = RunOnce,
51+
defaultAwaitTimeout = AwaitTimeoutInMillis(60000),
52+
sslContext = SSLContext.getDefault
53+
))
54+
}
55+
56+

build.sbt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lazy val commonSettings = Seq(
22
organization := "com.newmotion",
3-
scalaVersion := "2.12.8",
4-
crossScalaVersions := Seq(tnm.ScalaVersion.aged, "2.12.8"),
3+
scalaVersion := "2.12.11",
4+
crossScalaVersions := Seq("2.12.11"),
55
scalacOptions ++= Seq("-Xlint:-nullary-unit"),
66
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
77
)
@@ -16,6 +16,13 @@ lazy val commandLine = (project in file("cmd"))
1616
libraryDependencies ++= commandLineDeps,
1717
mainClass := Some("chargepoint.docile.Main"),
1818
assemblyJarName in assembly := "docile.jar",
19+
assemblyMergeStrategy in assembly := {
20+
case "reflect.properties" =>
21+
MergeStrategy.concat
22+
case x =>
23+
val oldStrategy = (assemblyMergeStrategy in assembly).value
24+
oldStrategy(x)
25+
},
1926
connectInput in run := true
2027
)
2128

@@ -60,7 +67,7 @@ def loaderDeps(scalaVersion: String) = Seq(
6067
)
6168

6269
lazy val commandLineDeps = Seq(
63-
"com.lihaoyi" % "ammonite" % "1.6.5" cross CrossVersion.full,
70+
"com.lihaoyi" % "ammonite" % "2.1.4" cross CrossVersion.full,
6471
"org.rogach" %% "scallop" % "3.1.3",
6572
"ch.qos.logback" % "logback-classic" % "1.2.3"
6673
)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.1.6
1+
sbt.version=1.3.10

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resolvers += "TNM" at "https://nexus.thenewmotion.com/content/groups/public"
22

3-
addSbtPlugin("com.newmotion" % "sbt-build-seed" % "5.0.4")
3+
addSbtPlugin("com.newmotion" % "sbt-build-seed" % "5.0.6")
44

55
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7")

0 commit comments

Comments
 (0)