From 8b77cf6cec10d5f573f56283eca4302029b49d42 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Fri, 24 May 2019 22:14:57 -0300 Subject: Using coursier for reading poms instead of ad-hoc xml parsing --- scalalib/src/GenIdeaImpl.scala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'scalalib') diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 2db28327..a9eefc65 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -1,6 +1,8 @@ package mill.scalalib import ammonite.runtime.SpecialClassLoader +import coursier.core.compatibility.xmlParseDom +import coursier.maven.Pom import coursier.{LocalRepositories, Repositories} import mill.api.Ctx.{Home, Log} import mill.api.Strict.Agg @@ -207,19 +209,15 @@ object GenIdeaImpl { // Hack so that Intellij does not complain about unresolved magic // imports in build.sc when in fact they are resolved - def sbtLibraryNameFromPom(pom : os.Path) : String = { - val xml = scala.xml.XML.loadFile(pom.toIO) - - val parent = xml \ "parent" - val artifactId = (xml \ "artifactId").text - val groupId = Some(xml \ "groupId").filter(_.nonEmpty).getOrElse(parent \ "groupId").text - val version = Some(xml \ "version").filter(_.nonEmpty).getOrElse(parent \ "version").text + def sbtLibraryNameFromPom(pomPath : os.Path) : String = { + val pom = xmlParseDom(os.read(pomPath)).flatMap(Pom.project).right.get + val artifactId = pom.module.name.value val artifactWithScalaVersion = artifactId.substring(artifactId.length - 5) match { case "_2.10" | "_2.11" | "_2.12" => artifactId case _ => artifactId + "_2.12" } - s"SBT: $groupId:$artifactWithScalaVersion:$version:jar" + s"SBT: ${pom.module.organization.value}:$artifactWithScalaVersion:${pom.version}:jar" } def libraryNames(resolvedJar: ResolvedLibrary) : Seq[String] = resolvedJar match { -- cgit v1.2.3