Skip to content

Commit

Permalink
Merge pull request #3 from alexarchambault/missing-dir
Browse files Browse the repository at this point in the history
Handle globs on missing directories
  • Loading branch information
alexarchambault committed May 5, 2023
2 parents a52a6bf + 4b020ca commit 2f27bd9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 10 additions & 7 deletions coursier/cputil/ClassPathUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object ClassPathUtil {
private implicit class CustomStringOps(private val str: String) extends AnyVal {
def endsWithIgnoreCase(suffix: String): Boolean =
str.length >= suffix.length &&
suffix.compareToIgnoreCase(str.substring(str.length - suffix.length)) == 0
suffix.compareToIgnoreCase(str.substring(str.length - suffix.length)) == 0
}

private val propertyRegex = Pattern.compile(
Expand Down Expand Up @@ -44,12 +44,15 @@ object ClassPathUtil {
value
}
def allJarsOf(dir: Path): Seq[Path] =
Files.list(dir)
.iterator
.asScala
.filter(_.toString.endsWithIgnoreCase(".jar"))
.toVector
.sortBy(_.getFileName)
if (Files.isDirectory(dir))
Files.list(dir)
.iterator
.asScala
.filter(_.toString.endsWithIgnoreCase(".jar"))
.toVector
.sortBy(_.getFileName)
else
Nil
val allJarsSuffixes = Seq("/", File.separator)
.distinct
.flatMap(sep => Seq("*", "*.jar").map(sep + _))
Expand Down
12 changes: 12 additions & 0 deletions test/coursier/cputil/tests/ClassPathUtilTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ class ClassPathUtilTests extends munit.FunSuite {
}
}

test("star missing dir") {
val tmpDir = os.temp.dir(prefix = "class-path-util-tests")

val sep = File.separator

for (glob <- testGlobs) {
val res =
ClassPathUtil.classPath(s"${tmpDir / "foo"}$sep$glob", _ => None).map(os.Path(_, os.pwd))
expect(res.isEmpty)
}
}

test("property") {
val initialCp = os.proc("cs", "fetch", "org.scala-lang:scala3-compiler_3:3.1.3")
.call()
Expand Down

0 comments on commit 2f27bd9

Please sign in to comment.