Skip to content

Commit

Permalink
consolidate PathSpec / FileSpec tests, fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
philwalk committed Sep 29, 2023
1 parent 337e035 commit 4074577
Show file tree
Hide file tree
Showing 24 changed files with 791 additions and 1,029 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ jsrc/*.jar
.bloop/
metals.sbt
.vscode
*Atfile
10 changes: 9 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
version = 3.7.14
preset = default
align.preset = more
maxColumn = 100
maxColumn = 200
docstrings.wrapMaxColumn = 100
docstrings.style = Asterisk
docstrings.oneline = keep

assumeStandardLibraryStripMargin = true
align.stripMargin = true
runner.dialect = Scala3
Expand All @@ -9,3 +14,6 @@ fileOverride {
runner.dialect = scala3
}
}
optIn.breakChainOnFirstMethodDot = false
rewrite.trailingCommas.style = keep

52 changes: 45 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
lazy val scala213 = "2.13.12"
lazy val scala331 = "3.3.1"
lazy val scalaVer = scala331

lazy val supportedScalaVersions = List(scala213, scala331)
//lazy val supportedScalaVersions = List(scalaVer)

//ThisBuild / envFileName := "dev.env" // sbt-dotenv plugin gets build environment here
ThisBuild / organization := "org.vastblue"
ThisBuild / scalaVersion := scalaVer
ThisBuild / version := "0.8.3-SNAPSHOT"
ThisBuild / version := "0.8.4-SNAPSHOT"

ThisBuild / crossScalaVersions := supportedScalaVersions
ThisBuild / organization := "org.vastblue"
ThisBuild / organizationName := "vastblue.org"
ThisBuild / organizationHomepage := Some(url("https://vastblue.org/"))

ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/philwalk/pallet"),
"scm:git@github.com:philwalk/pallet.git"
)
)

lazy val root = (project in file("."))
.settings(
crossScalaVersions := supportedScalaVersions,
name := "pallet"
ThisBuild / developers.withRank(KeyRanks.Invisible) := List(
Developer(
id = "philwalk",
name = "Phil Walker",
email = "philwalk9@gmail.com",
url = url("https://github.com/philwalk")
)
)

// Remove all additional repository other than Maven Central from POM
ThisBuild / publishTo := {
// For accounts created after Feb 2021:
val nexus = "https://s01.oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

ThisBuild / publishMavenStyle.withRank(KeyRanks.Invisible) := true

ThisBuild / crossScalaVersions := supportedScalaVersions

// For all Sonatype accounts created on or after February 2021
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"

resolvers += Resolver.mavenLocal

publishTo := sonatypePublishToBundle.value

lazy val root = (project in file(".")).settings(
crossScalaVersions := supportedScalaVersions,
name := "pallet"
)

libraryDependencies ++= Seq(
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"com.github.sbt" % "junit-interface" % "0.13.3" % Test
)

// If you created a new account on or after February 2021, add sonatypeCredentialHost settings:

/*
* build.sbt
* SemanticDB is enabled for all sub-projects via ThisBuild scope.
Expand Down
70 changes: 70 additions & 0 deletions jsrc/classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env -S scala @./classpathAtfileWindows

import vastblue.pathextend.*
import vastblue.pathextend.*

lazy val (psep, cp) = {
val ps = sys.props("path.separator")
val clp = sys.props("java.class.path").split(ps)
(ps, clp)
}
lazy val homedir = sys.props("user.home").replace('\\', '/')
lazy val scriptName = sys.props("script.path").norm.replaceAll(".*/", "")

def usage(msg: String=""): Nothing = {
if ( msg.nonEmpty ){
printf("%s\n", msg)
}
printf("%s [<options>]\n", scriptName)
val info = Seq(
"-d ; list classpath directories",
"-j ; list classpath jars",
"-v ; verbose",
)
for (s <- info){
printf("%s\n", s)
}
sys.exit(0)
}

// analyze classpath, selectively showing dirs, jars and bad entries
// usage: ${0##*/} [-dirs] [-jars]"
def main(args: Array[String]): Unit =
var verbose = false
var (dirs, jars) = (true, false)
args.indices.foreach { i =>
args(i) match {
case "-v" => verbose = true
case "-d" | "-dirs" => dirs = !dirs
case "-j" | "-jars" => jars = !jars
case arg =>
usage(s"unrecognized arg [$arg]")
}
}
if (!dirs && !jars && !verbose){
usage()
}
if (verbose){
printf("psep[%s]\n", psep)
}
for (e <- cp){
val fname = if (e.startsWith("~")){
e.replaceFirst("~",homedir)
} else {
e
}
if (verbose){
printf("%s\n", fname.norm)
}
val p = java.nio.file.Paths.get(fname)
val isdir = p.toFile.isDirectory
val isfil = p.toFile.isFile
(isfil, isdir) match {
case (true, false) =>
if (jars) printf("jar: %s\n", p.norm)
case (false, true) =>
if (dirs) printf("dir: %s\n", p.norm)
case _ =>
printf("%5s: %5s: %s\n", isdir, isfil, p.norm)
}
}
8 changes: 6 additions & 2 deletions jsrc/platform.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S scala @classpathAtfileClassesDir
#!/usr/bin/env -S scala @classpathAtfile

// hashbang line requires an classpath @file, containing:
// -cp target/scala-3.3.0/classes
Expand All @@ -7,7 +7,11 @@
import vastblue.Platform

def main(args: Array[String]): Unit =
Platform.main(args)
if (args.contains("-verbose")){
Platform.main(args.filter { _ != "-verbose" })
}
val cygdrivePrefix = Platform.reverseMountMap.get("cygdrive").getOrElse("not-found")
printf("cygdrivePrefix: [%s]\n", cygdrivePrefix)
for ((k,v) <- Platform.mountMap){
printf("%-22s: %s\n", k, v)
}
34 changes: 34 additions & 0 deletions jsrc/typeMinusAp.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env -S scala @classpathAtfile

import vastblue.pathextend.*
import vastblue.Platform.{getStdout, envPath, isWindows}
import scala.util.control.Breaks._
import java.nio.file.{Files => JFiles, Paths => JPaths}

def main(args: Array[String]): Unit =
for (arg <- args){
val list = findAllInPath(arg)
printf("found %d [%s] in PATH:\n", list.size, arg)
for (path <- list) {
printf(" [%s] found at [%s]\n", arg, path.norm)
printf("--version: [%s]\n", getStdout(path.norm, "--version"))
}
}

def fsep = java.io.File.separator
def exeSuffix: String = if (isWindows) ".exe" else ""

def findAllInPath(prog: String): Seq[Path] = {
val progname = prog.replace('\\', '/').split("/").last // remove path, if present
var found = List.empty[Path]
for (dir <- envPath) {
// sort .exe suffix ahead of no .exe suffix
for (name <- Seq(s"$dir$fsep$progname$exeSuffix", s"$dir$fsep$progname").distinct) {
val p = JPaths.get(name)
if (p.toFile.isFile) {
found ::= p.normalize
}
}
}
found.reverse
}
6 changes: 6 additions & 0 deletions jsrc/where.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S scala
def main(args: Array[String]): Unit = {
import scala.sys.process._
val whereExe = Seq("where.exe", "where").lazyLines_!.take(1).toList.mkString("").replace('\\', '/')
printf("whereExe[%s]\n", whereExe)
}
15 changes: 13 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.11")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
val SONATYPE_VERSION = sys.env.getOrElse("SONATYPE_VERSION", "3.9.21")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.11")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % SONATYPE_VERSION)
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

//resolvers += Resolver.sonatypeRepo("snapshots")
resolvers ++= Resolver.sonatypeOssRepos("snapshots")
29 changes: 0 additions & 29 deletions src/main/scala-2.13/vastblue/DriveColon.scala

This file was deleted.

40 changes: 40 additions & 0 deletions src/main/scala-2.13/vastblue/DriveRoot.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package vastblue

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

// empty string or uppercase "[A-Z]:"
def apply(s: String): DriveRoot = {
require(s.length <= 2, s"bad DriveRoot String [$s]")
val str: String = s match {
case dl if dl.matches("^[a-zA-Z]:") => dl.toUpperCase
case dl if dl.matches("^[a-zA-Z]") => s"$dl:".toUpperCase
case _ => ""
}
str
}

implicit class DriveRootExtend(dl: DriveRoot) {
def letter: String = dl.substring(0, 1).toLowerCase
def string: String = dl
def isEmpty: Boolean = string.isEmpty
def isDrive: Boolean = !isEmpty
def toPath: Path = Paths.get(dl.string + "/")
def workingDir: Path = Paths.get(dl.string).toAbsolutePath

def posix: String = if (cygdrive.endsWith("/")) {
s"$cygdrive${letter}"
} else {
s"$cygdrive/$letter" // Platform.cygdrive might be "/"
}
}
}
7 changes: 3 additions & 4 deletions src/main/scala-2.13/vastblue/file/EzPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EzPath(val initstring: String, val sl: Slash) {
}
}
object EzPath {
implicit class StExtend(s: String){
implicit class StExtend(s: String) {
def slash: String = s
}
// val winu = EzPath("c:\\opt", Unx) // valid
Expand Down Expand Up @@ -80,10 +80,9 @@ object EzPath {

def isWindows = !notWindows


def platformPrefix: String = Paths.get(".").toAbsolutePath.getRoot.toString match {
case "/" => ""
case s => s.take(2)
case s => s.take(2)
}

def winlikePathstr(s: String): Boolean = {
Expand All @@ -108,7 +107,7 @@ object EzPath {
override def toString = abs
}

implicit class PathExt(p: Path){
implicit class PathExt(p: Path) {
def slash(sl: Slash): String = {
if (sl == Win) {
p.toString.replace('/', '\\')
Expand Down
Loading

0 comments on commit 4074577

Please sign in to comment.