mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prefer to use allSettings where we actually need to use settings or don't need configuration at all
add hasSettings (later we can optimize it to avoid linear search) no need in the myUnloadedElements since for unknown element UnknownRunConfiguration will be created
This commit is contained in:
@@ -512,7 +512,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas
|
||||
|
||||
@Override
|
||||
public ConfigurationFactory getFactory() {
|
||||
return null;
|
||||
return UnknownConfigurationType.FACTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -529,12 +529,6 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConfigurationType getType() {
|
||||
return UnknownConfigurationType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunConfiguration clone() {
|
||||
return null;
|
||||
|
||||
@@ -176,6 +176,8 @@ abstract class RunManager {
|
||||
*/
|
||||
abstract fun refreshUsagesList(profile: RunProfile)
|
||||
|
||||
fun hasSettings(settings: RunnerAndConfigurationSettings) = allSettings.contains(settings)
|
||||
|
||||
fun suggestUniqueName(name: String?, type: ConfigurationType?): String {
|
||||
val settingsList = if (type == null) allSettings else getConfigurationSettingsList(type)
|
||||
return suggestUniqueName(name.nullize() ?: UNNAMED, settingsList.map { it.name })
|
||||
|
||||
@@ -31,11 +31,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
public interface RunnerAndConfigurationSettings {
|
||||
/**
|
||||
* Returns the type of the run configuration.
|
||||
*
|
||||
* @return the type of the run configuration, or null if the settings object was loaded from disk and no plugin corresponding to the
|
||||
* stored type of the run configuration is loaded.
|
||||
*/
|
||||
@Nullable
|
||||
@NotNull
|
||||
ConfigurationType getType();
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,11 +44,11 @@ public interface RunConfiguration extends RunProfile, Cloneable {
|
||||
|
||||
/**
|
||||
* Returns the type of the run configuration.
|
||||
*
|
||||
* @return the configuration type.
|
||||
*/
|
||||
@NotNull
|
||||
ConfigurationType getType();
|
||||
default ConfigurationType getType() {
|
||||
return getFactory().getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the factory that has created the run configuration.
|
||||
|
||||
@@ -98,12 +98,6 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConfigurationType getType() {
|
||||
return myFactory.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return myIcon;
|
||||
|
||||
-6
@@ -83,12 +83,6 @@ public class UnknownRunConfiguration implements RunConfiguration, WithoutOwnBefo
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConfigurationType getType() {
|
||||
return UnknownConfigurationType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunConfiguration clone() {
|
||||
try {
|
||||
|
||||
+1
-2
@@ -49,8 +49,7 @@ public class CopyConfigurationAction extends RunConfigurationTreeAction {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled4(DashboardRunConfigurationNode node) {
|
||||
return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains(
|
||||
node.getConfigurationSettings().getConfiguration());
|
||||
return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -41,8 +41,7 @@ public class EditConfigurationAction extends RunConfigurationTreeAction {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled4(DashboardRunConfigurationNode node) {
|
||||
return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains(
|
||||
node.getConfigurationSettings().getConfiguration());
|
||||
return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -40,8 +40,7 @@ public class RemoveConfigurationAction extends RunConfigurationTreeAction {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled4(DashboardRunConfigurationNode node) {
|
||||
return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains(
|
||||
node.getConfigurationSettings().getConfiguration());
|
||||
return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,7 +64,7 @@ class RunConfigurationNode extends AbstractTreeNode<Pair<RunnerAndConfiguration
|
||||
@Override
|
||||
protected void update(PresentationData presentation) {
|
||||
RunnerAndConfigurationSettings configurationSettings = getConfigurationSettings();
|
||||
boolean isStored = RunManager.getInstance(getProject()).getAllConfigurationsList().contains(configurationSettings.getConfiguration());
|
||||
boolean isStored = RunManager.getInstance(getProject()).hasSettings(configurationSettings);
|
||||
presentation.addText(configurationSettings.getName(),
|
||||
isStored ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
RunDashboardContributor contributor = RunDashboardContributor.getContributor(configurationSettings.getType());
|
||||
|
||||
+12
-33
@@ -25,19 +25,16 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.ModuleListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.SmartHashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@State(name = "ModuleRunConfigurationManager")
|
||||
@@ -51,8 +48,6 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo
|
||||
settings -> settings != null && usesMyModule(settings.getConfiguration());
|
||||
@NotNull
|
||||
private final RunManagerImpl myManager;
|
||||
@Nullable
|
||||
private List<Element> myUnloadedElements = null;
|
||||
|
||||
public ModuleRunConfigurationManager(@NotNull final Module module, @NotNull final RunManagerImpl runManager) {
|
||||
myModule = module;
|
||||
@@ -110,11 +105,6 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo
|
||||
public void writeExternal(@NotNull final Element element) throws WriteExternalException {
|
||||
LOG.debug("writeExternal(" + myModule + ")");
|
||||
myManager.writeConfigurations(element, getModuleRunConfigurationSettings());
|
||||
if (myUnloadedElements != null) {
|
||||
for (final Element unloadedElement : myUnloadedElements) {
|
||||
element.addContent(unloadedElement.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(@NotNull final Element element) {
|
||||
@@ -125,32 +115,21 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo
|
||||
|
||||
private void doReadExternal(@NotNull Element element) {
|
||||
LOG.debug("readExternal(" + myModule + ")");
|
||||
myUnloadedElements = null;
|
||||
final Set<String> existing = new HashSet<>();
|
||||
final Set<String> existing = new SmartHashSet<>();
|
||||
|
||||
for (final Element child : element.getChildren()) {
|
||||
final RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true);
|
||||
if (configuration == null && Comparing.strEqual(element.getName(), RunManagerImpl.CONFIGURATION)) {
|
||||
if (myUnloadedElements == null) myUnloadedElements = new ArrayList<>(2);
|
||||
myUnloadedElements.add(element);
|
||||
}
|
||||
|
||||
if (configuration != null) {
|
||||
existing.add(configuration.getUniqueID());
|
||||
}
|
||||
for (final Element child : element.getChildren(RunManagerImpl.CONFIGURATION)) {
|
||||
existing.add(myManager.loadConfiguration(child, true).getUniqueID());
|
||||
}
|
||||
|
||||
for (final RunConfiguration configuration : myManager.getAllConfigurationsList()) {
|
||||
if (!usesMyModule(configuration)) {
|
||||
RunnerAndConfigurationSettings settings = myManager.getSettings(configuration);
|
||||
if (settings != null) {
|
||||
existing.add(settings.getUniqueID());
|
||||
}
|
||||
}
|
||||
}
|
||||
myManager.removeNotExistingSharedConfigurations(existing);
|
||||
|
||||
// IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read
|
||||
myManager.setOrdered(false);
|
||||
|
||||
for (RunnerAndConfigurationSettings settings : myManager.getAllSettings()) {
|
||||
if (!usesMyModule(settings.getConfiguration())) {
|
||||
existing.add(settings.getUniqueID());
|
||||
}
|
||||
}
|
||||
|
||||
myManager.removeNotExistingSharedConfigurations(existing);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-34
@@ -16,27 +16,22 @@
|
||||
package com.intellij.execution.impl;
|
||||
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.execution.configurations.UnknownRunConfiguration;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.StateSplitterEx;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@State(name = "ProjectRunConfigurationManager", storages = @Storage(value = "runConfigurations", stateSplitter = ProjectRunConfigurationManager.RunConfigurationStateSplitter.class))
|
||||
public class ProjectRunConfigurationManager implements PersistentStateComponent<Element> {
|
||||
private final RunManagerImpl myManager;
|
||||
private List<Element> myUnloadedElements;
|
||||
|
||||
public ProjectRunConfigurationManager(@NotNull RunManagerImpl manager) {
|
||||
myManager = manager;
|
||||
@@ -46,50 +41,29 @@ public class ProjectRunConfigurationManager implements PersistentStateComponent<
|
||||
public Element getState() {
|
||||
Element state = new Element("state");
|
||||
myManager.writeConfigurations(state, myManager.getSharedConfigurations());
|
||||
if (!ContainerUtil.isEmpty(myUnloadedElements)) {
|
||||
for (Element unloadedElement : myUnloadedElements) {
|
||||
state.addContent(unloadedElement.clone());
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
if (myUnloadedElements != null) {
|
||||
myUnloadedElements.clear();
|
||||
}
|
||||
|
||||
Set<String> existing = new THashSet<>();
|
||||
for (Iterator<Element> iterator = state.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
Element child = iterator.next();
|
||||
RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true);
|
||||
if (configuration != null) {
|
||||
existing.add(configuration.getUniqueID());
|
||||
}
|
||||
else if (child.getName().equals(RunManagerImpl.CONFIGURATION)) {
|
||||
if (myUnloadedElements == null) {
|
||||
myUnloadedElements = new SmartList<>();
|
||||
}
|
||||
iterator.remove();
|
||||
myUnloadedElements.add(child);
|
||||
}
|
||||
for (Element child : state.getChildren(RunManagerImpl.CONFIGURATION)) {
|
||||
existing.add(myManager.loadConfiguration(child, true).getUniqueID());
|
||||
}
|
||||
|
||||
myManager.removeNotExistingSharedConfigurations(existing);
|
||||
|
||||
// IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read
|
||||
myManager.setOrdered(false);
|
||||
|
||||
if (myManager.getSelectedConfiguration() == null) {
|
||||
final List<RunConfiguration> allConfigurations = myManager.getAllConfigurationsList();
|
||||
for (final RunConfiguration configuration : allConfigurations) {
|
||||
final RunnerAndConfigurationSettings settings = myManager.getSettings(allConfigurations.get(0));
|
||||
if (!(configuration instanceof UnknownRunConfiguration)) {
|
||||
for (RunnerAndConfigurationSettings settings : myManager.getAllSettings()) {
|
||||
if (!(settings.getType() instanceof UnknownRunConfiguration)) {
|
||||
myManager.setSelectedConfiguration(settings);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read
|
||||
myManager.setOrdered(false);
|
||||
}
|
||||
|
||||
static class RunConfigurationStateSplitter extends StateSplitterEx {
|
||||
|
||||
+2
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,6 @@ import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListenerComposite;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListenerProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
@@ -36,9 +34,7 @@ public class RunConfigurationRefactoringElementListenerProvider implements Refac
|
||||
@Override
|
||||
public RefactoringElementListener getListener(final PsiElement element) {
|
||||
RefactoringElementListenerComposite composite = null;
|
||||
final List<RunConfiguration> configurations = RunManager.getInstance(element.getProject()).getAllConfigurationsList();
|
||||
|
||||
for (RunConfiguration configuration : configurations) {
|
||||
for (RunConfiguration configuration : RunManager.getInstance(element.getProject()).getAllConfigurationsList()) {
|
||||
if (configuration instanceof RefactoringListenerProvider) { // todo: perhaps better way to handle listeners?
|
||||
RefactoringElementListener listener;
|
||||
try {
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.diagnostic.catchAndLog
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.options.Scheme
|
||||
import com.intellij.openapi.options.SchemeManagerFactory
|
||||
import com.intellij.openapi.project.IndexNotReadyException
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -129,8 +128,8 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent
|
||||
private val schemeManagerProvider = SchemeManagerIprProvider("configuration")
|
||||
|
||||
private val schemeManager = SchemeManagerFactory.getInstance(project).create("workspace",
|
||||
object : LazySchemeProcessor<RunConfigurationScheme, RunConfigurationScheme>() {
|
||||
override fun createScheme(dataHolder: SchemeDataHolder<RunConfigurationScheme>, name: String, attributeProvider: Function<String, String?>, isBundled: Boolean): RunConfigurationScheme {
|
||||
object : LazySchemeProcessor<RunnerAndConfigurationSettingsImpl, RunnerAndConfigurationSettingsImpl>() {
|
||||
override fun createScheme(dataHolder: SchemeDataHolder<RunnerAndConfigurationSettingsImpl>, name: String, attributeProvider: Function<String, String?>, isBundled: Boolean): RunnerAndConfigurationSettingsImpl {
|
||||
val settings = RunnerAndConfigurationSettingsImpl(this@RunManagerImpl)
|
||||
val element = dataHolder.read()
|
||||
try {
|
||||
@@ -295,7 +294,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent
|
||||
}
|
||||
|
||||
if (!settings.isShared && existingSettings !== settings) {
|
||||
schemeManager.addScheme(settings as RunConfigurationScheme)
|
||||
schemeManager.addScheme(settings as RunnerAndConfigurationSettingsImpl)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -715,7 +714,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent
|
||||
fireRunConfigurationsRemoved(configurations)
|
||||
}
|
||||
|
||||
fun loadConfiguration(element: Element, isShared: Boolean): RunnerAndConfigurationSettings? {
|
||||
fun loadConfiguration(element: Element, isShared: Boolean): RunnerAndConfigurationSettings {
|
||||
val settings = RunnerAndConfigurationSettingsImpl(this)
|
||||
LOG.catchAndLog {
|
||||
settings.readExternal(element, isShared)
|
||||
@@ -1144,14 +1143,4 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent
|
||||
|
||||
changedSettings.forEach { myDispatcher.multicaster.runConfigurationChanged(it, null) }
|
||||
}
|
||||
}
|
||||
|
||||
internal interface RunConfigurationScheme : Scheme
|
||||
|
||||
//private class UnknownRunConfigurationScheme(private val name: String) : RunConfigurationScheme, SerializableScheme {
|
||||
// override fun getSchemeState() = SchemeState.UNCHANGED
|
||||
//
|
||||
// override fun writeScheme() = throw AssertionError("Must be not called")
|
||||
//
|
||||
// override fun getName() = name
|
||||
//}
|
||||
}
|
||||
+4
-6
@@ -26,6 +26,7 @@ import com.intellij.openapi.components.PathMacroManager
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.ExtensionException
|
||||
import com.intellij.openapi.options.Scheme
|
||||
import com.intellij.openapi.options.SchemeState
|
||||
import com.intellij.openapi.util.*
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
@@ -56,7 +57,7 @@ val SINGLETON = "singleton"
|
||||
class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val manager: RunManagerImpl,
|
||||
private var _configuration: RunConfiguration? = null,
|
||||
private var isTemplate: Boolean = false,
|
||||
private var singleton: Boolean = false) : Cloneable, RunnerAndConfigurationSettings, Comparable<Any>, RunConfigurationScheme, SerializableScheme {
|
||||
private var singleton: Boolean = false) : Cloneable, RunnerAndConfigurationSettings, Comparable<Any>, Scheme, SerializableScheme {
|
||||
enum class Level {
|
||||
WORKSPACE, PROJECT, TEMPORARY
|
||||
}
|
||||
@@ -293,7 +294,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m
|
||||
|
||||
override fun getConfigurationSettings(runner: ProgramRunner<*>) = configurationPerRunnerSettings.getOrCreateSettings(runner)
|
||||
|
||||
override fun getType() = _configuration?.type
|
||||
override fun getType(): ConfigurationType = _configuration?.type ?: UnknownConfigurationType.INSTANCE
|
||||
|
||||
public override fun clone(): RunnerAndConfigurationSettings {
|
||||
val copy = RunnerAndConfigurationSettingsImpl(manager, _configuration!!.clone(), false)
|
||||
@@ -337,10 +338,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m
|
||||
|
||||
override fun compareTo(other: Any) = if (other is RunnerAndConfigurationSettings) name.compareTo(other.name) else 0
|
||||
|
||||
override fun toString(): String {
|
||||
val type = type
|
||||
return "${if (type == null) "" else "${type.displayName}: "}${if (isTemplate) "<template>" else name}"
|
||||
}
|
||||
override fun toString() = "${type.displayName}: ${if (isTemplate) "<template>" else name}"
|
||||
|
||||
private inner class InfoProvider(override val runner: ProgramRunner<*>) : ConfigurationInfoProvider {
|
||||
override val configuration: RunConfiguration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -176,8 +176,7 @@ public class TemplateModuleBuilder extends ModuleBuilder {
|
||||
}
|
||||
|
||||
private void fixModuleName(Module module) {
|
||||
List<RunConfiguration> configurations = RunManager.getInstance(module.getProject()).getAllConfigurationsList();
|
||||
for (RunConfiguration configuration : configurations) {
|
||||
for (RunConfiguration configuration : RunManager.getInstance(module.getProject()).getAllConfigurationsList()) {
|
||||
if (configuration instanceof ModuleBasedConfiguration) {
|
||||
((ModuleBasedConfiguration)configuration).getConfigurationModule().setModule(module);
|
||||
}
|
||||
|
||||
-4
@@ -265,10 +265,6 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConfiguration() throws RuntimeConfigurationException {
|
||||
}
|
||||
|
||||
///////////////////////////////////Delegates
|
||||
@Override
|
||||
public void readExternal(final Element element) throws InvalidDataException {
|
||||
|
||||
Reference in New Issue
Block a user