Skip to content

Commit 492575f

Browse files
authored
Merge pull request #3 from cquiroz/java-time-packages
Java time packages
2 parents 956a838 + 82ea058 commit 492575f

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Both Scala 2.11 and Scala 2.12 (2.12.0-M5 and later) are supported.
1515

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

18-
- `libraryDependencies += "com.github.cquiroz" % "scala-java-time" % "2.0.0-M5"` (for Scala)
19-
- `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)
18+
- `libraryDependencies += "io.github.cquiroz" % "scala-java-time" % "2.0.0-M6"` (for Scala)
19+
- `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)
2020

2121
#### Documentation
2222

build.sbt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ val crossScalaVer = Seq(scalaVer, "2.10.6", "2.12.0")
1010
lazy val commonSettings = Seq(
1111
name := "scala-java-time",
1212
description := "java.time API implementation in Scala and Scala.js",
13-
version := "2.0.0-M5",
14-
organization := "com.github.cquiroz",
13+
version := "2.0.0-M6",
14+
organization := "io.github.cquiroz",
1515
homepage := Some(url("https://github.com/cquiroz/scala-java-time")),
1616
licenses := Seq("BSD 3-Clause License" -> url("https://opensource.org/licenses/BSD-3-Clause")),
1717

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

50+
/**
51+
* Copy source files and translate them to the java.time package
52+
*/
53+
def copyAndReplace(srcDirs: Seq[File], destinationDir: File): Seq[File] = {
54+
// Copy a directory and return the list of files
55+
def copyDirectory(source: File, target: File, overwrite: Boolean = false, preserveLastModified: Boolean = false): Set[File] =
56+
IO.copy(PathFinder(source).***.pair(Path.rebase(source, target)), overwrite, preserveLastModified)
57+
58+
val onlyScalaDirs = srcDirs.filter(_.getName.endsWith("scala"))
59+
// Copy the source files from the base project, exclude classes on java.util and dirs
60+
val generatedFiles: List[java.io.File] = onlyScalaDirs.foldLeft(Set.empty[File]) { (files, sourceDir) =>
61+
files ++ copyDirectory(sourceDir, destinationDir, overwrite = true)
62+
}.filterNot(_.isDirectory).filterNot(_.getParentFile.getName == "util").toList
63+
64+
// These replacements will in practice rename all the classes from
65+
// org.threeten to java.time
66+
def replacements(line: String): String = {
67+
line
68+
.replaceAll("package org.threeten$", "package java")
69+
.replaceAll("package object bp", "package object time")
70+
.replaceAll("package org.threeten.bp", "package java.time")
71+
.replaceAll("import org.threeten.bp", "import java.time")
72+
.replaceAll("private\\s*\\[bp\\]", "private[time]")
73+
}
74+
75+
// Visit each file and read the content replacing key strings
76+
generatedFiles.foreach { f =>
77+
val replacedLines = IO.readLines(f).map(replacements)
78+
IO.writeLines(f, replacedLines)
79+
}
80+
generatedFiles
81+
}
82+
5083
lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
5184
.jvmConfigure(_.enablePlugins(TestNGPlugin))
5285
.jsConfigure(_.enablePlugins(TestNGScalaJSPlugin))
5386
.settings(commonSettings: _*)
5487
.jvmSettings(
55-
micrositeExtraMdFiles := Map(file("README.md") -> "index.md"),
56-
88+
sourceGenerators in Compile += Def.task {
89+
val srcDirs = (sourceDirectories in Compile).value
90+
val destinationDir = (sourceManaged in Compile).value
91+
copyAndReplace(srcDirs, destinationDir)
92+
}.taskValue,
5793
resolvers += Resolver.sbtPluginRepo("releases"),
5894
// Fork the JVM test to ensure that the custom flags are set
5995
fork in Test := true,
@@ -63,6 +99,11 @@ lazy val scalajavatime = crossProject.crossType(CrossType.Full).in(file("."))
6399
javaOptions in Test ++= Seq("-Djava.locale.providers=CLDR"),
64100
TestNGPlugin.testNGSuites := Seq(((resourceDirectory in Test).value / "testng.xml").absolutePath)
65101
).jsSettings(
102+
sourceGenerators in Compile += Def.task {
103+
val srcDirs = (sourceDirectories in Compile).value
104+
val destinationDir = (sourceManaged in Compile).value
105+
copyAndReplace(srcDirs, destinationDir)
106+
}.taskValue,
66107
libraryDependencies ++= Seq(
67108
"com.github.cquiroz" %%% "scala-java-locales" % "0.4.0-cldr30"
68109
)

shared/src/main/scala/org/threeten/bp/format/DateTimeBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final class DateTimeBuilder() extends TemporalAccessor with Cloneable {
195195
resolveMakeChanges(targetField, lt)
196196
changes += 1
197197
scala.util.control.Breaks.break()
198-
case cldt: ChronoLocalDateTime[ChronoLocalDate] =>
198+
case cldt: ChronoLocalDateTime[_] =>
199199
resolveMakeChanges(targetField, cldt.toLocalDate)
200200
resolveMakeChanges(targetField, cldt.toLocalTime)
201201
changes += 1

0 commit comments

Comments
 (0)