-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PathMatcher: move to sysops, for sbt-scalafmt
- Loading branch information
Showing
11 changed files
with
61 additions
and
69 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
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
16 changes: 0 additions & 16 deletions
16
scalafmt-core/jvm-native/src/main/scala/org/scalafmt/config/PlatformPathMatcher.scala
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
scalafmt-core/shared/src/main/scala/org/scalafmt/config/PathMatcher.scala
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
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
8 changes: 3 additions & 5 deletions
8
...scalafmt/config/PlatformPathMatcher.scala → ...scalafmt/sysops/PlatformPathMatcher.scala
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
19 changes: 19 additions & 0 deletions
19
scalafmt-sysops/jvm-native/src/main/scala/org/scalafmt/sysops/PlatformPathMatcher.scala
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,19 @@ | ||
package org.scalafmt.sysops | ||
|
||
import java.nio.file | ||
|
||
object PlatformPathMatcher { | ||
val fs: file.FileSystem = file.FileSystems.getDefault | ||
|
||
def apply(pattern: String): PathMatcher = { | ||
try fs.getPathMatcher(pattern) | ||
catch { | ||
case e: IllegalArgumentException => | ||
val sb = new StringBuilder() | ||
sb.append("Invalid path matcher pattern: ").append(pattern) | ||
val err = e.getMessage | ||
if (null != err && err.nonEmpty) sb.append("; ").append(err) | ||
throw new ScalafmtSysException(sb.toString()) | ||
} | ||
}.matches | ||
} |
27 changes: 27 additions & 0 deletions
27
scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/PathMatcher.scala
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,27 @@ | ||
package org.scalafmt.sysops | ||
|
||
import java.nio.file.Path | ||
import java.util.regex.Pattern | ||
|
||
trait PathMatcher { | ||
def matches(path: Path): Boolean | ||
} | ||
|
||
object PathMatcher { | ||
|
||
class Regex(pattern: Pattern) extends PathMatcher { | ||
def matches(path: Path): Boolean = pattern.matcher(path.toString).find() | ||
} | ||
|
||
object Regex { | ||
def apply(regex: String): Regex = | ||
try new Regex(Pattern.compile(regex)) | ||
catch { | ||
case e: Throwable => | ||
val msg = s"Invalid path patcher regex: /$regex/; ${e.getMessage}" | ||
throw new ScalafmtSysException(msg) | ||
} | ||
|
||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
scalafmt-sysops/shared/src/main/scala/org/scalafmt/sysops/ScalafmtSysException.scala
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,3 @@ | ||
package org.scalafmt.sysops | ||
|
||
class ScalafmtSysException(e: String) extends Exception(e) |