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 10, 2024
1 parent 78b3f4a commit 90b20fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 19 additions & 2 deletions compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dotty.tools.io.{AbstractFile, VirtualDirectory}
import FileUtils.*
import dotty.tools.io.ClassPath
import dotty.tools.dotc.core.Contexts.*
import java.nio.file.Files

/**
* Provides factory methods for classpath. When creating classpath instances for a given path,
Expand Down Expand Up @@ -52,14 +53,30 @@ 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 =
if ctx.settings.usejavacp.value || scala.util.Properties.propOrFalse("scala.usejavacp") then
for
file <- files
a <- ClassPath.expandManifestPath(file.absolutePath)
path = java.nio.file.Paths.get(a.toURI()).nn
if Files.exists(path)
yield
newClassPath(AbstractFile.getFile(path))
else
Seq.empty

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
2 changes: 1 addition & 1 deletion project/RepublishPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ object RepublishPlugin extends AutoPlugin {

def compose(libs: List[String]): List[String] =
libs.map(fuzzyFind(classpaths, _)).reduceOption(_ ++ _).map(_.distinct).getOrElse(Nil)

// Compute the classpath entries
val entries = compose(actual).diff(compose(subtractions))
// Generate the MANIFEST for the pathing jar
Expand Down

0 comments on commit 90b20fe

Please sign in to comment.