diff --git a/platform/lang-impl/src/com/intellij/execution/util/StoringPropertyContainer.java b/platform/lang-impl/src/com/intellij/execution/util/StoringPropertyContainer.java index c36f2464d85e..501ec3c3f58f 100644 --- a/platform/lang-impl/src/com/intellij/execution/util/StoringPropertyContainer.java +++ b/platform/lang-impl/src/com/intellij/execution/util/StoringPropertyContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,64 +13,56 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.execution.util; import com.intellij.ide.util.PropertiesComponent; import com.intellij.util.config.AbstractProperty; import com.intellij.util.config.Storage; -import org.jetbrains.annotations.NonNls; +import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NotNull; -import java.util.HashMap; +import java.util.Map; public class StoringPropertyContainer extends AbstractProperty.AbstractPropertyContainer> { - private final HashMap, Boolean> myValues = new HashMap, Boolean>(); + private final Map, Boolean> myValues = new HashMap, Boolean>(); private final Storage myStorage; - public StoringPropertyContainer(@NonNls final String groupName, final PropertiesComponent propertiesComponent) { + public StoringPropertyContainer(String groupName, PropertiesComponent propertiesComponent) { this(new Storage.PropertiesComponentStorage(groupName, propertiesComponent)); } - public StoringPropertyContainer(final Storage storage) { + public StoringPropertyContainer(@NotNull Storage storage) { myStorage = storage; } - public void setIfUndefined(AbstractProperty property, boolean value) { + public void setIfUndefined(@NotNull AbstractProperty property, boolean value) { if (myStorage.get(property.getName()) == null) { setValueOf(property, value); } } @Override - protected void setValueOf(final AbstractProperty property, final Object value) { + protected void setValueOf(@NotNull AbstractProperty property, Object value) { myValues.put(property, (Boolean)value); onPropertyChanged(property, (Boolean)value); - myStorage.put(property.getName(), stringValue(value)); - } - - private String stringValue(final Object value) { - return value.toString(); + myStorage.put(property.getName(), value.toString()); } @Override - public boolean hasProperty(final AbstractProperty property) { + public boolean hasProperty(@NotNull AbstractProperty property) { return myValues.containsKey(property); } @Override - protected Object getValueOf(final AbstractProperty property) { + protected Object getValueOf(@NotNull AbstractProperty property) { Object value = myValues.get(property); if (value == null) { - final String stringValue = myStorage.get(property.getName()); - value = stringValue != null ? parseValue(stringValue) : property.getDefault(this); + String stringValue = myStorage.get(property.getName()); + value = stringValue != null ? Boolean.valueOf(stringValue) : property.getDefault(this); myValues.put(property, (Boolean)value); } return value; } - private Boolean parseValue(final String stringValue) { - return Boolean.valueOf(stringValue); - } - - protected void onPropertyChanged(final AbstractProperty property, final T value) {} + protected void onPropertyChanged(@NotNull AbstractProperty property, T value) { } } diff --git a/platform/platform-api/src/com/intellij/util/config/Storage.java b/platform/platform-api/src/com/intellij/util/config/Storage.java index 7f2fc6d733db..a2ab59baf11f 100644 --- a/platform/platform-api/src/com/intellij/util/config/Storage.java +++ b/platform/platform-api/src/com/intellij/util/config/Storage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -24,48 +24,53 @@ import java.util.Collections; import java.util.Iterator; import java.util.Map; -import org.jetbrains.annotations.NonNls; - public interface Storage { void put(String key, String value); String get(String key); class PropertiesComponentStorage implements Storage { private static final Logger LOG = Logger.getInstance("#com.intellij.util.config.Storage.PropertiesComponentStorage"); + private final PropertiesComponent myPropertiesComponent; private final String myPrefix; - public PropertiesComponentStorage(@NonNls String prefix, PropertiesComponent propertiesComponent) { + public PropertiesComponentStorage(String prefix, PropertiesComponent propertiesComponent) { LOG.assertTrue(propertiesComponent != null || ApplicationManager.getApplication().isUnitTestMode()); myPropertiesComponent = propertiesComponent; myPrefix = prefix; } - public PropertiesComponentStorage(@NonNls String prefix) { + public PropertiesComponentStorage(String prefix) { this(prefix, PropertiesComponent.getInstance()); } + @Override public void put(String key, String value) { - if (myPropertiesComponent != null) + if (myPropertiesComponent != null) { myPropertiesComponent.setValue(myPrefix + key, value); + } } + @Override public String get(String key) { return myPropertiesComponent != null ? myPropertiesComponent.getValue(myPrefix + key) : null; } + @Override public String toString() { - //noinspection HardCodedStringLiteral return "PropertiesComponentStorage: " + myPrefix; } } class MapStorage implements Storage { private final Map myValues = new HashMap(); + + @Override public String get(String key) { return myValues.get(key); } + @Override public void put(String key, String value) { myValues.put(key, value); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java index 6bc2f72ea45e..dcc23d09d43e 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTRunnerConsoleProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -67,14 +67,16 @@ public class SMTRunnerConsoleProperties extends TestConsoleProperties implements @NotNull String testFrameworkName, @NotNull Executor executor, boolean printTestingStartedTime) { - super(new Storage.PropertiesComponentStorage(testFrameworkName + "Support.", PropertiesComponent.getInstance()), - config.getProject(), - executor); + super(getStorage(testFrameworkName), config.getProject(), executor); myConfiguration = config; myCustomFilter = new CompositeFilter(config.getProject()); myPrintTestingStartedTime = printTestingStartedTime; } + private static Storage.PropertiesComponentStorage getStorage(String testFrameworkName) { + return new Storage.PropertiesComponentStorage(testFrameworkName + "Support.", PropertiesComponent.getInstance()); + } + public RunConfiguration getConfiguration() { return myConfiguration; } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java index 44cad56a144e..6a0628c764f4 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsForm.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -21,10 +21,8 @@ import com.intellij.execution.testframework.*; import com.intellij.execution.testframework.sm.SMRunnerUtil; import com.intellij.execution.testframework.sm.runner.*; import com.intellij.execution.testframework.sm.runner.ui.statistics.StatisticsPanel; -import com.intellij.execution.testframework.ui.AbstractTestTreeBuilder; import com.intellij.execution.testframework.ui.TestResultsPanel; import com.intellij.execution.testframework.ui.TestsProgressAnimator; -import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.progress.util.ColorProgressBar; @@ -218,12 +216,10 @@ public class SMTestRunnerResultsForm extends TestResultsPanel myStartTime = System.currentTimeMillis(); boolean printTestingStartedTime = true; if (myConsoleProperties instanceof SMTRunnerConsoleProperties) { - printTestingStartedTime = ((SMTRunnerConsoleProperties) myConsoleProperties).isPrintTestingStartedTime(); + printTestingStartedTime = ((SMTRunnerConsoleProperties)myConsoleProperties).isPrintTestingStartedTime(); } if (printTestingStartedTime) { - myTestsRootNode.addSystemOutput("Testing started at " - + DateFormatUtil.formatTime(myStartTime) - + " ...\n"); + myTestsRootNode.addSystemOutput("Testing started at " + DateFormatUtil.formatTime(myStartTime) + " ...\n"); } updateStatusLabel(false); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java index f3ff19ce70ae..5dbf65a7507b 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 25-May-2007 - */ package com.intellij.execution.testframework; import com.intellij.execution.ExecutionBundle; @@ -39,14 +34,19 @@ import com.intellij.util.config.AbstractProperty; import com.intellij.util.config.BooleanProperty; import com.intellij.util.config.Storage; import com.intellij.util.config.ToggleBooleanProperty; +import com.intellij.util.containers.ContainerUtil; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerManager; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; +/** + * @author anna + * @since 25-May-2007 + */ public abstract class TestConsoleProperties extends StoringPropertyContainer implements Disposable { public static final BooleanProperty SCROLL_TO_STACK_TRACE = new BooleanProperty("scrollToStackTrace", false); public static final BooleanProperty SORT_ALPHABETICALLY = new BooleanProperty("sortTestsAlphabetically", false); @@ -66,10 +66,9 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp private boolean myUsePredefinedMessageFilter = true; private GlobalSearchScope myScope; - protected final HashMap> myListeners = - new HashMap>(); + protected final Map> myListeners = ContainerUtil.newHashMap(); - public TestConsoleProperties(final Storage storage, Project project, Executor executor) { + public TestConsoleProperties(Storage storage, Project project, Executor executor) { super(storage); myProject = project; myExecutor = executor; @@ -91,8 +90,11 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp if (!(configuration instanceof ModuleRunProfile)) { return GlobalSearchScope.allScope(myProject); } - Module[] modules = ((ModuleRunProfile) configuration).getModules(); - if (modules.length == 0) return GlobalSearchScope.allScope(myProject); + + Module[] modules = ((ModuleRunProfile)configuration).getModules(); + if (modules.length == 0) { + return GlobalSearchScope.allScope(myProject); + } GlobalSearchScope scope = GlobalSearchScope.EMPTY_SCOPE; for (Module each : modules) { @@ -101,22 +103,21 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp return scope; } - public void addListener(final AbstractProperty property, final TestFrameworkPropertyListener listener) { - ArrayList listeners = myListeners.get(property); + public void addListener(@NotNull AbstractProperty property, @NotNull TestFrameworkPropertyListener listener) { + List listeners = myListeners.get(property); if (listeners == null) { - listeners = new ArrayList(); - myListeners.put(property, listeners); + myListeners.put(property, (listeners = ContainerUtil.newArrayList())); } listeners.add(listener); } - public void addListenerAndSendValue(final AbstractProperty property, final TestFrameworkPropertyListener listener) { + public void addListenerAndSendValue(@NotNull AbstractProperty property, @NotNull TestFrameworkPropertyListener listener) { addListener(property, listener); listener.onChanged(property.get(this)); } - public void removeListener(final AbstractProperty property, final TestFrameworkPropertyListener listener) { - final ArrayList listeners = myListeners.get(property); + public void removeListener(@NotNull AbstractProperty property, @NotNull TestFrameworkPropertyListener listener) { + List listeners = myListeners.get(property); if (listeners != null) { listeners.remove(listener); } @@ -131,25 +132,26 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp } public boolean isPaused() { - final XDebugSession debuggerSession = XDebuggerManager.getInstance(myProject).getDebugSession(getConsole()); + XDebugSession debuggerSession = XDebuggerManager.getInstance(myProject).getDebugSession(getConsole()); return debuggerSession != null && debuggerSession.isPaused(); } - protected void onPropertyChanged(final AbstractProperty property, final T value) { - final ArrayList listeners = myListeners.get(property); - if (listeners == null) return; - final Object[] propertyListeners = listeners.toArray(); - for (Object propertyListener : propertyListeners) { - final TestFrameworkPropertyListener listener = (TestFrameworkPropertyListener)propertyListener; - listener.onChanged(value); + @Override + protected void onPropertyChanged(@NotNull AbstractProperty property, T value) { + List listeners = myListeners.get(property); + if (listeners != null) { + for (Object o : listeners.toArray()) { + @SuppressWarnings("unchecked") TestFrameworkPropertyListener listener = (TestFrameworkPropertyListener)o; + listener.onChanged(value); + } } } - public void setConsole(final ConsoleView console) { + public void setConsole(ConsoleView console) { myConsole = console; } - + @Override public void dispose() { myListeners.clear(); } @@ -164,7 +166,6 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp * switching to any other test/suite in tests results view. It's highly not recommended to change * default behaviour. Please do it only in critical cases and only if you are sure that you need this feature. *

- *

* NB2: If you are using Service Messages based test runner please ensure that before each service message * (e.g. #teamcity[...]) you always send "\n" to the output stream. * @@ -186,16 +187,12 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp myUsePredefinedMessageFilter = usePredefinedMessageFilter; } - protected void appendAdditionalActions(DefaultActionGroup actionGroup, - ExecutionEnvironment environment, JComponent parent) { - } + protected void appendAdditionalActions(DefaultActionGroup actionGroup, ExecutionEnvironment environment, JComponent parent) { } @NotNull protected ToggleBooleanProperty createIncludeNonStartedInRerun() { - return new ToggleBooleanProperty( - ExecutionBundle.message("junit.runing.info.include.non.started.in.rerun.failed.action.name"), - null, - AllIcons.RunConfigurations.IncludeNonStartedTests_Rerun, - this, TestConsoleProperties.INCLUDE_NON_STARTED_IN_RERUN_FAILED); + String text = ExecutionBundle.message("junit.runing.info.include.non.started.in.rerun.failed.action.name"); + Icon icon = AllIcons.RunConfigurations.IncludeNonStartedTests_Rerun; + return new ToggleBooleanProperty(text, null, icon, this, INCLUDE_NON_STARTED_IN_RERUN_FAILED); } }