Skip to content

Java time packages #3

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 5 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Both Scala 2.11 and Scala 2.12 (2.12.0-M5 and later) are supported.

To get started with SBT, add one (or both) of these dependencies:

- `libraryDependencies += "com.github.cquiroz" % "scala-java-time" % "2.0.0-M5"` (for Scala)
- `libraryDependencies += "com.github.cquiroz" %%% "scala-java-time" % "2.0.0-M5"` (for Scala.js, [Scala.js plugin](http://www.scala-js.org/tutorial/basic/#sbt-setup) required)
- `libraryDependencies += "io.github.cquiroz" % "scala-java-time" % "2.0.0-M6"` (for Scala)
- `libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.0.0-M6"` (for Scala.js, [Scala.js plugin](http://www.scala-js.org/tutorial/basic/#sbt-setup) required)

#### Documentation

Expand Down
49 changes: 45 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ val crossScalaVer = Seq(scalaVer, "2.10.6", "2.12.0")
lazy val commonSettings = Seq(
name := "scala-java-time",
description := "java.time API implementation in Scala and Scala.js",
version := "2.0.0-M5",
organization := "com.github.cquiroz",
version := "2.0.0-M6",
organization := "io.github.cquiroz",
homepage := Some(url("https://github.com/cquiroz/scala-java-time")),
licenses := Seq("BSD 3-Clause License" -> url("https://opensource.org/licenses/BSD-3-Clause")),

Expand Down Expand Up @@ -47,13 +47,49 @@ lazy val root = project.in(file("."))
publishArtifact := false,
Keys.`package` := file(""))

/**
* Copy source files and translate them to the java.time package
*/
def copyAndReplace(srcDirs: Seq[File], destinationDir: File): Seq[File] = {
// Copy a directory and return the list of files
def copyDirectory(source: File, target: File, overwrite: Boolean = false, preserveLastModified: Boolean = false): Set[File] =
IO.copy(PathFinder(source).***.pair(Path.rebase(source, target)), overwrite, preserveLastModified)

val onlyScalaDirs = srcDirs.filter(_.getName.endsWith("scala"))
// Copy the source files from the base project, exclude classes on java.util and dirs
val generatedFiles: List[java.io.File] = onlyScalaDirs.foldLeft(Set.empty[File]) { (files, sourceDir) =>
files ++ copyDirectory(sourceDir, destinationDir, overwrite = true)
}.filterNot(_.isDirectory).filterNot(_.getParentFile.getName == "util").toList

// These replacements will in practice rename all the classes from
// org.threeten to java.time
def replacements(line: String): String = {
line
.replaceAll("package org.threeten$", "package java")
.replaceAll("package object bp", "package object time")
.replaceAll("package org.threeten.bp", "package java.time")
.replaceAll("import org.threeten.bp", "import java.time")
.replaceAll("private\\s*\\[bp\\]", "private[time]")
}

// Visit each file and read the content replacing key strings
generatedFiles.foreach { f =>
val replacedLines = IO.readLines(f).map(replacements)
IO.writeLines(f, replacedLines)
}
generatedFiles
}

lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
.jvmConfigure(_.enablePlugins(TestNGPlugin))
.jsConfigure(_.enablePlugins(TestNGScalaJSPlugin))
.settings(commonSettings: _*)
.jvmSettings(
micrositeExtraMdFiles := Map(file("README.md") -> "index.md"),

sourceGenerators in Compile += Def.task {
val srcDirs = (sourceDirectories in Compile).value
val destinationDir = (sourceManaged in Compile).value
copyAndReplace(srcDirs, destinationDir)
}.taskValue,
resolvers += Resolver.sbtPluginRepo("releases"),
// Fork the JVM test to ensure that the custom flags are set
fork in Test := true,
Expand All @@ -63,6 +99,11 @@ lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
javaOptions in Test ++= Seq("-Djava.locale.providers=CLDR"),
TestNGPlugin.testNGSuites := Seq(((resourceDirectory in Test).value / "testng.xml").absolutePath)
).jsSettings(
sourceGenerators in Compile += Def.task {
val srcDirs = (sourceDirectories in Compile).value
val destinationDir = (sourceManaged in Compile).value
copyAndReplace(srcDirs, destinationDir)
}.taskValue,
libraryDependencies ++= Seq(
"com.github.cquiroz" %%% "scala-java-locales" % "0.4.0-cldr30"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ final class DateTimeBuilder() extends TemporalAccessor with Cloneable {
resolveMakeChanges(targetField, lt)
changes += 1
scala.util.control.Breaks.break()
case cldt: ChronoLocalDateTime[ChronoLocalDate] =>
case cldt: ChronoLocalDateTime[_] =>
resolveMakeChanges(targetField, cldt.toLocalDate)
resolveMakeChanges(targetField, cldt.toLocalTime)
changes += 1
Expand Down