@@ -112,32 +112,22 @@ class ExtractDependencies extends Phase {
112
112
def binaryDependency (file : File , binaryClassName : String ) =
113
113
ctx.sbtCallback.binaryDependency(file, binaryClassName, fromClassName, sourceFile, dep.context)
114
114
115
- def processExternalDependency (depFile : AbstractFile ) = {
116
- def binaryClassName (classSegments : List [String ]) =
117
- classSegments.mkString(" ." ).stripSuffix(" .class" )
118
-
115
+ def processExternalDependency (depFile : AbstractFile , binaryClassName : String ) = {
119
116
depFile match {
120
117
case ze : ZipArchive # Entry => // The dependency comes from a JAR
121
- for (zip <- ze.underlyingSource; zipFile <- Option (zip.file)) {
122
- val classSegments = io.File (ze.path).segments
123
- binaryDependency(zipFile, binaryClassName(classSegments))
124
- }
125
-
118
+ ze.underlyingSource match
119
+ case Some (zip) if zip.file != null =>
120
+ binaryDependency(zip.file, binaryClassName)
121
+ case _ =>
126
122
case pf : PlainFile => // The dependency comes from a class file
127
- val packages = dep.to.ownersIterator
128
- .count(x => x.is(PackageClass ) && ! x.isEffectiveRoot)
129
- // We can recover the fully qualified name of a classfile from
130
- // its path
131
- val classSegments = pf.givenPath.segments.takeRight(packages + 1 )
132
123
// FIXME: pf.file is null for classfiles coming from the modulepath
133
124
// (handled by JrtClassPath) because they cannot be represented as
134
125
// java.io.File, since the `binaryDependency` callback must take a
135
126
// java.io.File, this means that we cannot record dependencies coming
136
127
// from the modulepath. For now this isn't a big deal since we only
137
128
// support having the standard Java library on the modulepath.
138
- if (pf.file != null )
139
- binaryDependency(pf.file, binaryClassName(classSegments))
140
-
129
+ if pf.file != null then
130
+ binaryDependency(pf.file, binaryClassName)
141
131
case _ =>
142
132
report.warning(s " sbt-deps: Ignoring dependency $depFile of class ${depFile.getClass}} " )
143
133
}
@@ -149,7 +139,25 @@ class ExtractDependencies extends Phase {
149
139
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
150
140
if (depFile.extension == " class" ) {
151
141
// Dependency is external -- source is undefined
152
- processExternalDependency(depFile)
142
+
143
+ // The fully qualified name on the JVM of the class corresponding to `dep.to`
144
+ val binaryClassName = {
145
+ val builder = new StringBuilder
146
+ val pkg = dep.to.enclosingPackageClass
147
+ if (! pkg.isEffectiveRoot) {
148
+ builder.append(pkg.fullName.mangledString)
149
+ builder.append(" ." )
150
+ }
151
+ val flatName = dep.to.flatName
152
+ // We create fake companion object symbols to hold the static members
153
+ // of Java classes, make sure to use the name of the actual Java class
154
+ // here.
155
+ val clsFlatName = if (dep.to.is(JavaDefined )) flatName.stripModuleClassSuffix else flatName
156
+ builder.append(clsFlatName.mangledString)
157
+ builder.toString
158
+ }
159
+
160
+ processExternalDependency(depFile, binaryClassName)
153
161
} else if (allowLocal || depFile.file != sourceFile) {
154
162
// We cannot ignore dependencies coming from the same source file because
155
163
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
0 commit comments