From 0eab6fd44a9c1f4fd7281072e3723a419bbfbc61 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 5 Mar 2014 12:03:38 +0100 Subject: [PATCH] test framework: refresh module file --- .../com/intellij/testFramework/ModuleTestCase.java | 5 ++++- .../openapi/module/impl/ModuleManagerImpl.java | 14 +++++--------- .../intellij/testFramework/PlatformTestCase.java | 10 +++++----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java index f6f140049f21..5930288f2c2c 100644 --- a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.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. @@ -39,6 +39,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; public abstract class ModuleTestCase extends IdeaTestCase { protected final Collection myModulesToDispose = new ArrayList(); @@ -100,6 +101,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { @Override public Module compute() { try { + LocalFileSystem.getInstance().refreshIoFiles(Collections.singletonList(moduleFile)); return ModuleManager.getInstance(myProject).loadModule(moduleFile.getAbsolutePath()); } catch (Exception e) { @@ -162,6 +164,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { FileUtil.copyDir(dirInTestDataFile, moduleDir); final Module module = createModule(moduleDir + "/" + newModuleFileName, moduleType); final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleDir); + assertNotNull(root); new WriteCommandAction.Simple(module.getProject()) { @Override protected void run() throws Throwable { diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 6041f613f1a0..9cabfb68416b 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 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. @@ -477,10 +477,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project @Override @NotNull - public Module loadModule(@NotNull String filePath) throws InvalidDataException, - IOException, - JDOMException, - ModuleWithNameAlreadyExists { + public Module loadModule(@NotNull String filePath) throws InvalidDataException, IOException, JDOMException, ModuleWithNameAlreadyExists { myModificationCount++; final ModifiableModuleModel modifiableModel = getModifiableModel(); final Module module = modifiableModel.loadModule(filePath); @@ -745,10 +742,9 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project } } - private Module loadModuleInternal(String filePath) - throws ModuleWithNameAlreadyExists, IOException, StateStorageException { - - final VirtualFile moduleFile = StandardFileSystems.local().findFileByPath(resolveShortWindowsName(filePath)); + private Module loadModuleInternal(String filePath) throws ModuleWithNameAlreadyExists, IOException, StateStorageException { + filePath = resolveShortWindowsName(filePath); + final VirtualFile moduleFile = StandardFileSystems.local().findFileByPath(filePath); if (moduleFile == null || !moduleFile.exists()) { throw new IOException(ProjectBundle.message("module.file.does.not.exist.error", filePath)); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index e1e6907985a4..59b8d4b95056 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.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. @@ -308,14 +308,14 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro protected static Module doCreateRealModuleIn(String moduleName, final Project project, final ModuleType moduleType) { final VirtualFile baseDir = project.getBaseDir(); assertNotNull(baseDir); - final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), - moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); + final File moduleFile = new File(FileUtil.toSystemDependentName(baseDir.getPath()), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); FileUtil.createIfDoesntExist(moduleFile); myFilesToDelete.add(moduleFile); return new WriteAction() { @Override - protected void run(Result result) throws Throwable { - final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); + protected void run(@NotNull Result result) throws Throwable { + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); + assertNotNull(virtualFile); Module module = ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType.getId()); module.getModuleFile(); result.setResult(module);