From 95bff30411753e5401cf4055a0818b894c10311a Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Thu, 30 Oct 2014 10:09:57 +0100 Subject: [PATCH 01/14] Testing framework now allows checking only specified warnings and highlightings (duplication removed) --- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index f188bfd0c207..dc0e25bfae3c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -396,12 +396,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public long checkHighlighting(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings) { - try { - return collectAndCheckHighlighting(checkWarnings, checkInfos, checkWeakWarnings); - } - catch (Exception e) { - throw new RuntimeException(e); - } + return checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings, false); } @Override From e0ada7c389312c148d6c77f9b7d4ffa390bdf55f Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 30 Oct 2014 12:35:38 +0300 Subject: [PATCH 02/14] IDEA-132130: Structural search inspection settings: toolbar isn't visible if there is a pattern with long name --- .../highlightTemplate/SSBasedInspectionOptions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionOptions.java b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionOptions.java index 8dd7211eefb4..db59f62ef7ef 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionOptions.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionOptions.java @@ -172,7 +172,9 @@ public class SSBasedInspectionOptions { public void run(AnActionButton button) { performMoveUpDown(true); } - }).createPanel() + }) + .setPreferredSize(new Dimension(-1, 100)) + .createPanel() ); new DoubleClickListener() { @Override From a7b64ff8d89e16bd734e75eaab95649d4dbbf5fc Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 30 Oct 2014 12:34:23 +0300 Subject: [PATCH 03/14] IDEA-114415 Unable to use debugger after failed debug of forked JUnit tests --- .../apiAdapters/TransportServiceWrapper.java | 4 ++++ .../intellij/debugger/impl/DebuggerUtilsImpl.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java b/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java index d6670355019a..2506a7410f2f 100644 --- a/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java +++ b/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java @@ -50,6 +50,10 @@ public class TransportServiceWrapper { return myTransport.startListening(); } + public TransportService.ListenKey startListening(String address) throws IOException { + return myTransport.startListening(address); + } + public void stopListening(final TransportService.ListenKey address) throws IOException { myTransport.stopListening(address); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java index 0f368bfb031f..c38dc234595b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java @@ -146,7 +146,20 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ return address; } catch (IOException e) { - throw new ExecutionException(DebugProcessImpl.processError(e)); + int tryNum = 0; + while (true) { + try { + TransportService.ListenKey listenKey = transportService.startListening("javadebug_" + (int)(Math.random()*1000)); + final String address = listenKey.address(); + transportService.stopListening(listenKey); + return address; + } + catch (Exception ex) { + if (tryNum++ > 10) { + throw new ExecutionException(DebugProcessImpl.processError(ex)); + } + } + } } } } \ No newline at end of file From d676450572fc9c5def76f3513305c2d05653d04c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 14:14:26 +0100 Subject: [PATCH 04/14] =?UTF-8?q?CompilerConfiguration=20=E2=80=94=20don't?= =?UTF-8?q?=20save=20defaults,=20but=20only=20DEFAULT=5FCOMPILER=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compiler/CompilerConfigurationImpl.java | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index 1ed63531e18f..e2b97a284a07 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -41,7 +41,10 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.ui.InputValidator; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Couple; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtilCore; @@ -50,11 +53,15 @@ import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinder; import com.intellij.util.ArrayUtil; import com.intellij.util.messages.MessageBusConnection; +import com.intellij.util.xmlb.Accessor; +import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; +import com.intellij.util.xmlb.XmlSerializer; import org.apache.oro.text.regex.*; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.java.compiler.JavaCompilers; import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl; import org.jetbrains.jps.model.serialization.java.compiler.AnnotationProcessorProfileSerializer; @@ -74,8 +81,8 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.CompilerConfiguration"); @NonNls public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home"; - @SuppressWarnings({"WeakerAccess"}) public String DEFAULT_COMPILER; - @NotNull private BackendCompiler myDefaultJavaCompiler; + private BackendCompiler myDefaultJavaCompiler; + private State myState = new State(); // extensions of the files considered as resource files private final List myRegexpResourcePatterns = new ArrayList(); @@ -124,16 +131,24 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements }); } + private static class State { + public String DEFAULT_COMPILER = JavaCompilers.JAVAC_ID; + + private boolean compilerWasSpecified; + } + @Override public Element getState() { Element state = new Element("state"); - try { - DefaultJDOMExternalizer.writeExternal(this, state); - } - catch (WriteExternalException e) { - LOG.error(e); - return null; - } + XmlSerializer.serializeInto(myState, state, new SkipDefaultValuesSerializationFilters() { + @Override + protected boolean accepts(@NotNull Accessor accessor, @NotNull Object bean, @Nullable Object beanValue) { + if (myState.compilerWasSpecified && "DEFAULT_COMPILER".equals(accessor.getName())) { + return true; + } + return super.accepts(accessor, bean, beanValue); + } + }); if (!myAddNotNullAssertions) { addChild(state, JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS).setAttribute( @@ -185,12 +200,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements @Override public void loadState(Element state) { - try { - readExternal(state); - } - catch (InvalidDataException e) { - LOG.error(e); - } + readExternal(state); } public void setProjectBytecodeTarget(@Nullable String level) { @@ -326,15 +336,15 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements for (FileType type : types) { compilerManager.addCompilableFileType(type); } - + myDefaultJavaCompiler = JAVAC_EXTERNAL_BACKEND; for (BackendCompiler compiler : myRegisteredCompilers) { - if (compiler.getId().equals(DEFAULT_COMPILER)) { + if (compiler.getId().equals(myState.DEFAULT_COMPILER)) { myDefaultJavaCompiler = compiler; break; } } - DEFAULT_COMPILER = myDefaultJavaCompiler.getId(); + myState.DEFAULT_COMPILER = myDefaultJavaCompiler.getId(); } public Collection getRegisteredJavaCompilers() { @@ -630,8 +640,12 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } - public void readExternal(Element parentNode) throws InvalidDataException { - DefaultJDOMExternalizer.readExternal(this, parentNode); + public void readExternal(Element parentNode) { + myState = XmlSerializer.deserialize(parentNode, State.class); + Element option = parentNode.getChild("option"); + if (!myProject.isDefault()) { + myState.compilerWasSpecified = option != null && "DEFAULT_COMPILER".equals(option.getAttributeValue("name")); + } final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS); if (notNullAssertions != null) { @@ -670,7 +684,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } } catch (MalformedPatternException e) { - throw new InvalidDataException(e); + LOG.error(e); } @@ -822,7 +836,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements */ public void setDefaultCompiler(BackendCompiler defaultCompiler) { myDefaultJavaCompiler = defaultCompiler; - DEFAULT_COMPILER = defaultCompiler.getId(); + myState.DEFAULT_COMPILER = defaultCompiler.getId(); } public void convertPatterns() { @@ -834,7 +848,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements try { ok = doConvertPatterns(); } - catch (MalformedPatternException e) { + catch (MalformedPatternException ignored) { ok = false; } if (!ok) { From 7d0d3ff9bab565f32dcd59e4e95c852292ec6604 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 15:38:48 +0100 Subject: [PATCH 05/14] cleanup --- .../execution/applet/AppletConfigurationType.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java index db9abb218ae5..06e0c14ac89e 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -30,6 +30,7 @@ public class AppletConfigurationType implements ConfigurationType { /**reflection*/ AppletConfigurationType() { myFactory = new ConfigurationFactoryEx(this) { + @Override public RunConfiguration createTemplateConfiguration(Project project) { return new AppletConfiguration(project, this); } @@ -41,26 +42,27 @@ public class AppletConfigurationType implements ConfigurationType { }; } + @Override public String getDisplayName() { return ExecutionBundle.message("applet.configuration.name"); } + @Override public String getConfigurationTypeDescription() { return ExecutionBundle.message("applet.configuration.description"); } + @Override public Icon getIcon() { return AllIcons.RunConfigurations.Applet; } + @Override public ConfigurationFactory[] getConfigurationFactories() { return new ConfigurationFactory[]{myFactory}; } - - - - + @Override @NotNull public String getId() { return "Applet"; From 141f3594aa1c0007523af903261f9a5330f016ee Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 15:49:08 +0100 Subject: [PATCH 06/14] cleanup --- .../execution/applet/AppletConfiguration.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java b/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java index 9839ec60cbad..0669cca5203e 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -26,7 +26,7 @@ import com.intellij.execution.util.JavaParametersUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.DefaultJDOMExternalizer; import com.intellij.openapi.util.InvalidDataException; @@ -47,11 +47,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; public class AppletConfiguration extends ModuleBasedConfiguration implements SingleClassConfiguration, RefactoringListenerProvider { - public String MAIN_CLASS_NAME; public String HTML_FILE_NAME; public boolean HTML_USED; @@ -73,6 +71,7 @@ public class AppletConfiguration extends ModuleBasedConfiguration getConfigurationEditor() { return new AppletConfigurable(getProject()); @@ -174,60 +178,64 @@ public class AppletConfiguration extends ModuleBasedConfiguration getValidModules() { return JavaRunConfigurationModule.getModulesForClass(getProject(), MAIN_CLASS_NAME); } + @Override public void readExternal(final Element parentNode) throws InvalidDataException { DefaultJDOMExternalizer.readExternal(this, parentNode); readModule(parentNode); final ArrayList parameters = new ArrayList(); - for ( - Iterator iterator = parentNode.getChildren(PARAMETER_ELEMENT_NAME).iterator(); iterator.hasNext();) { - final Element element = (Element)iterator.next(); - final String name = element.getAttributeValue(NAME_ATTR); - final String value = element.getAttributeValue(VALUE_ATTR); - parameters.add(new AppletParameter(name, value)); + for (final Element element : parentNode.getChildren(PARAMETER_ELEMENT_NAME)) { + parameters.add(new AppletParameter(element.getAttributeValue(NAME_ATTR), element.getAttributeValue(VALUE_ATTR))); } myAppletParameters = parameters.toArray(new AppletParameter[parameters.size()]); } + @Override public void writeExternal(final Element parentNode) throws WriteExternalException { writeModule(parentNode); DefaultJDOMExternalizer.writeExternal(this, parentNode); if (myAppletParameters != null) { - for (int i = 0; i < myAppletParameters.length; i++) { + for (AppletParameter myAppletParameter : myAppletParameters) { final Element element = new Element(PARAMETER_ELEMENT_NAME); parentNode.addContent(element); - element.setAttribute(NAME_ATTR, myAppletParameters[i].getName()); - element.setAttribute(VALUE_ATTR, myAppletParameters[i].getValue()); + element.setAttribute(NAME_ATTR, myAppletParameter.getName()); + element.setAttribute(VALUE_ATTR, myAppletParameter.getValue()); } } } + @Override public RefactoringElementListener getRefactoringElementListener(final PsiElement element) { if (HTML_USED) return null; return RefactoringListeners.getClassOrPackageListener(element, new RefactoringListeners.SingleClassConfigurationAccessor(this)); } + @Override public PsiClass getMainClass() { return getConfigurationModule().findClass(MAIN_CLASS_NAME); } + @Override public String suggestedName() { if (MAIN_CLASS_NAME == null) return null; return ProgramRunnerUtil.shortenName(JavaExecutionUtil.getShortClassName(MAIN_CLASS_NAME), 0); } + @Override public void setMainClassName(final String qualifiedName) { MAIN_CLASS_NAME = qualifiedName; } + @Override public void checkConfiguration() throws RuntimeConfigurationException { if (ALTERNATIVE_JRE_PATH_ENABLED){ if (ALTERNATIVE_JRE_PATH == null || ALTERNATIVE_JRE_PATH.length() == 0 || - !JavaSdkImpl.checkForJre(ALTERNATIVE_JRE_PATH)){ + !JavaSdk.checkForJre(ALTERNATIVE_JRE_PATH)){ throw new RuntimeConfigurationWarning(ExecutionBundle.message("jre.not.valid.error.message", ALTERNATIVE_JRE_PATH)); } } @@ -283,7 +291,7 @@ public class AppletConfiguration extends ModuleBasedConfiguration Date: Wed, 29 Oct 2014 15:53:45 +0100 Subject: [PATCH 07/14] get rid of deprecated RuntimeConfiguration usages --- .../configurations/ModuleBasedConfiguration.java | 10 +++++----- .../sm/runner/MockRuntimeConfiguration.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java b/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java index fedb79f10a42..2180f7d24edd 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/ModuleBasedConfiguration.java @@ -20,7 +20,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; @@ -37,7 +37,7 @@ import java.util.Set; * Base class for a configuration that is associated with a specific module. For example, Java run configurations use the selected module * to determine the run classpath. */ -public abstract class ModuleBasedConfiguration extends RuntimeConfiguration { +public abstract class ModuleBasedConfiguration extends LocatableConfigurationBase implements Cloneable, ModuleRunConfiguration { private static final Logger LOG = Logger.getInstance("#com.intellij.execution.configurations.ModuleBasedConfiguration"); private final ConfigurationModule myModule; @NonNls @@ -45,12 +45,12 @@ public abstract class ModuleBasedConfiguration modules = new HashSet(); for (Module classModule : classModules) { - ModuleUtil.collectModulesDependsOn(classModule, modules); + ModuleUtilCore.collectModulesDependsOn(classModule, modules); } if (modules.contains(originalModule)) setModule(originalModule); } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockRuntimeConfiguration.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockRuntimeConfiguration.java index 37dc7a96144a..2ccb61c7c7f8 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockRuntimeConfiguration.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/MockRuntimeConfiguration.java @@ -19,6 +19,7 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.Executor; import com.intellij.execution.configurations.*; import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.openapi.module.Module; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; @@ -31,9 +32,9 @@ import javax.swing.*; /** * @author Roman Chernyatchik */ -public class MockRuntimeConfiguration extends RuntimeConfiguration { +public class MockRuntimeConfiguration extends LocatableConfigurationBase implements Cloneable, ModuleRunConfiguration { public MockRuntimeConfiguration(final Project project) { - super("", project, new MockConfigurationFactory()); + super(project, new MockConfigurationFactory(), ""); } @Override @@ -57,6 +58,12 @@ public class MockRuntimeConfiguration extends RuntimeConfiguration { return null; } + @NotNull + @Override + public Module[] getModules() { + return Module.EMPTY_ARRAY; + } + private static class MockConfigurationFactory extends ConfigurationFactory { public MockConfigurationFactory() { super(new MyConfigurationType()); From 73d81a29b7b27c721b5538f356f4ddb497cbbc49 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 15:58:42 +0100 Subject: [PATCH 08/14] cleanup --- .../intellij/execution/impl/RunManagerImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java index f5de85ddf555..e97fa70f8427 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java @@ -38,6 +38,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import com.intellij.util.containers.WeakHashMap; import gnu.trove.THashMap; +import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -528,10 +529,10 @@ public class RunManagerImpl extends RunManagerEx implements PersistentStateCompo try { configuration.checkSettings(executor); } - catch (RuntimeConfigurationError er) { + catch (RuntimeConfigurationError ignored) { return false; } - catch (RuntimeConfigurationException e) { + catch (RuntimeConfigurationException ignored) { return true; } return true; @@ -1082,7 +1083,7 @@ public class RunManagerImpl extends RunManagerEx implements PersistentStateCompo settings.checkSettings(); icon = ProgramRunnerUtil.getConfigurationIcon(settings, false); } - catch (RuntimeConfigurationException e) { + catch (RuntimeConfigurationException ignored) { icon = ProgramRunnerUtil.getConfigurationIcon(settings, true); } myIconCalcTime.put(uniqueID, System.currentTimeMillis() - startTime); @@ -1118,10 +1119,12 @@ public class RunManagerImpl extends RunManagerEx implements PersistentStateCompo tasks = getBeforeRunTasks(settings); myConfigurationToBeforeTasksMap.put(settings, tasks); } - List result = new ArrayList(); + List result = new SmartList(); for (BeforeRunTask task : tasks) { - if (task.getProviderId() == taskProviderID) + if (task.getProviderId() == taskProviderID) { + //noinspection unchecked result.add((T)task); + } } return result; } @@ -1187,10 +1190,10 @@ public class RunManagerImpl extends RunManagerEx implements PersistentStateCompo @Override public final void setBeforeRunTasks(final RunConfiguration runConfiguration, @NotNull List tasks, boolean addEnabledTemplateTasksIfAbsent) { - List result = new ArrayList(tasks); + List result = new SmartList(tasks); if (addEnabledTemplateTasksIfAbsent) { List templates = getTemplateBeforeRunTasks(runConfiguration); - Set> idsToSet = new HashSet>(); + Set> idsToSet = new THashSet>(); for (BeforeRunTask task : tasks) { idsToSet.add(task.getProviderId()); } From 9577b9208057c3bfae7f27955e467a8d994d4bd8 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 16:20:31 +0100 Subject: [PATCH 09/14] =?UTF-8?q?DaemonCodeAnalyzerImpl=20=E2=80=94=20don'?= =?UTF-8?q?t=20save=20defaults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 54 +++++++++++-------- .../src/componentSets/Lang.xml | 1 - 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 83a332a50831..26219964c1fc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -34,7 +34,10 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.application.ex.ApplicationManagerEx; -import com.intellij.openapi.components.NamedComponent; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.components.StoragePathMacros; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -54,7 +57,9 @@ import com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.RefreshQueueImpl; @@ -85,7 +90,11 @@ import java.util.*; /** * This class also controls the auto-reparse and auto-hints. */ -public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements JDOMExternalizable, NamedComponent, Disposable { +@State( + name = "DaemonCodeAnalyzer", + storages = @Storage(file = StoragePathMacros.WORKSPACE_FILE) +) +public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements PersistentStateComponent, Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl"); private static final Key> MARKERS_IN_EDITOR_DOCUMENT_KEY = Key.create("MARKERS_IN_EDITOR_DOCUMENT"); @@ -377,12 +386,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements JDOM myPassExecutorService.cancelAll(true); } - @Override - @NotNull - public String getComponentName() { - return "DaemonCodeAnalyzer"; - } - @Override public void settingsChanged() { DaemonCodeAnalyzerSettings settings = DaemonCodeAnalyzerSettings.getInstance(); @@ -676,35 +679,40 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements JDOM return myLastIntentionHint; } + @Nullable @Override - public void writeExternal(@NotNull Element parentNode) throws WriteExternalException { - Element disableHintsElement = new Element(DISABLE_HINTS_TAG); - parentNode.addContent(disableHintsElement); + public Element getState() { + Element state = new Element("state"); + if (myDisabledHintsFiles.isEmpty()) { + return state; + } - List array = new ArrayList(); + List array = new SmartList(); for (VirtualFile file : myDisabledHintsFiles) { if (file.isValid()) { array.add(file.getUrl()); } } - Collections.sort(array); - for (String url : array) { - Element fileElement = new Element(FILE_TAG); - fileElement.setAttribute(URL_ATT, url); - disableHintsElement.addContent(fileElement); + if (!array.isEmpty()) { + Collections.sort(array); + + Element disableHintsElement = new Element(DISABLE_HINTS_TAG); + state.addContent(disableHintsElement); + for (String url : array) { + disableHintsElement.addContent(new Element(FILE_TAG).setAttribute(URL_ATT, url)); + } } + return state; } @Override - public void readExternal(@NotNull Element parentNode) throws InvalidDataException { + public void loadState(Element state) { myDisabledHintsFiles.clear(); - Element element = parentNode.getChild(DISABLE_HINTS_TAG); + Element element = state.getChild(DISABLE_HINTS_TAG); if (element != null) { - for (Object o : element.getChildren(FILE_TAG)) { - Element e = (Element)o; - + for (Element e : element.getChildren(FILE_TAG)) { String url = e.getAttributeValue(URL_ATT); if (url != null) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); diff --git a/platform/platform-resources/src/componentSets/Lang.xml b/platform/platform-resources/src/componentSets/Lang.xml index 89a9b361a4f0..d7fe240d0430 100644 --- a/platform/platform-resources/src/componentSets/Lang.xml +++ b/platform/platform-resources/src/componentSets/Lang.xml @@ -110,7 +110,6 @@ com.intellij.codeInsight.daemon.DaemonCodeAnalyzer com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl - From 36832b56ba6f99e6893307743b1e5da18604b933 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 17:32:46 +0100 Subject: [PATCH 10/14] =?UTF-8?q?DependencyValidationManager=20=E2=80=94?= =?UTF-8?q?=20don't=20save=20defaults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit simplification — introduce StateSplitterEx --- .../DependencyValidationManagerImpl.java | 129 ++++++++---------- .../encoding/EncodingProjectManagerImpl.java | 6 +- .../openapi/components/StateSplitter.java | 6 +- .../openapi/components/StateSplitterEx.java | 34 +++++ .../impl/stores/DirectoryStorageData.java | 43 ++++-- 5 files changed, 129 insertions(+), 89 deletions(-) create mode 100644 platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java diff --git a/platform/analysis-impl/src/com/intellij/packageDependencies/DependencyValidationManagerImpl.java b/platform/analysis-impl/src/com/intellij/packageDependencies/DependencyValidationManagerImpl.java index 7e6cd5b7353f..59bd15b49bc4 100644 --- a/platform/analysis-impl/src/com/intellij/packageDependencies/DependencyValidationManagerImpl.java +++ b/platform/analysis-impl/src/com/intellij/packageDependencies/DependencyValidationManagerImpl.java @@ -13,22 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.packageDependencies; import com.intellij.icons.AllIcons; import com.intellij.ide.IdeBundle; import com.intellij.openapi.components.*; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.PsiFile; import com.intellij.psi.search.scope.packageSet.*; import com.intellij.ui.LayeredIcon; +import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.UniqueNameGenerator; import com.intellij.util.ui.UIUtil; +import gnu.trove.THashMap; import org.jdom.Attribute; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -39,14 +41,13 @@ import javax.swing.*; import java.util.*; @State( - name="DependencyValidationManager", - storages= { + name = "DependencyValidationManager", + storages = { @Storage(file = StoragePathMacros.PROJECT_FILE), @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/scopes/", scheme = StorageScheme.DIRECTORY_BASED, - stateSplitter = DependencyValidationManagerImpl.ScopesStateSplitter.class)} + stateSplitter = DependencyValidationManagerImpl.ScopesStateSplitter.class)} ) public class DependencyValidationManagerImpl extends DependencyValidationManager { - private static final Logger LOG = Logger.getInstance("#com.intellij.packageDependencies.DependencyValidationManagerImpl"); private static final NotNullLazyValue ourSharedScopeIcon = new NotNullLazyValue() { @NotNull @Override @@ -58,7 +59,8 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager private final List myRules = new ArrayList(); private final NamedScopeManager myNamedScopeManager; - public boolean SKIP_IMPORT_STATEMENTS = false; + private boolean mySkipImportStatements; + private boolean mySkipImportStatementsWasSpecified; @NonNls private static final String DENY_RULE_KEY = "deny_rule"; @NonNls private static final String FROM_SCOPE_KEY = "from_scope"; @@ -67,8 +69,7 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager @NonNls private static final String UNNAMED_SCOPE = "unnamed_scope"; @NonNls private static final String VALUE = "value"; - - private final Map myUnnamedScopes = new HashMap(); + private final Map myUnnamedScopes = new THashMap(); public DependencyValidationManagerImpl(final Project project, NamedScopeManager namedScopeManager) { super(project); @@ -147,12 +148,12 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager @Override public boolean skipImportStatements() { - return SKIP_IMPORT_STATEMENTS; + return mySkipImportStatements; } @Override public void setSkipImportStatements(final boolean skip) { - SKIP_IMPORT_STATEMENTS = skip; + mySkipImportStatements = skip; } @NotNull @@ -206,12 +207,11 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager } @Override - public void loadState(final Element element) { - try { - DefaultJDOMExternalizer.readExternal(this, element); - } - catch (InvalidDataException e) { - LOG.info(e); + public void loadState(Element element) { + Element option = element.getChild("option"); + if (option != null && "SKIP_IMPORT_STATEMENTS".equals(option.getAttributeValue("name"))) { + mySkipImportStatementsWasSpecified = !myProject.isDefault(); + mySkipImportStatements = Boolean.parseBoolean(option.getAttributeValue("value")); } super.loadState(element); @@ -223,7 +223,7 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager final String packageSet = ((Element)unnamedScope).getAttributeValue(VALUE); myUnnamedScopes.put(packageSet, packageSetFactory.compile(packageSet)); } - catch (ParsingException e) { + catch (ParsingException ignored) { //skip pattern } } @@ -234,9 +234,8 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager private void readRules(Element element) { removeAllRules(); - List rules = element.getChildren(DENY_RULE_KEY); - for (Object rule1 : rules) { - DependencyRule rule = readRule((Element)rule1); + for (Element rule1 : element.getChildren(DENY_RULE_KEY)) { + DependencyRule rule = readRule(rule1); if (rule != null) { addRule(rule); } @@ -246,18 +245,17 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager @Override public Element getState() { Element element = super.getState(); - try { - DefaultJDOMExternalizer.writeExternal(this, element); + assert element != null; + if (mySkipImportStatements || mySkipImportStatementsWasSpecified) { + element.addContent(new Element("option").setAttribute("name", "SKIP_IMPORT_STATEMENTS").setAttribute("value", Boolean.toString(mySkipImportStatements))); } - catch (WriteExternalException e) { - LOG.info(e); - } - final List unnamedScopes = new ArrayList(myUnnamedScopes.keySet()); - Collections.sort(unnamedScopes); - for (final String unnamedScope : unnamedScopes) { - Element unnamedElement = new Element(UNNAMED_SCOPE); - unnamedElement.setAttribute(VALUE, unnamedScope); - element.addContent(unnamedElement); + + if (!myUnnamedScopes.isEmpty()) { + String[] unnamedScopes = myUnnamedScopes.keySet().toArray(new String[myUnnamedScopes.size()]); + Arrays.sort(unnamedScopes); + for (String unnamedScope : unnamedScopes) { + element.addContent(new Element(UNNAMED_SCOPE).setAttribute(VALUE, unnamedScope)); + } } writeRules(element); @@ -314,50 +312,44 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager return new DependencyRule(fromNamedScope, toNamedScope, Boolean.valueOf(denyRule).booleanValue()); } - public static class ScopesStateSplitter implements StateSplitter { - @Override - public List> splitState(Element e) { - final UniqueNameGenerator generator = new UniqueNameGenerator(); - final List> result = new ArrayList>(); - - final Element[] elements = JDOMUtil.getElements(e); - for (Element element : elements) { - if (element.getName().equals("scope")) { - element.detach(); - String scopeName = element.getAttributeValue("name"); - assert scopeName != null; - final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(scopeName)) + ".xml"; - result.add(Pair.create(element, name)); - } + static class ScopesStateSplitter extends StateSplitterEx { + @Override + public List> splitState(@NotNull Element state) { + UniqueNameGenerator generator = new UniqueNameGenerator(); + List> result = new SmartList>(); + for (Iterator iterator = state.getChildren("scope").iterator(); iterator.hasNext(); ) { + Element element = iterator.next(); + iterator.remove(); + String scopeName = element.getAttributeValue("name"); + assert scopeName != null; + result.add(Pair.create(element, generator.generateUniqueName(FileUtil.sanitizeFileName(scopeName)) + ".xml")); } - if (!e.getChildren().isEmpty()) { - result.add(Pair.create(e, generator.generateUniqueName("scope_settings") + ".xml")); - } - return result; + if (!state.getChildren().isEmpty()) { + result.add(Pair.create(state, generator.generateUniqueName("scope_settings") + ".xml")); + } + return result; } @Override - public void mergeStatesInto(Element target, Element[] elements) { - for (Element element : elements) { - if (element.getName().equals("scope")) { - element.detach(); - target.addContent(element); + public void mergeStateInto(@NotNull Element target, @NotNull Element subState) { + if (subState.getName().equals("scope")) { + target.addContent(subState); + } + else { + for (Iterator iterator = subState.getChildren().iterator(); iterator.hasNext(); ) { + Element configuration = iterator.next(); + iterator.remove(); + target.addContent(configuration); } - else { - final Element[] states = JDOMUtil.getElements(element); - for (Element state : states) { - state.detach(); - target.addContent(state); - } - for (Object attr : element.getAttributes()) { - target.setAttribute(((Attribute)attr).clone()); - } + for (Iterator iterator = subState.getAttributes().iterator(); iterator.hasNext(); ) { + Attribute attribute = iterator.next(); + iterator.remove(); + target.setAttribute(attribute); } } } } - private final List> myScopes = ContainerUtil.createLockFreeCopyOnWriteList(); private void reloadScopes() { @@ -377,8 +369,7 @@ public class DependencyValidationManagerImpl extends DependencyValidationManager private static void addScopesToList(@NotNull final List> scopeList, @NotNull final NamedScopesHolder holder) { - NamedScope[] scopes = holder.getScopes(); - for (NamedScope scope : scopes) { + for (NamedScope scope : holder.getScopes()) { scopeList.add(Pair.create(scope, holder)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingProjectManagerImpl.java index c61bd9e79362..81bc32b511af 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingProjectManagerImpl.java @@ -148,8 +148,10 @@ public class EncodingProjectManagerImpl extends EncodingProjectManager implement myModificationTracker.incModificationCount(); - myOldUTFGuessing = element.getAttributeValue("useUTFGuessing"); - myNative2AsciiForPropertiesFilesWasSpecified = native2AsciiForPropertiesFiles != null; + if (!myProject.isDefault()) { + myOldUTFGuessing = element.getAttributeValue("useUTFGuessing"); + myNative2AsciiForPropertiesFilesWasSpecified = native2AsciiForPropertiesFiles != null; + } } @Override diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitter.java b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitter.java index 19f7d7c52d13..cd7c68463030 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitter.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.openapi.components; import com.intellij.openapi.util.Pair; @@ -22,9 +21,10 @@ import org.jdom.Element; import java.util.List; /** - * @author mike + * @deprecated Use {@link StateSplitterEx} */ public interface StateSplitter { List> splitState(Element e); + void mergeStatesInto(Element target, Element[] elements); } diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java new file mode 100644 index 000000000000..f809b146c906 --- /dev/null +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.components; + +import com.intellij.openapi.util.Pair; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public abstract class StateSplitterEx implements StateSplitter { + @Override + public abstract List> splitState(@NotNull Element state); + + public abstract void mergeStateInto(@NotNull Element target, @NotNull Element subState); + + @Override + public final void mergeStatesInto(Element target, Element[] elements) { + throw new IllegalStateException(); + } +} \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DirectoryStorageData.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DirectoryStorageData.java index c340efe73113..ced0f467cce2 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DirectoryStorageData.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DirectoryStorageData.java @@ -17,6 +17,7 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.application.options.PathMacrosCollector; import com.intellij.openapi.components.StateSplitter; +import com.intellij.openapi.components.StateSplitterEx; import com.intellij.openapi.components.TrackingPathMacroSubstitutor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.JDOMUtil; @@ -243,24 +244,36 @@ public class DirectoryStorageData extends StorageDataBase { } @Nullable - public Element getCompositeStateAndArchive(@NotNull String componentName, @NotNull StateSplitter splitter) { - List subElements = new SmartList(); + public Element getCompositeStateAndArchive(@NotNull String componentName, @SuppressWarnings("deprecation") @NotNull StateSplitter splitter) { StateMap fileToState = myStates.get(componentName); - if (fileToState != null) { - for (String fileName : fileToState.keys()) { - Element state = fileToState.getStateAndArchive(fileName); - if (state == null) { - subElements.clear(); - break; - } - - subElements.add(state); - } + Element state = new Element(StorageData.COMPONENT); + if (fileToState == null || fileToState.isEmpty()) { + return state; } - Element state = new Element(StorageData.COMPONENT); - if (!subElements.isEmpty()) { - splitter.mergeStatesInto(state, subElements.toArray(new Element[subElements.size()])); + if (splitter instanceof StateSplitterEx) { + StateSplitterEx splitterEx = (StateSplitterEx)splitter; + for (String fileName : fileToState.keys()) { + Element subState = fileToState.getStateAndArchive(fileName); + if (subState == null) { + return null; + } + splitterEx.mergeStateInto(state, subState); + } + } + else { + List subElements = new SmartList(); + for (String fileName : fileToState.keys()) { + Element subState = fileToState.getStateAndArchive(fileName); + if (subState == null) { + return null; + } + subElements.add(state); + } + + if (!subElements.isEmpty()) { + splitter.mergeStatesInto(state, subElements.toArray(new Element[subElements.size()])); + } } return state; } From 474265a5236cbea8dcdd23f0d6bbe4aa5f8da8bd Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Oct 2014 17:35:43 +0100 Subject: [PATCH 11/14] cleanup --- .../impl/artifacts/ArtifactManagerImpl.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java index 3547d3847c25..837360fbc857 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java @@ -50,12 +50,12 @@ import java.util.*; * @author nik */ @State( - name = ArtifactManagerImpl.COMPONENT_NAME, - storages = { - @Storage(file = StoragePathMacros.PROJECT_FILE), - @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/artifacts/", scheme = StorageScheme.DIRECTORY_BASED, - stateSplitter = ArtifactManagerStateSplitter.class) - } + name = ArtifactManagerImpl.COMPONENT_NAME, + storages = { + @Storage(file = StoragePathMacros.PROJECT_FILE), + @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/artifacts/", scheme = StorageScheme.DIRECTORY_BASED, + stateSplitter = ArtifactManagerStateSplitter.class) + } ) public class ArtifactManagerImpl extends ArtifactManager implements ProjectComponent, PersistentStateComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.artifacts.ArtifactManagerImpl"); @@ -77,25 +77,30 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo ((ArtifactPointerManagerImpl)ArtifactPointerManager.getInstance(project)).setArtifactManager(this); } + @Override @NotNull public Artifact[] getArtifacts() { return myModel.getArtifacts(); } + @Override public Artifact findArtifact(@NotNull String name) { return myModel.findArtifact(name); } + @Override @NotNull public Artifact getArtifactByOriginal(@NotNull Artifact artifact) { return myModel.getArtifactByOriginal(artifact); } + @Override @NotNull public Artifact getOriginalArtifact(@NotNull Artifact artifact) { return myModel.getOriginalArtifact(artifact); } + @Override @NotNull public Collection getArtifactsByType(@NotNull ArtifactType type) { return myModel.getArtifactsByType(type); @@ -106,6 +111,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return myModel.getAllArtifactsIncludingInvalid(); } + @Override public ArtifactManagerState getState() { final ArtifactManagerState state = new ArtifactManagerState(); for (Artifact artifact : getAllArtifactsIncludingInvalid()) { @@ -127,7 +133,8 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo } } Collections.sort(artifactState.getPropertiesList(), new Comparator() { - public int compare(ArtifactPropertiesState o1, ArtifactPropertiesState o2) { + @Override + public int compare(@NotNull ArtifactPropertiesState o1, @NotNull ArtifactPropertiesState o2) { return o1.getId().compareTo(o2.getId()); } }); @@ -184,6 +191,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return packagingElement; } + @Override public void loadState(ArtifactManagerState managerState) { final List artifacts = new ArrayList(); for (ArtifactState state : managerState.getArtifacts()) { @@ -254,15 +262,18 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo } } + @Override public void disposeComponent() { LocalFileSystem.getInstance().removeWatchedRoots(myWatchedOutputs.values()); } + @Override @NotNull public String getComponentName() { return COMPONENT_NAME; } + @Override public void initComponent() { VirtualFileManager.getInstance().addVirtualFileListener(new ArtifactVirtualFileListener(myProject, this), myProject); updateWatchedRoots(); @@ -293,9 +304,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo } } + @Override public void projectOpened() { } + @Override public void projectClosed() { } @@ -354,6 +367,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo final ArtifactListener publisher = myProject.getMessageBus().syncPublisher(TOPIC); hasChanges = !removed.isEmpty() || !added.isEmpty() || !changed.isEmpty(); ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() { + @Override public void run() { for (ArtifactImpl artifact : removed) { publisher.artifactRemoved(artifact); @@ -381,9 +395,11 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo return myProject; } + @Override @NotNull public Artifact addArtifact(@NotNull final String name, @NotNull final ArtifactType type, final CompositePackagingElement root) { return new WriteAction() { + @Override protected void run(@NotNull final Result result) { final ModifiableArtifactModel model = createModifiableModel(); final ModifiableArtifact artifact = model.addArtifact(name, type); @@ -408,6 +424,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo final CompositePackagingElement root = model.getOrCreateModifiableArtifact(artifact).getRootElement(); PackagingElementFactory.getInstance().getOrCreateDirectory(root, relativePath).addOrFindChildren(elements); new WriteAction() { + @Override protected void run(@NotNull final Result result) { model.commit(); } @@ -434,6 +451,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo mySortedArtifacts = null; } + @Override protected List getArtifactsList() { return myArtifactsList; } From e3a8f92684caa6ee80425969af3d6ee78eb2ac4c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 30 Oct 2014 08:48:04 +0100 Subject: [PATCH 12/14] =?UTF-8?q?sanitizeFileName=20=E2=80=94=20don't=20cr?= =?UTF-8?q?eate=20stringBuilder/string=20if=20name=20is=20sanitized?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/openapi/util/io/FileUtil.java | 41 ++++++++++++++----- .../openapi/util/io/FileUtilLightTest.java | 17 +++++++- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index d7d632377ab4..473aa8acda70 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -1053,21 +1053,40 @@ public class FileUtil extends FileUtilRt { */ @NotNull public static String sanitizeFileName(@NotNull String name) { - StringBuilder result = new StringBuilder(); - - for (int i = 0; i < name.length(); i++) { - final char ch = name.charAt(i); - - if (ch > 0 && ch < 255) { - if (Character.isLetterOrDigit(ch)) { - result.append(ch); - } - else { - result.append("_"); + StringBuilder result = null; + int last = 0; + int length = name.length(); + for (int i = 0; i < length; i++) { + char c = name.charAt(i); + boolean appendReplacement = true; + if (c > 0 && c < 255) { + if (Character.isLetterOrDigit(c) || c == '_') { + continue; } } + else { + appendReplacement = false; + } + + if (result == null) { + result = new StringBuilder(); + } + if (last < i) { + result.append(name, last, i); + } + if (appendReplacement) { + result.append('_'); + } + last = i + 1; } + if (result == null) { + return name; + } + + if (last < length) { + result.append(name, last, length); + } return result.toString(); } diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java index dd1f46dace4c..e0c0f9b64130 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java @@ -24,7 +24,6 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import org.junit.Test; -import java.io.File; import java.io.IOException; import java.io.StringReader; import java.util.Arrays; @@ -32,6 +31,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.sameInstance; import static org.junit.Assert.*; public class FileUtilLightTest { @@ -198,4 +199,18 @@ public class FileUtilLightTest { String expected = SystemInfo.isWindows ? "~\\relative" : "~/relative"; assertEquals(expected, FileUtil.getLocationRelativeToUserHome(SystemProperties.getUserHome() + "/relative", false)); } + + @Test + public void sanitizeFileName() { + String newS = "tmp"; + assertThat(FileUtil.sanitizeFileName(newS), sameInstance(newS)); + assertThat(FileUtil.sanitizeFileName("_test"), sameInstance("_test")); + + assertThat(FileUtil.sanitizeFileName(" "), equalTo("_")); + assertThat(FileUtil.sanitizeFileName("\u2026"), equalTo("")); + assertThat(FileUtil.sanitizeFileName("q_test"), sameInstance("q_test")); + assertThat(FileUtil.sanitizeFileName("12_"), sameInstance("12_")); + assertThat(FileUtil.sanitizeFileName("12_ 123"), equalTo("12___123")); + assertThat(FileUtil.sanitizeFileName(" 12\u2026123"), equalTo("_12123")); + } } From a1b6f5c8aaaa9c66e449ab6e336eda2cb45a164d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 30 Oct 2014 10:07:25 +0100 Subject: [PATCH 13/14] =?UTF-8?q?simplification=20=E2=80=94=20introduce=20?= =?UTF-8?q?StateSplitterEx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArtifactManagerStateSplitter.java | 29 +-- .../converter/options/options.after.xml | 36 ++- .../inspection/converter/options/options.ipr | 2 - .../converter/scope/options.after.xml | 44 ++-- .../inspection/converter/scope/options.ipr | 2 - .../InspectionProfilesConverterTest.java | 13 +- .../profile/DefaultProjectProfileManager.java | 230 ++++++++---------- .../profile/ProjectProfileManager.java | 5 +- .../DependencyValidationManagerImpl.java | 53 ++-- .../InspectionProjectProfileManager.java | 27 +- .../InspectionProjectProfileManagerImpl.java | 61 ++--- .../MainConfigurationStateSplitter.java | 57 +++++ .../openapi/components/StateSplitterEx.java | 48 +++- .../impl/libraries/ProjectLibraryTable.java | 26 +- .../idea/copyright/CopyrightManager.java | 70 ++---- .../state/ProjectDictionarySplitter.java | 28 +-- 16 files changed, 341 insertions(+), 390 deletions(-) create mode 100644 platform/projectModel-api/src/com/intellij/openapi/components/MainConfigurationStateSplitter.java diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerStateSplitter.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerStateSplitter.java index 14fecb85dbdc..641257ac5e56 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerStateSplitter.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerStateSplitter.java @@ -15,37 +15,20 @@ */ package com.intellij.packaging.impl.artifacts; -import com.intellij.openapi.components.StateSplitter; -import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.components.StateSplitterEx; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.text.UniqueNameGenerator; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.serialization.artifact.ArtifactState; -import java.util.ArrayList; import java.util.List; /** * @author nik */ -public class ArtifactManagerStateSplitter implements StateSplitter { - public List> splitState(Element e) { - final UniqueNameGenerator generator = new UniqueNameGenerator(); - - List> result = new ArrayList>(); - - for (Element element : JDOMUtil.getElements(e)) { - final String name = generator.generateUniqueName(FileUtil.sanitizeFileName(element.getAttributeValue(ArtifactState.NAME_ATTRIBUTE))) + ".xml"; - result.add(Pair.create(element, name)); - } - - return result; - } - - public void mergeStatesInto(Element target, Element[] elements) { - for (Element e : elements) { - target.addContent(e); - } +final class ArtifactManagerStateSplitter extends StateSplitterEx { + @Override + public List> splitState(@NotNull Element state) { + return splitState(state, ArtifactState.NAME_ATTRIBUTE); } } diff --git a/java/java-tests/testData/inspection/converter/options/options.after.xml b/java/java-tests/testData/inspection/converter/options/options.after.xml index a76b8feb786a..d95147e70257 100644 --- a/java/java-tests/testData/inspection/converter/options/options.after.xml +++ b/java/java-tests/testData/inspection/converter/options/options.after.xml @@ -1,20 +1,18 @@ - - - - - - - - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/converter/options/options.ipr b/java/java-tests/testData/inspection/converter/options/options.ipr index 89406e94294d..1930a1f96000 100644 --- a/java/java-tests/testData/inspection/converter/options/options.ipr +++ b/java/java-tests/testData/inspection/converter/options/options.ipr @@ -59,7 +59,6 @@