Skip to content

Commit

Permalink
Merge pull request #20 from tindzk/bug/idea-scala213
Browse files Browse the repository at this point in the history
IDEA: Set language level for Scala library
  • Loading branch information
tindzk authored Jul 14, 2019
2 parents cf69777 + 9f03217 commit aabeb6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/main/scala/seed/generation/Idea.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ object Idea {
): Unit = {
val xml = IdeaFile.createLibrary(IdeaFile.Library(
libraryJar.getFileName.toString,
isScalaCompiler = false,
compilerClasses = List(),
compilerInfo = None,
classes = List(libraryJar.toAbsolutePath.toString),
javaDoc = javaDocJar.toList.map(_.toAbsolutePath.toString),
sources = sourcesJar.toList.map(_.toAbsolutePath.toString)))
Expand Down Expand Up @@ -122,8 +121,8 @@ object Idea {

val xml = IdeaFile.createLibrary(IdeaFile.Library(
name = build.project.scalaOrganisation + "-" + scalaVersion,
isScalaCompiler = true,
compilerClasses = scalaCompiler.compilerJars.map(_.toString),
compilerInfo = Some(IdeaFile.CompilerInfo(
scalaVersion, scalaCompiler.compilerJars.map(_.toString))),
classes = scalaCompiler.fullClassPath.map(_.toString),
javaDoc = List(),
sources = List()))
Expand Down
24 changes: 18 additions & 6 deletions src/main/scala/seed/generation/util/IdeaFile.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seed.generation.util

import seed.generation.Bloop

import pine._

/** XML writers for IDEA files */
Expand All @@ -14,9 +16,10 @@ object IdeaFile {
moduleDeps: List[String],
output: Option[Output])

case class CompilerInfo(version: String, compilerClasses: List[String])

case class Library(name: String,
isScalaCompiler: Boolean,
compilerClasses: List[String],
compilerInfo: Option[CompilerInfo],
classes: List[String],
javaDoc: List[String],
sources: List[String])
Expand Down Expand Up @@ -83,11 +86,20 @@ object IdeaFile {
}

def createLibrary(library: Library): String = {
val tpe = if (library.isScalaCompiler) Some("Scala") else None
val compilerPaths = library.compilerClasses
.map(path => xml"""<root url="file://$path" />""")
val tpe = library.compilerInfo.map(_ => "Scala")
val languageLevel =
library.compilerInfo.map { case CompilerInfo(version, _) =>
val level = "Scala_" + Bloop.majorMinorVersion(version)
.replaceAllLiterally(".", "_")
xml"""<language-level>$level</language-level>"""
}.toList
val compilerPaths = library.compilerInfo.fold(List[pine.Tag[Singleton]]())(
_.compilerClasses.map(path => xml"""<root url="file://$path" />"""))
val properties = if (compilerPaths.isEmpty) List() else List(xml"""
<properties><compiler-classpath>$compilerPaths</compiler-classpath></properties>
<properties>
$languageLevel
<compiler-classpath>$compilerPaths</compiler-classpath>
</properties>
""")
val classes = library.classes.map(path => xml"""<root url="jar://$path!/" />""")
val javaDoc = library.javaDoc.map(path => xml"""<root url="jar://$path!/" />""")
Expand Down
13 changes: 13 additions & 0 deletions src/test/scala/seed/generation/IdeaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ object IdeaSpec extends SimpleTestSuite {
assertEquals(profileNodes.head.attr("modules"),
Some("module212,module211"))

val scalaLibrary2_11_11 =
pine.XmlParser.fromString(FileUtils.readFileToString(
ideaPath.resolve("libraries").resolve("org_scala_lang_2_11_11.xml").toFile,
"UTF-8"))
val scalaLibrary2_12_8 =
pine.XmlParser.fromString(FileUtils.readFileToString(
ideaPath.resolve("libraries").resolve("org_scala_lang_2_12_8.xml").toFile,
"UTF-8"))
assertEquals(scalaLibrary2_11_11.byTagAll["language-level"].map(_.toText),
List("Scala_2_11"))
assertEquals(scalaLibrary2_12_8.byTagAll["language-level"].map(_.toText),
List("Scala_2_12"))

val module211 =
pine.XmlParser.fromString(FileUtils.readFileToString(
ideaPath.resolve("modules").resolve("module211.iml").toFile,
Expand Down

0 comments on commit aabeb6b

Please sign in to comment.