Skip to content

Commit

Permalink
refactored RuleCompiler companion obj into own file for reusability
Browse files Browse the repository at this point in the history
  • Loading branch information
rvacaru committed Jul 29, 2022
1 parent 10828f7 commit dc787e2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,4 @@ class RuleCompiler(
.map(_.notOk)
.getOrElse(Configured.Ok(classLoader))
}
}
object RuleCompiler {

def defaultClasspath: String = {
defaultClasspathPaths.mkString(File.pathSeparator)
}

def defaultClasspathPaths: List[AbsolutePath] = {
val classLoader = ClasspathOps.thisClassLoader
val paths = classLoader.getURLs.iterator.map { u =>
if (u.getProtocol.startsWith("bootstrap")) {
import java.nio.file._
val stream = u.openStream
val tmp = Files.createTempFile("bootstrap-" + u.getPath, ".jar")
try {
Files.copy(stream, tmp, StandardCopyOption.REPLACE_EXISTING)
} finally {
stream.close()
}
AbsolutePath(tmp)
} else {
AbsolutePath(Paths.get(u.toURI))
}
}
paths.toList
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,4 @@ class RuleCompiler(

Configured.Ok(classLoader)
}
}
object RuleCompiler {

def defaultClasspath: String = {
defaultClasspathPaths.mkString(File.pathSeparator)
}

def defaultClasspathPaths: List[AbsolutePath] = {
val classLoader = ClasspathOps.thisClassLoader
val paths = classLoader.getURLs.iterator.map { u =>
if (u.getProtocol.startsWith("bootstrap")) {
import java.nio.file._
val stream = u.openStream
val tmp = Files.createTempFile("bootstrap-" + u.getPath, ".jar")
try {
Files.copy(stream, tmp, StandardCopyOption.REPLACE_EXISTING)
} finally {
stream.close()
}
AbsolutePath(tmp)
} else {
AbsolutePath(Paths.get(u.toURI))
}
}
paths.toList
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScalafixToolbox {
new function.Function[String, RuleCompiler] {
override def apply(classpath: String) =
new RuleCompiler(
classpath + File.pathSeparator + RuleCompiler.defaultClasspath
classpath + File.pathSeparator + RuleCompilerClasspath.defaultClasspath
)
}

Expand Down

0 comments on commit dc787e2

Please sign in to comment.