Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openmole
openmole
Commits
f1f3fc4f
Unverified
Commit
f1f3fc4f
authored
Nov 30, 2016
by
Romain Reuillon
Browse files
[GUI] enh: compile jsir for GUI plugins.
parent
8b3bc11e
Changes
7
Hide whitespace changes
Inline
Side-by-side
openmole/build.sbt
View file @
f1f3fc4f
...
...
@@ -472,18 +472,20 @@ lazy val sharedGUI = OsgiProject(guiExt, "org.openmole.gui.ext.api") dependsOn(d
val
jqueryPath
=
s
"META-INF/resources/webjars/jquery/${Libraries.jqueryVersion}/jquery.js"
val
acePath
=
s
"META-INF/resources/webjars/ace/${Libraries.aceVersion}/src-min/ace.js"
lazy
val
bootstrapGUI
=
OsgiProject
(
guiServerDir
,
"org.openmole.gui.server.jscompile"
)
dependsOn
(
pluginManager
,
sharedGUI
,
serverGUI
,
fileServi
ce
)
settings
(
defaultSettings
:
_
*
)
settings
(
libraryDependencies
+=
"org.scala-js"
%%
"scalajs-library"
%
Libraries
.
scalajsVersion
,
lazy
val
jsCompile
=
OsgiProject
(
guiServerDir
,
"org.openmole.gui.server.jscompile"
,
imports
=
Seq
(
"*"
)
)
dependsOn
(
pluginManager
,
fileService
,
workspa
ce
)
settings
(
defaultSettings
:
_
*
)
settings
(
libraryDependencies
+=
"org.scala-js"
%%
"scalajs-library"
%
Libraries
.
scalajsVersion
%
"provided"
intransitive
()
,
libraryDependencies
+=
Libraries
.
scalajsTools
,
OsgiKeys
.
embeddedJars
:=
{
val
scalaLib
=
(
Keys
.
externalDependencyClasspath
in
Compile
).
value
.
filter
{
d
=>
d
.
data
.
getName
startsWith
"scalajs-library"
}.
head
val
dest
=
target
.
value
/
"scalajs-library.jar"
sbt
.
IO
.
copyFile
(
scalaLib
.
data
,
dest
)
Seq
(
dest
)
(
resourceDirectories
in
Compile
)
+=
(
crossTarget
.
value
/
"resources"
),
(
OsgiKeys
.
embeddedJars
)
:=
{
val
scalaLib
=
(
Keys
.
externalDependencyClasspath
in
Compile
).
value
.
filter
{
d
=>
d
.
data
.
getName
startsWith
"scalajs-library"
}.
head
val
dest
=
crossTarget
.
value
/
"resources/scalajs-library.jar"
dest
.
getParentFile
.
mkdirs
()
sbt
.
IO
.
copyFile
(
scalaLib
.
data
,
dest
)
Seq
()
},
guiProvidedScope
)
...
...
@@ -520,6 +522,8 @@ lazy val clientToolGUI = OsgiProject(guiClientDir, "org.openmole.gui.client.tool
guiProvidedScope
)
settings
(
defaultSettings
:
_
*
)
/* -------------------------- Server ----------------------- */
def
guiServerDir
=
guiDir
/
"server"
lazy
val
serverGUI
=
OsgiProject
(
guiServerDir
,
"org.openmole.gui.server.core"
)
settings
...
...
@@ -542,7 +546,8 @@ lazy val serverGUI = OsgiProject(guiServerDir, "org.openmole.gui.server.core") s
openmoleCrypto
,
module
,
market
,
extPluginGUI
extPluginGUI
,
jsCompile
)
settings
(
defaultSettings
:
_
*
)
lazy
val
state
=
OsgiProject
(
guiServerDir
,
"org.openmole.gui.server.state"
)
settings
...
...
openmole/gui/client/org.openmole.gui.client.core/src/main/scala/org/openmole/gui/client/core/Plugins.scala
View file @
f1f3fc4f
...
...
@@ -30,11 +30,11 @@ object Plugins {
private
def
buildJSObject
(
obj
:
String
)
=
scalajs
.
js
.
eval
(
s
"new $obj()"
)
def
updateGUIPlugin
=
OMPost
()[
Api
].
getGUIPlugins
().
call
().
foreach
{
ps
⇒
ps
.
authentications
.
map
{
p
⇒
buildJSObject
(
p
.
jsObject
).
asInstanceOf
[
Authentication
]
}
}
def
installGUIPlugins
=
???
//
def updateGUIPlugin = OMPost()[Api].getGUIPlugins().call().foreach { ps ⇒
//
ps.authentications.map { p ⇒
//
buildJSObject(p.jsObject).asInstanceOf[Authentication]
//
}
//
}
//
//
def installGUIPlugins = ???
}
openmole/gui/ext/org.openmole.gui.ext.api/src/main/scala/org/openmole/gui/ext/api/Shared.scala
View file @
f1f3fc4f
...
...
@@ -90,7 +90,7 @@ trait Api {
def
removePlugin
(
plugin
:
Plugin
)
:
Unit
//GUI PLUGINS
def
getGUIPlugins
()
:
AllPluginExtensionData
//
def getGUIPlugins(): AllPluginExtensionData
//MODEL WIZARDS
def
launchingCommands
(
path
:
SafePath
)
:
Seq
[
LaunchingCommand
]
...
...
openmole/gui/server/org.openmole.gui.server.core/src/main/scala/org/openmole/gui/server/core/GUIServer.scala
View file @
f1f3fc4f
...
...
@@ -19,8 +19,9 @@ package org.openmole.gui.server.core
import
java.io.File
import
java.util.concurrent.Semaphore
import
javax.servlet.http.
{
HttpServletResponse
,
HttpServletRequest
}
import
org.eclipse.jetty.server.
{
ServerConnector
,
Server
}
import
javax.servlet.http.
{
HttpServletRequest
,
HttpServletResponse
}
import
org.eclipse.jetty.server.
{
Server
,
ServerConnector
}
import
org.eclipse.jetty.servlet.DefaultServlet
import
org.eclipse.jetty.webapp._
import
org.openmole.core.tools.io.Network
...
...
@@ -28,8 +29,10 @@ import org.openmole.core.workspace.{ ConfigurationLocation, Workspace }
import
org.scalatra.auth.strategy.
{
BasicAuthStrategy
,
BasicAuthSupport
}
import
org.scalatra.servlet.ScalatraListener
import
javax.servlet.ServletContext
import
org.scalatra._
import
org.eclipse.jetty.util.resource.
{
Resource
⇒
Res
}
import
org.openmole.gui.server.jscompile.JSPack
import
org.openmole.tool.hash._
import
org.openmole.tool.file._
...
...
@@ -107,7 +110,7 @@ class GUIServer(port: Int, localhost: Boolean, http: Boolean) {
server
.
setHandler
(
context
)
def
start
()
=
server
.
start
def
join
()
:
GUIServer.ExitStatus
=
{
semaphore
.
acquire
()
semaphore
.
release
()
...
...
openmole/gui/server/org.openmole.gui.server.core/src/main/scala/org/openmole/gui/server/core/Plugins.scala
View file @
f1f3fc4f
...
...
@@ -40,4 +40,73 @@ object Plugins {
}
}
// def init(optimized: Boolean = true) = {
// jsSrc.recursiveDelete
// jsSrc.mkdirs
//
// def update() = {
// webapp.recursiveDelete
// webapp.mkdirs
// jsCompiled.mkdirs
//
// new File(webapp, "css").mkdirs
// new File(webapp, "fonts").mkdirs
// new File(webapp, "img").mkdirs
// new File(webapp, "WEB-INF").mkdirs
//
// //Copy all the fixed resources in the workspace if required
// val thisBundle = PluginManager.bundleForClass(classOf[GUIServer])
//
// //Add lib js files from webjars
// /* copyWebJarResource("d3", "3.5.5", "d3.min.js")
// copyWebJarResource("jquery", "2.1.3", "jquery.min.js")
// copyWebJarResource("bootstrap", "3.3.4", FilePath("dist/js/", "bootstrap.min.js"))
// copyWebJarResource("ace", "01.08.2014",
// FilePath("src-min/", "ace.js"),
// FilePath("src-min/", "theme-github.js"),
// FilePath("src-min/", "mode-scala.js"),
// FilePath("src-min/", "mode-sh.js"),
// FilePath("src-min/", "mode-text.js"))*/
//
// //All other resources
// /* copyURL(thisBundle.findEntries("/", "*.css", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.js", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.ttf", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.woff", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.woff2", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.svg", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.png", true).asScala)
// copyURL(thisBundle.findEntries("/", "*.eot", true).asScala)*/
//
// //Generates the pluginMapping js file
// new java.io.File(jsCompiled, "pluginMapping.js").withWriter() { writer ⇒
// writer.write("function fillMap() {\n")
// /* ServerFactories.factoriesUI.foreach {
// case (k, v) ⇒
// writer.write("UIFactories().factoryMap[\"" + k + "\" ] = new " + v.getClass.getName + "();\n")
// }
// ServerFactories.authenticationFactoriesUI.foreach {
// case (k, v) ⇒
// writer.write("UIFactories().authenticationMap[\"" + k + "\" ] = new " + v.getClass.getName + "();\n")
// }*/
// writer.write("}")
// }
// JSPack.link(Seq(copyJar("scalajs-library"), jsSrc), new java.io.File(jsCompiled, JS_FILE))
// }
//
// // Extract and copy all the .sjsir files from bundles to src
// for {
// b ← PluginManager.bundles
// entries ← Option(b.findEntries("/", "*.sjsir", true))
// entry ← entries.asScala
// } entry.openStream.copy(new java.io.File(jsSrc, entry.getFile.split("/").tail.mkString("-")))
//
// //Generates js files if
// // - the sources changed or
// // - the optimized js does not exists in optimized mode or
// // - the not optimized js does not exists in not optimized mode
// jsSrc.updateIfChanged(_ ⇒ update())
// if (!new File(jsCompiled, JS_FILE).exists) update()
// }
}
openmole/gui/server/org.openmole.gui.server.jscompile/src/main/scala/org/openmole/gui/server/jscompile/BootstrapJS.scala
deleted
100644 → 0
View file @
8b3bc11e
/*
* Copyright (C) 30/07/14 // mathieu.leclaire@openmole.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.openmole.gui.server.jscompile
import
java.net.URL
import
java.io.
{
FileOutputStream
,
File
}
import
org.openmole.core.pluginmanager.PluginManager
import
org.openmole.tool.file._
import
org.openmole.core.workspace.Workspace
import
org.openmole.core.fileservice._
import
org.openmole.tool.stream._
import
org.openmole.gui.server.core.
{
GUIServer
}
import
scala.collection.JavaConverters._
object
BootstrapJS
{
// Copy web resources and generate js file
val
webui
=
Workspace
.
file
(
"webui"
)
val
projects
=
new
File
(
webui
,
"projects"
)
val
jsSrc
=
new
File
(
webui
,
"js/src"
)
val
webapp
=
new
File
(
webui
,
"webapp"
)
val
jsCompiled
=
new
File
(
webapp
,
"js"
)
val
authKeys
=
Workspace
.
file
(
"persistent/keys"
)
val
JS_FILE
=
"plugins.js"
webui
.
mkdirs
projects
.
mkdirs
authKeys
.
mkdirs
def
init
(
optimized
:
Boolean
=
true
)
=
{
jsSrc
.
recursiveDelete
jsSrc
.
mkdirs
def
update
()
=
{
webapp
.
recursiveDelete
webapp
.
mkdirs
jsCompiled
.
mkdirs
new
File
(
webapp
,
"css"
).
mkdirs
new
File
(
webapp
,
"fonts"
).
mkdirs
new
File
(
webapp
,
"img"
).
mkdirs
new
File
(
webapp
,
"WEB-INF"
).
mkdirs
//Copy all the fixed resources in the workspace if required
val
thisBundle
=
PluginManager
.
bundleForClass
(
classOf
[
GUIServer
])
//Add lib js files from webjars
/* copyWebJarResource("d3", "3.5.5", "d3.min.js")
copyWebJarResource("jquery", "2.1.3", "jquery.min.js")
copyWebJarResource("bootstrap", "3.3.4", FilePath("dist/js/", "bootstrap.min.js"))
copyWebJarResource("ace", "01.08.2014",
FilePath("src-min/", "ace.js"),
FilePath("src-min/", "theme-github.js"),
FilePath("src-min/", "mode-scala.js"),
FilePath("src-min/", "mode-sh.js"),
FilePath("src-min/", "mode-text.js"))*/
//All other resources
/* copyURL(thisBundle.findEntries("/", "*.css", true).asScala)
copyURL(thisBundle.findEntries("/", "*.js", true).asScala)
copyURL(thisBundle.findEntries("/", "*.ttf", true).asScala)
copyURL(thisBundle.findEntries("/", "*.woff", true).asScala)
copyURL(thisBundle.findEntries("/", "*.woff2", true).asScala)
copyURL(thisBundle.findEntries("/", "*.svg", true).asScala)
copyURL(thisBundle.findEntries("/", "*.png", true).asScala)
copyURL(thisBundle.findEntries("/", "*.eot", true).asScala)*/
//Generates the pluginMapping js file
new
java
.
io
.
File
(
jsCompiled
,
"pluginMapping.js"
).
withWriter
()
{
writer
⇒
writer
.
write
(
"function fillMap() {\n"
)
/* ServerFactories.factoriesUI.foreach {
case (k, v) ⇒
writer.write("UIFactories().factoryMap[\"" + k + "\" ] = new " + v.getClass.getName + "();\n")
}
ServerFactories.authenticationFactoriesUI.foreach {
case (k, v) ⇒
writer.write("UIFactories().authenticationMap[\"" + k + "\" ] = new " + v.getClass.getName + "();\n")
}*/
writer
.
write
(
"}"
)
}
JSPack
.
link
(
Seq
(
copyJar
(
"scalajs-library"
),
jsSrc
),
new
java
.
io
.
File
(
jsCompiled
,
JS_FILE
))
}
// Extract and copy all the .sjsir files from bundles to src
for
{
b
←
PluginManager
.
bundles
entries
←
Option
(
b
.
findEntries
(
"/"
,
"*.sjsir"
,
true
))
entry
←
entries
.
asScala
}
entry
.
openStream
.
copy
(
new
java
.
io
.
File
(
jsSrc
,
entry
.
getFile
.
split
(
"/"
).
tail
.
mkString
(
"-"
)))
//Generates js files if
// - the sources changed or
// - the optimized js does not exists in optimized mode or
// - the not optimized js does not exists in not optimized mode
jsSrc
.
updateIfChanged
(
_
⇒
update
())
if
(!
new
File
(
jsCompiled
,
JS_FILE
).
exists
)
update
()
}
def
copyJar
(
name
:
String
)
=
{
val
libF
=
File
.
createTempFile
(
name
,
".jar"
)
libF
.
deleteOnExit
val
outLib
=
new
FileOutputStream
(
libF
)
getClass
.
getClassLoader
.
getResourceAsStream
(
name
+
".jar"
).
copy
(
outLib
)
libF
}
private
def
copyWebJarResource
(
resourceName
:
String
,
version
:
String
,
file
:
String
)
:
Unit
=
copyWebJarResource
(
resourceName
,
version
,
FilePath
(
""
,
file
))
private
def
copyWebJarResource
(
resourceName
:
String
,
version
:
String
,
filePaths
:
FilePath*
)
:
Unit
=
for
(
filePath
←
filePaths
)
new
File
(
jsCompiled
,
filePath
.
file
).
withOutputStream
{
fileStream
⇒
getClass
.
getClassLoader
.
getResourceAsStream
(
"/META-INF/resources/webjars/"
+
resourceName
+
"/"
+
version
+
"/"
+
filePath
.
path
+
filePath
.
file
).
copy
(
fileStream
)
}
private
def
copyURL
(
url
:
Iterator
[
URL
])
=
url
.
foreach
{
u
⇒
u
.
openStream
.
copy
(
new
File
(
webui
,
u
.
getFile
))
}
case
class
FilePath
(
path
:
String
,
file
:
String
)
}
\ No newline at end of file
openmole/gui/server/org.openmole.gui.server.jscompile/src/main/scala/org/openmole/gui/server/jscompile/JSPack.scala
View file @
f1f3fc4f
...
...
@@ -18,25 +18,29 @@ package org.openmole.gui.server.jscompile
*/
import
org.openmole.tool.file._
import
org.openmole.tool.stream._
import
java.io.File
import
org.scalajs.core.tools.io._
import
org.scalajs.core.tools.sem._
import
org.scalajs.core.tools.linker.backend.
{
OutputMode
,
ModuleKind
}
import
org.scalajs.core.tools.linker.backend.
{
ModuleKind
,
OutputMode
}
import
org.scalajs.core.tools.linker.Linker
import
org.scalajs.core.tools.logging.ScalaConsoleLogger
import
scala.collection.JavaConverters._
import
java.io.
{
FileOutputStream
,
File
}
import
java.io.File
import
org.openmole.core.workspace.Workspace
object
JSPack
{
def
link
(
inputClasspath
:
Seq
[
File
],
outputJSFile
:
File
)
:
Unit
=
{
def
link
(
inputDirectory
:
File
,
outputJSFile
:
File
)
:
Unit
=
Workspace
.
withTmpFile
(
"lib"
,
"jar"
)
{
jar
⇒
getClass
.
getClassLoader
.
getResourceAsStream
(
"scalajs-library.jar"
)
copy
jar
// Obtain VirtualScalaJSIRFile's from the input classpath
val
irCache
=
new
IRFileCache
().
newCache
val
irContainers
=
IRFileCache
.
IRContainer
.
fromClasspath
(
inputClasspath
)
val
sjsirFiles
=
irCache
.
cached
(
irContainers
)
//val irContainers = IRFileCache.IRContainer.fromJar(Seq(jar, inputDirector))
val
sjsirFiles
=
irCache
.
cached
(
Seq
(
IRFileCache
.
IRContainer
.
fromJar
(
jar
))
++
IRFileCache
.
IRContainer
.
fromDirectory
(
inputDirectory
)
)
// A bunch of options. Here we use all the defaults
val
semantics
=
Semantics
.
Defaults
...
...
@@ -50,12 +54,4 @@ object JSPack {
linker
.
link
(
sjsirFiles
,
WritableFileVirtualJSFile
(
outputJSFile
),
logger
)
}
/* def copyJar(name: String) = {
val libF = File.createTempFile(name, ".jar")
libF.deleteOnExit
val outLib = new FileOutputStream(libF)
getClass.getClassLoader.getResourceAsStream(name + ".jar").copy(outLib)
libF
}*/
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment