Skip to content

Commit

Permalink
Code refactoring. Separated Hydra logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
maris123 committed Nov 9, 2017
1 parent 61dc697 commit c7b7c4a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions
import org.jetbrains.jps.{ModuleChunk, ProjectPaths}
import com.intellij.openapi.diagnostic.{Logger => JpsLogger}
import org.jetbrains.jps.model.module.JpsModule

import scala.collection.JavaConverters._

Expand Down Expand Up @@ -79,24 +80,12 @@ object CompilationData {

val canonicalSources = sources.map(_.getCanonicalFile)

val hydraSettings = SettingsManager.getHydraSettings(context.getProjectDescriptor.getProject)
val hydraGlobalSettings = SettingsManager.getGlobalHydraSettings(context.getProjectDescriptor.getModel.getGlobal)
val scalaVersion = CompilerData.compilerVersion(module)
val hydraConfigFolder = if (target.isTests) "test" else "main"
val hydraOptions =
if (hydraSettings.isHydraEnabled && scalaVersion.nonEmpty && hydraGlobalSettings.containsArtifactsFor(scalaVersion.get, hydraSettings.getHydraVersion))
Seq("-sourcepath", outputGroups.map(_._1).mkString(File.pathSeparator), "-cpus", hydraSettings.getNumberOfCores,
"-YsourcePartitioner:" + hydraSettings.getSourcePartitioner, "-YhydraStore", Paths.get(hydraSettings.getHydraStorePath, module.getName, hydraConfigFolder).toString,
"-YpartitionFile", Paths.get(hydraSettings.getHydraStorePath, module.getName).toString, "-YrootDirectory", hydraSettings.getProjectRoot,
"-YtimingsFile", Paths.get(hydraSettings.getHydraStorePath, "timings.csv").toString, "-YhydraTag", s"${module.getName}/${hydraConfigFolder}")
else
Seq.empty
Log.debug("Hydra options: " + hydraOptions.mkString(" "))

val isCompile =
!JavaBuilderUtil.isCompileJavaIncrementally(context) &&
!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)

val hydraOptions = getHydraCompilerOptions(target, context, module, outputGroups)

CompilationData(canonicalSources, classpath, output, commonOptions ++ scalaOptions ++ hydraOptions, commonOptions ++ javaOptions,
order, cacheFile, relevantOutputToCacheMap, outputGroups,
ZincData(allSources, compilationStamp, isCompile))
Expand Down Expand Up @@ -229,4 +218,22 @@ object CompilationData {
"\nPlease configure separate output paths to proceed with the compilation." +
"\nTIP: you can use Project Artifacts to combine compiled classes if needed.")
}

private def getHydraCompilerOptions(target: ModuleBuildTarget, context: CompileContext, module: JpsModule, outputGroups: Seq[(File, File)]) = {
val hydraSettings = SettingsManager.getHydraSettings(context.getProjectDescriptor.getProject)
val hydraGlobalSettings = SettingsManager.getGlobalHydraSettings(context.getProjectDescriptor.getModel.getGlobal)
val scalaVersion = CompilerData.compilerVersion(module)
val hydraConfigFolder = if (target.isTests) "test" else "main"
val hydraOptions =
if (hydraSettings.isHydraEnabled && scalaVersion.nonEmpty && hydraGlobalSettings.containsArtifactsFor(scalaVersion.get, hydraSettings.getHydraVersion))
Seq("-sourcepath", outputGroups.map(_._1).mkString(File.pathSeparator), "-cpus", hydraSettings.getNumberOfCores,
"-YsourcePartitioner:" + hydraSettings.getSourcePartitioner, "-YhydraStore", Paths.get(hydraSettings.getHydraStorePath, module.getName, hydraConfigFolder).toString,
"-YpartitionFile", Paths.get(hydraSettings.getHydraStorePath, module.getName).toString, "-YrootDirectory", hydraSettings.getProjectRoot,
"-YtimingsFile", Paths.get(hydraSettings.getHydraStorePath, "timings.csv").toString, "-YhydraTag", s"${module.getName}/${hydraConfigFolder}")
else
Seq.empty
Log.debug("Hydra options: " + hydraOptions.mkString(" "))

hydraOptions
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.jetbrains.jps.incremental.scala.model.{IncrementalityType, LibrarySet
import org.jetbrains.jps.model.java.JpsJavaSdkType
import org.jetbrains.jps.model.module.JpsModule
import com.intellij.openapi.diagnostic.{Logger => JpsLogger}
import org.jetbrains.jps.cmdline.ProjectDescriptor

import scala.collection.JavaConverters._

Expand All @@ -27,34 +28,11 @@ object CompilerData {
val target = chunk.representativeTarget
val module = target.getModule

def useHydraCompiler(jars: CompilerJars): Boolean = {
val hydraGlobalSettings = SettingsManager.getGlobalHydraSettings(project.getModel.getGlobal)
val hydraProjectSettings = SettingsManager.getHydraSettings(project.getProject)

val enabled = hydraProjectSettings.isHydraEnabled
val compilerVer = compilerVersion(module)
val hydraArtifactsExist = compilerVer.map(v => hydraGlobalSettings.containsArtifactsFor(v, hydraProjectSettings.getHydraVersion)).getOrElse(false)
val res = enabled && hydraArtifactsExist

if (enabled && !res) {
val reason =
if (compilerVer.isEmpty) s"could not extract compiler version from module $module, ${compilerJarsIn(module)}"
else s"Hydra artifacts not found for ${compilerVer.get} and ${hydraProjectSettings.getHydraVersion}."

Log.error(s"Not using Hydra compiler for ${module.getName} because $reason")
}
res
}

val compilerJars = if (SettingsManager.hasScalaSdk(module)) {
compilerJarsIn(module).flatMap { case jars: CompilerJars =>
val compileJars =
if (useHydraCompiler(jars)) {
val scalaVersion = compilerVersion(module).get
val hydraData = HydraData(project.getProject, scalaVersion)
val hydraOtherJars = hydraData.otherJars
val extraJars = if(hydraOtherJars.nonEmpty) hydraOtherJars else jars.extra
CompilerJars(jars.library, hydraData.getCompilerJar.getOrElse(jars.compiler), extraJars)
if (useHydraCompiler(project, module, jars)) {
getHydraCompilerJars(project, module, jars)
} else jars
Log.info("Compiler jars: " + compileJars.files.map(_.getName))
val absentJars = compileJars.files.filter(!_.exists)
Expand Down Expand Up @@ -176,4 +154,30 @@ object CompilerData {

private def version(compiler: File): Option[String] = readProperty(compiler, "compiler.properties", "version.number")

private def useHydraCompiler(project: ProjectDescriptor, module: JpsModule, jars: CompilerJars): Boolean = {
val hydraGlobalSettings = SettingsManager.getGlobalHydraSettings(project.getModel.getGlobal)
val hydraProjectSettings = SettingsManager.getHydraSettings(project.getProject)

val enabled = hydraProjectSettings.isHydraEnabled
val compilerVer = compilerVersion(module)
val hydraArtifactsExist = compilerVer.map(v => hydraGlobalSettings.containsArtifactsFor(v, hydraProjectSettings.getHydraVersion)).getOrElse(false)
val res = enabled && hydraArtifactsExist

if (enabled && !res) {
val reason =
if (compilerVer.isEmpty) s"could not extract compiler version from module $module, ${compilerJarsIn(module)}"
else s"Hydra artifacts not found for ${compilerVer.get} and ${hydraProjectSettings.getHydraVersion}."

Log.error(s"Not using Hydra compiler for ${module.getName} because $reason")
}
res
}

private def getHydraCompilerJars(project: ProjectDescriptor, module: JpsModule, jars: CompilerJars) = {
val scalaVersion = compilerVersion(module).get
val hydraData = HydraData(project.getProject, scalaVersion)
val hydraOtherJars = hydraData.otherJars
val extraJars = if(hydraOtherJars.nonEmpty) hydraOtherJars else jars.extra
CompilerJars(jars.library, hydraData.getCompilerJar.getOrElse(jars.compiler), extraJars)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.jetbrains.plugins.hydra.notification

import com.intellij.openapi.module.Module
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.ui.{EditorNotificationPanel, EditorNotifications}
import org.jetbrains.plugins.hydra.HydraVersions
import org.jetbrains.plugins.hydra.compiler.HydraCompilerSettings
import org.jetbrains.plugins.hydra.settings.HydraApplicationSettings
import org.jetbrains.plugins.scala.compiler.CompileServerManager
import org.jetbrains.plugins.scala.project.notification.AbstractNotificationProvider
import org.jetbrains.plugins.hydra.notification.HydraArtifactsNotificationProvider._

Expand All @@ -31,11 +31,14 @@ class HydraArtifactsNotificationProvider(project: Project, notifications: Editor
}
}

override protected def createTask(module: Module): Runnable = () => CompileServerManager.showHydraCompileSettingsDialog(project)
override protected def createTask(module: Module): Runnable = () => showHydraCompileSettingsDialog()

override protected def panelText: String = s"No $developerKitTitle artifacts in module. Please download the artifacts."

override protected def developerKitTitle: String = HydraTitle

private def showHydraCompileSettingsDialog(): Unit = ShowSettingsUtil.getInstance().showSettingsDialog(project, "Hydra Compiler")

}

object HydraArtifactsNotificationProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,4 @@ object CompileServerManager {
def showCompileServerSettingsDialog(project: Project): Unit = {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Scala Compile Server")
}

def showHydraCompileSettingsDialog(project: Project): Unit = {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Hydra Compiler")
}
}

0 comments on commit c7b7c4a

Please sign in to comment.