use Path instead of VFS to open/import/create project — ProjectManagerEx.newProject

GitOrigin-RevId: 63b4d5441167cbf8e8d8994e45bd7d07458a9f11
This commit is contained in:
Vladimir Krivosheev
2019-07-10 17:06:00 +03:00
committed by intellij-monorepo-bot
parent af188f523c
commit e1a03fe6a3
31 changed files with 167 additions and 206 deletions
@@ -161,7 +161,7 @@ public class SaveProjectAsTemplateTest extends NewProjectWizardTestCase {
final Module module = super.createMainModule();
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
VirtualFile baseDir = module.getProject().getBaseDir();
VirtualFile baseDir = PlatformTestUtil.getOrCreateProjectTestBaseDir(module.getProject());
ContentEntry entry = model.addContentEntry(baseDir);
entry.addSourceFolder(baseDir, false);
model.commit();
@@ -36,7 +36,7 @@ class ProjectInspectionManagerTest {
private fun doTest(task: suspend (Project) -> Unit) {
runBlocking {
loadAndUseProjectInLoadComponentStateMode(tempDirManager, { it.path }, task)
loadAndUseProjectInLoadComponentStateMode(tempDirManager, { Paths.get(it.path) }, task)
}
}
@@ -224,7 +224,7 @@ class ProjectInspectionManagerTest {
<project version="4">
</project>""".trimIndent()
loadAndUseProjectInLoadComponentStateMode(tempDirManager, {
it.writeChild("test${ProjectFileType.DOT_DEFAULT_EXTENSION}", emptyProjectFile).path
Paths.get(it.writeChild("test${ProjectFileType.DOT_DEFAULT_EXTENSION}", emptyProjectFile).path)
}) { project ->
val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstance(project)
projectInspectionProfileManager.forceLoadSchemes()
@@ -1523,7 +1523,6 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
String body = StringUtil.repeat("\"String field = null;\"\n", 1000);
configureByText(StdFileTypes.JAVA, "class X{ void f() {" + body + "<caret>\n} }");
File temp = createTempDirectory();
final Project alienProject = createProject(createTempDirectory().toPath().resolve("alien.ipr"));
boolean succ2 = ProjectManagerEx.getInstanceEx().openProject(alienProject);
assertTrue(succ2);
@@ -95,9 +95,9 @@ internal class HeavyBuiltInWebServerTest {
@Test
fun `path outside of project`() = runBlocking {
val projectDir = tempDirManager.newPath().resolve("foo/bar")
val projectDirPath = projectDir.systemIndependentPath
createHeavyProject("$projectDirPath/test.ipr").use { project ->
createHeavyProject(projectDir.resolve("test.ipr")).use { project ->
projectDir.createDirectories()
val projectDirPath = projectDir.systemIndependentPath
LocalFileSystem.getInstance().refreshAndFindFileByPath(projectDirPath)
createModule(projectDirPath, project)
@@ -111,9 +111,9 @@ internal class HeavyBuiltInWebServerTest {
@Test
fun `file in hidden folder`() = runBlocking {
val projectDir = tempDirManager.newPath().resolve("foo/bar")
val projectDirPath = projectDir.systemIndependentPath
createHeavyProject("$projectDirPath/test.ipr").use { project ->
createHeavyProject(projectDir.resolve("test.ipr")).use { project ->
projectDir.createDirectories()
val projectDirPath = projectDir.systemIndependentPath
LocalFileSystem.getInstance().refreshAndFindFileByPath(projectDirPath)
createModule(projectDirPath, project)
@@ -7,6 +7,7 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.TemporaryDirectory
import com.intellij.testFramework.runInEdtAndWait
@@ -65,7 +66,7 @@ internal class TestManager(private val projectRule: ProjectRule, private val tem
runInEdtAndWait {
val normalizedFilePath = FileUtilRt.toSystemIndependentName(filePath!!)
if (annotation!!.relativeToProject) {
val root = projectRule.project.baseDir
val root = PlatformTestUtil.getOrCreateProjectTestBaseDir(projectRule.project)
runWriteAction {
fileToDelete = root.findOrCreateChildData(this@TestManager, normalizedFilePath)
}
@@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectEx
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.project.impl.ProjectImpl
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl
import com.intellij.openapi.vfs.ReadonlyStatusHandler
@@ -25,15 +24,12 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.intellij.lang.annotations.Language
import org.junit.Assume.assumeTrue
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import java.io.ByteArrayOutputStream
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.attribute.PosixFilePermission
import java.util.concurrent.TimeUnit
internal class ProjectStoreTest {
@@ -73,7 +69,7 @@ internal class ProjectStoreTest {
fun directoryBasedStorage() = runBlocking {
loadAndUseProjectInLoadComponentStateMode(tempDirManager, {
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/misc.xml", iprFileContent)
it.path
Paths.get(it.path)
}) { project ->
val testComponent = test(project as ProjectEx)
@@ -100,7 +96,7 @@ internal class ProjectStoreTest {
@Test
fun fileBasedStorage() = runBlocking {
loadAndUseProjectInLoadComponentStateMode(tempDirManager, {
it.writeChild("test${ProjectFileType.DOT_DEFAULT_EXTENSION}", iprFileContent).path
Paths.get(it.writeChild("test${ProjectFileType.DOT_DEFAULT_EXTENSION}", iprFileContent).path)
}) { project ->
test(project)
@@ -118,7 +114,7 @@ internal class ProjectStoreTest {
out.write(0xbf)
out.write(iprFileContent.toByteArray())
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/misc.xml", out.toByteArray())
it.path
Paths.get(it.path)
}) { project ->
val store = project.stateStore
assertThat(store.nameFile).doesNotExist()
@@ -153,7 +149,7 @@ internal class ProjectStoreTest {
loadAndUseProjectInLoadComponentStateMode(tempDirManager, {
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/misc.xml", iprFileContent)
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/.name", name)
it.path
Paths.get(it.path)
}) { project ->
val store = project.stateStore
assertThat(store.nameFile).hasContent(name)
@@ -187,7 +183,7 @@ internal class ProjectStoreTest {
<component name="ProjectLevelLoser" foo="old?" />
</project>""".trimIndent()
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/foo.xml", expected)
it.path
Paths.get(it.path)
}) { project ->
val obsoleteStorageBean = ObsoleteStorageBean()
val storageFileName = "foo.xml"
@@ -227,7 +223,7 @@ internal class ProjectStoreTest {
withTimeout(TimeUnit.SECONDS.toMillis(10)) {
loadAndUseProjectInLoadComponentStateMode(tempDirManager, {
it.writeChild("${Project.DIRECTORY_STORE_FOLDER}/misc.xml", iprFileContent)
it.path
Paths.get(it.path)
}) { project ->
val testComponent = test(project as ProjectEx)
testComponent.state!!.AAvalue = "s"
@@ -91,7 +91,7 @@ class ModuleAttachProcessor : ProjectAttachProcessor() {
override fun attachToProject(project: Project, projectDir: Path, callback: ProjectOpenedCallback?): Boolean {
val dotIdeaDir = projectDir.resolve(Project.DIRECTORY_STORE_FOLDER)
if (!dotIdeaDir.exists()) {
val newProject = ProjectManagerEx.getInstanceEx().newProject(projectDir, true, false) ?: return false
val newProject = ProjectManagerEx.getInstanceEx().newProject(projectDir, true) ?: return false
PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(projectDir, newProject)
StoreUtil.saveSettings(newProject)
runWriteAction { Disposer.dispose(newProject) }
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2013 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.macro;
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -25,6 +11,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
import gnu.trove.THashMap;
@@ -43,7 +30,7 @@ public class MacroManagerTest extends CodeInsightFixtureTestCase {
Map<String, Object> dataId2data = new THashMap<>();
dataId2data.put(CommonDataKeys.PROJECT.getName(), project);
dataId2data.put(CommonDataKeys.VIRTUAL_FILE.getName(), file);
dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), project.getBaseDir());
dataId2data.put(PlatformDataKeys.PROJECT_FILE_DIRECTORY.getName(), PlatformTestUtil.getOrCreateProjectTestBaseDir(project));
return SimpleDataContext.getSimpleContext(dataId2data, null);
}
@@ -201,16 +201,21 @@ public class VfsUtil extends VfsUtilCore {
}
@Nullable
public static VirtualFile findFile(@NotNull Path path, boolean refreshIfNeeded) {
return findFileByIoFile(path.toFile(), refreshIfNeeded);
public static VirtualFile findFile(@NotNull Path file, boolean refreshIfNeeded) {
return findFile(FileUtil.toSystemIndependentName(file.toAbsolutePath().toString()), refreshIfNeeded);
}
@Nullable
public static VirtualFile findFileByIoFile(@NotNull File file, boolean refreshIfNeeded) {
return findFile(FileUtil.toSystemIndependentName(file.getAbsolutePath()), refreshIfNeeded);
}
@Nullable
private static VirtualFile findFile(@NotNull String filePath, boolean refreshIfNeeded) {
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile virtualFile = fileSystem.findFileByIoFile(file);
VirtualFile virtualFile = fileSystem.findFileByPath(filePath);
if (refreshIfNeeded && (virtualFile == null || !virtualFile.isValid())) {
virtualFile = fileSystem.refreshAndFindFileByIoFile(file);
virtualFile = fileSystem.refreshAndFindFileByPath(filePath);
}
return virtualFile;
}
@@ -490,12 +490,13 @@ public class RecentProjectsManagerBase extends RecentProjectsManager implements
@Nullable
public Project doOpenProject(@NotNull @SystemIndependent String projectPath, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
Project existing = ProjectUtil.findAndFocusExistingProjectForPath(projectPath);
Path projectFile = Paths.get(projectPath);
Project existing = ProjectUtil.findAndFocusExistingProjectForPath(projectFile);
if (existing != null) {
return existing;
}
Path projectFile = Paths.get(projectPath);
if (Files.isDirectory(projectFile.resolve(Project.DIRECTORY_STORE_FOLDER))) {
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.of(PlatformProjectOpenProcessor.Option.REOPEN);
if (forceOpenInNewFrame) {
@@ -34,7 +34,10 @@ import com.intellij.ui.AppIcon;
import com.intellij.util.PathUtil;
import com.intellij.util.PlatformUtils;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.*;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
import javax.swing.*;
import java.awt.*;
@@ -87,7 +90,7 @@ public class ProjectUtil {
}
public static Project openOrImport(@NotNull Path path, Project projectToClose, boolean forceOpenInNewFrame) {
return openOrImport(FileUtil.toSystemIndependentName(path.toString()), projectToClose, forceOpenInNewFrame);
return openOrImport(path, new OpenProjectTask(forceOpenInNewFrame, projectToClose));
}
/**
@@ -99,24 +102,19 @@ public class ProjectUtil {
* null otherwise
*/
@Nullable
public static Project openOrImport(@NotNull @SystemIndependent String path, Project projectToClose, boolean forceOpenInNewFrame) {
return openOrImport(path, new OpenProjectTask(forceOpenInNewFrame, projectToClose));
public static Project openOrImport(@NotNull String path, Project projectToClose, boolean forceOpenInNewFrame) {
return openOrImport(Paths.get(path), new OpenProjectTask(forceOpenInNewFrame, projectToClose));
}
@Nullable
public static Project openOrImport(@NotNull Path path, @NotNull OpenProjectTask options) {
return openOrImport(FileUtil.toSystemIndependentName(path.toString()), options);
}
@Nullable
public static Project openOrImport(@NotNull @SystemIndependent String path, @NotNull OpenProjectTask options) {
Project existing = findAndFocusExistingProjectForPath(path);
public static Project openOrImport(@NotNull Path file, @NotNull OpenProjectTask options) {
Project existing = findAndFocusExistingProjectForPath(file);
if (existing != null) {
return existing;
}
NullableLazyValue<VirtualFile> lazyVirtualFile = NullableLazyValue.createValue(() -> {
VirtualFile result = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
VirtualFile result = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(file.toString()));
if (result != null) {
result.refresh(false, false);
}
@@ -136,7 +134,6 @@ public class ProjectUtil {
}
}
Path file = Paths.get(path);
if (isValidProjectPath(file)) {
return doOpenProject(file, options.getProjectToClose(), options.getForceOpenInNewFrame());
}
@@ -196,7 +193,7 @@ public class ProjectUtil {
}
}
Project existing = findAndFocusExistingProjectForPath(path);
Project existing = findAndFocusExistingProjectForPath(file);
if (existing != null) {
return existing;
}
@@ -284,10 +281,15 @@ public class ProjectUtil {
}
@Nullable
public static Project findAndFocusExistingProjectForPath(@NotNull String path) {
public static Project findAndFocusExistingProjectForPath(@NotNull Path file) {
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
if (openProjects.length == 0) {
return null;
}
String path= FileUtil.toSystemIndependentName(file.toString());
for (Project project : openProjects) {
if (!project.isDefault() && isSameProject(path, project)) {
if (isSameProject(path, project)) {
focusProjectWindow(project, false);
return project;
}
@@ -5,7 +5,6 @@ import com.intellij.configurationStore.StoreReloadManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -27,19 +26,13 @@ public abstract class ProjectManagerEx extends ProjectManager {
public abstract Project newProject(@Nullable String projectName, @NotNull String filePath, boolean useDefaultProjectSettings, boolean isDummy);
@Nullable
public abstract Project newProject(@NotNull Path filePath, boolean useDefaultProjectSettings, boolean isDummy);
@TestOnly
@NotNull
public final Project newProject(@Nullable String projectName, @NotNull String filePath) {
return ObjectUtils.assertNotNull(newProject(projectName, filePath, false, false));
}
public abstract Project newProject(@NotNull Path file, boolean useDefaultProjectSettings);
@Nullable
public abstract Project loadProject(@NotNull String filePath) throws IOException;
@Nullable
public abstract Project loadProject(@NotNull String filePath, @Nullable String projectName) throws IOException;
public abstract Project loadProject(@NotNull Path file, @Nullable String projectName) throws IOException;
public abstract boolean openProject(@NotNull Project project);
@@ -169,13 +169,18 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
private final Map<Project, String> myProjects = new WeakHashMap<>();
@Override
public Project newProject(@NotNull Path filePath, boolean useDefaultProjectSettings, boolean isDummy) {
return newProject(filePath.getFileName().toString(), FileUtil.toSystemIndependentName(filePath.toString()), useDefaultProjectSettings, isDummy);
public Project newProject(@NotNull Path file, boolean useDefaultProjectSettings) {
return newProject(file, null, useDefaultProjectSettings, true);
}
@Override
@Nullable
public Project newProject(@Nullable String projectName, @NotNull String filePath, boolean useDefaultProjectSettings, boolean isDummy) {
return newProject(Paths.get(toCanonicalName(filePath)), projectName, useDefaultProjectSettings, true);
}
@Nullable
public Project newProject(@NotNull Path projectFile, @Nullable String projectName, boolean useDefaultProjectSettings, boolean isRefreshVfsNeeded) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
//noinspection AssignmentToStaticFieldFromInstanceMethod
TEST_PROJECTS_CREATED++;
@@ -183,7 +188,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
checkProjectLeaksInTests();
}
Path projectFile = Paths.get(toCanonicalName(filePath));
if (Files.isRegularFile(projectFile)) {
try {
FileUtil.delete(projectFile);
@@ -203,7 +207,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
ProjectImpl project = doCreateProject(projectName, projectFile);
try {
initProject(projectFile, project, useDefaultProjectSettings ? getDefaultProject() : null, ProgressManager.getInstance().getProgressIndicator());
initProject(projectFile, project, isRefreshVfsNeeded, useDefaultProjectSettings ? getDefaultProject() : null, ProgressManager.getInstance().getProgressIndicator());
if (LOG_PROJECT_LEAKAGE_IN_TESTS) {
myProjects.put(project, null);
}
@@ -280,7 +284,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
return (int)myProjects.keySet().stream().filter(project -> project.isDisposed() && !((ProjectImpl)project).isTemporarilyDisposed()).count();
}
private static void initProject(@NotNull Path file, @NotNull ProjectImpl project, @Nullable Project template, @Nullable ProgressIndicator indicator) {
private static void initProject(@NotNull Path file, @NotNull ProjectImpl project, boolean isRefreshVfsNeeded, @Nullable Project template, @Nullable ProgressIndicator indicator) {
LOG.assertTrue(!project.isDefault());
if (indicator != null) {
indicator.setIndeterminate(false);
@@ -295,7 +299,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
boolean succeed = false;
try {
project.registerComponents();
project.getStateStore().setPath(file, true, template);
project.getStateStore().setPath(file, isRefreshVfsNeeded, template);
project.init(indicator);
succeed = true;
}
@@ -317,16 +321,15 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
@Override
@Nullable
public Project loadProject(@NotNull String filePath) throws IOException {
return loadProject(filePath, null);
return loadProject(Paths.get(filePath).toAbsolutePath(), null);
}
@Override
@Nullable
public Project loadProject(@NotNull String filePath, @Nullable String projectName) throws IOException {
public Project loadProject(@NotNull Path file, @Nullable String projectName) throws IOException {
try {
Path file = Paths.get(filePath).toAbsolutePath();
ProjectImpl project = doCreateProject(projectName, file);
initProject(file, project, null, ProgressManager.getInstance().getProgressIndicator());
initProject(file, project, /* isRefreshVfsNeeded = */ true, null, ProgressManager.getInstance().getProgressIndicator());
return project;
}
catch (Throwable t) {
@@ -551,7 +554,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
initProject(file, project, null, indicator);
initProject(file, project, /* isRefreshVfsNeeded = */ true, null, indicator);
}
catch (ProcessCanceledException e) {
return;
@@ -605,12 +608,12 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
ProjectImpl project = doCreateProject(null, path);
try {
if (!ApplicationManager.getApplication().isDispatchThread() && ProgressManager.getInstance().getProgressIndicator() != null) {
initProject(path, project, null, ProgressManager.getInstance().getProgressIndicator());
initProject(path, project, /* isRefreshVfsNeeded = */ true, null, ProgressManager.getInstance().getProgressIndicator());
}
else {
//noinspection CodeBlock2Expr
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
initProject(path, project, null, ProgressManager.getInstance().getProgressIndicator());
initProject(path, project, /* isRefreshVfsNeeded = */ true, null, ProgressManager.getInstance().getProgressIndicator());
}, ProjectBundle.message("project.load.progress"), canCancelProjectLoading(), project);
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.formatting;
import com.intellij.openapi.application.WriteAction;
@@ -6,15 +6,15 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public abstract class FileSetTestCase extends PlatformTestCase {
protected VirtualFile createFile(@NotNull String path) {
String[] dirNames = path.split("/");
VirtualFile baseDir = getProject().getBaseDir();
VirtualFile baseDir = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject());
for (int i = 0; i < dirNames.length - 1; i++) {
VirtualFile existing = VfsUtilCore.findRelativeFile(dirNames[i], baseDir);
if (existing == null) {
@@ -52,7 +52,7 @@ public class OverwriteProjectConfigurationTest extends PlatformTestCase {
}
private Project createProject() {
Project project = ProjectManagerEx.getInstanceEx().newProject("test", myProjectDir.getAbsolutePath());
Project project = ProjectManagerEx.getInstanceEx().newProject(myProjectDir.toPath(), false);
assertNotNull(project);
disposeOnTearDown(project);
return project;
@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.WritingAccessProvider;
import com.intellij.testFramework.EditorTestUtil;
@@ -136,7 +137,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
String moduleName;
ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
try {
VirtualFile moduleDir = getProject().getBaseDir().createChildDirectory(this, "moduleWithoutContentRoot");
VirtualFile moduleDir = VfsUtil.createDirectoryIfMissing(getProject().getBasePath() + "/moduleWithoutContentRoot");
moduleName = moduleModel.newModule(moduleDir.getPath() + "/moduleWithoutContentRoot.iml", EmptyModuleType.EMPTY_MODULE).getName();
moduleModel.commit();
}
@@ -60,6 +60,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
@@ -778,7 +779,7 @@ public class FileEncodingTest extends PlatformTestCase implements TestDialog {
File temp = createTempDirectory();
VirtualFile tempDir = ObjectUtils.assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp));
final Project newProject = ProjectManagerEx.getInstanceEx().newProject("new", tempDir.getPath());
Project newProject = ProjectManagerEx.getInstanceEx().newProject(Paths.get(tempDir.getPath()), false);
Disposer.register(getTestRootDisposable(), () -> ApplicationManager.getApplication().runWriteAction(() -> Disposer.dispose(newProject)));
PlatformTestUtil.saveProject(newProject);
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2018 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi;
import com.intellij.openapi.application.WriteAction;
@@ -20,6 +6,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.PsiModificationTrackerImpl;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import java.io.IOException;
@@ -51,8 +38,8 @@ public class PsiModificationTrackerTreeChangesUpdatesTest extends PlatformTestCa
public void testMoveFile() throws IOException {
WriteAction.runAndWait(() -> {
final VirtualFile dir1 = getProject().getBaseDir().createChildDirectory(this, "dir1");
final VirtualFile dir2 = getProject().getBaseDir().createChildDirectory(this, "dir2");
final VirtualFile dir1 = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).createChildDirectory(this, "dir1");
final VirtualFile dir2 = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).createChildDirectory(this, "dir2");
VirtualFile child = dir1.createChildData(this, "child");
long outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
@@ -67,8 +54,8 @@ public class PsiModificationTrackerTreeChangesUpdatesTest extends PlatformTestCa
public void testMoveDir() throws IOException {
WriteAction.runAndWait(() -> {
final VirtualFile dir1 = getProject().getBaseDir().createChildDirectory(this, "dir1");
final VirtualFile dir2 = getProject().getBaseDir().createChildDirectory(this, "dir2");
final VirtualFile dir1 = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).createChildDirectory(this, "dir1");
final VirtualFile dir2 = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).createChildDirectory(this, "dir2");
VirtualFile child = dir1.createChildDirectory(this, "child");
long outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
@@ -36,6 +36,7 @@ import org.junit.runners.model.Statement
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.nio.file.Files
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicBoolean
private var sharedModule: Module? = null
@@ -231,8 +232,8 @@ inline fun <T> Project.runInLoadComponentStateMode(task: () -> T): T {
}
}
fun createHeavyProject(path: String, useDefaultProjectSettings: Boolean = false): Project {
return ProjectManagerEx.getInstanceEx().newProject(null, path, useDefaultProjectSettings, false)!!
fun createHeavyProject(path: Path, useDefaultProjectSettings: Boolean = false): Project {
return ProjectManagerEx.getInstanceEx().newProject(path, useDefaultProjectSettings)!!
}
suspend fun Project.use(task: suspend (Project) -> Unit) {
@@ -296,7 +297,7 @@ suspend fun createProjectAndUseInLoadComponentStateMode(tempDirManager: Temporar
createOrLoadProject(tempDirManager, task = task, directoryBased = directoryBased, loadComponentState = true)
}
suspend fun loadAndUseProjectInLoadComponentStateMode(tempDirManager: TemporaryDirectory, projectCreator: (suspend (VirtualFile) -> String)? = null, task: suspend (Project) -> Unit) {
suspend fun loadAndUseProjectInLoadComponentStateMode(tempDirManager: TemporaryDirectory, projectCreator: (suspend (VirtualFile) -> Path)? = null, task: suspend (Project) -> Unit) {
createOrLoadProject(tempDirManager, projectCreator, task = task, directoryBased = false, loadComponentState = true)
}
@@ -315,14 +316,14 @@ suspend fun <T> runNonUndoableWriteAction(file: VirtualFile, runnable: suspend (
}
suspend fun createOrLoadProject(tempDirManager: TemporaryDirectory,
projectCreator: (suspend (VirtualFile) -> String)? = null,
projectCreator: (suspend (VirtualFile) -> Path)? = null,
directoryBased: Boolean = true,
loadComponentState: Boolean = false,
useDefaultProjectSettings: Boolean = true,
task: suspend (Project) -> Unit) {
withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) {
val filePath = if (projectCreator == null) {
tempDirManager.newPath("test${if (directoryBased) "" else ProjectFileType.DOT_DEFAULT_EXTENSION}", refreshVfs = true).systemIndependentPath
val file = if (projectCreator == null) {
tempDirManager.newPath("test${if (directoryBased) "" else ProjectFileType.DOT_DEFAULT_EXTENSION}", refreshVfs = true)
}
else {
val dir = tempDirManager.newVirtualDirectory()
@@ -332,8 +333,8 @@ suspend fun createOrLoadProject(tempDirManager: TemporaryDirectory,
}
val project = when (projectCreator) {
null -> createHeavyProject(filePath, useDefaultProjectSettings = useDefaultProjectSettings)
else -> ProjectManagerEx.getInstanceEx().loadProject(filePath)!!
null -> createHeavyProject(file, useDefaultProjectSettings = useDefaultProjectSettings)
else -> ProjectManagerEx.getInstanceEx().loadProject(file, null)!!
}
if (loadComponentState) {
@@ -222,9 +222,10 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
ApplicationManager.getApplication().runWriteAction(LightPlatformTestCase::cleanPersistedVFSContent);
Path tempFile = TemporaryDirectory.generateTemporaryPath(ProjectImpl.LIGHT_PROJECT_NAME + ProjectFileType.DOT_DEFAULT_EXTENSION);
ourProject = PlatformTestCase.createProject(tempFile);
ourPathToKeep = tempFile;
Path tempDirectory = TemporaryDirectory.generateTemporaryPath(ProjectImpl.LIGHT_PROJECT_NAME + ProjectFileType.DOT_DEFAULT_EXTENSION);
PlatformTestCase.synchronizeTempDirVfs(tempDirectory);
ourProject = PlatformTestCase.createProject(tempDirectory);
ourPathToKeep = tempDirectory;
ourPsiManager = null;
try {
@@ -31,8 +31,10 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.project.impl.ProjectImpl;
import com.intellij.openapi.project.impl.ProjectManagerImpl;
import com.intellij.openapi.project.impl.TooManyProjectLeakedException;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
@@ -152,6 +154,14 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
tempDir.refresh(false, true);
}
public static void synchronizeTempDirVfs(@NotNull Path tempDir) {
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(tempDir.toString()));
// null is ok, because Path can be only generated, but not created
if (virtualFile != null) {
synchronizeTempDirVfs(Objects.requireNonNull(virtualFile));
}
}
protected void initApplication() throws Exception {
boolean firstTime = ourApplication == null;
ourApplication = IdeaTestApplication.getInstance(null);
@@ -277,15 +287,12 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
return createProject(projectFile);
}
@NotNull
public static Project createProject(@NotNull File projectFile) {
return createProject(projectFile.toPath());
}
@NotNull
public static Project createProject(@NotNull Path file) {
try {
return Objects.requireNonNull(ProjectManagerEx.getInstanceEx().newProject(file, /* useDefaultProjectSettings = */ false, false));
ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance();
// in tests it is caller responsibility to refresh VFS (because often not only the project file must be refreshed, but the whole dir - so, no need to refresh several times)
return Objects.requireNonNull(projectManager.newProject(file, null, /* useDefaultProjectSettings = */ false, /* isRefreshVfsNeeded = */ false));
}
catch (TooManyProjectLeakedException e) {
if (ourReportedLeakedProjects) {
@@ -41,10 +41,7 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.ex.temp.TempFileSystem;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
@@ -979,4 +976,26 @@ public class PlatformTestUtil {
" * Created by ${USER} on ${DATE}.\n" +
" */\n", parentDisposable);
}
/**
* 1. Think twice before use - do you really need to use VFS.
* 2. Think again.
* 3. Be aware that this method doesn't refresh VFS as it should be done in tests (see {@link PlatformTestCase#synchronizeTempDirVfs}) (it is assumed that project is already created in a correct way).
*/
@NotNull
public static VirtualFile getOrCreateProjectTestBaseDir(@NotNull Project project) {
try {
String path = Objects.requireNonNull(project.getBasePath());
VirtualFile result = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (result != null) {
return result;
}
// createDirectories executes in write action
return Objects.requireNonNull(VfsUtil.createDirectories(Objects.requireNonNull(project.getBasePath())));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -21,9 +21,7 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingManager;
@@ -45,6 +43,7 @@ import org.junit.Assert;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
@@ -55,7 +54,7 @@ import java.util.stream.Stream;
* @author mike
*/
@SuppressWarnings("TestOnlyProblems")
class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixture {
final class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixture {
private Project myProject;
private final Set<Path> myFilesToDelete = new HashSet<>();
private IdeaTestApplication myApplication;
@@ -126,6 +125,9 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
catch (NoSuchFileException ignore) {
errors = Collections.emptyList();
}
CompoundRuntimeException.throwIfNotEmpty(errors);
});
}
@@ -152,9 +154,9 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
.run();
}
private void setUpProject() throws IOException {
Path tempDirectory = FileUtil.createTempDirectory(myName, "").toPath();
PlatformTestCase.synchronizeTempDirVfs(Objects.requireNonNull(LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(tempDirectory.toString()))));
private void setUpProject() {
Path tempDirectory = TemporaryDirectory.generateTemporaryPath(myName);
PlatformTestCase.synchronizeTempDirVfs(tempDirectory);
myFilesToDelete.add(tempDirectory);
myProject = PlatformTestCase.createProject(generateProjectPath(tempDirectory));
@@ -1,18 +1,4 @@
/*
* 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.
* 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs;
import com.intellij.openapi.util.Pair;
@@ -26,6 +12,7 @@ import com.intellij.openapi.vcs.impl.projectlevelman.AllVcses;
import com.intellij.openapi.vcs.impl.projectlevelman.AllVcsesI;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.VfsTestUtil;
import com.intellij.testFramework.vcs.MockChangeListManager;
import com.intellij.testFramework.vcs.MockContentRevision;
@@ -44,7 +31,7 @@ public class LocalChangesUnderRootsTest extends PlatformTestCase {
super.setUp();
myChangeListManager = new MockChangeListManager();
myBaseDir = myProject.getBaseDir();
myBaseDir = PlatformTestUtil.getOrCreateProjectTestBaseDir(myProject);
myLocalChangesUnderRoots = new LocalChangesUnderRoots(myChangeListManager, ProjectLevelVcsManager.getInstance(myProject));
}
@@ -61,7 +48,7 @@ public class LocalChangesUnderRootsTest extends PlatformTestCase {
Change changeAfterCommunity = createChangeForPath("readme.txt");
Change changeInCommunity = createChangeForPath("community/com.txt");
myChangeListManager.addChanges(changeBeforeCommunity, changeAfterCommunity, changeInCommunity);
Map<VirtualFile, Collection<Change>> expected = new HashMap<>();
expected.put(roots.get(0), Arrays.asList(changeBeforeCommunity, changeAfterCommunity));
expected.put(roots.get(1), Collections.singletonList(changeInCommunity));
@@ -95,7 +82,7 @@ public class LocalChangesUnderRootsTest extends PlatformTestCase {
for (Pair<String, String> pathAndVc : pathAndVcs) {
String path = pathAndVc.first;
String vcs = pathAndVc.second;
VirtualFile vf;
if (path.equals(myBaseDir.getPath())) {
vf = myBaseDir;
@@ -117,5 +104,5 @@ public class LocalChangesUnderRootsTest extends PlatformTestCase {
ContentRevision afterRevision = new MockContentRevision(filePath, new VcsRevisionNumber.Int(2));
return new Change(beforeRevision, afterRevision);
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.changes.committed;
import com.intellij.openapi.application.ApplicationManager;
@@ -12,6 +12,7 @@ import com.intellij.openapi.vcs.changes.VcsModifiableDirtyScope;
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.vcs.FileBasedTest;
import com.intellij.util.Consumer;
import com.intellij.util.ui.UIUtil;
@@ -126,7 +127,7 @@ public class VcsDirtyScopeTest extends FileBasedTest {
private Data createData() throws IOException {
final Data data = new Data();
data.baseDir = myProjectFixture.getProject().getBaseDir();
data.baseDir = PlatformTestUtil.getOrCreateProjectTestBaseDir(myProjectFixture.getProject());
final IOException[] exc = new IOException[1];
final File ioFile = new File(data.baseDir.getPath());
final File[] files = ioFile.listFiles();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit;
import com.intellij.execution.RunManager;
@@ -29,7 +15,6 @@ import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
* @author Dmitry Avdeev
*/
public class PluginProjectWizardTest extends NewProjectWizardTestCase {
public void testPluginProject() throws Exception {
createSdk("devkit", IdeaJdk.getInstance());
Project project = createProjectFromTemplate(PluginModuleType.getInstance().getName(), null, null);
@@ -1,18 +1,4 @@
/*
* 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.
* 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.testAssistant;
import com.intellij.openapi.application.ApplicationManager;
@@ -42,12 +28,8 @@ public class TestDataGuessByExistingFilesUtilTest extends TestDataPathTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
VirtualFile resourcesDir = ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<VirtualFile, IOException>() {
@Override
public VirtualFile compute() throws IOException {
return myContentRoot.createChildDirectory(TestDataGuessByExistingFilesUtilTest.this, RESOURCES_ROOT_NAME);
}
});
VirtualFile resourcesDir = ApplicationManager.getApplication().runWriteAction((ThrowableComputable<VirtualFile, IOException>)() -> myContentRoot.createChildDirectory(this, RESOURCES_ROOT_NAME));
PsiTestUtil.addSourceRoot(myFixture.getModule(), resourcesDir, JavaResourceRootType.RESOURCE);
}
@@ -1,8 +1,8 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.testAssistant;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
@@ -17,12 +17,12 @@ abstract public class TestDataPathTestCase extends JavaCodeInsightFixtureTestCas
@Override
public void setUp() throws Exception {
super.setUp();
myContentRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(myFixture.getTempDirPath());
myContentRoot = VfsUtil.createDirectoryIfMissing(myFixture.getTempDirPath());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
myProjectSubdir = myFixture.getProject().getBaseDir().createChildDirectory(this, "projectSubdir");
myProjectSubdir = VfsUtil.createDirectoryIfMissing(myFixture.getProject().getBasePath() + "/projectSubdir");
myContentRootSubdir = myContentRoot.createChildDirectory(this, "contentRootSubdir");
}
catch (IOException e) {
@@ -50,8 +50,7 @@ public abstract class GradleCompilingTestCase extends GradleImportingTestCase {
}
private static String getArtifactBaseOutputPath(Project project) {
String outputUrl = project.getBaseDir().getUrl() + "/out/artifacts";
return FileUtil.toSystemIndependentName(VfsUtilCore.urlToPath(outputUrl));
return project.getBasePath() + "/out/artifacts";
}
private static String getArtifactBaseOutputPath(Module module) {
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.service.task
import com.intellij.openapi.application.runWriteAction
@@ -7,6 +7,7 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotifica
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.UsefulTestCase
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@@ -20,7 +21,6 @@ import org.junit.Before
import org.junit.Test
class GradleTaskManagerTest: UsefulTestCase() {
private lateinit var myTestFixture: IdeaProjectTestFixture
private lateinit var myProject: Project
private lateinit var tm: GradleTaskManager
@@ -68,7 +68,8 @@ class GradleTaskManagerTest: UsefulTestCase() {
@Test
fun `test task manager uses wrapper task when wrapper already exists`() {
runWriteAction {
val wrapperProps = myProject.baseDir
val baseDir = PlatformTestUtil.getOrCreateProjectTestBaseDir(myProject)
val wrapperProps = baseDir
.createChildDirectory(this, "gradle")
.createChildDirectory(this, "wrapper")
.createChildData(this, "gradle-wrapper.properties")
@@ -106,8 +107,7 @@ class GradleTaskManagerTest: UsefulTestCase() {
private fun writeBuildScript(scriptText: String) {
runWriteAction {
VfsUtil.saveText(myProject.baseDir.createChildData(this, "build.gradle"),
scriptText)
VfsUtil.saveText(PlatformTestUtil.getOrCreateProjectTestBaseDir(myProject).createChildData(this, "build.gradle"), scriptText)
}
}
}
@@ -11,6 +11,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.spellchecker.SpellCheckerManager;
import com.intellij.spellchecker.inspection.SpellcheckerInspectionTestCase;
import com.intellij.spellchecker.settings.SpellCheckerSettings;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NotNull;
@@ -38,7 +39,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
List<String> oldPaths = settings.getCustomDictionariesPaths();
WriteAction.runAndWait(() -> {
dictDir = getProject().getBaseDir().createChildDirectory(this, getDictDirName());
dictDir = VfsUtil.createDirectoryIfMissing(getProject().getBasePath() + "/" + getDictDirName());
VfsUtil.copyDirectory(this, myFixture.copyDirectoryToProject(getTestName(true), getDictDirName()), dictDir, null);
});
@@ -190,12 +191,12 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
public void testMoveDict() throws IOException {
try {
doBeforeCheck();
WriteAction.run(() -> getTestDictionaryFile().move(this, getProject().getBaseDir()));
WriteAction.run(() -> getTestDictionaryFile().move(this, PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject())));
doAfterCheck();
}
finally {
WriteAction.run(() -> {
final VirtualFile child = getProject().getBaseDir().findChild(TEST_DIC);
final VirtualFile child = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).findChild(TEST_DIC);
if (child.exists()) {
child.delete(this);
}
@@ -237,12 +238,12 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase {
public void testMoveDictDir() throws IOException {
try {
doBeforeCheck();
WriteAction.run(() -> dictDir.move(this, getProject().getBaseDir().createChildDirectory(this, "new_dir")));
WriteAction.run(() -> dictDir.move(this, PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).createChildDirectory(this, "new_dir")));
doAfterCheck();
}
finally {
WriteAction.run(() -> {
final VirtualFile dir = getProject().getBaseDir().findChild("new_dir");
final VirtualFile dir = PlatformTestUtil.getOrCreateProjectTestBaseDir(getProject()).findChild("new_dir");
if (dir.exists()) {
dir.delete(this);
}