Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae3538b

Browse files
committed
Backport 'Remove custom IntelliJ project files'
Backport of #11112
1 parent aad0070 commit ae3538b

25 files changed

+8
-1168
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
# eclipse, intellij
4141
/.classpath
4242
/.project
43-
/src/intellij*/*.iml
44-
/src/intellij*/*.ipr
45-
/src/intellij*/*.iws
4643
**/.cache
4744
/.idea
4845
/.settings

README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ scala/
5151
+---/library Scala Standard Library
5252
+---/reflect Scala Reflection
5353
+---/compiler Scala Compiler
54-
+---/intellij IntelliJ project templates
5554
+--spec/ The Scala language specification
5655
+--scripts/ Scripts for the CI jobs (including building releases)
5756
+--test/ The Scala test suite
@@ -134,15 +133,6 @@ temporarily commenting them out in `~/.sbt/0.13/plugins/plugins.sbt`).
134133
We recommend to keep local test files in the `sandbox` directory which is listed in
135134
the `.gitignore` of the Scala repo.
136135

137-
#### Incremental compilation
138-
139-
Note that sbt's incremental compilation is often too coarse for the Scala compiler
140-
codebase and re-compiles too many files, resulting in long build times (check
141-
[sbt#1104](https://github.com/sbt/sbt/issues/1104) for progress on that front). In the
142-
meantime you can:
143-
- Use IntelliJ IDEA for incremental compiles (see [IDE Setup](#ide-setup) below) - its
144-
incremental compiler is a bit less conservative, but usually correct.
145-
146136
#### Bootstrapping locally
147137

148138
To perform a bootstrap using sbt
@@ -171,18 +161,15 @@ be easily executed locally.
171161

172162
### IDE setup
173163

174-
You may use IntelliJ IDEA (see [src/intellij/README.md](src/intellij/README.md)),
175-
the Scala IDE for Eclipse (see [src/eclipse/README.md](src/eclipse/README.md)),
176-
or ENSIME (see [this page on the ENSIME site](http://ensime.org/editors/)).
177-
178-
In order to use IntelliJ's incremental compiler:
179-
- run `dist/mkBin` in sbt to get a build and the runner scripts in `build/quick/bin`
180-
- run "Build" - "Make Project" in IntelliJ
164+
In IntelliJ IDEA, use "File - Open...", select the project folder and use
165+
"Open as: sbt project".
166+
- JUnit tests can be launched / debugged from the IDE, including tests that
167+
run the compiler (e.g., `QuickfixTest`).
168+
- Building in IntelliJ interoperates with the sbt build; the compiler script in
169+
`build/quick/bin` (generated by running `sbt dist/mkBin`) runs the classfiles
170+
built via the IDE.
181171

182-
Now you can edit and build in IntelliJ and use the scripts (compiler, REPL) to
183-
directly test your changes. You can also run the `scala`, `scalac` and `partest`
184-
commands in sbt. Enable "Ant mode" (explained above) to prevent sbt's incremental
185-
compiler from re-compiling (too many) files before each `partest` invocation.
172+
In VSCode / Metals, open the project directory and import the project as ususal.
186173

187174
# Coding guidelines
188175

build.sbt

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,168 +1228,9 @@ commands ++= {
12281228

12291229
addCommandAlias("scalap", "scalap/compile:runMain scala.tools.scalap.Main -usejavacp")
12301230

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-
12351231
// aliases to projects to prevent name clashes
1236-
def compilerP = compiler
12371232
def testP = test
12381233

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-
13931234
/** Find a specific module's JAR in a classpath, comparing only organization and name */
13941235
def findJar(files: Seq[Attributed[File]], dep: ModuleID): Option[Attributed[File]] = {
13951236
def extract(m: ModuleID) = (m.organization, m.name)

project/plugins.sbt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ libraryDependencies += "org.pantsbuild" % "jarjar" % "1.7.2"
1313

1414
libraryDependencies += "biz.aQute.bnd" % "biz.aQute.bndlib" % "6.1.0"
1515

16-
enablePlugins(BuildInfoPlugin)
17-
18-
// configure sbt-buildinfo to send the externalDependencyClasspath to the main build, which allows using it for the IntelliJ project config
19-
20-
lazy val buildClasspath = taskKey[String]("Colon-separated (or semicolon-separated in case of Windows) list of entries on the sbt build classpath.")
21-
22-
buildClasspath := (Compile / externalDependencyClasspath).value.map(_.data).mkString(java.io.File.pathSeparator)
23-
24-
buildInfoKeys := Seq[BuildInfoKey](buildClasspath)
25-
26-
buildInfoPackage := "scalabuild"
27-
2816
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
2917

3018
libraryDependencies ++= Seq(

project/project/plugins.sbt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/intellij/README.md

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/intellij/benchmarks.iml.SAMPLE

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/intellij/compiler.iml.SAMPLE

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/intellij/compilerOptionsExporter.iml.SAMPLE

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)