-
Notifications
You must be signed in to change notification settings - Fork 3
Import the PhantomJS env from the Scala.js core repository. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
826e8e7
52bdb27
34f7971
78d3a06
930c81f
097575d
158937e
8cc7e62
8674467
79910e8
804bd21
8c35f58
ee09489
748782b
9c2c87d
65188be
6dd414a
be34887
cbf8a9d
6d61185
33a3b17
fc536f9
4901b4f
0b1045d
830d7ee
590bdc1
fbac5a4
4b20915
4519ba6
308f5cd
e429d25
c8c33fb
7dff77b
16ddfb6
bcec88d
398242f
9a9c9ef
d2a8aac
cc94b92
61d236f
7fb802c
dea0e55
88e447f
dc5f279
81ecbb3
e03694f
dfc27e0
f16ad8d
0be4132
1ceb6b7
ed4f8a8
d1d8d39
af71a21
b1f6b15
8ca4287
0deaef6
37f2322
88cd9f5
c5a213d
e003671
5ef08a7
8be06c9
1289294
f18e504
af9f021
0216ccb
a9062ec
84ac65e
b11efdc
309de30
eafa7f3
eeb1289
7959ce2
b9b9f87
60877a5
72e7df1
5fb205e
9110106
af2be21
a628a79
c1f2bfe
e51a9cb
73582a5
6771f21
bf2bd78
55afe7a
425390e
93424ad
c189f1b
5d52df8
62559a7
34ddcb6
f470dea
686d8a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
sudo: false | ||
language: scala | ||
scala: | ||
- 2.10.6 | ||
- 2.11.11 | ||
- 2.12.2 | ||
jdk: | ||
- oraclejdk8 | ||
install: | ||
- if [[ "${TRAVIS_SCALA_VERSION}" == "2.10.6" ]]; then TEST_SBT_PLUGIN=true; else TEST_SBT_PLUGIN=false; fi | ||
# The default ivy resolution takes way too much time, and times out Travis builds. | ||
# We use coursier instead. | ||
- mkdir -p $HOME/.sbt/0.13/plugins/ | ||
- echo 'addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC3")' > $HOME/.sbt/0.13/plugins/coursier.sbt | ||
# While there is no published version of Scala.js 1.x, we have to locally build a snapshot. | ||
- git clone https://github.com/scala-js/scala-js.git | ||
- cd scala-js | ||
- git checkout f21e7f5ea652fe4a186f1ecd8c0070fbb80edc80 | ||
- sbt ++$TRAVIS_SCALA_VERSION ir/publishLocal tools/publishLocal jsEnvs/publishLocal jsEnvsTestKit/publishLocal | ||
- | | ||
if [[ "${TEST_SBT_PLUGIN}" == "true" ]]; then | ||
sbt ++$TRAVIS_SCALA_VERSION testAdapter/publishLocal sbtPlugin/publishLocal && | ||
sbt ++2.11.11 compiler/publishLocal library/publishLocal testInterface/publishLocal | ||
fi | ||
- cd .. | ||
script: | ||
- sbt ++$TRAVIS_SCALA_VERSION scalajs-phantomjs-env/test scalajs-phantomjs-env/doc | ||
- | | ||
if [[ "${TEST_SBT_PLUGIN}" == "true" ]]; then | ||
sbt scalajs-phantomjs-env/publishLocal sbt-scalajs-env-phantomjs/publishLocal && \ | ||
cd sbt-plugin-test && \ | ||
sbt jetty9/run && \ | ||
cd .. | ||
fi | ||
cache: | ||
directories: | ||
- $HOME/.ivy2/cache | ||
- $HOME/.sbt | ||
- $HOME/.coursier/cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check: Neither ivy nor coursier copy local artifacts to the cache? Otherwise this would be a problem, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No they don't ;) (I checked). Even if they did, each new |
||
before_cache: | ||
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete | ||
- find $HOME/.sbt -name "*.lock" -print -delete | ||
- rm $HOME/.sbt/0.13/plugins/coursier.sbt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
val scalaJSVersion = "1.0.0-SNAPSHOT" | ||
|
||
inThisBuild(Seq( | ||
version := "0.1.0-SNAPSHOT", | ||
organization := "org.scala-js", | ||
|
||
crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.2"), | ||
scalaVersion := "2.10.6", | ||
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), | ||
|
||
homepage := Some(url("https://www.scala-js.org/")), | ||
licenses += ("BSD New", | ||
url("https://github.com/scala-js/scala-js-env-phantomjs/blob/master/LICENSE")), | ||
scmInfo := Some(ScmInfo( | ||
url("https://github.com/scala-js/scala-js-env-phantomjs"), | ||
"scm:git:git@github.com:scala-js/scala-js-env-phantomjs.git", | ||
Some("scm:git:git@github.com:scala-js/scala-js-env-phantomjs.git"))) | ||
)) | ||
|
||
val commonSettings = Def.settings( | ||
// Scaladoc linking | ||
apiURL := { | ||
val name = moduleName.value | ||
val v = version.value | ||
Some(url(s"https://www.scala-js.org/api/$name/$v/")) | ||
}, | ||
autoAPIMappings := true, | ||
|
||
publishMavenStyle := true, | ||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) | ||
Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else | ||
Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
}, | ||
pomExtra := ( | ||
<developers> | ||
<developer> | ||
<id>sjrd</id> | ||
<name>Sébastien Doeraene</name> | ||
<url>https://github.com/sjrd/</url> | ||
</developer> | ||
<developer> | ||
<id>gzm0</id> | ||
<name>Tobias Schlatter</name> | ||
<url>https://github.com/gzm0/</url> | ||
</developer> | ||
<developer> | ||
<id>nicolasstucki</id> | ||
<name>Nicolas Stucki</name> | ||
<url>https://github.com/nicolasstucki/</url> | ||
</developer> | ||
</developers> | ||
), | ||
pomIncludeRepository := { _ => false } | ||
) | ||
|
||
lazy val root: Project = project.in(file(".")). | ||
settings( | ||
publishArtifact in Compile := false, | ||
publish := {}, | ||
publishLocal := {}, | ||
|
||
clean := clean.dependsOn( | ||
clean in `scalajs-phantomjs-env`, | ||
clean in `sbt-scalajs-env-phantomjs` | ||
).value | ||
) | ||
|
||
lazy val `scalajs-phantomjs-env`: Project = project.in(file("phantomjs-env")). | ||
settings( | ||
commonSettings, | ||
|
||
libraryDependencies ++= Seq( | ||
"org.scala-js" %% "scalajs-js-envs" % scalaJSVersion, | ||
"org.eclipse.jetty" % "jetty-websocket" % "8.1.16.v20140903" % "provided", | ||
"org.eclipse.jetty" % "jetty-server" % "8.1.16.v20140903" % "provided", | ||
|
||
"com.novocode" % "junit-interface" % "0.11" % "test", | ||
"org.scala-js" %% "scalajs-js-envs-test-kit" % scalaJSVersion % "test" | ||
) | ||
) | ||
|
||
lazy val `sbt-scalajs-env-phantomjs`: Project = project.in(file("phantomjs-sbt-plugin")). | ||
settings( | ||
commonSettings, | ||
|
||
sbtPlugin := true, | ||
scalaBinaryVersion := | ||
CrossVersion.binaryScalaVersion(scalaVersion.value), | ||
|
||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion), | ||
|
||
// Add API mappings for sbt (seems they don't export their API URL) | ||
apiMappings ++= { | ||
val deps = (externalDependencyClasspath in Compile).value | ||
val sbtJars = deps filter { attributed => | ||
val p = attributed.data.getPath | ||
p.contains("/org.scala-sbt/") && p.endsWith(".jar") | ||
} | ||
val docUrl = | ||
url(s"http://www.scala-sbt.org/${sbtVersion.value}/api/") | ||
sbtJars.map(_.data -> docUrl).toMap | ||
} | ||
). | ||
dependsOn(`scalajs-phantomjs-env`) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ __ ____ PhantomJS support for Scala.js ** | ||
** / __/ __// _ | / / / _ | __ / // __/ (c) 2013-2017, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ https://www.scala-js.org/ ** | ||
** /____/\___/_/ |_/____/_/ | |__/ /____/ ** | ||
** |/____/ ** | ||
\* */ | ||
|
||
package org.scalajs.jsenv.phantomjs | ||
|
||
import javax.servlet.http.HttpServletRequest | ||
|
||
import org.eclipse.jetty.server.Server | ||
import org.eclipse.jetty.server.nio.SelectChannelConnector | ||
import org.eclipse.jetty.websocket.{WebSocket, WebSocketHandler} | ||
import org.eclipse.jetty.util.component.{LifeCycle, AbstractLifeCycle} | ||
import org.eclipse.jetty.util.log | ||
|
||
private[phantomjs] final class JettyWebsocketManager( | ||
wsListener: WebsocketListener) extends WebsocketManager { thisMgr => | ||
|
||
private[this] var webSocketConn: WebSocket.Connection = null | ||
private[this] var closed = false | ||
|
||
// We can just set the logger here, since we are supposed to be protected by | ||
// the private ClassLoader that loads us reflectively. | ||
log.Log.setLog(new WSLogger("root")) | ||
|
||
private[this] val connector = new SelectChannelConnector | ||
|
||
connector.setHost("localhost") | ||
connector.setPort(0) | ||
|
||
private[this] val server = new Server() | ||
|
||
server.addConnector(connector) | ||
server.setHandler(new WebSocketHandler { | ||
// Support Hixie 76 for Phantom.js | ||
getWebSocketFactory().setMinVersion(-1) | ||
|
||
override def doWebSocketConnect( | ||
request: HttpServletRequest, protocol: String): WebSocket = | ||
new ComWebSocketListener | ||
}) | ||
|
||
server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener { | ||
override def lifeCycleStarted(event: LifeCycle): Unit = { | ||
if (event.isRunning()) | ||
wsListener.onRunning() | ||
} | ||
}) | ||
|
||
private class ComWebSocketListener extends WebSocket.OnTextMessage { | ||
override def onOpen(connection: WebSocket.Connection): Unit = { | ||
thisMgr.synchronized { | ||
if (isConnected) | ||
throw new IllegalStateException("Client connected twice") | ||
connection.setMaxIdleTime(Int.MaxValue) | ||
webSocketConn = connection | ||
} | ||
wsListener.onOpen() | ||
} | ||
|
||
override def onClose(statusCode: Int, reason: String): Unit = { | ||
thisMgr.synchronized { | ||
webSocketConn = null | ||
closed = true | ||
} | ||
wsListener.onClose() | ||
server.stop() | ||
|
||
if (statusCode != 1000) { | ||
throw new Exception("Abnormal closing of connection. " + | ||
s"Code: $statusCode, Reason: $reason") | ||
} | ||
} | ||
|
||
override def onMessage(message: String): Unit = | ||
wsListener.onMessage(message) | ||
} | ||
|
||
private class WSLogger(fullName: String) extends log.AbstractLogger { | ||
private[this] var debugEnabled = false | ||
|
||
def debug(msg: String, args: Object*): Unit = | ||
if (debugEnabled) log("DEBUG", msg, args) | ||
|
||
def debug(msg: String, thrown: Throwable): Unit = | ||
if (debugEnabled) log("DEBUG", msg, thrown) | ||
|
||
def debug(thrown: Throwable): Unit = | ||
if (debugEnabled) log("DEBUG", thrown) | ||
|
||
def getName(): String = fullName | ||
|
||
def ignore(ignored: Throwable): Unit = () | ||
|
||
def info(msg: String, args: Object*): Unit = log("INFO", msg, args) | ||
def info(msg: String, thrown: Throwable): Unit = log("INFO", msg, thrown) | ||
def info(thrown: Throwable): Unit = log("INFO", thrown) | ||
|
||
def warn(msg: String, args: Object*): Unit = log("WARN", msg, args) | ||
def warn(msg: String, thrown: Throwable): Unit = log("WARN", msg, thrown) | ||
def warn(thrown: Throwable): Unit = log("WARN", thrown) | ||
|
||
def isDebugEnabled(): Boolean = debugEnabled | ||
def setDebugEnabled(enabled: Boolean): Unit = debugEnabled = enabled | ||
|
||
private def log(lvl: String, msg: String, args: Object*): Unit = | ||
wsListener.log(s"$lvl: $msg " + args.mkString(", ")) | ||
|
||
private def log(lvl: String, msg: String, thrown: Throwable): Unit = | ||
wsListener.log(s"$lvl: $msg $thrown\n{$thrown.getStackStrace}") | ||
|
||
private def log(lvl: String, thrown: Throwable): Unit = | ||
wsListener.log(s"$lvl: $thrown\n{$thrown.getStackStrace}") | ||
|
||
protected def newLogger(fullName: String) = new WSLogger(fullName) | ||
} | ||
|
||
def start(): Unit = server.start() | ||
|
||
def stop(): Unit = server.stop() | ||
|
||
def isConnected: Boolean = webSocketConn != null && !closed | ||
def isClosed: Boolean = closed | ||
|
||
def localPort: Int = connector.getLocalPort() | ||
|
||
def sendMessage(msg: String): Unit = synchronized { | ||
if (webSocketConn != null) | ||
webSocketConn.sendMessage(msg) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double check, this will all go away (starting at
git clone .../scala-js.git
) once we have a published version of SJS 1.x, right? (comment?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed.