test framework: refresh module file

This commit is contained in:
Roman Shevchenko
2014-03-05 12:05:36 +01:00
parent 0c1cf4d047
commit 0eab6fd44a
3 changed files with 14 additions and 15 deletions
@@ -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<Module> myModulesToDispose = new ArrayList<Module>();
@@ -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 {
@@ -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));
}
@@ -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<Module>() {
@Override
protected void run(Result<Module> result) throws Throwable {
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
protected void run(@NotNull Result<Module> 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);