Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
philwalk committed Oct 3, 2023
1 parent 4074577 commit 6f104c3
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 962 deletions.
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ ThisBuild / organization := "org.vastblue"
ThisBuild / organizationName := "vastblue.org"
ThisBuild / organizationHomepage := Some(url("https://vastblue.org/"))

//cancelable in Global := true

parallelExecution := false

ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/philwalk/pallet"),
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.4
sbt.version=1.9.6
7 changes: 7 additions & 0 deletions src/main/scala-2.13/vastblue/Info.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vastblue

object Info {
lazy val scalaRuntimeVersion: String = {
scala.util.Properties.versionNumberString
}
}
26 changes: 1 addition & 25 deletions src/main/scala-2.13/vastblue/pathextend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import java.io.{FileOutputStream, OutputStreamWriter}
import java.security.{DigestInputStream, MessageDigest}
import scala.jdk.CollectionConverters._
import vastblue.Platform._
import vastblue.time.FileTime
import vastblue.time.FileTime._
import vastblue.DriveRoot._

// TODO: factor out code common to scala3 and scala2.13 versions
Expand Down Expand Up @@ -97,30 +95,9 @@ object pathextend {
def pathFields = p.iterator.asScala.toList
def reversePath: String = pathFields.reverse.mkString("/")
def lastModified: Long = p.toFile.lastModified
def lastModifiedTime = whenModified(p.toFile)
def lastModSeconds: Double = {
secondsBetween(lastModifiedTime, now).toDouble
}
def lastModMinutes: Double = lastModSeconds / 60.0
def lastModHours: Double = lastModMinutes / 60.0
def lastModDays: Double = round(lastModHours / 24.0)
def weekDay: java.time.DayOfWeek = {
p.lastModifiedTime.getDayOfWeek
}
def round(number: Double, scale: Int = 6): Double = {
BigDecimal(number).setScale(scale, BigDecimal.RoundingMode.HALF_UP).toDouble
}
def age: String = { // readable description of lastModified
if (lastModMinutes <= 60.0) {
"%1.2f minutes".format(lastModMinutes)
} else if (lastModHours <= 24.0) {
"%1.2f hours".format(lastModHours)
} else if (lastModDays <= 365.25) {
"%1.2f days".format(lastModDays)
} else {
"%1.2f years".format(lastModDays / 365.25)
}
}

def files: Seq[JFile] = p.toFile match {
case f if f.isDirectory => f.files
Expand Down Expand Up @@ -155,7 +132,6 @@ object pathextend {
def contentAnyEncoding: String = p.toFile.contentAnyEncoding
def bytes: Array[Byte] = JFiles.readAllBytes(p)
def byteArray: Array[Byte] = bytes
def ageInDays: Double = FileTime.ageInDays(p.toFile)

def trimmedLines: Seq[String] = linesCharset(DefaultCharset).map { _.trim }
def trimmedSql: Seq[String] =
Expand Down Expand Up @@ -568,7 +544,7 @@ object pathextend {
} else {
val posix = if (str.drop(1).startsWith(":")) {
val driveRoot = DriveRoot(str.take(2))
str.drop(2).string match {
str.drop(2) match {
case "/" =>
driveRoot.posix
case pathstr if pathstr.startsWith("/") =>
Expand Down
114 changes: 0 additions & 114 deletions src/main/scala-2.13/vastblue/time/TimeExtensions.scala

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/scala-3/vastblue/DriveRoot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import java.nio.file.{Path, Paths}
import DriveRoot._
import vastblue.Platform.cygdrive

opaque type DriveRoot = String

// DriveRoot Strings must match "" or "[A-Z]:"
// The `toPath` method resolves path to root of disk,
// rather than the one returned by `Paths.get("C:")`.
object DriveRoot {
type DriveRoot = String
opaque type DriveRoot = String

// empty string or uppercase "[A-Z]:"
def apply(s: String): DriveRoot = {
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala-3/vastblue/Info.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package vastblue

object Info {
import java.io.FileInputStream
import java.util.jar.JarInputStream

lazy val scalaRuntimeVersion: String = {
val scala3LibJar = classOf[CanEqual[_, _]].getProtectionDomain.getCodeSource.getLocation.toURI.getPath
val manifest = new JarInputStream(new FileInputStream(scala3LibJar)).getManifest
manifest.getMainAttributes.getValue("Implementation-Version")
}
}
26 changes: 1 addition & 25 deletions src/main/scala-3/vastblue/pathextend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import java.io.{FileOutputStream, OutputStreamWriter}
import java.security.{DigestInputStream, MessageDigest}
import scala.jdk.CollectionConverters.*
import vastblue.Platform.*
import vastblue.time.FileTime
import vastblue.time.FileTime.*
import vastblue.DriveRoot.*

// TODO: factor out code common to scala3 and scala2.13 versions
Expand Down Expand Up @@ -97,30 +95,9 @@ object pathextend {
def pathFields = p.iterator.asScala.toList
def reversePath: String = pathFields.reverse.mkString("/")
def lastModified: Long = p.toFile.lastModified
def lastModifiedTime = whenModified(p.toFile)
def lastModSeconds: Double = {
secondsBetween(lastModifiedTime, now).toDouble
}
def lastModMinutes: Double = lastModSeconds / 60.0
def lastModHours: Double = lastModMinutes / 60.0
def lastModDays: Double = round(lastModHours / 24.0)
def weekDay: java.time.DayOfWeek = {
p.lastModifiedTime.getDayOfWeek
}
def round(number: Double, scale: Int = 6): Double = {
BigDecimal(number).setScale(scale, BigDecimal.RoundingMode.HALF_UP).toDouble
}
def age: String = { // readable description of lastModified
if (lastModMinutes <= 60.0) {
"%1.2f minutes".format(lastModMinutes)
} else if (lastModHours <= 24.0) {
"%1.2f hours".format(lastModHours)
} else if (lastModDays <= 365.25) {
"%1.2f days".format(lastModDays)
} else {
"%1.2f years".format(lastModDays / 365.25)
}
}

def files: Seq[JFile] = p.toFile match {
case f if f.isDirectory => f.files
Expand Down Expand Up @@ -155,7 +132,6 @@ object pathextend {
def contentAnyEncoding: String = p.toFile.contentAnyEncoding
def bytes: Array[Byte] = JFiles.readAllBytes(p)
def byteArray: Array[Byte] = bytes
def ageInDays: Double = FileTime.ageInDays(p.toFile)

def trimmedLines: Seq[String] = linesCharset(DefaultCharset).map { _.trim }
def trimmedSql: Seq[String] =
Expand Down Expand Up @@ -568,7 +544,7 @@ object pathextend {
} else {
val posix = if (str.drop(1).startsWith(":")) {
val driveRoot = DriveRoot(str.take(2))
str.drop(2).string match {
str.drop(2) match {
case "/" =>
driveRoot.posix
case pathstr if pathstr.startsWith("/") =>
Expand Down
Loading

0 comments on commit 6f104c3

Please sign in to comment.