From b63683ff998614f4175c02630316fece28792320 Mon Sep 17 00:00:00 2001 From: Maris Date: Sat, 14 Oct 2017 16:08:56 +0300 Subject: [PATCH] Pass all Hydra specific settings. Fix #1 Fix #4 --- .../scala/data/CompilationData.scala | 9 +- .../incremental/scala/data/CompilerData.scala | 2 +- .../scala/model/HydraSettings.java | 4 + .../scala/model/HydraSettingsImpl.java | 32 ++++-- .../compiler/HydraCompilerConfigurable.scala | 14 ++- .../HydraCompilerConfigurationPanel.form | 105 +++++++++++++----- .../HydraCompilerConfigurationPanel.java | 83 +++++++++++--- .../scala/compiler/HydraCompilerSettings.java | 36 ------ .../compiler/HydraCompilerSettings.scala | 89 +++++++++++++++ ...ScalaHydraCompilerConfigurationPanel.scala | 42 ++++++- .../plugins/scala/project/Versions.scala | 4 +- .../settings/HydraApplicationSettings.scala | 4 + 12 files changed, 329 insertions(+), 95 deletions(-) delete mode 100644 src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.java create mode 100644 src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.scala diff --git a/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala b/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala index 1926f065d37..846b86d3125 100644 --- a/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala +++ b/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilationData.scala @@ -2,6 +2,7 @@ package org.jetbrains.jps.incremental.scala package data import java.io.{File, IOException} +import java.nio.file.Paths import java.util import java.util.Collections @@ -12,6 +13,7 @@ import org.jetbrains.jps.incremental.{CompileContext, ModuleBuildTarget} 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 scala.collection.JavaConverters._ @@ -34,6 +36,7 @@ case class CompilationData(sources: Seq[File], } object CompilationData { + private val Log: JpsLogger = JpsLogger.getInstance(CompilationData.getClass.getName) private val compilationStamp = System.nanoTime() def from(sources: Seq[File], allSources: Seq[File], context: CompileContext, chunk: ModuleChunk): Either[String, CompilationData] = { @@ -81,9 +84,13 @@ object CompilationData { val scalaVersion = CompilerData.compilerVersion(module) val hydraOptions = if (hydraSettings.isHydraEnabled && scalaVersion.nonEmpty && hydraGlobalSettings.containsArtifactsFor(scalaVersion.get, hydraSettings.getHydraVersion)) - Seq("-sourcepath", outputGroups.map(_._1).mkString(File.pathSeparator), "-cpus", "2") + Seq("-sourcepath", outputGroups.map(_._1).mkString(File.pathSeparator), "-cpus", hydraSettings.getNumberOfCores, + "-YsourcePartitioner:" + hydraSettings.getSourcePartitioner, "-YhydraStore", hydraSettings.getHydraStorePath, + "-YpartitionFile", Paths.get(hydraSettings.getHydraStorePath, module.getName).toString, "-YrootDirectory", hydraSettings.getProjectRoot, + "-YtimingsFile", Paths.get(hydraSettings.getHydraStorePath, "timings.csv").toString, "-YhydraTag", module.getName) else Seq.empty + Log.debug("Hydra options: " + hydraOptions.mkString(" ")) val isCompile = !JavaBuilderUtil.isCompileJavaIncrementally(context) && diff --git a/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilerData.scala b/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilerData.scala index aa9dea22436..6a145e1cee7 100644 --- a/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilerData.scala +++ b/jps-plugin/src/org/jetbrains/jps/incremental/scala/data/CompilerData.scala @@ -20,7 +20,7 @@ import scala.collection.JavaConverters._ case class CompilerData(compilerJars: Option[CompilerJars], javaHome: Option[File], incrementalType: IncrementalityType) object CompilerData { - private val Log: JpsLogger = JpsLogger.getInstance(CompilationData.getClass.getName) + private val Log: JpsLogger = JpsLogger.getInstance(CompilerData.getClass.getName) def from(context: CompileContext, chunk: ModuleChunk): Either[String, CompilerData] = { val project = context.getProjectDescriptor diff --git a/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettings.java b/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettings.java index 7c97fc4111a..ce95d9e1aa2 100644 --- a/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettings.java +++ b/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettings.java @@ -10,5 +10,9 @@ */ public interface HydraSettings extends JpsElement { boolean isHydraEnabled(); + String getNumberOfCores(); String getHydraVersion(); + String getSourcePartitioner(); + String getHydraStorePath(); + String getProjectRoot(); } diff --git a/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettingsImpl.java b/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettingsImpl.java index 35b530bf566..efee23cd0b6 100644 --- a/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettingsImpl.java +++ b/jpsShared/src/org/jetbrains/jps/incremental/scala/model/HydraSettingsImpl.java @@ -4,9 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.ex.JpsElementBase; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.nio.file.Paths; /** * @author Maris Alexandru @@ -14,24 +12,38 @@ public class HydraSettingsImpl extends JpsElementBase implements HydraSettings{ public static final HydraSettings DEFAULT = new HydraSettingsImpl(new State()); - private final State myState; + private final State state; public HydraSettingsImpl(State state) { - this.myState = state; + this.state = state; } @Override - public boolean isHydraEnabled() { return myState.isHydraEnabled; } + public boolean isHydraEnabled() { return state.isHydraEnabled; } @Override public String getHydraVersion() { - return myState.hydraVersion; + return state.hydraVersion; } + @Override + public String getNumberOfCores() { + return state.noOfCores; + } + + @Override + public String getHydraStorePath() { return Paths.get(state.hydraStorePath).toString(); } + + @Override + public String getSourcePartitioner() { return state.sourcePartitioner; } + + @Override + public String getProjectRoot() { return Paths.get(state.projectRoot).toString(); } + @NotNull @Override public HydraSettingsImpl createCopy() { - return new HydraSettingsImpl(XmlSerializerUtil.createCopy(myState)); + return new HydraSettingsImpl(XmlSerializerUtil.createCopy(state)); } @Override @@ -42,5 +54,9 @@ public void applyChanges(@NotNull HydraSettingsImpl hydraSettings) { public static class State { public boolean isHydraEnabled = false; public String hydraVersion = ""; + public String noOfCores = Integer.toString((int) Math.ceil(Runtime.getRuntime().availableProcessors()/2D)); + public String hydraStorePath = ""; + public String sourcePartitioner = ""; + public String projectRoot = ""; } } diff --git a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurable.scala b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurable.scala index 5d1ac74eb0c..a8fd52692e7 100644 --- a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurable.scala +++ b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurable.scala @@ -18,18 +18,28 @@ class HydraCompilerConfigurable (project: Project, settings: HydraCompilerSettin override def isModified: Boolean = form.isHydraEnabled != settings.isHydraEnabled || form.getUsername != HydraCredentialsManager.getLogin || form.getPassword != HydraCredentialsManager.getPlainPassword || - form.selectedVersion != settings.hydraVersion + form.selectedVersion != settings.hydraVersion || + form.selectedNoOfCores != settings.noOfCores || + form.selectedSourcePartitioner != settings.sourcePartitioner || + form.getHydraStoreDirectory != settings.hydraStorePath override def reset() { form.setUsername(HydraCredentialsManager.getLogin) form.setPassword(HydraCredentialsManager.getPlainPassword) form.setIsHydraEnabled(settings.isHydraEnabled) + form.setSelectedNoOfCores(settings.noOfCores) + form.setSelectedVersion(settings.hydraVersion) + form.setSelectedSourcePartitioner(settings.sourcePartitioner) + form.setHydraStoreDirectory(settings.hydraStorePath) } override def apply() { BuildManager.getInstance().clearState(project) - settings.isHydraEnabled = form.isHydraEnabled settings.hydraVersion = form.selectedVersion + settings.isHydraEnabled = form.isHydraEnabled + settings.noOfCores = form.selectedNoOfCores + settings.sourcePartitioner = form.selectedSourcePartitioner + settings.hydraStorePath = form.getHydraStoreDirectory HydraCredentialsManager.setCredentials(form.getUsername, form.getPassword) } } \ No newline at end of file diff --git a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.form b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.form index c5fe5b903a0..dff9c17a0f8 100644 --- a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.form +++ b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.form @@ -3,12 +3,12 @@ - + - + @@ -18,33 +18,15 @@ - + - - - - - - - - - - - - - - - - - - - + @@ -52,7 +34,7 @@ - + @@ -60,7 +42,7 @@ - + @@ -68,7 +50,7 @@ - + @@ -76,7 +58,7 @@ - + @@ -85,7 +67,76 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.java b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.java index 762b3e8d2ee..228ef0391ae 100644 --- a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.java +++ b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerConfigurationPanel.java @@ -1,12 +1,15 @@ package org.jetbrains.plugins.scala.compiler; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; +import org.jetbrains.annotations.NotNull; import org.jetbrains.sbt.project.template.SComboBox; import javax.swing.*; import java.awt.*; +import java.util.Arrays; /** * @author Maris Alexandru @@ -18,9 +21,12 @@ public class HydraCompilerConfigurationPanel { protected JCheckBox enableHydraCheckBox; protected JButton downloadButton; protected SComboBox hydraVersionComboBox; + protected SComboBox noOfCoresComboBox; + protected SComboBox sourcePartitionerComboBox; + protected TextFieldWithBrowseButton hydraStoreDirectoryField; public HydraCompilerConfigurationPanel() { - //TODO Hydra Version ComboBox + } public JPanel getContentPanel() { @@ -51,6 +57,28 @@ public boolean isHydraEnabled() { return enableHydraCheckBox.isSelected(); } + public Color getDefaultValueColor() { + return findColorByKey("TextField.inactiveForeground", "nimbusDisabledText"); + } + + public Color getChangedValueColor() { + return findColorByKey("TextField.foreground"); + } + + @NotNull + private static Color findColorByKey(String... colorKeys) { + Color c = null; + for (String key : colorKeys) { + c = UIManager.getColor(key); + if (c != null) { + break; + } + } + + assert c != null : "Can't find color for keys " + Arrays.toString(colorKeys); + return c; + } + /** * @noinspection ALL */ @@ -70,6 +98,10 @@ public boolean isHydraEnabled() { return new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); } + private void createUIComponents() { + // TODO: place custom component creation code here + } + { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPORTANT!! <<< @@ -88,34 +120,55 @@ public boolean isHydraEnabled() { contentPanel = new JPanel(); contentPanel.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1)); final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(5, 6, new Insets(0, 0, 0, 0), -1, -1)); + panel1.setLayout(new GridLayoutManager(8, 8, new Insets(0, 0, 0, 0), -1, -1)); contentPanel.add(panel1, new GridConstraints(0, 0, 3, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); final JLabel label1 = new JLabel(); label1.setText("Username"); - panel1.add(label1, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - panel1.add(spacer1, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); - final Spacer spacer2 = new Spacer(); - panel1.add(spacer2, new GridConstraints(4, 0, 1, 5, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + panel1.add(label1, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); userTextField = new JTextField(); - panel1.add(userTextField, new GridConstraints(0, 2, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); - passwordTextField = new JPasswordField(); - panel1.add(passwordTextField, new GridConstraints(1, 2, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + panel1.add(userTextField, new GridConstraints(0, 3, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label2 = new JLabel(); label2.setText("Password"); - panel1.add(label2, new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel1.add(label2, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); enableHydraCheckBox = new JCheckBox(); enableHydraCheckBox.setText("Enable Hydra"); - panel1.add(enableHydraCheckBox, new GridConstraints(2, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel1.add(enableHydraCheckBox, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JLabel label3 = new JLabel(); label3.setText("Hydra Version"); - panel1.add(label3, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel1.add(label3, new GridConstraints(2, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); downloadButton = new JButton(); downloadButton.setEnabled(true); downloadButton.setText("Download"); - panel1.add(downloadButton, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel1.add(downloadButton, new GridConstraints(3, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); hydraVersionComboBox = new SComboBox(); - panel1.add(hydraVersionComboBox, new GridConstraints(2, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); + hydraVersionComboBox.setModel(defaultComboBoxModel1); + panel1.add(hydraVersionComboBox, new GridConstraints(2, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 6, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final Spacer spacer2 = new Spacer(); + panel1.add(spacer2, new GridConstraints(2, 5, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + passwordTextField = new JPasswordField(); + panel1.add(passwordTextField, new GridConstraints(1, 3, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + final JLabel label4 = new JLabel(); + label4.setText("Number of cores"); + panel1.add(label4, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + panel1.add(spacer3, new GridConstraints(7, 0, 1, 6, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + noOfCoresComboBox = new SComboBox(); + final DefaultComboBoxModel defaultComboBoxModel2 = new DefaultComboBoxModel(); + noOfCoresComboBox.setModel(defaultComboBoxModel2); + panel1.add(noOfCoresComboBox, new GridConstraints(4, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + sourcePartitionerComboBox = new SComboBox(); + panel1.add(sourcePartitionerComboBox, new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label5 = new JLabel(); + label5.setText("Source Partitioner"); + panel1.add(label5, new GridConstraints(5, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label6 = new JLabel(); + label6.setText("Hydra Store"); + panel1.add(label6, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + hydraStoreDirectoryField = new TextFieldWithBrowseButton(); + panel1.add(hydraStoreDirectoryField, new GridConstraints(6, 2, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } /** diff --git a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.java b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.java deleted file mode 100644 index 97caecc0a63..00000000000 --- a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.jetbrains.plugins.scala.compiler; - -import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; -import com.intellij.util.xmlb.XmlSerializerUtil; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Maris Alexandru - */ -@State( - name = "HydraSettings", - storages = {@Storage("hydra.xml")} -) -class HydraCompilerSettings implements PersistentStateComponent { - public boolean isHydraEnabled = false; - - public String hydraVersion = ""; - - public HydraCompilerSettings getState() { - return this; - } - public void loadState(HydraCompilerSettings state) { - XmlSerializerUtil.copyBean(state, this); - } - - public static HydraCompilerSettings getInstance() { - return ServiceManager.getService(HydraCompilerSettings.class); - } -} - diff --git a/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.scala b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.scala new file mode 100644 index 00000000000..64447732195 --- /dev/null +++ b/src/org/jetbrains/plugins/scala/compiler/HydraCompilerSettings.scala @@ -0,0 +1,89 @@ +package org.jetbrains.plugins.scala.compiler + +import java.io.File + +import com.intellij.openapi.components._ +import com.intellij.openapi.project.Project +import org.jetbrains.plugins.scala.compiler.SourcePartitioner.Auto + +import scala.beans.BeanProperty + +/** + * @author Maris Alexandru + */ +@State( + name = "HydraSettings", + storages = Array(new Storage("hydra.xml")) +) +class HydraCompilerSettings(project: Project) extends PersistentStateComponent[HydraCompilerSettingsState] { + + private val ProjectRoot: String = getProjectRootPath + + var isHydraEnabled: Boolean = false + + var hydraVersion: String = "0.9.5" + + var noOfCores: String = Math.ceil(Runtime.getRuntime.availableProcessors()/2D).toInt.toString + + var hydraStorePath: String = getDefaultHydraStorePath + + var sourcePartitioner: String = Auto.value + + override def getState: HydraCompilerSettingsState = { + val state = new HydraCompilerSettingsState() + state.hydraVersion = hydraVersion + state.noOfCores = noOfCores + state.isHydraEnabled = isHydraEnabled + state.hydraStorePath = hydraStorePath + state.sourcePartitioner = sourcePartitioner + state.projectRoot = ProjectRoot + state + } + + override def loadState(state: HydraCompilerSettingsState): Unit = { + isHydraEnabled = state.isHydraEnabled + hydraVersion = state.hydraVersion + noOfCores = state.noOfCores + hydraStorePath = state.hydraStorePath + sourcePartitioner = state.sourcePartitioner + } + + def getDefaultHydraStorePath: String = ProjectRoot + File.separator + ".hydra" + + private def getProjectRootPath: String = project.getBaseDir.getPresentableUrl +} + +object HydraCompilerSettings { + def getInstance(project: Project): HydraCompilerSettings = ServiceManager.getService(project, classOf[HydraCompilerSettings]) +} + +class HydraCompilerSettingsState { + @BeanProperty + var isHydraEnabled: Boolean = false + + @BeanProperty + var hydraVersion: String = "" + + @BeanProperty + var noOfCores: String = "" + + @BeanProperty + var hydraStorePath: String = "" + + @BeanProperty + var sourcePartitioner: String = "" + + @BeanProperty + var projectRoot: String = "" +} + +object SourcePartitioner { + sealed abstract class SourcePartitioner(val value: String) + + case object Auto extends SourcePartitioner("auto") + case object Explicit extends SourcePartitioner("explicit") + case object Plain extends SourcePartitioner("plain") + case object Package extends SourcePartitioner("package") + + val values: Seq[SourcePartitioner] = Seq(Auto, Explicit, Plain, Package) +} diff --git a/src/org/jetbrains/plugins/scala/compiler/ScalaHydraCompilerConfigurationPanel.scala b/src/org/jetbrains/plugins/scala/compiler/ScalaHydraCompilerConfigurationPanel.scala index e08f74b895f..1590dc63e28 100644 --- a/src/org/jetbrains/plugins/scala/compiler/ScalaHydraCompilerConfigurationPanel.scala +++ b/src/org/jetbrains/plugins/scala/compiler/ScalaHydraCompilerConfigurationPanel.scala @@ -3,7 +3,8 @@ package org.jetbrains.plugins.scala.compiler import java.awt.event.{ActionEvent, FocusEvent, FocusListener} import javax.swing.event.DocumentEvent -import com.intellij.openapi.ui.Messages +import com.intellij.openapi.fileChooser.FileChooserDescriptor +import com.intellij.openapi.ui.{Messages, TextComponentAccessor} import org.jetbrains.plugins.scala.caches.HydraArtifactsCache import org.jetbrains.plugins.scala.extensions import com.intellij.openapi.project.Project @@ -18,6 +19,8 @@ import scala.util.{Failure, Success} */ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraCompilerSettings, hydraGlobalSettings: HydraApplicationSettings) extends HydraCompilerConfigurationPanel { + private val fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) + private val documentAdapter = new DocumentAdapter { override def textChanged(documentEvent: DocumentEvent): Unit = downloadButton.setEnabled(getUsername.nonEmpty && getPassword.nonEmpty) } @@ -28,7 +31,7 @@ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraComp override def focusLost(e: FocusEvent): Unit = if (getUsername.nonEmpty && getPassword.nonEmpty && (HydraCredentialsManager.getLogin != getUsername || HydraCredentialsManager.getPlainPassword != getPassword)) { HydraCredentialsManager.setCredentials(getUsername, getPassword) - hydraVersionComboBox.setItems(Versions.loadHydraVersions) + hydraVersionComboBox.setItems(downloadHydraVersions) } } @@ -37,20 +40,53 @@ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraComp userTextField.getDocument.addDocumentListener(documentAdapter) passwordTextField.getDocument.addDocumentListener(documentAdapter) passwordTextField.addFocusListener(focusListener) - hydraVersionComboBox.setItems(Versions.loadHydraVersions) + hydraVersionComboBox.setItems(downloadHydraVersions) downloadButton.addActionListener((_: ActionEvent) => onDownload()) + noOfCoresComboBox.setItems(Array.range(1, Runtime.getRuntime.availableProcessors() + 1).map(_.toString).sortWith(_ > _)) + sourcePartitionerComboBox.setItems(SourcePartitioner.values.map(_.value).toArray) + + hydraStoreDirectoryField.addBrowseFolderListener("", "Hydra Store Path", null, fileChooserDescriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) + hydraStoreDirectoryField.setText(settings.hydraStorePath) + + hydraStoreDirectoryField.getTextField.getDocument.addDocumentListener(new DocumentAdapter() { + override protected def textChanged(e: DocumentEvent): Unit = { + hydraStoreDirectoryField.getTextField.setForeground(if (hydraStoreDirectoryField.getText == settings.getDefaultHydraStorePath) getDefaultValueColor + else getChangedValueColor) + } + }) def selectedVersion: String = hydraVersionComboBox.getSelectedItem.toString + def setSelectedVersion(version: String): Unit = hydraVersionComboBox.setSelectedItem(version) + + def selectedNoOfCores: String = noOfCoresComboBox.getSelectedItem.toString + + def setSelectedNoOfCores(numberOfCores: String): Unit = noOfCoresComboBox.setSelectedItem(numberOfCores) + + def selectedSourcePartitioner: String = sourcePartitionerComboBox.getSelectedItem.toString + + def setSelectedSourcePartitioner(sourcePartitioner: String): Unit = sourcePartitionerComboBox.setSelectedItem(sourcePartitioner) + + def getHydraStoreDirectory: String = hydraStoreDirectoryField.getText + + def setHydraStoreDirectory(path: String): Unit = hydraStoreDirectoryField.setText(path) + def onDownload(): Unit = { val scalaVersions = for { module <- project.scalaModules scalaVersion <- module.sdk.compilerVersion } yield scalaVersion + downloadVersionWithProgress(scalaVersions, selectedVersion) settings.hydraVersion = selectedVersion } + private def downloadHydraVersions = { + (Versions.loadHydraVersions ++ hydraGlobalSettings.getDownloadedHydraVersions) + .distinct + .sortWith(Version(_) >= Version(_)) + } + private def downloadVersionWithProgress(scalaVersions: Seq[String], hydraVersion: String): Unit = { val filteredScalaVersions = for { rawVersion <- scalaVersions.distinct diff --git a/src/org/jetbrains/plugins/scala/project/Versions.scala b/src/org/jetbrains/plugins/scala/project/Versions.scala index b60b79bb523..c97b6d14d7b 100644 --- a/src/org/jetbrains/plugins/scala/project/Versions.scala +++ b/src/org/jetbrains/plugins/scala/project/Versions.scala @@ -105,8 +105,8 @@ object Versions { val Hydra = Entity("https://repo.triplequote.com/artifactory/ivy-releases/com.triplequote/", ".+>(.*\\d+\\.\\d+\\.\\d+.*)/<.*".r, - Version("0.9.4"), - Seq("0.9.4") + Version("0.9.5"), + Seq("0.9.5") ) } } \ No newline at end of file diff --git a/src/org/jetbrains/plugins/scala/settings/HydraApplicationSettings.scala b/src/org/jetbrains/plugins/scala/settings/HydraApplicationSettings.scala index b2e57736e99..693adbe2626 100644 --- a/src/org/jetbrains/plugins/scala/settings/HydraApplicationSettings.scala +++ b/src/org/jetbrains/plugins/scala/settings/HydraApplicationSettings.scala @@ -33,6 +33,10 @@ class HydraApplicationSettings extends PersistentStateComponent[HydraApplication state } + def getDownloadedHydraVersions: Array[String] = { + for { (_, hydraVersion) <- artifactPaths.keySet.toArray } yield hydraVersion + } + private def convertArtifactsFromStateToSettings(artifacts: java.util.Map[String, java.util.List[String]]) = { val resultArtifacts = for { (key, value) <- artifacts.asScala