From f6b05534cc4af0ad78622a3a7e687dbe1e1f8a1c Mon Sep 17 00:00:00 2001 From: andres-pipicello-olx <36170539+andres-pipicello-olx@users.noreply.github.com> Date: Thu, 31 Jan 2019 09:07:43 -0300 Subject: Added compiler-classpath properties to generated IntelliJ xml files (#531) --- scalalib/src/GenIdeaImpl.scala | 62 ++++++++++++++++++---- .../idea/libraries/scala-library-2.12.4.jar.xml | 8 +++ 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 07b32a3e..e815ffbd 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -8,6 +8,7 @@ import mill.api.Ctx.{Home, Log} import mill.api.Strict.Agg import mill.api.{Loose, Strict} import mill.{T, scalalib} +import os.Path import scala.util.Try @@ -98,12 +99,33 @@ object GenIdeaImpl { .filter(_.toIO.exists) }.getOrElse(Seq()) + case class ResolvedModule( + path: Segments, + classpath: Loose.Agg[Path], + module: JavaModule, + pluginClasspath: Loose.Agg[Path], + scalaOptions: Seq[String], + compilerClasspath: Loose.Agg[Path], + libraryClasspath: Loose.Agg[Path] + ) + val resolved = for((path, mod) <- modules) yield { val scalaLibraryIvyDeps = mod match{ case x: ScalaModule => x.scalaLibraryIvyDeps - case _ => T.task{Nil} + case _ => T.task{Loose.Agg.empty[Dep]} } val allIvyDeps = T.task{mod.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ mod.compileIvyDeps()} + + val scalaCompilerClasspath = mod match{ + case x: ScalaModule => x.scalaCompilerClasspath + case _ => T.task{Loose.Agg.empty[PathRef]} + } + + + val externalLibraryDependencies = T.task{ + mod.resolveDeps(scalaLibraryIvyDeps)() + } + val externalDependencies = T.task{ mod.resolveDeps(allIvyDeps)() ++ Task.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten @@ -124,19 +146,26 @@ object GenIdeaImpl { val resolvedCp: Loose.Agg[PathRef] = evalOrElse(evaluator, externalDependencies, Loose.Agg.empty) val resolvedSrcs: Loose.Agg[PathRef] = evalOrElse(evaluator, externalSources, Loose.Agg.empty) val resolvedSp: Loose.Agg[PathRef] = evalOrElse(evaluator, scalacPluginDependencies, Loose.Agg.empty) + val resolvedCompilerCp: Loose.Agg[PathRef] = evalOrElse(evaluator, scalaCompilerClasspath, Loose.Agg.empty) + val resolvedLibraryCp: Loose.Agg[PathRef] = evalOrElse(evaluator, externalLibraryDependencies, Loose.Agg.empty) val scalacOpts: Seq[String] = evalOrElse(evaluator, scalacOptions, Seq()) - ( + ResolvedModule( path, resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path), mod, resolvedSp.map(_.path).filter(_.ext == "jar"), - scalacOpts + scalacOpts, + resolvedCompilerCp.map(_.path), + resolvedLibraryCp.map(_.path) ) } + val moduleLabels = modules.map(_.swap).toMap - val allResolved = resolved.flatMap(_._2) ++ buildLibraryPaths ++ buildDepsPaths + val allResolved = resolved.flatMap(_.classpath) ++ buildLibraryPaths ++ buildDepsPaths + + val librariesProperties = resolved.flatMap(x => x.libraryClasspath.map(_ -> x.compilerClasspath)).toMap val commonPrefix = if (allResolved.isEmpty) 0 @@ -216,8 +245,8 @@ object GenIdeaImpl { val compilerSettings = resolved .foldLeft(Map[(Loose.Agg[os.Path], Seq[String]), Vector[JavaModule]]()) { (r, q) => - val key = (q._4, q._5) - r + (key -> (r.getOrElse(key, Vector()) :+ q._3)) + val key = (q.pluginClasspath, q.scalaOptions) + r + (key -> (r.getOrElse(key, Vector()) :+ q.module)) } val allBuildLibraries : Set[ResolvedLibrary] = @@ -249,16 +278,15 @@ object GenIdeaImpl { val libraries = resolvedLibraries(allResolved).map{ resolved => import resolved.path - val url = if (path.ext == "jar") "jar://" + path + "!/" else "file://" + path val name = libraryName(resolved) val sources = resolved match { case CoursierResolved(_, _, s) => s.map(p => "jar://" + p + "!/") case OtherResolved(_) => None } - Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, url, sources)) + Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, path, sources, librariesProperties.getOrElse(path, Loose.Agg.empty))) } - val moduleFiles = resolved.map{ case (path, resolvedDeps, mod, _, _) => + val moduleFiles = resolved.map{ case ResolvedModule(path, resolvedDeps, mod, _, _, _, _) => val Seq( resourcesPathRefs: Seq[PathRef], sourcesPathRef: Seq[PathRef], @@ -375,9 +403,21 @@ object GenIdeaImpl { } - def libraryXmlTemplate(name: String, url: String, sources: Option[String]) = { + def libraryXmlTemplate(name: String, path: os.Path, sources: Option[String], compilerClassPath: Loose.Agg[Path]) = { + val url = if (path.ext == "jar") "jar://" + path + "!/" else "file://" + path + val isScalaLibrary = compilerClassPath.nonEmpty - + + { if(isScalaLibrary) { + + + { + compilerClassPath.toList.sortBy(_.wrapped).map(p => ) + } + + + } + } diff --git a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml index 5f6d7263..5f7c5056 100644 --- a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml +++ b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml @@ -1,5 +1,13 @@ + + + + + + + + -- cgit v1.2.3