Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JPS: refactoring

  • Loading branch information...
commit 3e09ecec0c4ce0b9d636dadb57d22be882b86141 1 parent 47164a2
@pavelfatin pavelfatin authored
View
29 jps-plugin/src/org/jetbrains/jps/incremental/scala/TargetTimestamps.scala
@@ -11,33 +11,30 @@ class TargetTimestamps(context: CompileContext) {
def get(target: ModuleBuildTarget): Option[Long] = {
Some(timestampFile(target)).filter(_.exists).flatMap { file =>
- val in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))
-
- try {
- Some(in.readLong())
- } catch {
- case _: IOException => None
- } finally {
- in.close()
+ using(new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) { in =>
+ try {
+ Some(in.readLong())
+ } catch {
+ case _: IOException => None
+ }
}
}
}
def set(target: ModuleBuildTarget, timestamp: Long) {
- val out = {
- val file = timestampFile(target)
- new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
- }
+ val file = timestampFile(target)
- try {
+ using(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { out =>
out.writeLong(timestamp)
- } finally {
- out.close()
}
}
private def timestampFile(target: ModuleBuildTarget): File = {
paths.getTargetDataRoot(target)
- new File(paths.getTargetDataRoot(target), "timestamp.dat")
+ new File(paths.getTargetDataRoot(target), TargetTimestamps.Filename)
}
}
+
+private object TargetTimestamps {
+ private val Filename = "timestamp.dat"
+}
View
18 jps-plugin/src/org/jetbrains/jps/incremental/scala/package.scala
@@ -6,6 +6,24 @@ import _root_.java.util.Properties
* @author Pavel Fatin
*/
package object scala {
+ type Closeable = {
+ def close()
+ }
+
+ def using[A <: Closeable, B](resource: A)(block: A => B): B = {
+ try {
+ block(resource)
+ } finally {
+ resource.close()
+ }
+ }
+
+ def extractor[A, B](f: A => B) = new Extractor[A, B](f)
+
+ class Extractor[A, B](f: A => B) {
+ def unapply(a: A): Some[B] = Some(f(a))
+ }
+
implicit def toRightBiasedEiter[A, B](either: Either[A, B]): Either.RightProjection[A, B] = either.right
implicit def toPipedObject[T](value: T) = new {
View
24 jps-plugin/src/org/jetbrains/jps/incremental/scala/remote/package.scala
@@ -1,24 +0,0 @@
-package org.jetbrains.jps.incremental.scala
-
-/**
- * @author Pavel Fatin
- */
-package object remote {
- type Closeable = {
- def close()
- }
-
- def using[A <: Closeable, B](resource: A)(block: A => B): B = {
- try {
- block(resource)
- } finally {
- resource.close()
- }
- }
-
- def extractor[A, B](f: A => B) = new Extractor[A, B](f)
-
- class Extractor[A, B](f: A => B) {
- def unapply(a: A): Some[B] = Some(f(a))
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.