Skip to content

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

Merged
merged 94 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
826e8e7
Add full support for projects requiring DOM
gzm0 Apr 9, 2014
52bdb27
Fix scala-js/scala-js#595: Test SBT plugin in published form on Travis
gzm0 May 7, 2014
34f7971
Fix scala-js/scala-js#799: Make PhantomJS runner fail if JS code fails
gzm0 Jul 3, 2014
78d3a06
Fix scala-js/scala-js#820: Properly escape script file names in Phant…
gzm0 Jul 11, 2014
930c81f
Fix scala-js/scala-js#865: Inherit existing shell environment in exte…
gzm0 Jul 24, 2014
097575d
Fix scala-js/scala-js#898: Check existence of prototype of target in …
gzm0 Aug 7, 2014
158937e
Fix scala-js/scala-js#962: Allow to pass additional arguments to Phan…
gzm0 Aug 22, 2014
8cc7e62
Implement System.exit() through environment setting (scala-js/scala-j…
gzm0 Aug 22, 2014
8674467
Add option to PhantomJSEnv to not immediately terminate (fix scala-js…
gzm0 Aug 25, 2014
79910e8
Upgrade default Scala version to 2.11.2
gzm0 Nov 4, 2014
804bd21
Refactor JSEnv to support async running
gzm0 Oct 18, 2014
8c35f58
Remove JSEnv constructor-blow up. Use default args
gzm0 Nov 3, 2014
ee09489
Clean up standalone sbt test project
gzm0 Nov 4, 2014
748782b
Make PhantomJSEnv a ComJSEnv
gzm0 Nov 4, 2014
9c2c87d
Fix scala-js/scala-js#1266: Proper connection closing on Node.js ComJ…
gzm0 Nov 14, 2014
65188be
Fix scala-js/scala-js#1288: Make stage a setting in sbt plugin
gzm0 Nov 21, 2014
6dd414a
Fix scala-js/scala-js#1282: Don't load same class twice in PhantomJet…
gzm0 Nov 18, 2014
be34887
Fix scala-js/scala-js#1025: Turn the sbt plugin into an AutoPlugin.
sjrd Nov 24, 2014
cbf8a9d
Throw more aggressively on PhantomJSCom failure
gzm0 Nov 25, 2014
6d61185
Fix initialization race in PhantomJSEnv
gzm0 Nov 25, 2014
33a3b17
Fix scala-js/scala-js#1304: Fragment messages to limit total size to …
gzm0 Nov 25, 2014
fc536f9
Merge pull request scala-js/scala-js#1305 from gzm0/phantom-com-fixes
sjrd Nov 25, 2014
4901b4f
Add factories to sbt plugin for PhantomJSEnv and NodeJSEnv
gzm0 Nov 25, 2014
0b1045d
Fix scala-js/scala-js#1308: Auto import RuntimeDOM builder
gzm0 Nov 25, 2014
830d7ee
Centralize overriding of stop in ComJSEnv
gzm0 Nov 26, 2014
590bdc1
Improve information in thrown ComClosedExceptions
gzm0 Nov 27, 2014
fbac5a4
Fix scala-js/scala-js#1073: New test framework interface (aligned wit…
gzm0 Nov 20, 2014
4b20915
Merge pull request scala-js/scala-js#1289 from gzm0/test-interface
sjrd Nov 27, 2014
4519ba6
Fix scala-js/scala-js#1319: Use correct default class loader in Phant…
gzm0 Nov 27, 2014
308f5cd
Remove sbtplugin.JSUtils
gzm0 Nov 27, 2014
e429d25
Fix scala-js/scala-js#1287: Reorganize package names and artifacts
gzm0 Nov 27, 2014
c8c33fb
Fix scala-js/scala-js#1315: Add timeout to AsyncJSRunner.await and us…
gzm0 Nov 30, 2014
7dff77b
Fix scala-js/scala-js#1330: Remove sleep-wait in PhantomJSEnv
gzm0 Nov 30, 2014
16ddfb6
Fix scala-js/scala-js#1331: Repair %%% the macro (using a hack)
gzm0 Dec 1, 2014
bcec88d
Fix scala-js/scala-js#1343: Add a RetryingComJSEnv and use it for CI
gzm0 Dec 1, 2014
398242f
Merge pull request scala-js/scala-js#1345 from gzm0/retry-jsenv
sjrd Dec 1, 2014
9a9c9ef
Fix scala-js/scala-js#1067: Add a simple CrossProject mechanism
gzm0 Dec 1, 2014
d2a8aac
Fix scala-js/scala-js#1408: packageJSDependencies is broken.
sjrd Dec 24, 2014
cc94b92
Upgrade to Scala 2.11.5.
sjrd Jan 8, 2015
61d236f
Fix scala-js/scala-js#1458: Use file:/// URIs for files in PhantomJS …
sjrd Jan 15, 2015
7fb802c
Fix one potential race condition in startup of PhantomComRunner.
sjrd Jan 17, 2015
dea0e55
Add more diagnostics in PhantomJSEnv.
sjrd Jan 18, 2015
88e447f
Add support for timeouts in ComJSRunner.receive().
sjrd Jan 20, 2015
dc5f279
Strengthen the guarantees of AsyncJSRunner.stop().
sjrd Jan 21, 2015
81ecbb3
Fix scala-js/scala-js#1496: Allow partial paths in jsDependencies.
sjrd Feb 26, 2015
e03694f
Upgrade to Scala 2.10.5 and 2.11.6.
sjrd Mar 5, 2015
dfc27e0
Fix scala-js/scala-js#1571: Make FrameworkDetector resilient to other…
fomkin Mar 26, 2015
f16ad8d
Fix scala-js/scala-js#1569: Allow crossProject's JVM and JS parts to …
fomkin Mar 26, 2015
0be4132
Merge pull request scala-js/scala-js#1570 from yelbota/fix-1569
sjrd Mar 31, 2015
1ceb6b7
Fix scala-js/scala-js#1564: Allow filtering of JS dependency manifests
gzm0 Apr 16, 2015
ed4f8a8
Merge pull request scala-js/scala-js#1605 from gzm0/manifest-filter
sjrd Apr 23, 2015
d1d8d39
Fix scala-js/scala-js#1621: Don't skip packaging JS dependencies by d…
gzm0 Apr 29, 2015
af71a21
Fix scala-js/scala-js#1592: Support for minified JS dependencies
gzm0 Apr 23, 2015
b1f6b15
Fix the CI matrix to actually run the testSuite with PhantomJS. -_-'
sjrd May 5, 2015
8ca4287
Fix scala-js/scala-js#1594: Ensure PhantomJSEnv throws upon syntax error
gzm0 May 14, 2015
0deaef6
Fix a bunch of style issues discovered by Scalastyle.
sjrd May 29, 2015
37f2322
Add Scalastyle with a basic configuration.
sjrd May 29, 2015
88cd9f5
Fix scala-js/scala-js#1752: Build for and upgrade to Scala 2.11.7.
sjrd Jun 25, 2015
c5a213d
Fix scala-js/scala-js#1845: Add scalaJSOutputWrapper sbt setting.
nicolasstucki Aug 26, 2015
e003671
Fix scala-js/scala-js#1917: Add -Xfatal-warnings for ScalaDoc generation
gzm0 Oct 23, 2015
5ef08a7
Fix scala-js/scala-js#1690: Add JUnit framework and plugin.
nicolasstucki Oct 7, 2015
8be06c9
Factor basic JSEnv tests in trait
gzm0 Nov 27, 2015
1289294
Fix scala-js/scala-js#2053: Always use UTF8 in PhantomJSEnv
gzm0 Nov 27, 2015
f18e504
Tools refactoring
gzm0 Jan 17, 2016
af9f021
Make private everything that can be in tools and js-envs.
sjrd Jan 17, 2016
0216ccb
Fix scala-js/scala-js#2202: Prevent concurrent use of linker in sbt
gzm0 Jan 26, 2016
a9062ec
Fix scala-js/scala-js#2198: Allow non-existent classpath entries
gzm0 Jan 26, 2016
84ac65e
Merge pull request scala-js/scala-js#2201 from gzm0/empty-classpath-e…
sjrd Jan 27, 2016
b11efdc
Fix scala-js/scala-js#2005: Add cross-version shared source directories.
sjrd Feb 6, 2016
309de30
Fix scala-js/scala-js#2226: Remove timeout from PhantomJSEnv socket c…
nicolasstucki Feb 11, 2016
eafa7f3
Fix scala-js/scala-js#2243: fix JSDependencies cache path.
nicolasstucki Mar 9, 2016
eeb1289
Fix scala-js/scala-js#2284: Upgrade to 2.11.8.
nicolasstucki Mar 14, 2016
7959ce2
Fix scala-js/scala-js#2350: Add an sbt setting isScalaJSProject.
sjrd Apr 24, 2016
b9b9f87
Remove Jasmine from sbtPluginTest.
nicolasstucki Apr 26, 2016
60877a5
Fix scala-js/scala-js#2250: Split jsEnvs, creating jsEnvsTestKit, jsE…
nicolasstucki Apr 25, 2016
72e7df1
Merge pull request scala-js/scala-js#2360 from nicolasstucki/sbt-plug…
sjrd Apr 26, 2016
5fb205e
Fix scala-js/scala-js#2375: Move Node and Phantom CustomInitFilesTest…
nicolasstucki May 2, 2016
9110106
Fix scala-js/scala-js#2376: PhantomJSEnv does not escape JS code
gzm0 May 1, 2016
af2be21
Fix JUnit Scala decoded names.
nicolasstucki Apr 27, 2016
a628a79
Fix scala-js/scala-js#2494: Store the location of source map files as…
sjrd Jul 6, 2016
c1f2bfe
Deprecate RhinoJSEnv without replacement.
sjrd Sep 6, 2016
e51a9cb
Separate all PhantomJS-related things in distinct projects.
sjrd Mar 27, 2017
73582a5
Use VirtualJSFiles instead of ResolvedJSDependency in the JSEnv API.
sjrd Mar 28, 2017
6771f21
Do not use jsDependencies (nor jQuery) in sbt-plugin-test/withDOM.
sjrd Apr 5, 2017
bf2bd78
Unify the parameter names of external JS env constructors.
sjrd Apr 8, 2017
55afe7a
Merge '0.6.x' into 'master'.
sjrd Apr 9, 2017
425390e
Fix scala-js/scala-js#2883: Remove packageJSLauncher
gzm0 Apr 9, 2017
93424ad
Merge pull request scala-js/scala-js#2884 from gzm0/no-package-launcher
gzm0 Apr 10, 2017
c189f1b
Fix scala-js/scala-js#2874: Remove the distinction libs/code in the J…
sjrd Apr 10, 2017
5d52df8
Restore the test for scala-js/scala-js#2202 (concurrent use of the li…
sjrd Apr 13, 2017
62559a7
Fix scala-js/scala-js#2875: Remove JSEnv.loadLibs, resolvedJSEnv and …
sjrd Apr 12, 2017
34ddcb6
Upgrade to Scala 2.11.11.
sjrd Apr 24, 2017
f470dea
Merge '0.6.x' into 'master'.
sjrd Apr 28, 2017
686d8a3
Import the PhantomJS env from the Scala.js core repository.
sjrd May 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .travis.yml
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 ..
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they don't ;) (I checked). Even if they did, each new publishLocal would override the previous thing anyway, and they would have to use the updated one, because otherwise it would simply be unbearable even for local iterative development.

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
107 changes: 107 additions & 0 deletions build.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)
}

}
Loading