Permalink
Browse files

Determine JVM SDK relying on configuration data

  • Loading branch information...
1 parent dd1e47b commit 44d94c4fecf3c48672f91d45d59bd3e0b735166b @pavelfatin pavelfatin committed Dec 23, 2012
@@ -101,9 +101,9 @@ class ScalaBuilder extends ModuleLevelBuilder(BuilderCategory.TRANSLATOR) {
CompilationData.from(sources, context, chunk).map { compilationData =>
val settings = SettingsManager.getGlobalSettings(context.getProjectDescriptor.getModel.getGlobal)
- val server = if (settings.isCompilationServerEnabled) {
+ val server = if (settings.isCompileServerEnabled) {
ScalaBuilder.cleanLocalServerCache()
- new RemoteServer(InetAddress.getByName(null), settings.getCompilationServerPort)
+ new RemoteServer(InetAddress.getByName(null), settings.getCompileServerPort)
} else {
ScalaBuilder.localServer
}
@@ -15,7 +15,7 @@ import collection.JavaConverters._
/**
* @author Pavel Fatin
*/
-case class CompilerData(javaHome: File, compilerJars: Option[CompilerJars])
+case class CompilerData(compilerJars: Option[CompilerJars], javaHome: Option[File])
object CompilerData {
def from(context: CompileContext, chunk: ModuleChunk): Either[String, CompilerData] = {
@@ -31,14 +31,26 @@ object CompilerData {
Option(module.getSdk(JpsJavaSdkType.INSTANCE))
.toRight("No JDK in module " + module.getName)
- .flatMap { jdk =>
+ .flatMap { moduleJdk =>
+
+ val globalSettings = SettingsManager.getGlobalSettings(model.getGlobal)
+
+ val jvmSdk = if (globalSettings.isCompileServerEnabled) {
+ Option(globalSettings.getCompileServerSdk).flatMap { sdkName =>
+ val libraries = model.getGlobal.getLibraryCollection.getLibraries(JpsJavaSdkType.INSTANCE).asScala
+ libraries.find(_.getName == sdkName).map(_.getProperties)
+ }
+ } else {
+ Option(model.getProject.getSdkReferencesTable.getSdkReference(JpsJavaSdkType.INSTANCE))
+ .flatMap(references => Option(references.resolve)).map(_.getProperties)
+ }
- val javaHome = {
- val directory = new File(jdk.getHomePath)
- Either.cond(directory.exists, directory, "JDK home directory does not exists: " + directory)
+ val javaHome = if (jvmSdk.exists(_ == moduleJdk)) Right(None) else {
+ val directory = new File(moduleJdk.getHomePath)
+ Either.cond(directory.exists, Some(directory), "JDK home directory does not exists: " + directory)
}
- javaHome.map(CompilerData(_, jars))
+ javaHome.map(CompilerData(jars, _))
}
}
}
@@ -29,13 +29,7 @@ class CompilerFactoryImpl(sbtData: SbtData) extends CompilerFactory {
val classpathOptions = ClasspathOptions.javac(compiler = false)
- val javaHome = {
- val home = compilerData.javaHome
- val vmHome = new File(System.getProperty("java.home"))
- if (home.getCanonicalPath == vmHome.getCanonicalPath) None else Some(home)
- }
-
- AggressiveCompile.directOrFork(scala, classpathOptions, javaHome)
+ AggressiveCompile.directOrFork(scala, classpathOptions, compilerData.javaHome)
}
new CompilerImpl(javac, scalac, fileToStore)
@@ -6,7 +6,9 @@
* @author Pavel Fatin
*/
public interface GlobalSettings extends JpsElement {
- boolean isCompilationServerEnabled();
+ boolean isCompileServerEnabled();
- int getCompilationServerPort();
+ int getCompileServerPort();
+
+ String getCompileServerSdk();
}
@@ -16,14 +16,18 @@ public GlobalSettingsImpl(State state) {
myState = state;
}
- public boolean isCompilationServerEnabled() {
+ public boolean isCompileServerEnabled() {
return myState.COMPILE_SERVER_ENABLED;
}
- public int getCompilationServerPort() {
+ public int getCompileServerPort() {
return myState.COMPILE_SERVER_PORT;
}
+ public String getCompileServerSdk() {
+ return myState.COMPILE_SERVER_SDK;
+ }
+
@NotNull
@Override
public GlobalSettingsImpl createCopy() {
@@ -39,5 +43,7 @@ public void applyChanges(@NotNull GlobalSettingsImpl compilerSettings) {
public boolean COMPILE_SERVER_ENABLED = true;
public int COMPILE_SERVER_PORT = 3200;
+
+ public String COMPILE_SERVER_SDK;
}
}
@@ -16,13 +16,15 @@ case class Arguments(sbtData: SbtData, compilerData: CompilerData, compilationDa
val compilerJarPaths = compilerData.compilerJars.map(jars => filesToPaths(jars.library +: jars.compiler +: jars.extra))
+ val javaHomePath = compilerData.javaHome.map(fileToPath)
+
Seq(
fileToPath(sbtData.interfaceJar),
fileToPath(sbtData.sourceJar),
fileToPath(sbtData.interfacesHome),
sbtData.javaClassVersion,
optionToString(compilerJarPaths),
- fileToPath(compilerData.javaHome),
+ optionToString(javaHomePath),
filesToPaths(compilationData.sources),
filesToPaths(compilationData.classpath),
fileToPath(compilationData.output),
@@ -46,7 +48,7 @@ object Arguments {
PathToFile(interfacesHome),
javaClassVersion,
StringToOption(compilerJarPaths),
- PathToFile(javaHome),
+ StringToOption(javaHomePath),
PathsToFiles(sources),
PathsToFiles(classpath),
PathToFile(output),
@@ -64,7 +66,11 @@ object Arguments {
CompilerJars(libraryJar, compilerJar, extraJars)
}
- val compilerData = CompilerData(javaHome, compilerJars)
+ val javaHome = javaHomePath.map {
+ case PathToFile(file) => file
+ }
+
+ val compilerData = CompilerData(compilerJars, javaHome)
val outputToCacheMap = outputs.zip(caches).toMap

0 comments on commit 44d94c4

Please sign in to comment.