diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-27 19:15:36 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-04-02 03:32:03 -0400 |
commit | 52b30bcd4c1bb46879075f3a77d6eb3df3688c3a (patch) | |
tree | af9c68bc41e99f0bb2e44141dcdce2003d26b43c /stage1 | |
parent | 2476e2ec1100813ae4e05cf2183feff8bf5ec8ea (diff) | |
download | cbt-52b30bcd4c1bb46879075f3a77d6eb3df3688c3a.tar.gz cbt-52b30bcd4c1bb46879075f3a77d6eb3df3688c3a.tar.bz2 cbt-52b30bcd4c1bb46879075f3a77d6eb3df3688c3a.zip |
verify classpath feature to identify duplicate classes
Diffstat (limited to 'stage1')
-rw-r--r-- | stage1/ClassPath.scala | 30 | ||||
-rw-r--r-- | stage1/resolver.scala | 5 |
2 files changed, 33 insertions, 2 deletions
diff --git a/stage1/ClassPath.scala b/stage1/ClassPath.scala index 539efc7..b13bdaf 100644 --- a/stage1/ClassPath.scala +++ b/stage1/ClassPath.scala @@ -27,4 +27,34 @@ case class ClassPath(files: Seq[File] = Seq()){ if( f.getName.endsWith(".jar") /* !f.isDirectory */ ) "" else "/" ) }.sorted + + def verify( lib: Stage1Lib ) = { + val ( directories, jarFiles ) = files.partition(_.isDirectory) + val all = lib.autoRelative( + directories + ) ++ jarFiles.flatMap{ f => + import collection.JavaConverters._ + new java.util.jar.JarFile(f).entries.asScala.filterNot(_.isDirectory).toVector.map( + f -> _.toString + ) + } + val duplicates = + all + .groupBy( _._2 ) + .filter( _._2.size > 1 ) + .filter( _._1 endsWith ".class" ) + .mapValues( _.map( _._1 ) ) + .toSeq + .sortBy( _._1 ) + assert( + duplicates.isEmpty, + { + "Conflicting:\n\n" + + duplicates.map{ + case ( path, locations ) => + path + " exits in multiple locations:\n" + locations.mkString("\n") + }.mkString("\n\n") + } + ) + } } diff --git a/stage1/resolver.scala b/stage1/resolver.scala index 48099e5..f4a9b13 100644 --- a/stage1/resolver.scala +++ b/stage1/resolver.scala @@ -130,8 +130,9 @@ trait DependencyImplementation extends Dependency{ } // FIXME: these probably need to update outdated as well - def classpath : ClassPath = exportedClasspath ++ dependencyClasspath - def dependencyClasspath : ClassPath = taskCache[DependencyImplementation]( "dependencyClasspath" ).memoize{ + def classpath: ClassPath = exportedClasspath ++ dependencyClasspath + def verifyClasspath: Unit = classpath.verify(lib) + def dependencyClasspath: ClassPath = taskCache[DependencyImplementation]( "dependencyClasspath" ).memoize{ ClassPath( transitiveDependencies .flatMap(_.exportedClasspath.files) |