From e9d4f71b493514a49e914bc062bf08aa3dda2437 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 31 Jan 2017 15:16:17 +0100 Subject: [PATCH] save using store.save to avoid global flag manipulation cleanup (overrides) --- .../testFramework/CompilerTester.java | 11 +++++---- .../openapi/project/ex/ProjectEx.java | 3 ++- .../testFramework/PlatformTestUtil.java | 23 ++++++++----------- .../impl/ModuleFixtureBuilderImpl.java | 14 +++++------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java index 749964d60e01..feb0142e5faf 100644 --- a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java +++ b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java @@ -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. @@ -47,6 +47,9 @@ import org.junit.Assert; import javax.swing.*; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -183,10 +186,10 @@ public class CompilerTester { PlatformTestUtil.saveProject(getProject()); CompilerTestUtil.saveApplicationSettings(); for (Module module : myModules) { - File ioFile = new File(module.getModuleFilePath()); - if (!ioFile.exists()) { + Path ioFile = Paths.get(module.getModuleFilePath()); + if (!Files.exists(ioFile)) { getProject().save(); - assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); + assert Files.exists(ioFile) : "File does not exist: " + ioFile.toString(); } } runnable.consume(callback); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java index a44339933569..da3255d0f931 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 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. @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; public interface ProjectEx extends Project { interface ProjectSaved { Topic TOPIC = Topic.create("SaveProjectTopic", ProjectSaved.class, Topic.BroadcastDirection.NONE); + void saved(@NotNull final Project project); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 1bedc86f6cd4..1447e23a6d0c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -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. @@ -31,9 +31,9 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.ex.ApplicationEx; -import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.application.impl.LaterInvocator; +import com.intellij.openapi.components.ServiceKt; +import com.intellij.openapi.components.impl.stores.StoreUtil; import com.intellij.openapi.editor.Document; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.ExtensionPointName; @@ -71,7 +71,10 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.InvocationEvent; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; import java.nio.charset.Charset; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -532,16 +535,8 @@ public class PlatformTestUtil { return SystemInfo.isAppleJvm ? FileUtil.toCanonicalPath(home + "/../Classes/classes.jar") : home + "/lib/rt.jar"; } - public static void saveProject(Project project) { - ApplicationEx application = ApplicationManagerEx.getApplicationEx(); - boolean oldValue = application.isDoNotSave(); - try { - application.doNotSave(false); - project.save(); - } - finally { - application.doNotSave(oldValue); - } + public static void saveProject(@NotNull Project project) { + StoreUtil.save(ServiceKt.getStateStore(project), project); } public static class TestInfo { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java index 11f4a3665cfa..f8036964b5ce 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java @@ -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. @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -115,14 +116,11 @@ public abstract class ModuleFixtureBuilderImpl implemen protected abstract T instantiateFixture(); Module buildModule() { - final Module[] module = {null}; - - ApplicationManager.getApplication().runWriteAction(() -> { - module[0] = createModule(); - initModule(module[0]); + return ApplicationManager.getApplication().runWriteAction((Computable)() -> { + Module module = createModule(); + initModule(module); + return module; }); - - return module[0]; } protected void initModule(Module module) {