-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consolidate PathSpec / FileSpec tests, fix formatting
- Loading branch information
Showing
24 changed files
with
791 additions
and
1,029 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ jsrc/*.jar | |
.bloop/ | ||
metals.sbt | ||
.vscode | ||
*Atfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.