@@ -28,13 +28,18 @@ import org.vertx.java.platform.{Container => JContainer}
28
28
import org .vertx .java .platform .{Verticle => JVerticle }
29
29
import org .vertx .java .platform .VerticleFactory
30
30
import org .vertx .scala .platform .Verticle
31
+ import java .io .{FilenameFilter , File }
32
+ import scala .util .matching .Regex
31
33
32
34
/**
33
35
* @author swilliams
34
- *
36
+ * @author Ranie Jade Ramiso
37
+ * @author Galder Zamarreño
35
38
*/
36
39
class ScalaVerticleFactory extends VerticleFactory {
37
40
41
+ import ScalaVerticleFactory ._
42
+
38
43
protected val SUFFIX : String = " .scala"
39
44
40
45
private val settings = new Settings ()
@@ -56,8 +61,6 @@ class ScalaVerticleFactory extends VerticleFactory {
56
61
this .jcontainer = jcontainer
57
62
this .loader = aloader
58
63
59
- println(" HELLO WORLD" )
60
-
61
64
initializeScalaInterpreter()
62
65
}
63
66
@@ -93,12 +96,14 @@ class ScalaVerticleFactory extends VerticleFactory {
93
96
}
94
97
95
98
private def initializeScalaInterpreter (): Unit = {
96
- val scalaLibrary = classLoader.getResource(" ./lib/scala-library-2.10.2.jar" ).toExternalForm
97
- val scalaReflectLibrary = classLoader.getResource(" ./lib/scala-reflect-2.10.2.jar" ).toExternalForm
98
- val modLangScala = classLoader.getResource(" ./" ).toExternalForm
99
+ for {
100
+ jar <- findAll(classLoader, " lib" , JarFileRegex )
101
+ } yield {
102
+ println(s " Found $jar, add to compiler bootstrap " )
103
+ settings.bootclasspath.append(jar.getAbsolutePath)
104
+ }
99
105
100
- settings.bootclasspath.append(scalaLibrary.replaceFirst(" file:" , " " ))
101
- settings.bootclasspath.append(scalaReflectLibrary.replaceFirst(" file:" , " " ))
106
+ val modLangScala = classLoader.getResource(" ./" ).toExternalForm
102
107
settings.bootclasspath.append(modLangScala.replaceFirst(" file:" , " " ))
103
108
104
109
settings.usejavacp.value = true
@@ -108,4 +113,45 @@ class ScalaVerticleFactory extends VerticleFactory {
108
113
interpreter.setContextClassLoader()
109
114
}
110
115
116
+ }
117
+
118
+ object ScalaVerticleFactory {
119
+
120
+ val JarFileRegex = " ^(.*\\ .jar)$" .r
121
+
122
+ /**
123
+ * Find all files matching the given regular expression in the directory.
124
+ * Note that the search is not recursive.
125
+ *
126
+ * @param directory File denoting directory to search files in
127
+ * @param regex regular expression to match
128
+ * @return an [[scala.Array[File ]] representing the collection of files matching
129
+ * the regular expression
130
+ */
131
+ def findAll (directory : File , regex : Regex ): Array [File ] = {
132
+ println(s " Find $regex pattern in $directory" )
133
+ // Protect against null return from listing files
134
+ val files : Array [File ] = directory.listFiles(new FilenameFilter {
135
+ def accept (dir : File , name : String ): Boolean = {
136
+ regex.findFirstIn(name).isDefined
137
+ }
138
+ })
139
+ Option (files).getOrElse(Array [File ]())
140
+ }
141
+
142
+ /**
143
+ * Find all files matching the given regular expression in a path within a
144
+ * classloader. Note that the search is not recursive.
145
+ *
146
+ * @param classLoader class repository where to look for files
147
+ * @param path String representing the path within the classloader where to look for files
148
+ * @param regex regular expression to match
149
+ * @return an [[scala.Array[File ]] representing the collection of files matching
150
+ * the regular expression
151
+ */
152
+ def findAll (classLoader : ClassLoader , path : String , regex : Regex ): Array [File ] = {
153
+ println(s " Find $regex pattern in $classLoader" )
154
+ findAll(new File (classLoader.getResources(path).nextElement().toURI), regex)
155
+ }
156
+
111
157
}
0 commit comments