Skip to content

Commit

Permalink
Add support for Class-Path entries in Manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Jul 8, 2024
1 parent 78b3f4a commit f9df501
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 11 additions & 2 deletions compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ class ClassPathFactory {

// Internal
protected def classesInPathImpl(path: String, expand: Boolean)(using Context): List[ClassPath] =
for {
val files = for {
file <- expandPath(path, expand)
dir <- {
def asImage = if (file.endsWith(".jimage")) Some(AbstractFile.getFile(file)) else None
Option(AbstractFile.getDirectory(file)).orElse(asImage)
}
}
yield newClassPath(dir)
yield dir

val expanded = for file <- files
a <- ClassPath.expandManifestPath(file.absolutePath)
yield
newClassPath(AbstractFile.getFile(a.getPath().toString()))

files.map(newClassPath) ++ expanded

end classesInPathImpl

private def createSourcePath(file: AbstractFile)(using Context): ClassPath =
if (file.isJarOrZip)
Expand Down
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/io/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ object ClassPath {

val baseDir = file.parent
new Jar(file).classPathElements map (elem =>
specToURL(elem) getOrElse (baseDir / elem).toURL
specToURL(elem, baseDir) getOrElse (baseDir / elem).toURL
)
}

def specToURL(spec: String): Option[URL] =
try Some(new URI(spec).toURL)
catch case _: MalformedURLException | _: URISyntaxException => None
def specToURL(spec: String, basedir: Directory): Option[URL] =
try
val uri = new URI(spec)
if uri.isAbsolute() then Some(uri.toURL())
else
Some(basedir.resolve(Path(spec)).toURL)
catch
case _: MalformedURLException | _: URISyntaxException => None

def manifests: List[java.net.URL] = {
import scala.jdk.CollectionConverters.EnumerationHasAsScala
Expand Down

0 comments on commit f9df501

Please sign in to comment.