Skip to content

Commit

Permalink
Artifacts repository is configurable and changed default hydra versio…
Browse files Browse the repository at this point in the history
…n to latest. Fix #6 Fix #18
  • Loading branch information
maris123 committed Oct 30, 2017
1 parent 5812355 commit 0978543
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ object CompilationData {
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", hydraSettings.getHydraStorePath,
"-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", module.getName)
"-YtimingsFile", Paths.get(hydraSettings.getHydraStorePath, "timings.csv").toString, "-YhydraTag", s"${module.getName}/${hydraConfigFolder}")
else
Seq.empty
Log.debug("Hydra options: " + hydraOptions.mkString(" "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import scala.collection.breakOut
*/
object HydraVersions {

private val MinHydraVersion = "2.11.8"
private val UnsupportedHydraVersion = "2.12.0"
private val compilerRegex = """.*scala-compiler-(\d+\.\d+\.\d+)(-SNAPSHOT)?\.jar""".r
private val MinScalaVersion = "2.11.8"
private val UnsupportedScalaVersion = "2.12.0"
private val CompilerRegex = """.*scala-compiler-(\d+\.\d+\.\d+)(-SNAPSHOT)?\.jar""".r

private final val Log: Logger = Logger.getInstance(this.getClass.getName)

Expand All @@ -26,11 +26,11 @@ object HydraVersions {
val scalaVersionsPerModule: Map[ScalaModule, String] = (for {
module <- scalaModules
classpathFile <- module.sdk.compilerClasspath
mtch <- compilerRegex.findFirstMatchIn(classpathFile.getName)
mtch <- CompilerRegex.findFirstMatchIn(classpathFile.getName)
scalaVersion = mtch.group(1)
if scalaVersion != UnsupportedHydraVersion
if scalaVersion != UnsupportedScalaVersion
version = Version(scalaVersion)
if version >= Version(MinHydraVersion)
if version >= Version(MinScalaVersion)
} yield module -> version.presentation)(breakOut)

if (scalaModules.size != scalaVersionsPerModule.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class HydraCompilerConfigurable (project: Project) extends AbstractConfigurable(
form.selectedVersion != settings.hydraVersion ||
form.selectedNoOfCores != settings.noOfCores ||
form.selectedSourcePartitioner != settings.sourcePartitioner ||
form.getHydraStoreDirectory != settings.hydraStorePath
form.getHydraStoreDirectory != settings.hydraStorePath ||
form.getHydraRepository != hydraGlobalSettings.hydraRepositoryUrl ||
form.getHydraRepositoryRealm != hydraGlobalSettings.hydraRepositoryRealm

override def reset() {
form.setUsername(HydraCredentialsManager.getLogin)
Expand All @@ -34,6 +36,8 @@ class HydraCompilerConfigurable (project: Project) extends AbstractConfigurable(
form.setSelectedVersion(settings.hydraVersion)
form.setSelectedSourcePartitioner(settings.sourcePartitioner)
form.setHydraStoreDirectory(settings.hydraStorePath)
form.setHydraRepository(hydraGlobalSettings.hydraRepositoryUrl)
form.setHydraRepositoryRealm(hydraGlobalSettings.hydraRepositoryRealm)
}

override def apply() {
Expand All @@ -43,6 +47,8 @@ class HydraCompilerConfigurable (project: Project) extends AbstractConfigurable(
settings.noOfCores = form.selectedNoOfCores
settings.sourcePartitioner = form.selectedSourcePartitioner
settings.hydraStorePath = form.getHydraStoreDirectory
hydraGlobalSettings.hydraRepositoryUrl = form.getHydraRepository
hydraGlobalSettings.hydraRepositoryRealm = form.getHydraRepositoryRealm
HydraCredentialsManager.setCredentials(form.getUsername, form.getPassword)
EditorNotifications.updateAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@
</constraints>
<properties/>
</component>
<component id="4030c" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Hydra Repository"/>
</properties>
</component>
<component id="21055" class="javax.swing.JTextField" binding="hydraRepository">
<constraints>
<grid row="3" column="4" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="e3352" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Repository Realm"/>
</properties>
</component>
<component id="d9b2b" class="javax.swing.JTextField" binding="realmTextField">
<constraints>
<grid row="4" column="4" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class HydraCompilerConfigurationPanel {
protected SComboBox noOfCoresComboBox;
protected SComboBox sourcePartitionerComboBox;
protected TextFieldWithBrowseButton hydraStoreDirectoryField;
protected JTextField hydraRepository;
protected JTextField realmTextField;

public HydraCompilerConfigurationPanel() {

Expand Down Expand Up @@ -169,6 +171,16 @@ private void createUIComponents() {
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));
final JLabel label7 = new JLabel();
label7.setText("Hydra Repository");
panel1.add(label7, new GridConstraints(3, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
hydraRepository = new JTextField();
panel1.add(hydraRepository, new GridConstraints(3, 4, 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 label8 = new JLabel();
label8.setText("Repository Realm");
panel1.add(label8, new GridConstraints(4, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
realmTextField = new JTextField();
panel1.add(realmTextField, new GridConstraints(4, 4, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.plugins.hydra.compiler

import java.io.File
import java.nio.file.Paths

import com.intellij.openapi.components._
import com.intellij.openapi.project.Project
Expand All @@ -23,7 +24,7 @@ class HydraCompilerSettings(project: Project) extends PersistentStateComponent[H

var isHydraSettingsEnabled: Boolean = false

var hydraVersion: String = "0.9.5"
var hydraVersion: String = ""

var noOfCores: String = Math.ceil(Runtime.getRuntime.availableProcessors()/2D).toInt.toString

Expand Down Expand Up @@ -52,7 +53,7 @@ class HydraCompilerSettings(project: Project) extends PersistentStateComponent[H
isHydraSettingsEnabled = state.isHydraSettingsEnabled
}

def getDefaultHydraStorePath: String = ProjectRoot + File.separator + ".hydra"
def getDefaultHydraStorePath: String = Paths.get(ProjectRoot, ".hydra", "idea").toString

private def getProjectRootPath: String = project.getBaseDir.getPresentableUrl
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,43 @@ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraComp
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)
override def textChanged(documentEvent: DocumentEvent): Unit =
downloadButton.setEnabled(getUsername.nonEmpty && getPassword.nonEmpty && getHydraRepository.nonEmpty)
}

private val focusListener = new FocusListener {
override def focusGained(e: FocusEvent): Unit = {}

override def focusLost(e: FocusEvent): Unit = if (getUsername.nonEmpty && getPassword.nonEmpty &&
(HydraCredentialsManager.getLogin != getUsername || HydraCredentialsManager.getPlainPassword != getPassword)) {
(HydraCredentialsManager.getLogin != getUsername ||
HydraCredentialsManager.getPlainPassword != getPassword ||
hydraGlobalSettings.hydraRepositoryUrl != getHydraRepository ||
hydraGlobalSettings.hydraRepositoryRealm != getHydraRepositoryRealm)) {

HydraCredentialsManager.setCredentials(getUsername, getPassword)
hydraGlobalSettings.hydraRepositoryUrl = getHydraRepository
hydraVersionComboBox.setItems(HydraVersions.downloadHydraVersions)
hydraVersionComboBox.setSelectedItem(settings.hydraVersion)
}
}

hydraGlobalSettings.getState
setDefaultHydraVersion

hydraRepository.setText(hydraGlobalSettings.hydraRepositoryUrl)
hydraRepository.addFocusListener(focusListener)
hydraRepository.getDocument.addDocumentListener(documentAdapter)

realmTextField.setText(hydraGlobalSettings.hydraRepositoryRealm)
realmTextField.addFocusListener(focusListener)
realmTextField.getDocument.addDocumentListener(documentAdapter)

userTextField.addFocusListener(focusListener)
userTextField.getDocument.addDocumentListener(documentAdapter)

passwordTextField.getDocument.addDocumentListener(documentAdapter)
passwordTextField.addFocusListener(focusListener)
hydraVersionComboBox.setItems(HydraVersions.downloadHydraVersions)

downloadButton.addActionListener((_: ActionEvent) => onDownload())
noOfCoresComboBox.setItems(Array.range(1, Runtime.getRuntime.availableProcessors() + 1).map(_.toString).sortWith(_ > _))
sourcePartitionerComboBox.setItems(SourcePartitioner.values.map(_.value).toArray)
Expand Down Expand Up @@ -71,6 +89,14 @@ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraComp

def setHydraStoreDirectory(path: String): Unit = hydraStoreDirectoryField.setText(path)

def getHydraRepository: String = hydraRepository.getText

def setHydraRepository(repositoryUrl: String): Unit = hydraRepository.setText(repositoryUrl)

def getHydraRepositoryRealm: String = realmTextField.getText

def setHydraRepositoryRealm(realm: String): Unit = realmTextField.setText(realm)

def onDownload(): Unit = {
val scalaVersions = HydraVersions.getSupportedScalaVersions(project)

Expand Down Expand Up @@ -103,4 +129,9 @@ class ScalaHydraCompilerConfigurationPanel(project: Project, settings: HydraComp
private def downloadVersion(scalaVersions: Seq[String], hydraVersion: String): (String => Unit) => Unit =
(listener: (String) => Unit) => scalaVersions.foreach(version => HydraArtifactsCache.downloadIfNotPresent(version, hydraVersion, listener))

private def setDefaultHydraVersion = {
val hydraVersions = HydraVersions.downloadHydraVersions
hydraVersionComboBox.setItems(hydraVersions)
setSelectedVersion(hydraVersions.head)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.plugins.hydra.settings

import java.io.File
import java.net.URL
import java.util

import com.intellij.openapi.components._
Expand All @@ -18,18 +19,22 @@ import scala.collection.JavaConverters._
class HydraApplicationSettings extends PersistentStateComponent[HydraApplicationSettingsState]{

var artifactPaths: Map[(String, String), List[String]] = Map.empty
var hydraRepositoryUrl: String = HydraApplicationSettings.DefaultHydraRepositoryUrl
var hydraRepositoryRealm: String = HydraApplicationSettings.DefaultHydraRepositoryRealm
private val KeySeparator = "_"

override def loadState(state: HydraApplicationSettingsState): Unit = {
state.removeMapEntriesThatDontExist()
artifactPaths = convertArtifactsFromStateToSettings(state.getGlobalArtifactPaths)
hydraRepositoryUrl = state.getHydraRepositoryUrl
}

override def getState: HydraApplicationSettingsState = {
val state = new HydraApplicationSettingsState
val artifacts = artifactPaths map { case((scalaVer, hydraVer), value) => (scalaVer + KeySeparator + hydraVer, value.asJava)}
state.setGlobalArtifactPaths(artifacts.asJava)
state.removeMapEntriesThatDontExist()
state.setHydraRepositoryUrl(hydraRepositoryUrl)
artifactPaths = convertArtifactsFromStateToSettings(state.getGlobalArtifactPaths)
state
}
Expand All @@ -42,6 +47,10 @@ class HydraApplicationSettings extends PersistentStateComponent[HydraApplication
for { (scalaVersion, _) <- artifactPaths.keySet.toArray } yield scalaVersion
}

def getHydraRepositoryName: String = new URL(HydraApplicationSettings.getInstance().hydraRepositoryUrl).getHost

def getHydraRepositoryUrl: String = if(hydraRepositoryUrl.endsWith("/")) hydraRepositoryUrl.dropRight(1) else hydraRepositoryUrl

private def convertArtifactsFromStateToSettings(artifacts: java.util.Map[String, java.util.List[String]]) = {
val resultArtifacts = for {
(key, value) <- artifacts.asScala
Expand All @@ -57,6 +66,12 @@ class HydraApplicationSettingsState {
@BeanProperty
var globalArtifactPaths: java.util.Map[String, java.util.List[String]] = new java.util.HashMap()

@BeanProperty
var hydraRepositoryUrl: String = HydraApplicationSettings.DefaultHydraRepositoryUrl

@BeanProperty
var hydraRepositoryRealm: String = HydraApplicationSettings.DefaultHydraRepositoryRealm

def removeMapEntriesThatDontExist(): Unit = {
globalArtifactPaths = globalArtifactPaths.asScala.filter(entry => checkIfArtifactsExist(entry._2)).asJava
}
Expand All @@ -67,5 +82,8 @@ class HydraApplicationSettingsState {
}

object HydraApplicationSettings {
val DefaultHydraRepositoryName = "repo.triplequote.com"
val DefaultHydraRepositoryUrl = s"https://$DefaultHydraRepositoryName/artifactory"
val DefaultHydraRepositoryRealm = "Artifactory Realm"
def getInstance(): HydraApplicationSettings = ServiceManager.getService(classOf[HydraApplicationSettings])
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.plugins.scala.project

import com.intellij.util.net.HttpConfigurable
import org.jetbrains.plugins.hydra.compiler.HydraCredentialsManager
import org.jetbrains.plugins.hydra.settings.HydraApplicationSettings
import org.jetbrains.plugins.scala.buildinfo.BuildInfo
import org.jetbrains.plugins.scala.project.Platform.{Dotty, Scala}

Expand Down Expand Up @@ -55,7 +56,7 @@ object Versions {
private def loadLinesFrom(url: String): Try[Seq[String]] = {
Try(HttpConfigurable.getInstance().openHttpConnection(url)).map { connection =>
try {
if(url.contains(Entity.Hydra.url))
if(url.contains(HydraApplicationSettings.getInstance().getHydraRepositoryUrl))
connection.setRequestProperty("Authorization", "Basic " + HydraCredentialsManager.getBasicAuthEncoding())
Source.fromInputStream(connection.getInputStream).getLines().toVector
} finally {
Expand All @@ -66,15 +67,16 @@ object Versions {

private def loadVersionsForHydra() = {
val entity = Entity.Hydra
val repoUrl = HydraApplicationSettings.getInstance().getHydraRepositoryUrl + entity.url

def downloadHydraVersions(url: String): Seq[String] =
loadVersionsFrom(url, { case entity.pattern(number) => number }).getOrElse(entity.hardcodedVersions).map(Version(_))
.filter(_ >= entity.minVersion).map(_.presentation)

loadVersionsFrom(entity.url, {
loadVersionsFrom(repoUrl, {
case entity.pattern(number) => number
}).map { versions =>
versions.flatMap(version => downloadHydraVersions(s"""${entity.url}$version/""")).distinct
versions.flatMap(version => downloadHydraVersions(s"""$repoUrl$version/""")).distinct
}
}

Expand Down Expand Up @@ -103,7 +105,7 @@ object Versions {
Version("0.2.0"),
Seq("0.2.0-RC1"))

val Hydra = Entity("https://repo.triplequote.com/artifactory/ivy-releases/com.triplequote/",
val Hydra = Entity("/ivy-releases/com.triplequote/",
".+>(.*\\d+\\.\\d+\\.\\d+.*)/<.*".r,
Version("0.9.5"),
Seq("0.9.5")
Expand Down
Loading

0 comments on commit 0978543

Please sign in to comment.