Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

JPS: retrieve and use Java compiler options

  • Loading branch information...
commit fe23bfb23a93b20a39362c6117eb4e6d253558fa 1 parent f21fd39
Pavel Fatin pavelfatin authored
2  jps-plugin/src/org/jetbrains/jps/incremental/scala/ScalaBuilder.scala
@@ -147,7 +147,7 @@ private class IdeClient(compilerName: String,
147 147 throw new RuntimeException("Unknown source file: " + source)
148 148 }
149 149 val compiledClass = {
150   - // TODO expect future JSP API to load the generated file content lazily (on demand)
  150 + // TODO expect future JPS API to load the generated file content lazily (on demand)
151 151 val content = new BinaryContent(FileUtil.loadFileBytes(module))
152 152 new CompiledClass(module, source, name, content)
153 153 }
1  jps-plugin/src/org/jetbrains/jps/incremental/scala/ScalaBuilderService.java
@@ -45,6 +45,7 @@ public ExitCode build(CompileContext context,
45 45 }
46 46 }
47 47
  48 + // TODO expect future JPS API to provide a more elegant way to substitute default Java compiler
48 49 private static class StubTargetBuilder extends TargetBuilder<JavaSourceRootDescriptor, ModuleBuildTarget> {
49 50 public StubTargetBuilder() {
50 51 super(Collections.<BuildTargetType<ModuleBuildTarget>>emptyList());
53 jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala
@@ -8,6 +8,9 @@ import org.jetbrains.jps.incremental.scala.SettingsManager
8 8 import collection.JavaConverters._
9 9 import org.jetbrains.jps.incremental.scala.model.Order
10 10 import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
  11 +import org.jetbrains.jps.model.java.JpsJavaExtensionService
  12 +import org.jetbrains.jps.model.java.LanguageLevel._
  13 +import org.jetbrains.jps.model.module.JpsModule
11 14
12 15 /**
13 16 * @author Pavel Fatin
@@ -36,8 +39,9 @@ object CompilationData {
36 39 val scalaOptions = Option(SettingsManager.getFacetSettings(module))
37 40 .map(_.getCompilerOptions.toSeq).getOrElse(Seq.empty)
38 41
  42 + val project = context.getProjectDescriptor.getModel.getProject
  43 +
39 44 val order = {
40   - val project = context.getProjectDescriptor.getModel.getProject
41 45 val projectSettings = SettingsManager.getProjectSettings(project)
42 46 projectSettings.getCompilationOrder
43 47 }
@@ -55,12 +59,57 @@ object CompilationData {
55 59 Option(encoding).map(Seq("-encoding", _)).getOrElse(Seq.empty)
56 60 }
57 61
58   - val javaOptions = Seq("-g:lines,vars,source")
  62 + val javaOptions = javaOptionsFor(module)
59 63
60 64 CompilationData(sources, classpath, output, commonOptions ++ scalaOptions, commonOptions ++ javaOptions, order, cacheFile, relevantOutputToCacheMap)
61 65 }
62 66 }
63 67
  68 + // TODO expect future JPS API to provide a public API for Java options retrieval
  69 + private def javaOptionsFor(module: JpsModule): Seq[String] = {
  70 + val config = {
  71 + val project = module.getProject
  72 + val compilerConfig = JpsJavaExtensionService.getInstance.getOrCreateCompilerConfiguration(project)
  73 + compilerConfig.getCurrentCompilerOptions
  74 + }
  75 +
  76 + var options: Vector[String] = Vector.empty
  77 +
  78 + if (config.DEBUGGING_INFO) {
  79 + options :+= "-g"
  80 + }
  81 +
  82 + if (config.DEPRECATION) {
  83 + options :+= "-deprecation"
  84 + }
  85 +
  86 + if (config.GENERATE_NO_WARNINGS) {
  87 + options :+= "-nowarn"
  88 + }
  89 +
  90 + javaLanguageLevelFor(module).foreach { level =>
  91 + options :+= "-source"
  92 + options :+= level
  93 + }
  94 +
  95 + if (!config.ADDITIONAL_OPTIONS_STRING.isEmpty) {
  96 + options ++= config.ADDITIONAL_OPTIONS_STRING.split("\\s+").toSeq
  97 + }
  98 +
  99 + options
  100 + }
  101 +
  102 + private def javaLanguageLevelFor(module: JpsModule): Option[String] = {
  103 + Option(JpsJavaExtensionService.getInstance.getLanguageLevel(module)).collect {
  104 + case JDK_1_3 => "1.3"
  105 + case JDK_1_4 => "1.4"
  106 + case JDK_1_5 => "1.5"
  107 + case JDK_1_6 => "1.6"
  108 + case JDK_1_7 => "1.7"
  109 + case JDK_1_8 => "8"
  110 + }
  111 + }
  112 +
64 113 private def createOutputToCacheMap(context: CompileContext): Map[File, File] = {
65 114 val buildTargetIndex = context.getProjectDescriptor.getBuildTargetIndex
66 115 val paths = context.getProjectDescriptor.dataManager.getDataPaths

0 comments on commit fe23bfb

Please sign in to comment.
Something went wrong with that request. Please try again.