Skip to content

Commit

Permalink
Determine JVM SDK relying on configuration data
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfatin committed Dec 23, 2012
1 parent dd1e47b commit 44d94c4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
Expand Up @@ -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
}
Expand Down
Expand Up @@ -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] = {
Expand All @@ -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, _))
}
}
}
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -6,7 +6,9 @@
* @author Pavel Fatin
*/
public interface GlobalSettings extends JpsElement {
boolean isCompilationServerEnabled();
boolean isCompileServerEnabled();

int getCompilationServerPort();
int getCompileServerPort();

String getCompileServerSdk();
}
Expand Up @@ -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() {
Expand All @@ -39,5 +43,7 @@ public static class State {
public boolean COMPILE_SERVER_ENABLED = true;

public int COMPILE_SERVER_PORT = 3200;

public String COMPILE_SERVER_SDK;
}
}
Expand Up @@ -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),
Expand All @@ -46,7 +48,7 @@ object Arguments {
PathToFile(interfacesHome),
javaClassVersion,
StringToOption(compilerJarPaths),
PathToFile(javaHome),
StringToOption(javaHomePath),
PathsToFiles(sources),
PathsToFiles(classpath),
PathToFile(output),
Expand All @@ -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

Expand Down

0 comments on commit 44d94c4

Please sign in to comment.