Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydra module specific settings #34

Open
wants to merge 3 commits into
base: hydra-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.jetbrains.jps.incremental.scala;

import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.incremental.scala.model.CompilerSettingsImpl;
import org.jetbrains.jps.incremental.scala.model.GlobalHydraSettingsImpl;
import org.jetbrains.jps.incremental.scala.model.HydraCompilerSettingsImpl;
import org.jetbrains.jps.incremental.scala.model.HydraSettingsImpl;
import org.jetbrains.jps.model.JpsGlobal;
import org.jetbrains.jps.model.JpsProject;
Expand All @@ -12,7 +15,9 @@
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Maris Alexandru
Expand All @@ -38,15 +43,48 @@ private HydraSettingsSerializer() {

@Override
public void loadExtension(@NotNull JpsProject jpsProject, @NotNull Element componentTag) {
HydraSettingsImpl.State state = XmlSerializer.deserialize(componentTag, HydraSettingsImpl.State.class);
HydraSettingsImpl settings = new HydraSettingsImpl(state == null ? new HydraSettingsImpl.State() : state);
HydraSettingsImpl.State state = getHydraSettingsState(componentTag);

HydraCompilerSettingsImpl defaultSettings = loadSettings(componentTag);

Map<String, String> moduleToProfile = new HashMap<String, String>();
Map<String, HydraCompilerSettingsImpl> profileToSettings = new HashMap<String, HydraCompilerSettingsImpl>();

for (Element profileElement : componentTag.getChildren("profile")) {
String profile = profileElement.getAttributeValue("name");
HydraCompilerSettingsImpl settings = loadSettings(profileElement);
profileToSettings.put(profile, settings);

List<String> modules = StringUtil.split(profileElement.getAttributeValue("modules"), ",");
for (String module : modules) {
moduleToProfile.put(module, profile);
}
}

HydraSettingsImpl settings = new HydraSettingsImpl(state == null ? new HydraSettingsImpl.State() : state, defaultSettings, profileToSettings, moduleToProfile);
SettingsManager.setHydraSettings(jpsProject, settings);
}

@Override
public void saveExtension(@NotNull JpsProject jpsProject, @NotNull Element componentTag) {
// do nothing
}

private static HydraCompilerSettingsImpl loadSettings(Element componentTag) {
HydraCompilerSettingsImpl.State state = XmlSerializer.deserialize(componentTag, HydraCompilerSettingsImpl.State.class);
return new HydraCompilerSettingsImpl(state == null ? new HydraCompilerSettingsImpl.State() : state);
}

private HydraSettingsImpl.State getHydraSettingsState(Element componentTag) {
Element stateConfiguration = componentTag.getChild("HydraCompilerConfigurationState");
HydraSettingsImpl.State state = new HydraSettingsImpl.State();

if (stateConfiguration != null) {
state = XmlSerializer.deserialize(stateConfiguration, HydraSettingsImpl.State.class);
}

return state;
}
}

private static class GlobalHydraSettingsSerializer extends JpsGlobalExtensionSerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object CompilationData {
!JavaBuilderUtil.isCompileJavaIncrementally(context) &&
!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)

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

CompilationData(canonicalSources, classpath, output, commonOptions ++ scalaOptions ++ hydraOptions, commonOptions ++ javaOptions,
order, cacheFile, relevantOutputToCacheMap, outputGroups,
Expand Down Expand Up @@ -219,15 +219,17 @@ object CompilationData {
"\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)]) = {
private def getHydraCompilerOptions(target: ModuleBuildTarget, context: CompileContext, module: JpsModule, chunk: ModuleChunk, outputGroups: Seq[(File, File)]): Seq[String] = {
val hydraSettings = SettingsManager.getHydraSettings(context.getProjectDescriptor.getProject)
val hydraProfileCompilerSettings = hydraSettings.getCompilerSettings(chunk)
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,
hydraProfileCompilerSettings.getCompilerOptions.toSeq ++
Seq("-sourcepath", outputGroups.map(_._1).mkString(File.pathSeparator),
"-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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.jps.incremental.scala.model;

/**
* @author Maris Alexandru
*/
public interface HydraCompilerSettings {
String[] getCompilerOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.jetbrains.jps.incremental.scala.model;

import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.ex.JpsElementBase;

import java.util.ArrayList;
import java.util.List;

/**
* @author Maris Alexandru
*/
public class HydraCompilerSettingsImpl extends JpsElementBase<HydraCompilerSettingsImpl> implements HydraCompilerSettings {
public static final HydraCompilerSettingsImpl DEFAULT = new HydraCompilerSettingsImpl(new State());

private State state;

public HydraCompilerSettingsImpl(State state) {
this.state = state;
}

@Override
public String[] getCompilerOptions() {
List<String> list = new ArrayList<String>();

if (state.noOfCores != null) {
list.add("-cpus");
list.add(state.noOfCores);
}

if (state.sourcePartitioner != null) {
list.add("-YsourcePartitioner:" + state.sourcePartitioner);
}

return list.toArray(new String[list.size()]);
}

@NotNull
@Override
public HydraCompilerSettingsImpl createCopy() {
return new HydraCompilerSettingsImpl(XmlSerializerUtil.createCopy(state));
}

@Override
public void applyChanges(@NotNull HydraCompilerSettingsImpl hydraCompilerSettings) {
// do nothing
}

public static class State {
public String noOfCores;
public String sourcePartitioner;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.jps.incremental.scala.model;

import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.model.JpsElement;

import java.util.List;
Expand All @@ -10,9 +11,8 @@
*/
public interface HydraSettings extends JpsElement {
boolean isHydraEnabled();
String getNumberOfCores();
String getHydraVersion();
String getSourcePartitioner();
String getHydraStorePath();
String getProjectRoot();
HydraCompilerSettings getCompilerSettings(ModuleChunk chunk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@

import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.ModuleChunk;
import org.jetbrains.jps.model.ex.JpsElementBase;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

/**
* @author Maris Alexandru
*/
public class HydraSettingsImpl extends JpsElementBase<HydraSettingsImpl> implements HydraSettings{
public static final HydraSettings DEFAULT = new HydraSettingsImpl(new State());
public static final HydraSettings DEFAULT = new HydraSettingsImpl(new State(), HydraCompilerSettingsImpl.DEFAULT,
new HashMap<String, HydraCompilerSettingsImpl>(), new HashMap<String, String>());

private final State state;

public HydraSettingsImpl(State state) {
private HydraCompilerSettingsImpl myDefaultSettings;

private Map<String, HydraCompilerSettingsImpl> myProfileToSettings;

private Map<String, String> myModuleToProfile;

public HydraSettingsImpl(State state, HydraCompilerSettingsImpl defaultSettings, Map<String, HydraCompilerSettingsImpl> profileToSettings, Map<String, String> moduleToProfile) {
this.state = state;
this.myDefaultSettings = defaultSettings;
this.myProfileToSettings = profileToSettings;
this.myModuleToProfile = moduleToProfile;
}

@Override
Expand All @@ -26,24 +39,32 @@ public String getHydraVersion() {
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; }
public String getProjectRoot() { return Paths.get(state.projectRoot).toString(); }

@Override
public String getProjectRoot() { return Paths.get(state.projectRoot).toString(); }
public HydraCompilerSettings getCompilerSettings(ModuleChunk chunk) {
String module = chunk.representativeTarget().getModule().getName();
String profile = myModuleToProfile.get(module);
return profile == null ? myDefaultSettings : myProfileToSettings.get(profile);
}

@NotNull
@Override
public HydraSettingsImpl createCopy() {
return new HydraSettingsImpl(XmlSerializerUtil.createCopy(state));
HydraCompilerSettingsImpl defaultSettings = myDefaultSettings.createCopy();

Map<String, HydraCompilerSettingsImpl> profileToSettings = new HashMap<String, HydraCompilerSettingsImpl>();
for (Map.Entry<String, HydraCompilerSettingsImpl> entry : myProfileToSettings.entrySet()) {
profileToSettings.put(entry.getKey(), entry.getValue().createCopy());
}

HashMap<String, String> moduleToProfile = new HashMap<String, String>(myModuleToProfile);

return new HydraSettingsImpl(XmlSerializerUtil.createCopy(state), defaultSettings, profileToSettings, moduleToProfile);
}

@Override
Expand All @@ -54,9 +75,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 noOfCores = Integer.toString((int) Math.ceil(Runtime.getRuntime().availableProcessors()/2D));
public String hydraStorePath = "";
public String sourcePartitioner = "";
//public String sourcePartitioner = "";
public String projectRoot = "";
}
}
4 changes: 2 additions & 2 deletions scala/scala-impl/resources/META-INF/scala-plugin-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@
<applicationService serviceInterface="org.jetbrains.plugins.hydra.settings.HydraApplicationSettings"
serviceImplementation="org.jetbrains.plugins.hydra.settings.HydraApplicationSettings"/>

<projectService serviceInterface="org.jetbrains.plugins.hydra.compiler.HydraCompilerSettings"
serviceImplementation="org.jetbrains.plugins.hydra.compiler.HydraCompilerSettings"/>
<projectService serviceInterface="org.jetbrains.plugins.hydra.compiler.HydraCompilerConfiguration"
serviceImplementation="org.jetbrains.plugins.hydra.compiler.HydraCompilerConfiguration"/>

<projectService serviceInterface="org.jetbrains.plugins.scala.lang.scaladoc.generate.ScaladocSettings"
serviceImplementation="org.jetbrains.plugins.scala.lang.scaladoc.generate.ScaladocSettings"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,48 @@ import com.intellij.openapi.project.Project
import com.intellij.ui.EditorNotifications
import org.jetbrains.plugins.hydra.settings.HydraApplicationSettings
import org.jetbrains.plugins.scala.project.AbstractConfigurable
import scala.collection.JavaConverters._

/**
* @author Maris Alexandru
*/
class HydraCompilerConfigurable (project: Project) extends AbstractConfigurable("Hydra Compiler"){
private val settings = HydraCompilerSettings.getInstance(project)
private val settings = HydraCompilerConfiguration.getInstance(project)
private val hydraGlobalSettings = HydraApplicationSettings.getInstance()
private val form = new ScalaHydraCompilerConfigurationPanel(project, settings, hydraGlobalSettings)

private val profiles = form.getHydraProfilesPanel

override def createComponent(): JPanel = form.getContentPanel

override def isModified: Boolean = form.isHydraEnabled != settings.isHydraEnabled ||
form.getUsername != HydraCredentialsManager.getLogin ||
form.getPassword != HydraCredentialsManager.getPlainPassword ||
form.getHydraVersion != settings.hydraVersion ||
form.selectedNoOfCores != settings.noOfCores ||
form.selectedSourcePartitioner != settings.sourcePartitioner ||
form.getHydraRepository != hydraGlobalSettings.getHydraRepositoryUrl ||
form.getHydraRepositoryRealm != hydraGlobalSettings.hydraRepositoryRealm
form.getHydraRepositoryRealm != hydraGlobalSettings.hydraRepositoryRealm ||
profiles.getDefaultProfile.getSettings.getState != settings.defaultProfile.getSettings.getState ||
!profiles.getModuleProfiles.asScala.corresponds(settings.customProfiles)(_.getSettings.getState == _.getSettings.getState)

override def reset() {
form.setUsername(HydraCredentialsManager.getLogin)
form.setPassword(HydraCredentialsManager.getPlainPassword)
form.setIsHydraEnabled(settings.isHydraEnabled)
form.setSelectedNoOfCores(settings.noOfCores)
form.setHydraVersion(settings.hydraVersion)
form.setSelectedSourcePartitioner(settings.sourcePartitioner)
form.setHydraRepository(hydraGlobalSettings.getHydraRepositoryUrl)
form.setHydraRepositoryRealm(hydraGlobalSettings.hydraRepositoryRealm)
profiles.initProfiles(settings.defaultProfile, settings.customProfiles.asJava)
}

override def apply() {
BuildManager.getInstance().clearState(project)
settings.defaultProfile = profiles.getDefaultProfile
settings.customProfiles = profiles.getModuleProfiles.asScala
settings.hydraVersion = form.getHydraVersion
settings.isHydraEnabled = form.isHydraEnabled
settings.noOfCores = form.selectedNoOfCores
settings.sourcePartitioner = form.selectedSourcePartitioner
hydraGlobalSettings.setHydraRepositopryUrl(form.getHydraRepository)
hydraGlobalSettings.hydraRepositoryRealm = form.getHydraRepositoryRealm
HydraCredentialsManager.setCredentials(form.getUsername, form.getPassword)
EditorNotifications.updateAll()
BuildManager.getInstance().clearState(project)
}
}
Loading