@@ -1228,168 +1228,9 @@ commands ++= {
1228
1228
1229
1229
addCommandAlias(" scalap" , " scalap/compile:runMain scala.tools.scalap.Main -usejavacp" )
1230
1230
1231
- lazy val intellij = taskKey[Unit ](" Update the library classpaths in the IntelliJ project files." )
1232
-
1233
- def moduleDeps (p : Project , config : Configuration = Compile ) = (p / config / externalDependencyClasspath).map(a => (p.id, a.map(_.data)))
1234
-
1235
1231
// aliases to projects to prevent name clashes
1236
- def compilerP = compiler
1237
1232
def testP = test
1238
1233
1239
- intellij := {
1240
- import xml ._
1241
- import xml .transform ._
1242
-
1243
- val s = streams.value
1244
- val compilerScalaInstance = (LocalProject (" compiler" ) / scalaInstance).value
1245
-
1246
- val modules : List [(String , Seq [File ])] = {
1247
- // for the sbt build module, the dependencies are fetched from the project's build using sbt-buildinfo
1248
- val buildModule = (" scala-build" , scalabuild.BuildInfo .buildClasspath.split(java.io.File .pathSeparator).toSeq.map(new File (_)))
1249
- // `sbt projects` lists all modules in the build
1250
- buildModule :: List (
1251
- moduleDeps(bench).value,
1252
- moduleDeps(compilerP).value,
1253
- // moduleDeps(dist).value, // No sources, therefore no module in IntelliJ
1254
- moduleDeps(interactive).value,
1255
- moduleDeps(junit).value,
1256
- moduleDeps(library).value,
1257
- // moduleDeps(libraryAll).value, // No sources
1258
- moduleDeps(manual).value,
1259
- moduleDeps(partest).value,
1260
- moduleDeps(partestJavaAgent).value,
1261
- moduleDeps(reflect).value,
1262
- moduleDeps(repl).value,
1263
- moduleDeps(replJline).value,
1264
- // moduleDeps(replJlineEmbedded).value, // No sources
1265
- // moduleDeps(root).value, // No sources
1266
- // moduleDeps(scalaDist).value, // No sources
1267
- moduleDeps(scalacheck, config = Test ).value,
1268
- moduleDeps(scaladoc).value,
1269
- moduleDeps(scalap).value,
1270
- moduleDeps(testP).value,
1271
- moduleDeps(compilerOptionsExporter).value
1272
- )
1273
- }
1274
-
1275
- def moduleDep (name : String , jars : Seq [File ]) = {
1276
- val entries = jars.map(f => s """ <root url="jar:// ${f.toURI.getPath}!/" /> """ ).mkString(" \n " )
1277
- s """ | <library name=" $name-deps">
1278
- | <CLASSES>
1279
- | $entries
1280
- | </CLASSES>
1281
- | <JAVADOC />
1282
- | <SOURCES />
1283
- | </library> """ .stripMargin
1284
- }
1285
-
1286
- def starrDep (jars : Seq [File ]) = {
1287
- val entries = jars.map(f => s """ <root url="file:// ${f.toURI.getPath}" /> """ ).mkString(" \n " )
1288
- s """ | <library name="starr" type="Scala">
1289
- | <properties>
1290
- | <option name="languageLevel" value="Scala_2_12" />
1291
- | <compiler-classpath>
1292
- | $entries
1293
- | </compiler-classpath>
1294
- | </properties>
1295
- | <CLASSES />
1296
- | <JAVADOC />
1297
- | <SOURCES />
1298
- | </library> """ .stripMargin
1299
- }
1300
-
1301
- def replaceLibrary (data : Node , libName : String , libType : Option [String ], newContent : String ) = {
1302
- object rule extends RewriteRule {
1303
- var transformed = false
1304
- def checkAttrs (attrs : MetaData ) = {
1305
- def check (key : String , expected : String ) = {
1306
- val a = attrs(key)
1307
- a != null && a.text == expected
1308
- }
1309
- check(" name" , libName) && libType.forall(tp => check(" type" , tp))
1310
- }
1311
-
1312
- override def transform (n : Node ): Seq [Node ] = n match {
1313
- case e @ Elem (_, " library" , attrs, _, _, _* ) if checkAttrs(attrs) =>
1314
- transformed = true
1315
- XML .loadString(newContent)
1316
- case other =>
1317
- other
1318
- }
1319
- }
1320
- object trans extends RuleTransformer (rule)
1321
- val r = trans(data)
1322
- if (! rule.transformed) sys.error(s " Replacing library classpath for $libName failed, no existing library found. " )
1323
- r
1324
- }
1325
-
1326
- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1327
- val ipr = intellijDir / " scala.ipr"
1328
- backupIdea(intellijDir)
1329
- if (! ipr.exists) {
1330
- intellijCreateFromSample((ThisBuild / baseDirectory).value)
1331
- }
1332
- s.log.info(" Updating library classpaths in src/intellij/scala.ipr." )
1333
- val content = XML .loadFile(ipr)
1334
-
1335
- val newStarr = replaceLibrary(content, " starr" , Some (" Scala" ), starrDep(compilerScalaInstance.allJars))
1336
- val newModules = modules.foldLeft(newStarr)({
1337
- case (res, (modName, jars)) =>
1338
- if (jars.isEmpty) res // modules without dependencies
1339
- else replaceLibrary(res, s " $modName-deps " , None , moduleDep(modName, jars))
1340
- })
1341
-
1342
- // I can't figure out how to keep the entity escapes for \n in the attribute values after this use of XML transform.
1343
- // Patching the original version back in with more brutish parsing.
1344
- val R = """ (?ims)(.*)(<copyright>.*</copyright>)(.*)""" .r
1345
- val oldContents = IO .read(ipr)
1346
- XML .save(ipr.getAbsolutePath, newModules)
1347
- oldContents match {
1348
- case R (_, withEscapes, _) =>
1349
- val newContents = IO .read(ipr)
1350
- val R (pre, toReplace, post) = newContents
1351
- IO .write(ipr, pre + withEscapes + post)
1352
- case _ =>
1353
- // .ipr file hasn't been updated from `intellijFromSample` yet
1354
- }
1355
- }
1356
-
1357
- lazy val intellijFromSample = taskKey[Unit ](" Create fresh IntelliJ project files from src/intellij/*.SAMPLE." )
1358
-
1359
- def backupIdea (ideaDir : File ): Unit = {
1360
- val temp = IO .createTemporaryDirectory
1361
- IO .copyDirectory(ideaDir, temp)
1362
- println(s " Backed up existing src/intellij to $temp" )
1363
- }
1364
-
1365
- intellijFromSample := {
1366
- val s = streams.value
1367
- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1368
- val ipr = intellijDir / " scala.ipr"
1369
- backupIdea(intellijDir)
1370
- intellijCreateFromSample((ThisBuild / baseDirectory).value)
1371
- }
1372
-
1373
- def intellijCreateFromSample (basedir : File ): Unit = {
1374
- val files = basedir / " src/intellij" * " *.SAMPLE"
1375
- val copies = files.get.map(f => (f, new File (f.getAbsolutePath.stripSuffix(" .SAMPLE" ))))
1376
- IO .copy(copies, CopyOptions () withOverwrite true )
1377
- }
1378
-
1379
- lazy val intellijToSample = taskKey[Unit ](" Update src/intellij/*.SAMPLE using the current IntelliJ project files." )
1380
-
1381
- intellijToSample := {
1382
- val s = streams.value
1383
- val intellijDir = (ThisBuild / baseDirectory).value / " src/intellij"
1384
- val ipr = intellijDir / " scala.ipr"
1385
- backupIdea(intellijDir)
1386
- val existing = intellijDir * " *.SAMPLE"
1387
- IO .delete(existing.get)
1388
- val current = intellijDir * (" *.iml" || " *.ipr" )
1389
- val copies = current.get.map(f => (f, new File (f.getAbsolutePath + " .SAMPLE" )))
1390
- IO .copy(copies)
1391
- }
1392
-
1393
1234
/** Find a specific module's JAR in a classpath, comparing only organization and name */
1394
1235
def findJar (files : Seq [Attributed [File ]], dep : ModuleID ): Option [Attributed [File ]] = {
1395
1236
def extract (m : ModuleID ) = (m.organization, m.name)
0 commit comments