From 32d7291170f6b9710e919c48302fa04e78ec4766 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 26 Jun 2017 21:34:13 -0700 Subject: Add support for generating ensime configuration file --- stage2/plugins/Ensime.scala | 295 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 stage2/plugins/Ensime.scala diff --git a/stage2/plugins/Ensime.scala b/stage2/plugins/Ensime.scala new file mode 100644 index 0000000..019ab87 --- /dev/null +++ b/stage2/plugins/Ensime.scala @@ -0,0 +1,295 @@ +package cbt + +import java.io.{File, FileNotFoundException} +import java.lang.management.ManagementFactory +import java.util.{Map => JMap} +import scala.collection.JavaConverters._ +import scala.sys.process._ +import scala.util.Try +import scala.util.control.NonFatal + +/** + * Plugin that provides ENSIME (http://ensime.org/) support. + * + * The central method provided by this plugin is `ensime`, which will generate an ENSIME + * configuration file describing the current build. This configuration file may be used by ENSIME + * server and clients, adding IDE capabilities to plain text editors. + * + * Most methods and helper classes were copied verbatim or with minor changes from the + * ensime-related projects, ensime-server (https://github.com/ensime/ensime-server) and ensime-sbt + * (https://github.com/ensime/ensime-sbt). Licensed under the Apache 2.0 License. + */ +trait Ensime extends BaseBuild { + import Ensime._ + + /** The Java (JDK, not JRE) root directory that will be used to launch ENSIME. */ + def ensimeJavaHome: File = jdkHome + + /** Flags to be passed to ENSIME JVM process. */ + def ensimeJavaFlags: Seq[String] = baseJavaFlags(ensimeServerVersion) + + /** The version of ensime to use. */ + def ensimeServerVersion: String = "2.0.0-SNAPSHOT" + + /** All jars required to launch ENSIME-server, including its dependencies. */ + def ensimeServerJars: Seq[File] = { + val deps = Dependencies(Resolver(mavenCentral, sonatypeReleases, sonatypeSnapshots).bind( + MavenDependency("org.ensime", s"server_$scalaMajorVersion", ensimeServerVersion) + )) + (deps.dependencies ++ deps.transitiveDependencies).flatMap(_.exportedClasspathArray) + } + + /** Version of Scala that ENSIME will assume is used in this build. */ + def ensimeScalaVersion: String = defaultScalaVersion + + /** The scala compiler's jars. */ + def ensimeScalaJars: Seq[File] = new ScalaDependencies( + context.cbtLastModified, + context.paths.mavenCache, + scalaVersion + ).dependencies.flatMap(_.exportedClasspathArray) + + /** ENSIME server and client configuration. */ + def ensimeConfig: EnsimeConfig = EnsimeConfig( + scalaCompilerJars = ensimeScalaJars, + ensimeServerJars = ensimeServerJars, + ensimeServerVersion = ensimeServerVersion, + rootDir = projectDirectory, + cacheDir = projectDirectory / ".ensime_cache", + javaHome = ensimeJavaHome, + name = name, + scalaVersion = ensimeScalaVersion, + javaSources = jdkSource.toSeq, + javaFlags = ensimeJavaFlags, + projects = EnsimeProject( + id = EnsimeProjectId( + project = name, + config = "compile" + ), + depends = Nil, // currently only one project is supported + sources = sources.filter(_.isDirectory), + targets = Seq(compileTarget), + scalacOptions = scalacOptions.toList, + javacOptions = Nil, + libraryJars = transitiveDependencies.flatMap(_.exportedClasspathArray).toList, + librarySources = resolveWithClassifier(transitiveDependencies, Classifier.sources), + libraryDocs = resolveWithClassifier(transitiveDependencies, Classifier.javadoc) + ) :: Nil + ) + + /** Generate an ENSIME configuration file for this build. */ + def ensime: File = lib.writeIfChanged( + projectDirectory / ".ensime", + ensimeConfig.toSexp + ) + +} + +object Ensime { + + def jdkHome: File = List( + // manual + sys.env.get("JDK_HOME"), + sys.env.get("JAVA_HOME"), + // fallback + sys.props.get("java.home").map(new File(_).getParent), + sys.props.get("java.home"), + // osx + Try("/usr/libexec/java_home".!!.trim).toOption + ).flatten.filter { n => + new File(n + "/lib/tools.jar").exists + }.headOption.map(new File(_).getCanonicalFile).getOrElse( + throw new FileNotFoundException( + """Could not automatically find the JDK/lib/tools.jar. + |You must explicitly set JDK_HOME or JAVA_HOME.""".stripMargin + ) + ) + + def jdkSource: Option[File] = { + val src = new File(jdkHome, "src.zip") + if (src.exists) Some(src) else None + } + + def baseJavaFlags(serverVersion: String) = { + val raw = ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList + + // WORKAROUND https://github.com/ensime/ensime-sbt/issues/91 + // WORKAROUND https://github.com/ensime/ensime-server/issues/1756 + val StackSize = "-Xss[^ ]+".r + val MinHeap = "-Xms[^ ]+".r + val MaxHeap = "-Xmx[^ ]+".r + val MaxPerm = "-XX:MaxPermSize=[^ ]+".r + val corrected = raw.filter { + case StackSize() => false + case MinHeap() => false + case MaxHeap() => false + case MaxPerm() => false + case other => true + } + val memory = Seq( + "-Xss2m", + "-Xms512m", + "-Xmx4g" + ) + + val server = serverVersion.substring(0, 3) + val java = sys.props("java.version").substring(0, 3) + val versioned = (java, server) match { + case (_, "1.0") | ("1.6" | "1.7", _) => Seq( + "-XX:MaxPermSize=256m" + ) + case _ => List( + "-XX:MaxMetaspaceSize=256m", + // these improve ensime-server performance + "-XX:StringTableSize=1000003", + "-XX:+UnlockExperimentalVMOptions", + "-XX:SymbolTableSize=1000003" + ) + } + + // WORKAROUND: https://github.com/scala/scala/pull/5592 + val zipFix = Seq("-Dscala.classpath.closeZip=true") + + corrected ++ memory ++ versioned ++ zipFix + } + + /** Attempt to download a maven dependency with a given classifer. Warn if it is not available. */ + def resolveWithClassifier(dependencies: Seq[Dependency], classifier: Classifier)(implicit logger: Logger, + cache: JMap[AnyRef, AnyRef], classLoaderCache: ClassLoaderCache): Seq[File] = { + val classifierName = classifier.name.getOrElse("") + val classified = dependencies.collect{ case m: BoundMavenDependency => + m.copy(mavenDependency = m.mavenDependency.copy(classifier = classifier)) + } + classified.flatMap{ dependency => + try { + dependency.exportedJars + } catch { + case NonFatal(_) => + logger.resolver( + s"ensime: could not find $classifierName of ${dependency.mavenDependency.serialize}") + Seq.empty + } + } + } + + final case class EnsimeConfig( + scalaCompilerJars: Seq[File], + ensimeServerJars: Seq[File], + ensimeServerVersion: String, + rootDir: File, + cacheDir: File, + javaHome: File, + name: String, + scalaVersion: String, + javaSources: Seq[File], + javaFlags: Seq[String], + projects: Seq[EnsimeProject] + ) { + def toSexp: String = sexp(this) + } + + final case class EnsimeProjectId( + project: String, + config: String + ) + + final case class EnsimeProject( + id: EnsimeProjectId, + depends: Seq[EnsimeProjectId], + sources: Seq[File], + targets: Seq[File], + scalacOptions: Seq[String], + javacOptions: Seq[String], + libraryJars: Seq[File], + librarySources: Seq[File], + libraryDocs: Seq[File] + ) + + /* EnsimeModules are required for backwards-compatibility with clients. + * They can automatically be derived from projects (see method below). */ + private final case class EnsimeModule( + name: String, + mainRoots: Set[File], + testRoots: Set[File], + targets: Set[File], + testTargets: Set[File], + dependsOnNames: Set[String], + compileJars: Set[File], + runtimeJars: Set[File], + testJars: Set[File], + sourceJars: Set[File], + docJars: Set[File] + ) + + private def ensimeProjectsToModule(p: Iterable[EnsimeProject]): EnsimeModule = { + val name = p.head.id.project + val deps = for { + s <- p + d <- s.depends + if d.project != name + } yield d.project + val (mains, tests) = p.toSet.partition(_.id.config == "compile") + val mainSources = mains.flatMap(_.sources) + val mainTargets = mains.flatMap(_.targets) + val mainJars = mains.flatMap(_.libraryJars) + val testSources = tests.flatMap(_.sources) + val testTargets = tests.flatMap(_.targets) + val testJars = tests.flatMap(_.libraryJars).toSet -- mainJars + val sourceJars = p.flatMap(_.librarySources).toSet + val docJars = p.flatMap(_.libraryDocs).toSet + EnsimeModule( + name, mainSources, testSources, mainTargets, testTargets, deps.toSet, + mainJars, Set.empty, testJars, sourceJars, docJars + ) + } + + private def sexp(value: Any): String = value match { + case s: String => s""""$s"""" + case f: File => sexp(f.getAbsolutePath) + case (k, v) => s":$k ${sexp(v)}\n" + case xss: Traversable[_] if xss.isEmpty => "nil" + case xss: Traversable[_] => xss.map(sexp(_)).mkString("(", " ", ")") + case EnsimeProjectId(project, config) => sexp(List( + "project" -> project, + "config" -> config + )) + case proj: EnsimeProject => sexp(List( + "id" -> proj.id, + "depends" -> proj.depends, + "sources" -> proj.sources, + "targets" -> proj.targets, + "scalac-options" -> proj.scalacOptions, + "javac-options" -> proj.javacOptions, + "library-jars" -> proj.libraryJars, + "library-sources" -> proj.librarySources, + "library-docs" -> proj.libraryDocs + )) + case conf: EnsimeConfig => sexp(List( + "root-dir" -> conf.rootDir, + "cache-dir" -> conf.cacheDir, + "scala-compiler-jars" -> conf.scalaCompilerJars, + "ensime-server-jars" -> conf.ensimeServerJars, + "ensime-server-version" -> conf.ensimeServerVersion, + "name" -> conf.name, + "scala-version" -> conf.scalaVersion, + "java-home" -> conf.javaHome, + "java-flags" -> conf.javaFlags, + "java-sources" -> conf.javaSources, + "projects" -> conf.projects, + "subprojects" -> List(ensimeProjectsToModule(conf.projects)) + )) + case module: EnsimeModule => sexp(List( + "name" -> module.name, + "source-roots" -> (module.mainRoots ++ module.testRoots), + "targets" -> module.targets, + "test-targets" -> module.testTargets, + "depends-on-modules" -> module.dependsOnNames, + "compile-deps" -> module.compileJars, + "runtime-deps" -> module.runtimeJars, + "test-deps" -> module.testJars, + "doc-jars"-> module.docJars, + "reference-source-roots" -> module.sourceJars + )) + } + +} -- cgit v1.2.3 From 30e2c8a8c29cc006fd9ad99644ae6eaab76ceeb7 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 27 Jun 2017 00:15:26 -0700 Subject: Add NOTICE file --- NOTICE | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 NOTICE diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..a4593bc --- /dev/null +++ b/NOTICE @@ -0,0 +1,13 @@ +======================================================================== +NOTICE files +======================================================================== + +The following NOTICEs pertain to software distributed with this project. + +ENSIME sbt plugin +Copyright 2014 - 2017 Sam Halliday +Copyright 2010 - 2017 https://github.com/ensime/ensime-sbt/graphs + +Some files are copied from external sources and carry additional +license information which must also be distributed along with this +file and the LICENSE file. -- cgit v1.2.3 From a6eafa3e926bb52ac718f66e7ad35867327fcb83 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 2 Jul 2017 15:12:41 -0700 Subject: Move helper methods to their corresponding companion objects --- stage2/plugins/Ensime.scala | 174 ++++++++++++++++++++++---------------------- 1 file changed, 89 insertions(+), 85 deletions(-) diff --git a/stage2/plugins/Ensime.scala b/stage2/plugins/Ensime.scala index 019ab87..6e825ab 100644 --- a/stage2/plugins/Ensime.scala +++ b/stage2/plugins/Ensime.scala @@ -172,22 +172,6 @@ object Ensime { } } - final case class EnsimeConfig( - scalaCompilerJars: Seq[File], - ensimeServerJars: Seq[File], - ensimeServerVersion: String, - rootDir: File, - cacheDir: File, - javaHome: File, - name: String, - scalaVersion: String, - javaSources: Seq[File], - javaFlags: Seq[String], - projects: Seq[EnsimeProject] - ) { - def toSexp: String = sexp(this) - } - final case class EnsimeProjectId( project: String, config: String @@ -206,7 +190,7 @@ object Ensime { ) /* EnsimeModules are required for backwards-compatibility with clients. - * They can automatically be derived from projects (see method below). */ + * They can automatically be derived from projects (see method EnsimeModule.fromProjects). */ private final case class EnsimeModule( name: String, mainRoots: Set[File], @@ -220,76 +204,96 @@ object Ensime { sourceJars: Set[File], docJars: Set[File] ) - - private def ensimeProjectsToModule(p: Iterable[EnsimeProject]): EnsimeModule = { - val name = p.head.id.project - val deps = for { - s <- p - d <- s.depends - if d.project != name - } yield d.project - val (mains, tests) = p.toSet.partition(_.id.config == "compile") - val mainSources = mains.flatMap(_.sources) - val mainTargets = mains.flatMap(_.targets) - val mainJars = mains.flatMap(_.libraryJars) - val testSources = tests.flatMap(_.sources) - val testTargets = tests.flatMap(_.targets) - val testJars = tests.flatMap(_.libraryJars).toSet -- mainJars - val sourceJars = p.flatMap(_.librarySources).toSet - val docJars = p.flatMap(_.libraryDocs).toSet - EnsimeModule( - name, mainSources, testSources, mainTargets, testTargets, deps.toSet, - mainJars, Set.empty, testJars, sourceJars, docJars - ) + private object EnsimeModule { + def fromProjects(p: Iterable[EnsimeProject]): EnsimeModule = { + val name = p.head.id.project + val deps = for { + s <- p + d <- s.depends + if d.project != name + } yield d.project + val (mains, tests) = p.toSet.partition(_.id.config == "compile") + val mainSources = mains.flatMap(_.sources) + val mainTargets = mains.flatMap(_.targets) + val mainJars = mains.flatMap(_.libraryJars) + val testSources = tests.flatMap(_.sources) + val testTargets = tests.flatMap(_.targets) + val testJars = tests.flatMap(_.libraryJars).toSet -- mainJars + val sourceJars = p.flatMap(_.librarySources).toSet + val docJars = p.flatMap(_.libraryDocs).toSet + EnsimeModule( + name, mainSources, testSources, mainTargets, testTargets, deps.toSet, + mainJars, Set.empty, testJars, sourceJars, docJars + ) + } } - private def sexp(value: Any): String = value match { - case s: String => s""""$s"""" - case f: File => sexp(f.getAbsolutePath) - case (k, v) => s":$k ${sexp(v)}\n" - case xss: Traversable[_] if xss.isEmpty => "nil" - case xss: Traversable[_] => xss.map(sexp(_)).mkString("(", " ", ")") - case EnsimeProjectId(project, config) => sexp(List( - "project" -> project, - "config" -> config - )) - case proj: EnsimeProject => sexp(List( - "id" -> proj.id, - "depends" -> proj.depends, - "sources" -> proj.sources, - "targets" -> proj.targets, - "scalac-options" -> proj.scalacOptions, - "javac-options" -> proj.javacOptions, - "library-jars" -> proj.libraryJars, - "library-sources" -> proj.librarySources, - "library-docs" -> proj.libraryDocs - )) - case conf: EnsimeConfig => sexp(List( - "root-dir" -> conf.rootDir, - "cache-dir" -> conf.cacheDir, - "scala-compiler-jars" -> conf.scalaCompilerJars, - "ensime-server-jars" -> conf.ensimeServerJars, - "ensime-server-version" -> conf.ensimeServerVersion, - "name" -> conf.name, - "scala-version" -> conf.scalaVersion, - "java-home" -> conf.javaHome, - "java-flags" -> conf.javaFlags, - "java-sources" -> conf.javaSources, - "projects" -> conf.projects, - "subprojects" -> List(ensimeProjectsToModule(conf.projects)) - )) - case module: EnsimeModule => sexp(List( - "name" -> module.name, - "source-roots" -> (module.mainRoots ++ module.testRoots), - "targets" -> module.targets, - "test-targets" -> module.testTargets, - "depends-on-modules" -> module.dependsOnNames, - "compile-deps" -> module.compileJars, - "runtime-deps" -> module.runtimeJars, - "test-deps" -> module.testJars, - "doc-jars"-> module.docJars, - "reference-source-roots" -> module.sourceJars - )) + final case class EnsimeConfig( + scalaCompilerJars: Seq[File], + ensimeServerJars: Seq[File], + ensimeServerVersion: String, + rootDir: File, + cacheDir: File, + javaHome: File, + name: String, + scalaVersion: String, + javaSources: Seq[File], + javaFlags: Seq[String], + projects: Seq[EnsimeProject] + ) { + def toSexp: String = EnsimeConfig.sexp(this) + } + object EnsimeConfig { + private def sexp(value: Any): String = value match { + case s: String => s""""$s"""" + case f: File => sexp(f.getAbsolutePath) + case (k, v) => s":$k ${sexp(v)}\n" + case xss: Traversable[_] if xss.isEmpty => "nil" + case xss: Traversable[_] => xss.map(sexp(_)).mkString("(", " ", ")") + case EnsimeProjectId(project, config) => sexp(List( + "project" -> project, + "config" -> config + )) + case proj: EnsimeProject => sexp(List( + "id" -> proj.id, + "depends" -> proj.depends, + "sources" -> proj.sources, + "targets" -> proj.targets, + "scalac-options" -> proj.scalacOptions, + "javac-options" -> proj.javacOptions, + "library-jars" -> proj.libraryJars, + "library-sources" -> proj.librarySources, + "library-docs" -> proj.libraryDocs + )) + case conf: EnsimeConfig => sexp(List( + "root-dir" -> conf.rootDir, + "cache-dir" -> conf.cacheDir, + "scala-compiler-jars" -> conf.scalaCompilerJars, + "ensime-server-jars" -> conf.ensimeServerJars, + "ensime-server-version" -> conf.ensimeServerVersion, + "name" -> conf.name, + "scala-version" -> conf.scalaVersion, + "java-home" -> conf.javaHome, + "java-flags" -> conf.javaFlags, + "java-sources" -> conf.javaSources, + "projects" -> conf.projects, + // subprojects are required for backwards-compatibility with older clients + // (ensime-server does not require them) + "subprojects" -> List(EnsimeModule.fromProjects(conf.projects)) + )) + case module: EnsimeModule => sexp(List( + "name" -> module.name, + "source-roots" -> (module.mainRoots ++ module.testRoots), + "targets" -> module.targets, + "test-targets" -> module.testTargets, + "depends-on-modules" -> module.dependsOnNames, + "compile-deps" -> module.compileJars, + "runtime-deps" -> module.runtimeJars, + "test-deps" -> module.testJars, + "doc-jars"-> module.docJars, + "reference-source-roots" -> module.sourceJars + )) + } } } -- cgit v1.2.3 From 1b6557a2972a866aa616af43598caa63564c8ed5 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 2 Jul 2017 17:09:29 -0700 Subject: Add support for sub-projects --- stage2/plugins/Ensime.scala | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/stage2/plugins/Ensime.scala b/stage2/plugins/Ensime.scala index 6e825ab..46b5775 100644 --- a/stage2/plugins/Ensime.scala +++ b/stage2/plugins/Ensime.scala @@ -61,20 +61,7 @@ trait Ensime extends BaseBuild { scalaVersion = ensimeScalaVersion, javaSources = jdkSource.toSeq, javaFlags = ensimeJavaFlags, - projects = EnsimeProject( - id = EnsimeProjectId( - project = name, - config = "compile" - ), - depends = Nil, // currently only one project is supported - sources = sources.filter(_.isDirectory), - targets = Seq(compileTarget), - scalacOptions = scalacOptions.toList, - javacOptions = Nil, - libraryJars = transitiveDependencies.flatMap(_.exportedClasspathArray).toList, - librarySources = resolveWithClassifier(transitiveDependencies, Classifier.sources), - libraryDocs = resolveWithClassifier(transitiveDependencies, Classifier.javadoc) - ) :: Nil + projects = findProjects(this) ) /** Generate an ENSIME configuration file for this build. */ @@ -172,6 +159,30 @@ object Ensime { } } + /** Find and convert all (transitive) dependencies of a build to a sequence of ENSIME projects. */ + def findProjects(root: BaseBuild)(implicit logger: Logger, cache: JMap[AnyRef, AnyRef], classLoaderCache: ClassLoaderCache): Seq[EnsimeProject] = { + def asProject(base: BaseBuild) = EnsimeProject( + id = EnsimeProjectId( + project = base.name, + config = "compile" + ), + depends = base.transitiveDependencies.collect{ + case b: BaseBuild => EnsimeProjectId(b.name, "compile") + }, + sources = base.sources.filter(_.isDirectory), + targets = Seq(base.compileTarget), + scalacOptions = base.scalacOptions.toList, + javacOptions = Nil, // TODO get javac options from base build + libraryJars = base.transitiveDependencies.flatMap(_.exportedClasspathArray).toList, + librarySources = resolveWithClassifier(base.transitiveDependencies, Classifier.sources), + libraryDocs = resolveWithClassifier(base.transitiveDependencies, Classifier.javadoc) + ) + + Seq(asProject(root)) ++ root.transitiveDependencies.collect{ case b: BaseBuild => + asProject(b) + } + } + final case class EnsimeProjectId( project: String, config: String @@ -279,7 +290,7 @@ object Ensime { "projects" -> conf.projects, // subprojects are required for backwards-compatibility with older clients // (ensime-server does not require them) - "subprojects" -> List(EnsimeModule.fromProjects(conf.projects)) + "subprojects" -> conf.projects.groupBy(_.id.project).mapValues(EnsimeModule.fromProjects)//conf.projects.flatMap(proj => EnsimeModule.fromProjects(conf.projects)) )) case module: EnsimeModule => sexp(List( "name" -> module.name, -- cgit v1.2.3 From 6a744a2f71bd832993debe044824ac314121d80f Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 2 Jul 2017 17:59:23 -0700 Subject: Consolidate tasks --- stage2/plugins/Ensime.scala | 56 +++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/stage2/plugins/Ensime.scala b/stage2/plugins/Ensime.scala index 46b5775..e5f25fb 100644 --- a/stage2/plugins/Ensime.scala +++ b/stage2/plugins/Ensime.scala @@ -20,48 +20,34 @@ import scala.util.control.NonFatal * (https://github.com/ensime/ensime-sbt). Licensed under the Apache 2.0 License. */ trait Ensime extends BaseBuild { - import Ensime._ - - /** The Java (JDK, not JRE) root directory that will be used to launch ENSIME. */ - def ensimeJavaHome: File = jdkHome - - /** Flags to be passed to ENSIME JVM process. */ - def ensimeJavaFlags: Seq[String] = baseJavaFlags(ensimeServerVersion) /** The version of ensime to use. */ def ensimeServerVersion: String = "2.0.0-SNAPSHOT" - /** All jars required to launch ENSIME-server, including its dependencies. */ - def ensimeServerJars: Seq[File] = { - val deps = Dependencies(Resolver(mavenCentral, sonatypeReleases, sonatypeSnapshots).bind( - MavenDependency("org.ensime", s"server_$scalaMajorVersion", ensimeServerVersion) - )) - (deps.dependencies ++ deps.transitiveDependencies).flatMap(_.exportedClasspathArray) - } - - /** Version of Scala that ENSIME will assume is used in this build. */ - def ensimeScalaVersion: String = defaultScalaVersion - - /** The scala compiler's jars. */ - def ensimeScalaJars: Seq[File] = new ScalaDependencies( - context.cbtLastModified, - context.paths.mavenCache, - scalaVersion - ).dependencies.flatMap(_.exportedClasspathArray) - /** ENSIME server and client configuration. */ - def ensimeConfig: EnsimeConfig = EnsimeConfig( - scalaCompilerJars = ensimeScalaJars, - ensimeServerJars = ensimeServerJars, - ensimeServerVersion = ensimeServerVersion, + def ensimeConfig: Ensime.EnsimeConfig = Ensime.EnsimeConfig( + scalaCompilerJars = { + new ScalaDependencies( + context.cbtLastModified, + context.paths.mavenCache, + scalaVersion + ).dependencies.flatMap(_.exportedClasspathArray) + }, + ensimeServerJars = { + val deps = Dependencies(Resolver(mavenCentral, sonatypeReleases, sonatypeSnapshots).bind( + MavenDependency("org.ensime", s"server_$scalaMajorVersion", ensimeServerVersion) + )) + (deps.dependencies ++ deps.transitiveDependencies).flatMap(_.exportedClasspathArray) + }, + ensimeServerVersion = scalaVersion, rootDir = projectDirectory, cacheDir = projectDirectory / ".ensime_cache", - javaHome = ensimeJavaHome, + javaHome = Ensime.jdkHome, name = name, - scalaVersion = ensimeScalaVersion, - javaSources = jdkSource.toSeq, - javaFlags = ensimeJavaFlags, - projects = findProjects(this) + scalaVersion = scalaVersion, + javaSources = Ensime.jdkSource.toSeq, + javaFlags = Ensime.baseJavaFlags(ensimeServerVersion), + projects = Ensime.findProjects(this) ) /** Generate an ENSIME configuration file for this build. */ @@ -97,7 +83,7 @@ object Ensime { if (src.exists) Some(src) else None } - def baseJavaFlags(serverVersion: String) = { + def baseJavaFlags(serverVersion: String): Seq[String] = { val raw = ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList // WORKAROUND https://github.com/ensime/ensime-sbt/issues/91 -- cgit v1.2.3 From 0d224a86c9b8cd7c70540d3e31460aab4fe2907a Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 2 Jul 2017 18:26:11 -0700 Subject: Remove top-level ensime server version setting --- stage2/plugins/Ensime.scala | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/stage2/plugins/Ensime.scala b/stage2/plugins/Ensime.scala index e5f25fb..191f676 100644 --- a/stage2/plugins/Ensime.scala +++ b/stage2/plugins/Ensime.scala @@ -21,9 +21,6 @@ import scala.util.control.NonFatal */ trait Ensime extends BaseBuild { - /** The version of ensime to use. */ - def ensimeServerVersion: String = "2.0.0-SNAPSHOT" - /** ENSIME server and client configuration. */ def ensimeConfig: Ensime.EnsimeConfig = Ensime.EnsimeConfig( scalaCompilerJars = { @@ -35,18 +32,18 @@ trait Ensime extends BaseBuild { }, ensimeServerJars = { val deps = Dependencies(Resolver(mavenCentral, sonatypeReleases, sonatypeSnapshots).bind( - MavenDependency("org.ensime", s"server_$scalaMajorVersion", ensimeServerVersion) + MavenDependency("org.ensime", s"server_$scalaMajorVersion", "2.0.0-SNAPSHOT") )) (deps.dependencies ++ deps.transitiveDependencies).flatMap(_.exportedClasspathArray) }, - ensimeServerVersion = scalaVersion, + ensimeServerVersion = "2.0.0-SNAPSHOT", rootDir = projectDirectory, cacheDir = projectDirectory / ".ensime_cache", javaHome = Ensime.jdkHome, name = name, scalaVersion = scalaVersion, javaSources = Ensime.jdkSource.toSeq, - javaFlags = Ensime.baseJavaFlags(ensimeServerVersion), + javaFlags = Ensime.baseJavaFlags, projects = Ensime.findProjects(this) ) @@ -83,7 +80,7 @@ object Ensime { if (src.exists) Some(src) else None } - def baseJavaFlags(serverVersion: String): Seq[String] = { + def baseJavaFlags: Seq[String] = { val raw = ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList // WORKAROUND https://github.com/ensime/ensime-sbt/issues/91 @@ -102,28 +99,18 @@ object Ensime { val memory = Seq( "-Xss2m", "-Xms512m", - "-Xmx4g" + "-Xmx4g", + "-XX:MaxMetaspaceSize=256m", + // these improve ensime-server performance + "-XX:StringTableSize=1000003", + "-XX:+UnlockExperimentalVMOptions", + "-XX:SymbolTableSize=1000003" ) - val server = serverVersion.substring(0, 3) - val java = sys.props("java.version").substring(0, 3) - val versioned = (java, server) match { - case (_, "1.0") | ("1.6" | "1.7", _) => Seq( - "-XX:MaxPermSize=256m" - ) - case _ => List( - "-XX:MaxMetaspaceSize=256m", - // these improve ensime-server performance - "-XX:StringTableSize=1000003", - "-XX:+UnlockExperimentalVMOptions", - "-XX:SymbolTableSize=1000003" - ) - } - // WORKAROUND: https://github.com/scala/scala/pull/5592 val zipFix = Seq("-Dscala.classpath.closeZip=true") - corrected ++ memory ++ versioned ++ zipFix + corrected ++ memory ++ zipFix } /** Attempt to download a maven dependency with a given classifer. Warn if it is not available. */ -- cgit v1.2.3