Skip to content

Commit 90b20fe

Browse files
committed
Add support for Class-Path entries in Manifest
1 parent 78b3f4a commit 90b20fe

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dotty.tools.io.{AbstractFile, VirtualDirectory}
77
import FileUtils.*
88
import dotty.tools.io.ClassPath
99
import dotty.tools.dotc.core.Contexts.*
10+
import java.nio.file.Files
1011

1112
/**
1213
* Provides factory methods for classpath. When creating classpath instances for a given path,
@@ -52,14 +53,30 @@ class ClassPathFactory {
5253

5354
// Internal
5455
protected def classesInPathImpl(path: String, expand: Boolean)(using Context): List[ClassPath] =
55-
for {
56+
val files = for {
5657
file <- expandPath(path, expand)
5758
dir <- {
5859
def asImage = if (file.endsWith(".jimage")) Some(AbstractFile.getFile(file)) else None
5960
Option(AbstractFile.getDirectory(file)).orElse(asImage)
6061
}
6162
}
62-
yield newClassPath(dir)
63+
yield dir
64+
65+
val expanded =
66+
if ctx.settings.usejavacp.value || scala.util.Properties.propOrFalse("scala.usejavacp") then
67+
for
68+
file <- files
69+
a <- ClassPath.expandManifestPath(file.absolutePath)
70+
path = java.nio.file.Paths.get(a.toURI()).nn
71+
if Files.exists(path)
72+
yield
73+
newClassPath(AbstractFile.getFile(path))
74+
else
75+
Seq.empty
76+
77+
files.map(newClassPath) ++ expanded
78+
79+
end classesInPathImpl
6380

6481
private def createSourcePath(file: AbstractFile)(using Context): ClassPath =
6582
if (file.isJarOrZip)

compiler/src/dotty/tools/io/ClassPath.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,18 @@ object ClassPath {
152152

153153
val baseDir = file.parent
154154
new Jar(file).classPathElements map (elem =>
155-
specToURL(elem) getOrElse (baseDir / elem).toURL
155+
specToURL(elem, baseDir) getOrElse (baseDir / elem).toURL
156156
)
157157
}
158158

159-
def specToURL(spec: String): Option[URL] =
160-
try Some(new URI(spec).toURL)
161-
catch case _: MalformedURLException | _: URISyntaxException => None
159+
def specToURL(spec: String, basedir: Directory): Option[URL] =
160+
try
161+
val uri = new URI(spec)
162+
if uri.isAbsolute() then Some(uri.toURL())
163+
else
164+
Some(basedir.resolve(Path(spec)).toURL)
165+
catch
166+
case _: MalformedURLException | _: URISyntaxException => None
162167

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

project/RepublishPlugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ object RepublishPlugin extends AutoPlugin {
220220

221221
def compose(libs: List[String]): List[String] =
222222
libs.map(fuzzyFind(classpaths, _)).reduceOption(_ ++ _).map(_.distinct).getOrElse(Nil)
223-
223+
224224
// Compute the classpath entries
225225
val entries = compose(actual).diff(compose(subtractions))
226226
// Generate the MANIFEST for the pathing jar

0 commit comments

Comments
 (0)