Skip to content
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

Fix #90: Upgrade to Scala 2.12 #99

Merged
merged 5 commits into from
Jan 13, 2017
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ libraryDependencies ++= Seq(
```
Latest `version`: [![Maven][mavenImg]][mavenLink]

Although this library is currently only actively developed for Scala 2.11 and 2.12,
you can find reasonably recent versions of this library for Scala 2.10 [here](https://oss.sonatype.org/#nexus-search;quick~better-files)
Although this library is currently only actively developed for Scala 2.12,
you can find reasonably recent versions of this library for Scala 2.10 and 2.11 [here](https://oss.sonatype.org/#nexus-search;quick~better-files)

## Tests [![codecov][codecovImg]][codecovLink]
* [FileSpec](core/src/test/scala/better/files/FileSpec.scala)
Expand All @@ -71,8 +71,8 @@ you can find reasonably recent versions of this library for Scala 2.10 [here](ht
[codacyImg2]: https://api.codacy.com/project/badge/grade/0e2aeb7949bc49e6802afcc43a7a1aa1
[codacyLink]: https://www.codacy.com/app/pathikrit/better-files/dashboard

[mavenImg]: https://img.shields.io/maven-central/v/com.github.pathikrit/better-files_2.11.svg
[mavenImg2]: https://maven-badges.herokuapp.com/maven-central/com.github.pathikrit/better-files_2.11/badge.svg
[mavenImg]: https://img.shields.io/maven-central/v/com.github.pathikrit/better-files_2.12.svg
[mavenImg2]: https://maven-badges.herokuapp.com/maven-central/com.github.pathikrit/better-files_2.12/badge.svg
[mavenLink]: http://search.maven.org/#search%7Cga%7C1%7Cbetter-files

[gitterImg]: https://img.shields.io/gitter/room/pathikrit/better-files.svg
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ val repo = "better-files"

lazy val commonSettings = Seq(
organization := s"com.github.$username",
scalaVersion := "2.11.8",
crossScalaVersions := Seq("2.11.8"),
scalaVersion := "2.12.1",
crossScalaVersions := Seq("2.12.1"),
crossVersion := CrossVersion.binary,
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint"),
scalacOptions ++= Seq(
Expand All @@ -16,7 +16,7 @@ lazy val commonSettings = Seq(
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yinline-warnings",
//"-Yinline-warnings", //Removed in 2.12?
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test:
override:
- sbt +clean +coverage +test
# post:
# - cp -r target/scala-2.11/ $CIRCLE_ARTIFACTS
# - cp -r target/scala-2.12/ $CIRCLE_ARTIFACTS

deployment:
master:
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/better/files/Cmds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package better.files
import java.nio.file.attribute.{PosixFileAttributes, PosixFilePermission, PosixFilePermissions}
import java.util.zip.{Deflater, ZipOutputStream}

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.io.Codec

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ object Cmds {
* @return file
*/
def chmod(permissions: String, file: File): File =
file.setPermissions(PosixFilePermissions.fromString(permissions).toSet)
file.setPermissions(PosixFilePermissions.fromString(permissions).asScala.toSet)

def chmod_+(permission: PosixFilePermission, file: File): File =
file.addPermission(permission)
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/scala/better/files/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.time.Instant
import java.util.zip.{Deflater, ZipFile}
import javax.xml.bind.DatatypeConverter

import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.io.{BufferedSource, Codec, Source}
import scala.util.Properties

Expand Down Expand Up @@ -194,7 +194,7 @@ class File private(val path: Path) {
* @return all lines in this file
*/
def lines(implicit codec: Codec): Traversable[String] =
Files.readAllLines(path, codec)
Files.readAllLines(path, codec).asScala

/**
* Iterate over lines in a file (auto-close stream on complete)
Expand Down Expand Up @@ -233,7 +233,7 @@ class File private(val path: Path) {
* @return
*/
def appendLines(lines: String*)(implicit openOptions: File.OpenOptions = File.OpenOptions.append, codec: Codec): this.type = {
Files.write(path, lines, codec, openOptions: _*)
Files.write(path, lines.asJava, codec, openOptions: _*)
this
}

Expand Down Expand Up @@ -352,7 +352,7 @@ class File private(val path: Path) {
newOutputStream(openOptions).autoClosed

def newFileChannel(implicit openOptions: File.OpenOptions = File.OpenOptions.default, attributes: File.Attributes = File.Attributes.default): FileChannel =
FileChannel.open(path, openOptions.toSet, attributes: _*)
FileChannel.open(path, openOptions.toSet.asJava, attributes: _*)

def fileChannel(implicit openOptions: File.OpenOptions = File.OpenOptions.default, attributes: File.Attributes = File.Attributes.default): ManagedResource[FileChannel] =
newFileChannel(openOptions, attributes).autoClosed
Expand Down Expand Up @@ -502,13 +502,13 @@ class File private(val path: Path) {
walk()(visitOptions).map(f => Files.size(f.path)).sum

def permissions(implicit linkOptions: File.LinkOptions = File.LinkOptions.default): Set[PosixFilePermission] =
Files.getPosixFilePermissions(path, linkOptions: _*).toSet
Files.getPosixFilePermissions(path, linkOptions: _*).asScala.toSet

def permissionsAsString(implicit linkOptions: File.LinkOptions = File.LinkOptions.default): String =
PosixFilePermissions.toString(permissions(linkOptions))
PosixFilePermissions.toString(permissions(linkOptions).asJava)

def setPermissions(permissions: Set[PosixFilePermission]): this.type = {
Files.setPosixFilePermissions(path, permissions)
Files.setPosixFilePermissions(path, permissions.asJava)
this
}

Expand Down Expand Up @@ -681,7 +681,7 @@ class File private(val path: Path) {
walk()(visitOptions).map(relativize)

def relativize(destination: File): Path =
path relativize destination.path
path.relativize(destination.path)

def isSamePathAs(that: File): Boolean =
this.path == that.path
Expand Down Expand Up @@ -779,7 +779,7 @@ class File private(val path: Path) {
def unzipTo(destination: File)(implicit codec: Codec): destination.type = {
for {
zipFile <- new ZipFile(toJava, codec).autoClosed
entry <- zipFile.entries()
entry <- zipFile.entries().asScala
file = destination.createChild(entry.getName, entry.isDirectory)
if !entry.isDirectory
} zipFile.getInputStream(entry) > file.newOutputStream
Expand Down Expand Up @@ -821,7 +821,7 @@ object File {
Paths.get(uri)

def roots: Iterable[File] =
FileSystems.getDefault.getRootDirectories.map(File.apply)
FileSystems.getDefault.getRootDirectories.asScala.map(File.apply)

def root: File =
roots.head
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/scala/better/files/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ trait Implicits {
new BufferedWriter(writer)
}

implicit class BufferedIteratorOps[A](it: BufferedIterator[A]) {
def headOption: Option[A] =
when(it.hasNext)(it.head) // TODO: https://issues.scala-lang.org/browse/SI-9691
}

implicit class FileChannelOps(fc: FileChannel) {
def toMappedByteBuffer: MappedByteBuffer =
fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ abstract class ThreadBackedFileMonitor(val root: File, maxDepth: Int) extends Fi
override def run() = Iterator.continually(service.take()) foreach process
}
thread.setDaemon(true)
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler {
override def uncaughtException(thread: Thread, exception: Throwable) = onException(exception)
})
thread.setUncaughtExceptionHandler((thread, exception) => onException(exception))

def this(root: File, recursive: Boolean = true) = this(root, if (recursive) Int.MaxValue else 0)

Expand All @@ -26,8 +24,8 @@ abstract class ThreadBackedFileMonitor(val root: File, maxDepth: Int) extends Fi

val path = key.watchable().asInstanceOf[Path]

import scala.collection.JavaConversions._
key.pollEvents() foreach {
import scala.collection.JavaConverters._
key.pollEvents().asScala foreach {
case event: WatchEvent[Path] @unchecked =>
val target: File = path resolve event.context()
if (reactTo(target)) {
Expand Down