Permalink
Browse files

JPS: retrieve and use Java compiler options

  • Loading branch information...
1 parent f21fd39 commit fe23bfb23a93b20a39362c6117eb4e6d253558fa @pavelfatin pavelfatin committed Dec 7, 2012
View
2 jps-plugin/src/org/jetbrains/jps/incremental/scala/ScalaBuilder.scala
@@ -147,7 +147,7 @@ private class IdeClient(compilerName: String,
throw new RuntimeException("Unknown source file: " + source)
}
val compiledClass = {
- // TODO expect future JSP API to load the generated file content lazily (on demand)
+ // TODO expect future JPS API to load the generated file content lazily (on demand)
val content = new BinaryContent(FileUtil.loadFileBytes(module))
new CompiledClass(module, source, name, content)
}
View
1 jps-plugin/src/org/jetbrains/jps/incremental/scala/ScalaBuilderService.java
@@ -45,6 +45,7 @@ public ExitCode build(CompileContext context,
}
}
+ // TODO expect future JPS API to provide a more elegant way to substitute default Java compiler
private static class StubTargetBuilder extends TargetBuilder<JavaSourceRootDescriptor, ModuleBuildTarget> {
public StubTargetBuilder() {
super(Collections.<BuildTargetType<ModuleBuildTarget>>emptyList());
View
53 jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala
@@ -8,6 +8,9 @@ import org.jetbrains.jps.incremental.scala.SettingsManager
import collection.JavaConverters._
import org.jetbrains.jps.incremental.scala.model.Order
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
+import org.jetbrains.jps.model.java.JpsJavaExtensionService
+import org.jetbrains.jps.model.java.LanguageLevel._
+import org.jetbrains.jps.model.module.JpsModule
/**
* @author Pavel Fatin
@@ -36,8 +39,9 @@ object CompilationData {
val scalaOptions = Option(SettingsManager.getFacetSettings(module))
.map(_.getCompilerOptions.toSeq).getOrElse(Seq.empty)
+ val project = context.getProjectDescriptor.getModel.getProject
+
val order = {
- val project = context.getProjectDescriptor.getModel.getProject
val projectSettings = SettingsManager.getProjectSettings(project)
projectSettings.getCompilationOrder
}
@@ -55,12 +59,57 @@ object CompilationData {
Option(encoding).map(Seq("-encoding", _)).getOrElse(Seq.empty)
}
- val javaOptions = Seq("-g:lines,vars,source")
+ val javaOptions = javaOptionsFor(module)
CompilationData(sources, classpath, output, commonOptions ++ scalaOptions, commonOptions ++ javaOptions, order, cacheFile, relevantOutputToCacheMap)
}
}
+ // TODO expect future JPS API to provide a public API for Java options retrieval
+ private def javaOptionsFor(module: JpsModule): Seq[String] = {
+ val config = {
+ val project = module.getProject
+ val compilerConfig = JpsJavaExtensionService.getInstance.getOrCreateCompilerConfiguration(project)
+ compilerConfig.getCurrentCompilerOptions
+ }
+
+ var options: Vector[String] = Vector.empty
+
+ if (config.DEBUGGING_INFO) {
+ options :+= "-g"
+ }
+
+ if (config.DEPRECATION) {
+ options :+= "-deprecation"
+ }
+
+ if (config.GENERATE_NO_WARNINGS) {
+ options :+= "-nowarn"
+ }
+
+ javaLanguageLevelFor(module).foreach { level =>
+ options :+= "-source"
+ options :+= level
+ }
+
+ if (!config.ADDITIONAL_OPTIONS_STRING.isEmpty) {
+ options ++= config.ADDITIONAL_OPTIONS_STRING.split("\\s+").toSeq
+ }
+
+ options
+ }
+
+ private def javaLanguageLevelFor(module: JpsModule): Option[String] = {
+ Option(JpsJavaExtensionService.getInstance.getLanguageLevel(module)).collect {
+ case JDK_1_3 => "1.3"
+ case JDK_1_4 => "1.4"
+ case JDK_1_5 => "1.5"
+ case JDK_1_6 => "1.6"
+ case JDK_1_7 => "1.7"
+ case JDK_1_8 => "8"
+ }
+ }
+
private def createOutputToCacheMap(context: CompileContext): Map[File, File] = {
val buildTargetIndex = context.getProjectDescriptor.getBuildTargetIndex
val paths = context.getProjectDescriptor.dataManager.getDataPaths

0 comments on commit fe23bfb

Please sign in to comment.