@@ -33,13 +33,62 @@ val mUnitVersion = "0.7.27"
33
33
* overriding certain modules on boot-up. This allows for example the use the
34
34
* TestFX for use in headless UI testing.
35
35
*
36
+ * To add other libraries as modules see `controlsFXModule` as an example.
37
+ *
36
38
* ./mill mill.scalalib.GenIdea/idea
39
+ *
40
+ * TODO: https://stackoverflow.com/questions/46616520/list-modules-in-jar-file
37
41
*
38
42
* @see https://github.com/com-lihaoyi/mill/pull/775#issuecomment-826091576
39
43
*/
40
- trait javaFX extends ScalaModule with JavaModule {
41
- def scalaVersion = T { ScalaVersion }
44
+ trait OpenJFX extends JavaModule {
45
+
46
+ // Modules
47
+
48
+ val BASE_ = s " base "
49
+ val CONTROLS_ = s " controls "
50
+ val FXML_ = s " fxml "
51
+ val GRAPHICS_ = s " graphics "
52
+ val MEDIA_ = s " media "
53
+ val SWING_ = s " swing "
54
+ val WEB_ = s " web "
55
+ val CONTROLSFX_ = s " controlsfx "
56
+
57
+ // Extra modules
58
+ // Note that the module name and the library name are not the same
59
+ val controlsFXModule = " org.controlsfx.controls"
60
+
61
+ // Module libraries
62
+ val BASE = s " org.openjfx:javafx- $BASE_: $javaFXVersion"
63
+ val CONTROLS = s " org.openjfx:javafx- $CONTROLS_: $javaFXVersion"
64
+ val FXML = s " org.openjfx:javafx- $FXML_: $javaFXVersion"
65
+ val GRAPHICS = s " org.openjfx:javafx- $GRAPHICS_: $javaFXVersion"
66
+ val MEDIA = s " org.openjfx:javafx- $MEDIA_: $javaFXVersion"
67
+ val SWING = s " org.openjfx:javafx- $SWING_: $javaFXVersion"
68
+ val WEB = s " org.openjfx:javafx- $WEB_: $javaFXVersion"
69
+ val CONTROLSFX = s " org.controlsfx: $CONTROLSFX_: $controlsFXVersion"
42
70
71
+ // OpenFX/JavaFX libraries
72
+ val javaFXModuleNames = Seq (BASE_ , CONTROLS_ , FXML_ , GRAPHICS_ , MEDIA_ , SWING_ , WEB_ )
73
+
74
+
75
+ /* TODO: we need a better way to identify modules in the JARs
76
+ see: https://stackoverflow.com/questions/46616520/list-modules-in-jar-file
77
+ see: https://www.daniweb.com/programming/software-development/threads/291837/best-way-executing-jar-from-java-code-then-killing-parent-java-code
78
+ see: https://in.relation.to/2017/12/06/06-calling-jdk-tools-programmatically-on-java-9/
79
+ see: https://www.pluralsight.com/guides/creating-opening-jar-files-java-programming-language
80
+ see: https://stackoverflow.com/questions/320510/viewing-contents-of-a-jar-file
81
+ see: https://www.baeldung.com/java-compress-and-uncompress
82
+ see: https://github.com/srikanth-lingala/zip4j
83
+ // List of modules (note that a single Jar may have ore than one module)
84
+ val modules = javaFXModuleNames.map(n => n -> s"org.openjfx:javafx-$n:$javaFXVersion") // OpenFX
85
+ .toMap
86
+ ++ // Other modules
87
+ Map( "controlsfx" -> s"org.controlsfx:controlsfx:$controlsFXVersion") // ControlsFX
88
+ println(modules)
89
+ */
90
+
91
+ // TODO: after version 0.10.0 iof Mill put test in the managed/unmanaged classes
43
92
val ivyMunit = ivy " org.scalameta::munit::0.7.27 "
44
93
val ivyMunitInterface = " munit.Framework"
45
94
@@ -55,58 +104,28 @@ trait javaFX extends ScalaModule with JavaModule {
55
104
Some ((_ : coursier.core.Resolution ).withOsInfo(coursier.core.Activation .Os .fromProperties(sys.props.toMap)))
56
105
}
57
106
58
- /**
59
- * We setup JavaFX using managed libraries pretty much as any other library.
60
- * However, we must use the [[resolutionCustomizer ]] to ensure that the proper
61
- * OS dependent libraries are correctly downloaded. In order to ise JavaFX or
62
- * OpenJFX we must include these libraries in the module path and module names
63
- * to the JVM parameters. We can automate this via [[forkArgs ]].
64
- *
65
- * Here we list the dependencies via the Mill `ivy` macro (uses Coursier). We
66
- * could automate this too because the naming of the libraries and models uses
67
- * a consistent convention. We leave that as an exercise to the reader.
68
- *
69
- * Note that any dependencies are loaded automatically so no need to add
70
- * all the JavaFX libraries. We have these here as an example.
71
- *
72
- * @return an aggregation of the dependencies
73
- */
74
- override def ivyDeps = Agg (
75
- /* ivy"org.openjfx:javafx-base:$javaFXVersion",
76
- ivy"org.openjfx:javafx-controls:$javaFXVersion",
77
- ivy"org.openjfx:javafx-fxml:$javaFXVersion",
78
- ivy"org.openjfx:javafx-graphics:$javaFXVersion",
79
- ivy"org.openjfx:javafx-media:$javaFXVersion",
80
- ivy"org.openjfx:javafx-swing:$javaFXVersion",
81
- ivy"org.openjfx:javafx-web:$javaFXVersion",*/
82
- ivy " org.openjfx:javafx-controls: $javaFXVersion" ,
83
- ivy " org.controlsfx:controlsfx: $controlsFXVersion"
84
- )
85
-
86
-
87
- // OpenFX/JavaFX libraries
88
- // private lazy val javaFXModuleNames = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
89
- // Extra OpenFX library
90
- private lazy val controlsFXModuleName = " org.controlsfx.controls"
91
-
92
107
/**
93
108
* Here we setup the Java modules so that they can be loaded prior to
94
109
* application boot. We can indicate which modules are visible and even opt
95
110
* to substitute some of those. For example using TestFX to allow for headless
96
111
* testing.
97
112
*
113
+ * Note that with managed libraries, we may pull in additional modules. So we
114
+ * attempt here to identify (via naming convention), which libraries are modules.
115
+ * These corresponding modules are then added to the JVM command line.
116
+ *
98
117
* @return the list of parameters for the JVM
99
118
*/
100
119
override def forkArgs : Target [Seq [String ]] = T {
101
120
// get the managed libraries
102
- val unmanaged : Loose .Agg [PathRef ] = runClasspath()
121
+ val allLibs : Loose .Agg [PathRef ] = runClasspath()
103
122
// get the OpenJFX and related managed libraries
104
- val s : Loose .Agg [String ] = unmanaged .map(_.path.toString())
105
- .filter{
106
- s =>
107
- val t = s.toLowerCase()
108
- t.contains(" javafx" ) || t.contains(" controlsfx" )
109
- }
123
+ val s : Loose .Agg [String ] = allLibs .map(_.path.toString())
124
+ .filter{
125
+ s =>
126
+ val t = s.toLowerCase()
127
+ t.contains(" javafx" ) || t.contains(" controlsfx" )
128
+ }
110
129
111
130
// Create the JavaFX module names (convention is amenable to automation)
112
131
import scala .util .matching .Regex
@@ -119,7 +138,7 @@ trait javaFX extends ScalaModule with JavaModule {
119
138
.map(_.get)
120
139
// Now generate the module names
121
140
val modulesNames = javaFXModules.map( m => s " javafx. $m" ) ++
122
- Seq (controlsFXModuleName ) // no standard convention, so add it manually
141
+ Seq (controlsFXModule ) // no standard convention, so add it manually
123
142
124
143
// Add to the modules list
125
144
Seq (
@@ -134,36 +153,44 @@ trait javaFX extends ScalaModule with JavaModule {
134
153
}
135
154
136
155
156
+ // TODO: after version 0.10.0 of Mill put test in the managed/unmanaged classes
137
157
object test extends Tests {
138
158
159
+ // TODO: after version 0.10.0 of Mill remove this
160
+ // sse https://github.com/com-lihaoyi/mill/issues/1406
139
161
override def resolutionCustomizer : Task [Option [Resolution => Resolution ]] = T .task {
140
162
Some ((_ : coursier.core.Resolution ).withOsInfo(coursier.core.Activation .Os .fromProperties(sys.props.toMap)))
141
163
}
142
-
143
- // override def ivyDeps = Agg(ivyMunit)
144
- // sse https://github.com/com-lihaoyi/mill/issues/1406
145
- override def ivyDeps = Agg (
146
- ivy " org.openjfx:javafx-controls: $javaFXVersion" ,
147
- ivy " org.controlsfx:controlsfx: $controlsFXVersion" ,
148
- ivyMunit)
149
164
150
165
// https://github.com/com-lihaoyi/mill#097---2021-05-14
151
166
// def testFrameworks = Seq(ivyMunitInterface)
152
167
def testFramework = ivyMunitInterface
153
168
}
154
169
155
170
}
171
+ object HelloWorldJava extends OpenJFX {
172
+
173
+ override def mainClass : T [Option [String ]] = Some (" helloworld.HelloWorld" )
174
+
175
+ override def ivyDeps = Agg (
176
+ ivy " $CONTROLS" ,
177
+ ivy " $CONTROLSFX"
178
+ )
156
179
157
- object HelloWorldJava extends javaFX {
158
180
159
- override def mainClass : T [Option [String ]] = Some (" helloworld.HelloWorld" )
160
181
161
182
}
162
183
163
- object HelloWorldScala extends javaFX {
184
+
185
+ object HelloWorldScala extends OpenJFX with ScalaModule {
186
+ def scalaVersion = T { ScalaVersion }
164
187
165
188
override def mainClass : T [Option [String ]] = Some (" helloworld.HelloWorld" )
166
189
190
+ override def ivyDeps = Agg (
191
+ ivy " $CONTROLS" ,
192
+ ivy " $CONTROLSFX"
193
+ )
167
194
}
168
195
169
196
0 commit comments