@@ -1488,164 +1488,9 @@ commands ++= {
14881488
14891489addCommandAlias(" scalap" , " scalap/compile:runMain scala.tools.scalap.Main -usejavacp" )
14901490
1491- lazy val intellij = taskKey[Unit ](" Update the library classpaths in the IntelliJ project files." )
1492-
1493- def moduleDeps (p : Project , config : Configuration = Compile ) = (p / config / externalDependencyClasspath).map(a => (p.id, a.map(_.data)))
1494-
14951491// aliases to projects to prevent name clashes
1496- def compilerP = compiler
14971492def testP = test
14981493
1499- intellij := {
1500- import xml ._
1501- import xml .transform ._
1502-
1503- val s = streams.value
1504- val compilerScalaInstance = (LocalProject (" compiler" ) / scalaInstance).value
1505-
1506- val modules : List [(String , Seq [File ])] = {
1507- // for the sbt build module, the dependencies are fetched from the project's build using sbt-buildinfo
1508- val buildModule = (" scala-build" , scalabuild.BuildInfo .buildClasspath.split(java.io.File .pathSeparator).toSeq.map(new File (_)))
1509- // `sbt projects` lists all modules in the build
1510- buildModule :: List (
1511- moduleDeps(bench).value,
1512- moduleDeps(compilerP).value,
1513- moduleDeps(interactive).value,
1514- moduleDeps(junit).value,
1515- moduleDeps(library).value,
1516- moduleDeps(manual).value,
1517- moduleDeps(partest).value,
1518- moduleDeps(partestJavaAgent).value,
1519- moduleDeps(reflect).value,
1520- moduleDeps(repl).value,
1521- moduleDeps(replFrontend).value,
1522- moduleDeps(scalacheck, config = Test ).value.copy(_1 = " scalacheck-test" ),
1523- moduleDeps(scaladoc).value,
1524- moduleDeps(scalap).value,
1525- moduleDeps(tastytest).value,
1526- moduleDeps(testP).value,
1527- moduleDeps(testkit).value,
1528- )
1529- }
1530-
1531- def moduleDep (name : String , jars : Seq [File ]) = {
1532- val entries = jars.map(f => s """ <root url="jar:// ${f.toURI.getPath}!/" /> """ ).mkString(" \n " )
1533- s """ | <library name=" $name-deps">
1534- | <CLASSES>
1535- | $entries
1536- | </CLASSES>
1537- | <JAVADOC />
1538- | <SOURCES />
1539- | </library> """ .stripMargin
1540- }
1541-
1542- def starrDep (jars : Seq [File ]) = {
1543- val entries = jars.map(f => s """ <root url="file:// ${f.toURI.getPath}" /> """ ).mkString(" \n " )
1544- s """ | <library name="starr" type="Scala">
1545- | <properties>
1546- | <option name="languageLevel" value="Scala_2_12" />
1547- | <compiler-classpath>
1548- | $entries
1549- | </compiler-classpath>
1550- | </properties>
1551- | <CLASSES />
1552- | <JAVADOC />
1553- | <SOURCES />
1554- | </library> """ .stripMargin
1555- }
1556-
1557- def replaceLibrary (data : Node , libName : String , libType : Option [String ], newContent : String ) = {
1558- object rule extends RewriteRule {
1559- var transformed = false
1560- def checkAttrs (attrs : MetaData ) = {
1561- def check (key : String , expected : String ) = {
1562- val a = attrs(key)
1563- a != null && a.text == expected
1564- }
1565- check(" name" , libName) && libType.forall(tp => check(" type" , tp))
1566- }
1567-
1568- override def transform (n : Node ): Seq [Node ] = n match {
1569- case e @ Elem (_, " library" , attrs, _, _* ) if checkAttrs(attrs) =>
1570- transformed = true
1571- XML .loadString(newContent)
1572- case other =>
1573- other
1574- }
1575- }
1576- object trans extends RuleTransformer (rule)
1577- val r = trans(data)
1578- if (! rule.transformed) sys.error(s " Replacing library classpath for $libName failed, no existing library found. " )
1579- r
1580- }
1581-
1582- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1583- val ipr = intellijDir / " scala.ipr"
1584- backupIdea(intellijDir)
1585- if (! ipr.exists) {
1586- intellijCreateFromSample((ThisBuild / baseDirectory).value)
1587- }
1588- s.log.info(" Updating library classpaths in src/intellij/scala.ipr." )
1589- val content = XML .loadFile(ipr)
1590-
1591- val newStarr = replaceLibrary(content, " starr" , Some (" Scala" ), starrDep(compilerScalaInstance.allJars))
1592- val newModules = modules.foldLeft(newStarr)({
1593- case (res, (modName, jars)) =>
1594- if (jars.isEmpty) res // modules without dependencies
1595- else replaceLibrary(res, s " $modName-deps " , None , moduleDep(modName, jars))
1596- })
1597-
1598- // I can't figure out how to keep the entity escapes for \n in the attribute values after this use of XML transform.
1599- // Patching the original version back in with more brutish parsing.
1600- val R = """ (?ims)(.*)(<copyright>.*</copyright>)(.*)""" .r
1601- val oldContents = IO .read(ipr)
1602- XML .save(ipr.getAbsolutePath, newModules)
1603- oldContents match {
1604- case R (_, withEscapes, _) =>
1605- val newContents = IO .read(ipr)
1606- val R (pre, toReplace, post) = newContents
1607- IO .write(ipr, pre + withEscapes + post)
1608- case _ =>
1609- // .ipr file hasn't been updated from `intellijFromSample` yet
1610- }
1611- }
1612-
1613- lazy val intellijFromSample = taskKey[Unit ](" Create fresh IntelliJ project files from src/intellij/*.SAMPLE." )
1614-
1615- def backupIdea (ideaDir : File ): Unit = {
1616- val temp = IO .createTemporaryDirectory
1617- IO .copyDirectory(ideaDir, temp)
1618- println(s " Backed up existing src/intellij to $temp" )
1619- }
1620-
1621- intellijFromSample := {
1622- val s = streams.value
1623- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1624- val ipr = intellijDir / " scala.ipr"
1625- backupIdea(intellijDir)
1626- intellijCreateFromSample((ThisBuild / baseDirectory).value)
1627- }
1628-
1629- def intellijCreateFromSample (basedir : File ): Unit = {
1630- val files = basedir / " src/intellij" * " *.SAMPLE"
1631- val copies = files.get.map(f => (f, new File (f.getAbsolutePath.stripSuffix(" .SAMPLE" ))))
1632- IO .copy(copies, CopyOptions () withOverwrite true )
1633- }
1634-
1635- lazy val intellijToSample = taskKey[Unit ](" Update src/intellij/*.SAMPLE using the current IntelliJ project files." )
1636-
1637- intellijToSample := {
1638- val s = streams.value
1639- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1640- val ipr = intellijDir / " scala.ipr"
1641- backupIdea(intellijDir)
1642- val existing = intellijDir * " *.SAMPLE"
1643- IO .delete(existing.get)
1644- val current = intellijDir * (" *.iml" || " *.ipr" )
1645- val copies = current.get.map(f => (f, new File (f.getAbsolutePath + " .SAMPLE" )))
1646- IO .copy(copies)
1647- }
1648-
16491494/** Find a specific module's JAR in a classpath, comparing only organization and name */
16501495def findJar (files : Seq [Attributed [File ]], dep : ModuleID ): Option [Attributed [File ]] = {
16511496 def extract (m : ModuleID ) = (m.organization, m.name)
0 commit comments