Skip to content

Commit

Permalink
Initial support for Scala 3 #12
Browse files Browse the repository at this point in the history
Some changes to MVCfx since ScalaFXML is not available for Scala 3
  • Loading branch information
jpsacha committed Nov 24, 2021
1 parent b29534c commit 2c1645a
Show file tree
Hide file tree
Showing 17 changed files with 664 additions and 90 deletions.
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version = 2.7.5
version = 3.1.1

runner.dialect = scala3

preset = IntelliJ
align.preset = more
Expand Down
158 changes: 109 additions & 49 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,73 @@ import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _}
// JAR_BUILT_BY - Name to be added to Jar metadata field "Built-By" (defaults to System.getProperty("user.name")
//

val projectVersion = "0.3.6.1-SNAPSHOT"
val versionTagDir = if (projectVersion.endsWith("SNAPSHOT")) "master" else "v." + projectVersion
val _scalaVersions = Seq("2.13.7", "2.12.15")
val _scalaVersion = _scalaVersions.head
val projectVersion = "0.3.6.1-SNAPSHOT"
val versionTagDir = if (projectVersion.endsWith("SNAPSHOT")) "master" else "v." + projectVersion
val _scalaVersions = Seq("2.13.7", "2.12.15", "3.0.2", "3.1.0")
val _scalaVersion = _scalaVersions.head
val _javaFXVersion = "16"

version := projectVersion
crossScalaVersions := _scalaVersions
scalaVersion := _scalaVersion
publishArtifact := false
publish / skip := true
sonatypeProfileName := "org.scalafx"
ThisBuild / version := projectVersion
ThisBuild / crossScalaVersions := _scalaVersions
ThisBuild / scalaVersion := _scalaVersion
ThisBuild / publishArtifact := false
ThisBuild / publish / skip := true
ThisBuild / sonatypeProfileName := "org.scalafx"

lazy val OSName = System.getProperty("os.name") match {
case n if n.startsWith("Linux") => "linux"
case n if n.startsWith("Mac") => "mac"
case n if n.startsWith("Windows") => "win"
case _ => throw new Exception("Unknown platform!")
}

lazy val JavaFXModuleNames = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
lazy val JavaFXModuleLibsProvided: Seq[ModuleID] =
JavaFXModuleNames.map(m => "org.openjfx" % s"javafx-$m" % _javaFXVersion % "provided" classifier OSName)
lazy val JavaFXModuleLibs: Seq[ModuleID] =
JavaFXModuleNames.map(m => "org.openjfx" % s"javafx-$m" % _javaFXVersion classifier OSName)

def isScala2(scalaVersion: String): Boolean = {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, _)) => true
case _ => false
}
}

def isScala2_13plus(scalaVersion: String): Boolean = {
def isScala2_12(scalaVersion: String): Boolean = {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, n)) if n >= 13 => true
case _ => false
case Some((2, 12)) => true
case _ => false
}
}

def isScala2_13(scalaVersion: String): Boolean = {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, 13)) => true
case _ => false
}
}

// Add src/main/scala-3- for Scala 2.13 and older
// and src/main/scala-3+ for Scala versions older than 3 and newer
def versionSubDir(scalaVersion: String): String =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, _)) => "scala-2"
case Some((3, _)) => "scala-3"
case _ => throw new Exception(s"Unsupported scala version $scalaVersion")
}

// ScalaFX Extras project
lazy val scalaFXExtras = (project in file("scalafx-extras")).settings(
scalaFXExtrasSettings,
name := "scalafx-extras",
description := "The ScalaFX Extras",
Compile / doc / scalacOptions ++= Seq(
"-sourcepath", baseDirectory.value.toString,
"-doc-root-content", baseDirectory.value + "/src/main/scala/root-doc.creole",
"-doc-source-url", "https://github.com/SscalaFX-Extras/scalafx-extras/blob/" + versionTagDir + "/scalafx/€{FILE_PATH}.scala"
"-sourcepath",
baseDirectory.value.toString,
"-doc-root-content",
baseDirectory.value + "/src/main/scala/root-doc.creole"
),
Compile / doc / scalacOptions ++= (
Option(System.getenv("GRAPHVIZ_DOT_PATH")) match {
case Some(path) => Seq("-diagrams", "-diagrams-dot-path", path)
case None => Seq.empty[String]
})
)

// ScalaFX Extras Demos project
Expand All @@ -70,13 +88,12 @@ lazy val scalaFXExtrasDemos = (project in file("scalafx-extras-demos")).settings
"-Xmx512M",
"-Djavafx.verbose"
),
scalacOptions ++= Seq("-deprecation"),
libraryDependencies ++= JavaFXModuleLibs,
publishArtifact := false,
libraryDependencies ++= Seq(
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
"ch.qos.logback" % "logback-classic" % "1.2.7"
),
)
).dependsOn(scalaFXExtras % "compile;test->test")

// Resolvers
Expand All @@ -89,33 +106,71 @@ lazy val scalaFXExtrasSettings = Seq(
organization := "org.scalafx",
version := projectVersion,
crossScalaVersions := _scalaVersions,
scalaVersion := _scalaVersion,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xcheckinit", "-encoding", "utf8", "-feature"),
scalaVersion := _scalaVersion,
// SAdd version specific directories
Compile / unmanagedSourceDirectories += (Compile / sourceDirectory).value / versionSubDir(scalaVersion.value),
Test / unmanagedSourceDirectories += (Test / sourceDirectory).value / versionSubDir(scalaVersion.value),
//
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-encoding",
"utf8",
"-feature"
) ++
(
if (isScala2(scalaVersion.value))
Seq("-Xcheckinit")
else
Seq.empty[String]
),
Compile / doc / scalacOptions ++= Opts.doc.title("ScalaFX Extras API"),
Compile / doc / scalacOptions ++= Opts.doc.version(projectVersion),
Compile / doc / scalacOptions += s"-doc-external-doc:${scalaInstance.value.libraryJars.head}#http://www.scala-lang.org/api/${scalaVersion.value}/",
Compile / doc / scalacOptions ++= Seq("-doc-footer", s"ScalaFX Extras API v.$projectVersion"),
Compile / doc / scalacOptions ++= (
if(isScala2(scalaVersion.value))
Seq(
s"-doc-external-doc:${scalaInstance.value.libraryJars.head}#http://www.scala-lang.org/api/${scalaVersion.value}/",
"-doc-source-url", "https://github.com/SscalaFX-Extras/scalafx-extras/blob/" + versionTagDir + "/scalafx/€{FILE_PATH}.scala"
) ++ (
Option(System.getenv("GRAPHVIZ_DOT_PATH")) match {
case Some(path) => Seq("-diagrams", "-diagrams-dot-path", path)
case None => Seq.empty[String]
}
)
else
Seq.empty[String]
),
// If using Scala 2.13 or better, enable macro processing through compiler option
scalacOptions += (if (isScala2_13plus(scalaVersion.value)) "-Ymacro-annotations" else ""),
scalacOptions += (if (isScala2_13(scalaVersion.value)) "-Ymacro-annotations" else ""),
// If using Scala 2.12 or lower, enable macro processing through compiler plugin
libraryDependencies ++= (
if (!isScala2_13plus(scalaVersion.value))
if (isScala2_12(scalaVersion.value))
Seq(compilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full))
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full
))
else
Seq.empty[sbt.ModuleID]
),
),
javacOptions ++= Seq(
// "-target", "1.8",
// "-source", "1.8",
"-Xlint:deprecation"),
"-Xlint:deprecation"
),
libraryDependencies ++= Seq(
"com.beachape" %% "enumeratum" % "1.7.0",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalafx" %% "scalafx" % "16.0.0-R25",
"org.scalafx" %% "scalafxml-core-sfx8" % "0.5",
"org.scalatest" %% "scalatest" % "3.2.10" % "test"
"org.scalafx" %% "scalafx" % "16.0.0-R25",
"org.scalatest" %% "scalatest" % "3.2.10" % "test"
) ++ JavaFXModuleLibsProvided,
libraryDependencies ++= (
if (isScala2(scalaVersion.value))
Seq(
"com.beachape" %% "enumeratum" % "1.7.0",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalafx" %% "scalafxml-core-sfx8" % "0.5"
)
else
Seq.empty[sbt.ModuleID]
),
// Use `pomPostProcess` to remove dependencies marked as "provided" from publishing in POM
// This is to avoid dependency on wrong OS version JavaFX libraries
// See also [https://stackoverflow.com/questions/27835740/sbt-exclude-certain-dependency-only-during-publish]
Expand All @@ -124,17 +179,17 @@ lazy val scalaFXExtrasSettings = Seq(
override def transform(node: XmlNode): XmlNodeSeq = node match {
case e: Elem if e.label == "dependency" && e.child.exists(c => c.label == "scope" && c.text == "provided") =>
val organization = e.child.filter(_.label == "groupId").flatMap(_.text).mkString
val artifact = e.child.filter(_.label == "artifactId").flatMap(_.text).mkString
val version = e.child.filter(_.label == "version").flatMap(_.text).mkString
val artifact = e.child.filter(_.label == "artifactId").flatMap(_.text).mkString
val version = e.child.filter(_.label == "version").flatMap(_.text).mkString
Comment(s"provided dependency $organization#$artifact;$version has been omitted")
case _ => node
}
}).transform(node).head
},
autoAPIMappings := true,
manifestSetting,
run / fork := true,
Test / fork := true,
run / fork := true,
Test / fork := true,
Test / parallelExecution := false,
resolvers += Resolver.sonatypeRepo("snapshots"),
// print junit-style XML for CI
Expand All @@ -146,7 +201,7 @@ lazy val scalaFXExtrasSettings = Seq(

lazy val manifestSetting = packageOptions += {
Package.ManifestAttributes(
"Created-By" -> "Simple Build Tool",
"Created-By" -> "Simple Build Tool",
"Built-By" -> Option(System.getenv("JAR_BUILT_BY")).getOrElse(System.getProperty("user.name")),
"Build-Jdk" -> System.getProperty("java.version"),
"Specification-Title" -> name.value,
Expand All @@ -164,14 +219,19 @@ import xerial.sbt.Sonatype._
// Metadata needed by Maven Central
// See also http://maven.apache.org/pom.html#Developers
lazy val mavenCentralSettings = Seq(
homepage := Some(new URL("http://www.scalafx.org/")),
startYear := Some(2016),
licenses := Seq(("BSD", new URL("https://github.com/scalafx/scalafx-extras/blob/master/LICENSE.txt"))),
sonatypeProfileName := "org.scalafx",
homepage := Some(new URL("http://www.scalafx.org/")),
startYear := Some(2016),
licenses := Seq(("BSD", new URL("https://github.com/scalafx/scalafx-extras/blob/master/LICENSE.txt"))),
sonatypeProfileName := "org.scalafx",
sonatypeProjectHosting := Some(GitHubHosting("org.scalafx", "scalafx-extras", "jpsacha@gmail.com")),
publishMavenStyle := true,
publishTo := sonatypePublishToBundle.value,
publishMavenStyle := true,
publishTo := sonatypePublishToBundle.value,
developers := List(
Developer(id="jpsacha", name="Jarek Sacha", email="jpsacha@gmail.com", url=url("https://github.com/jpsacha"))
Developer(
id = "jpsacha",
name = "Jarek Sacha",
email = "jpsacha@gmail.com",
url = url("https://github.com/jpsacha")
)
)
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2016, ScalaFX Project
* Copyright (c) 2011-2021, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2018, ScalaFX Project
* Copyright (c) 2011-2021, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2011-2021, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ScalaFX Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.scalafx.extras.mvcfx.stopwatch

import javafx.util as jfxu

import org.scalafx.extras.mvcfx.MVCfx

/**
* StopWatch generator/loader.
*/
class StopWatch(val model: StopWatchModel = new StopWatchModel())
extends MVCfx[StopWatchController]("/org/scalafx/extras/mvcfx/stopwatch/StopWatch.fxml") {

def controllerInstance: StopWatchController = new StopWatchController(model)
}
Loading

0 comments on commit 2c1645a

Please sign in to comment.