summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Roeser <le.petit.fou@web.de>2019-10-24 09:19:48 +0200
committerGitHub <noreply@github.com>2019-10-24 09:19:48 +0200
commit4f3942f42db2a95afba8cefdba92f35aae1f4962 (patch)
tree77e6f7684fe6278d593ec4f5953c65b02266dd15
parent32a3ef704c198da692c1985bae55aca5130ad9c6 (diff)
downloadmill-4f3942f42db2a95afba8cefdba92f35aae1f4962.tar.gz
mill-4f3942f42db2a95afba8cefdba92f35aae1f4962.tar.bz2
mill-4f3942f42db2a95afba8cefdba92f35aae1f4962.zip
GenIdea: Improves sources handling, better guessing and triggering to download (#719)
See also https://github.com/lihaoyi/mill/issues/708
-rwxr-xr-xscalalib/src/GenIdeaImpl.scala32
1 files changed, 28 insertions, 4 deletions
diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala
index 9280949d..c0e41426 100755
--- a/scalalib/src/GenIdeaImpl.scala
+++ b/scalalib/src/GenIdeaImpl.scala
@@ -1,5 +1,7 @@
package mill.scalalib
+import scala.collection.immutable
+
import ammonite.runtime.SpecialClassLoader
import coursier.core.compatibility.xmlParseDom
import coursier.maven.Pom
@@ -84,8 +86,8 @@ case class GenIdeaImpl(evaluator: Evaluator,
.map(x => (x.millModuleSegments, x))
.toSeq
.distinct
-
- val buildLibraryPaths =
+
+ val buildLibraryPaths: immutable.Seq[Path] =
if (!fetchMillModules) Nil
else sys.props.get("MILL_BUILD_LIBRARIES") match {
case Some(found) => found.split(',').map(os.Path(_)).distinct.toList
@@ -101,6 +103,20 @@ case class GenIdeaImpl(evaluator: Evaluator,
None,
ctx
)
+
+ // Also trigger resolve sources, but don't use them (will happen implicitly by Idea)
+ {
+ scalalib.Lib.resolveDependencies(
+ repos.toList,
+ Lib.depToDependency(_, "2.12.8", ""),
+ for(name <- artifactNames)
+ yield ivy"com.lihaoyi::mill-$name:${sys.props("MILL_VERSION")}",
+ true,
+ None,
+ ctx
+ )
+ }
+
res.items.toList.map(_.path)
}
@@ -250,13 +266,14 @@ case class GenIdeaImpl(evaluator: Evaluator,
.toMap
sealed trait ResolvedLibrary { def path : os.Path }
- case class CoursierResolved(path : os.Path, pom : os.Path, sources : Option[os.Path])
- extends ResolvedLibrary
+ case class CoursierResolved(path : os.Path, pom : os.Path, sources : Option[os.Path]) extends ResolvedLibrary
case class OtherResolved(path : os.Path) extends ResolvedLibrary
+ case class WithSourcesResolved(path : os.Path, sources: Option[os.Path]) extends ResolvedLibrary
// Tries to group jars with their poms and sources.
def toResolvedJar(path : os.Path) : Option[ResolvedLibrary] = {
val inCoursierCache = path.startsWith(os.Path(coursier.paths.CoursierPaths.cacheDirectory()))
+ val inIvyLikeLocal = (path / os.up).last == "jars"
val isSource = path.last.endsWith("sources.jar")
val isPom = path.ext == "pom"
if (inCoursierCache && (isSource || isPom)) {
@@ -268,6 +285,10 @@ case class GenIdeaImpl(evaluator: Evaluator,
val sources = Some(path / os.up / s"$withoutExt-sources.jar")
.filter(_.toIO.exists())
Some(CoursierResolved(path, pom, sources))
+ } else if (inIvyLikeLocal && path.ext == "jar") {
+ val sources = Some(path / os.up / os.up / "srcs" / s"${path.baseName}-sources.jar")
+ .filter(_.toIO.exists())
+ Some(WithSourcesResolved(path, sources))
} else Some(OtherResolved(path))
}
@@ -290,6 +311,8 @@ case class GenIdeaImpl(evaluator: Evaluator,
Seq(sbtLibraryNameFromPom(pom), pathToLibName(path))
case CoursierResolved(path, _, _) =>
Seq(pathToLibName(path))
+ case WithSourcesResolved(path, _) =>
+ Seq(pathToLibName(path))
case OtherResolved(path) =>
Seq(pathToLibName(path))
}
@@ -335,6 +358,7 @@ case class GenIdeaImpl(evaluator: Evaluator,
val names = libraryNames(resolved)
val sources = resolved match {
case CoursierResolved(_, _, s) => s.map(p => "jar://" + p + "!/")
+ case WithSourcesResolved(_, s) => s.map(p => "jar://" + p + "!/")
case OtherResolved(_) => None
}
for(name <- names) yield Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, path, sources, librariesProperties.getOrElse(path, Loose.Agg.empty)))