From 57eb7d80b31928cf6a4962536c536ae016368a2a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 5 Jul 2019 16:41:06 +0200 Subject: [PATCH] use Path instead of VFS to open/import/create project GitOrigin-RevId: aa9e1585ab96f3dbc5e83ae62d5aa7b31ad93d64 --- .../codeInspection/InspectionApplication.java | 10 +- .../intellij/conversion/XmlBasedSettings.java | 30 +++-- .../impl/ArtifactsSettingsImpl.java | 19 +--- .../impl/ComponentManagerSettingsImpl.java | 22 +--- .../impl/ConversionContextImpl.java | 79 +++++++------- .../conversion/impl/ConversionRunner.java | 73 ++++++------- .../conversion/impl/ModuleSettingsImpl.java | 35 ++---- .../conversion/impl/MultiFilesSettings.java | 28 ++--- .../impl/ProjectConversionUtil.java | 34 ++---- .../impl/ProjectLibrariesSettingsImpl.java | 19 +--- .../conversion/impl/ProjectSettingsImpl.java | 22 +--- .../impl/RunManagerSettingsImpl.java | 14 ++- .../conversion/impl/SettingsXmlFile.java | 30 ++--- .../impl/WorkspaceSettingsImpl.java | 21 +--- .../conversion/impl/XmlBasedSettingsImpl.java | 23 +--- .../impl/ui/ConvertProjectDialog.java | 39 +++---- .../ide/impl/convert/JDomConvertingUtil.java | 65 +++-------- .../impl/convert/ProjectFileVersionImpl.java | 7 +- .../projectWizard/AbstractNewProjectStep.java | 3 - .../projectWizard/ExistingModuleLoader.java | 10 +- .../platform/ModuleAttachProcessor.kt | 5 +- .../templates/TemplateModuleBuilder.java | 46 ++++---- .../projectImport/ProjectOpenProcessor.java | 3 +- .../conversion/ConversionListener.java | 23 +--- .../conversion/ConversionService.java | 13 +-- .../conversion/DummyConversionService.java | 13 +-- .../ide/RecentDirectoryProjectsManager.java | 16 +-- .../ide/RecentProjectsManagerBase.java | 12 +- .../com/intellij/ide/impl/ProjectUtil.java | 5 + .../com/intellij/idea/IdeaApplication.java | 31 +++--- .../openapi/project/ex/ProjectManagerEx.java | 7 +- .../project/impl/ProjectManagerImpl.java | 22 ++-- .../PlatformProjectOpenProcessor.java | 103 ++++++++++++------ .../platform/ProjectBaseDirectory.java | 59 ++++++---- .../conversion/ProjectConversionTestUtil.java | 21 +--- .../intellij/impl/ConversionResultImpl.java | 29 ++--- .../intellij/impl/ConversionServiceImpl.java | 35 +++--- .../checkout/ProjectDirCheckoutListener.java | 19 ++-- .../vcs/impl/BasicDefaultVcsRootPolicy.java | 26 ----- .../platform/PlatformVcsDetector.java | 35 ++++-- .../AppEngineFacetConverterTest.java | 27 +---- 41 files changed, 460 insertions(+), 673 deletions(-) delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/impl/BasicDefaultVcsRootPolicy.java diff --git a/platform/lang-impl/src/com/intellij/codeInspection/InspectionApplication.java b/platform/lang-impl/src/com/intellij/codeInspection/InspectionApplication.java index 4dab54b7c381..d22b8c9b00e9 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/InspectionApplication.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/InspectionApplication.java @@ -33,14 +33,12 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScopesCore; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; -import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtilRt; import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.SystemIndependent; import java.io.File; import java.io.IOException; @@ -116,7 +114,7 @@ public class InspectionApplication { Disposable disposable = Disposer.newDisposable(); try { - run(FileUtilRt.toSystemIndependentName(PathUtil.getCanonicalPath(myProjectPath)), disposable); + run(Paths.get(FileUtil.toCanonicalPath(myProjectPath)), disposable); } finally { Disposer.dispose(disposable); @@ -131,8 +129,8 @@ public class InspectionApplication { myHelpProvider.printHelpAndExit(); } - private void run(@NotNull @SystemIndependent String projectPath, @NotNull Disposable parentDisposable) throws IOException, JDOMException { - VirtualFile vfsProject = LocalFileSystem.getInstance().findFileByPath(projectPath); + private void run(@NotNull Path projectPath, @NotNull Disposable parentDisposable) throws IOException, JDOMException { + VirtualFile vfsProject = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(projectPath.toString())); if (vfsProject == null) { logError(InspectionsBundle.message("inspection.application.file.cannot.be.found", projectPath)); printHelp(); @@ -185,7 +183,7 @@ public class InspectionApplication { } PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(vfsDir); - scope = new AnalysisScope(psiDirectory); + scope = new AnalysisScope(Objects.requireNonNull(psiDirectory)); } logMessageLn(1, InspectionsBundle.message("inspection.done")); diff --git a/platform/lang-impl/src/com/intellij/conversion/XmlBasedSettings.java b/platform/lang-impl/src/com/intellij/conversion/XmlBasedSettings.java index 8e1b14138eaa..d7e95a3e0b3a 100644 --- a/platform/lang-impl/src/com/intellij/conversion/XmlBasedSettings.java +++ b/platform/lang-impl/src/com/intellij/conversion/XmlBasedSettings.java @@ -1,29 +1,25 @@ -/* - * Copyright 2000-2011 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.conversion; -import org.jdom.Document; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.nio.file.Path; public interface XmlBasedSettings { @NotNull Element getRootElement(); - File getFile(); + /** + * @deprecated Use {@link #getPath()} + */ + @Deprecated + default File getFile() { + throw new AbstractMethodError(); + } + + default Path getPath() { + return getFile().toPath(); + } } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ArtifactsSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ArtifactsSettingsImpl.java index 210bac80277b..a386bd9f2fde 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ArtifactsSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ArtifactsSettingsImpl.java @@ -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.conversion.impl; import com.intellij.conversion.ArtifactsSettings; @@ -22,13 +8,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; +import java.nio.file.Path; import java.util.Collection; /** * @author Eugene.Kudelevsky */ public class ArtifactsSettingsImpl extends MultiFilesSettings implements ArtifactsSettings { - protected ArtifactsSettingsImpl(@Nullable File projectFile, + protected ArtifactsSettingsImpl(@Nullable Path projectFile, @Nullable File[] settingsFiles, @NotNull ConversionContextImpl context) throws CannotConvertException { super(projectFile, settingsFiles, context); diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ComponentManagerSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ComponentManagerSettingsImpl.java index 65bc2637c8bf..66b1d1ed7f80 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ComponentManagerSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ComponentManagerSettingsImpl.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2009 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.conversion.impl; import com.intellij.conversion.CannotConvertException; @@ -22,14 +7,13 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.io.File; +import java.nio.file.Path; /** * @author nik */ public class ComponentManagerSettingsImpl extends XmlBasedSettingsImpl implements ComponentManagerSettings { - - protected ComponentManagerSettingsImpl(File file, ConversionContextImpl context) throws CannotConvertException { + protected ComponentManagerSettingsImpl(Path file, ConversionContextImpl context) throws CannotConvertException { super(file, context); } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java index 1d1d387b756d..7f5454312bbf 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionContextImpl.java @@ -37,6 +37,9 @@ import org.jetbrains.jps.model.serialization.PathMacroUtil; 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.*; /** @@ -44,19 +47,19 @@ import java.util.*; */ public class ConversionContextImpl implements ConversionContext { private static final Logger LOG = Logger.getInstance("#com.intellij.conversion.impl.ConversionContextImpl"); - private final Map mySettingsFiles = new HashMap<>(); + private final Map mySettingsFiles = new HashMap<>(); private final StorageScheme myStorageScheme; - private final File myProjectBaseDir; - private final File myProjectFile; - private final File myWorkspaceFile; + private final Path myProjectBaseDir; + private final Path myProjectFile; + private final Path myWorkspaceFile; private final File[] myModuleFiles; private ProjectSettingsImpl myProjectSettings; private WorkspaceSettingsImpl myWorkspaceSettings; - private final List myNonExistingModuleFiles = new ArrayList<>(); + private final List myNonExistingModuleFiles = new ArrayList<>(); private final Map myFile2ModuleSettings = new HashMap<>(); private final Map myName2ModuleSettings = new HashMap<>(); private RunManagerSettingsImpl myRunManagerSettings; - private File mySettingsBaseDir; + private Path mySettingsBaseDir; private ComponentManagerSettings myCompilerManagerSettings; private ComponentManagerSettings myProjectRootManagerSettings; private ComponentManagerSettingsImpl myModulesSettings; @@ -65,36 +68,36 @@ public class ConversionContextImpl implements ConversionContext { private ComponentManagerSettings myProjectFileVersionSettings; private final Set myPerformedConversionIds; - public ConversionContextImpl(String projectPath) throws CannotConvertException { - myProjectFile = new File(projectPath); + public ConversionContextImpl(@NotNull Path projectPath) throws CannotConvertException { + myProjectFile = projectPath; - File modulesFile; - if (myProjectFile.isDirectory()) { + Path modulesFile; + if (Files.isDirectory(myProjectFile)) { myStorageScheme = StorageScheme.DIRECTORY_BASED; myProjectBaseDir = myProjectFile; - mySettingsBaseDir = new File(myProjectBaseDir.getAbsolutePath(), Project.DIRECTORY_STORE_FOLDER); - modulesFile = new File(mySettingsBaseDir, "modules.xml"); - myWorkspaceFile = new File(mySettingsBaseDir, "workspace.xml"); + mySettingsBaseDir = myProjectBaseDir.toAbsolutePath().resolve(Project.DIRECTORY_STORE_FOLDER); + modulesFile = mySettingsBaseDir.resolve("modules.xml"); + myWorkspaceFile = mySettingsBaseDir.resolve("workspace.xml"); } else { myStorageScheme = StorageScheme.DEFAULT; - myProjectBaseDir = myProjectFile.getParentFile(); + myProjectBaseDir = myProjectFile.getParent(); modulesFile = myProjectFile; - myWorkspaceFile = new File(StringUtil.trimEnd(projectPath, ProjectFileType.DOT_DEFAULT_EXTENSION) + WorkspaceFileType.DOT_DEFAULT_EXTENSION); + myWorkspaceFile = Paths.get(StringUtil.trimEnd(projectPath.toString(), ProjectFileType.DOT_DEFAULT_EXTENSION) + WorkspaceFileType.DOT_DEFAULT_EXTENSION); } - myModuleFiles = modulesFile.exists() ? findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement()) : new File[0]; + myModuleFiles = Files.exists(modulesFile) ? findModuleFiles(JDomConvertingUtil.load(modulesFile)) : new File[0]; myPerformedConversionIds = loadPerformedConversionIds(); } public Set getAllProjectFiles() { - final HashSet files = new HashSet<>(Arrays.asList(myModuleFiles)); + Set files = new HashSet<>(Arrays.asList(myModuleFiles)); if (myStorageScheme == StorageScheme.DEFAULT) { - files.add(myProjectFile); - files.add(myWorkspaceFile); + files.add(myProjectFile.toFile()); + files.add(myWorkspaceFile.toFile()); } else { - addFilesRecursively(mySettingsBaseDir, files); + addFilesRecursively(mySettingsBaseDir.toFile(), files); } return files; } @@ -120,7 +123,7 @@ public class ConversionContextImpl implements ConversionContext { @Override @NotNull public File getProjectBaseDir() { - return myProjectBaseDir; + return myProjectBaseDir.toFile(); } @Override @@ -172,7 +175,7 @@ public class ConversionContextImpl implements ConversionContext { @Override @NotNull public String collapsePath(@NotNull String path) { - ReplacePathToMacroMap map = createCollapseMacroMap(PathMacroUtil.PROJECT_DIR_MACRO_NAME, myProjectBaseDir); + ReplacePathToMacroMap map = createCollapseMacroMap(PathMacroUtil.PROJECT_DIR_MACRO_NAME, myProjectBaseDir.toFile()); return map.substitute(path, SystemInfo.isFileSystemCaseSensitive); } @@ -262,13 +265,13 @@ public class ConversionContextImpl implements ConversionContext { @Nullable public ComponentManagerSettingsImpl createProjectSettings(@NotNull final String fileName) { try { - File file; + Path file; if (myStorageScheme == StorageScheme.DEFAULT) { file = myProjectFile; } else { - file = new File(mySettingsBaseDir, fileName); - if (!file.exists()) { + file = mySettingsBaseDir.resolve(fileName); + if (!Files.exists(file)) { return null; } } @@ -284,7 +287,7 @@ public class ConversionContextImpl implements ConversionContext { private static Element findGlobalLibraryElement(String name) throws CannotConvertException { final File file = PathManager.getOptionsFile("applicationLibraries"); if (file.exists()) { - final Element root = JDomConvertingUtil.loadDocument(file).getRootElement(); + final Element root = JDomConvertingUtil.load(file.toPath()); final Element libraryTable = JDomSerializationUtil.findComponent(root, "libraryTable"); if (libraryTable != null) { return findLibraryInTable(libraryTable, name); @@ -310,7 +313,7 @@ public class ConversionContextImpl implements ConversionContext { private ExpandMacroToPathMap createExpandMacroMap() { final ExpandMacroToPathMap macros = new ExpandMacroToPathMap(); - final String projectDir = FileUtil.toSystemIndependentName(myProjectBaseDir.getAbsolutePath()); + final String projectDir = FileUtil.toSystemIndependentName(myProjectBaseDir.toAbsolutePath().toString()); macros.addMacroExpand(PathMacroUtil.PROJECT_DIR_MACRO_NAME, projectDir); PathMacrosImpl.getInstanceEx().addMacroExpands(macros); return macros; @@ -318,13 +321,13 @@ public class ConversionContextImpl implements ConversionContext { @Override public File getSettingsBaseDir() { - return mySettingsBaseDir; + return mySettingsBaseDir.toFile(); } @NotNull @Override public File getProjectFile() { - return myProjectFile; + return myProjectFile.toFile(); } @Override @@ -342,7 +345,7 @@ public class ConversionContextImpl implements ConversionContext { myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, myProjectFile, null, this); } else { - final File[] files = new File(mySettingsBaseDir, "runConfigurations").listFiles(FileFilters.filesWithExtension("xml")); + File[] files = mySettingsBaseDir.resolve("runConfigurations").toFile().listFiles(FileFilters.filesWithExtension("xml")); myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, null, files, this); } } @@ -362,7 +365,7 @@ public class ConversionContextImpl implements ConversionContext { public ModuleSettings getModuleSettings(File moduleFile) throws CannotConvertException { ModuleSettingsImpl settings = myFile2ModuleSettings.get(moduleFile); if (settings == null) { - settings = new ModuleSettingsImpl(moduleFile, this); + settings = new ModuleSettingsImpl(moduleFile.toPath(), this); myFile2ModuleSettings.put(moduleFile, settings); myName2ModuleSettings.put(settings.getModuleName(), settings); } @@ -383,7 +386,7 @@ public class ConversionContextImpl implements ConversionContext { return myName2ModuleSettings.get(moduleName); } - public List getNonExistingModuleFiles() { + public List getNonExistingModuleFiles() { return myNonExistingModuleFiles; } @@ -393,11 +396,11 @@ public class ConversionContextImpl implements ConversionContext { return myStorageScheme; } - public File getWorkspaceFile() { + public Path getWorkspaceFile() { return myWorkspaceFile; } - public void saveFiles(Collection files, List usedRunners) throws IOException { + public void saveFiles(Collection files, List usedRunners) throws IOException { Set performedConversions = new HashSet<>(); for (ConversionRunner runner : usedRunners) { final ConverterProvider provider = runner.getProvider(); @@ -419,7 +422,7 @@ public class ConversionContextImpl implements ConversionContext { } } - for (File file : files) { + for (Path file : files) { final SettingsXmlFile xmlFile = mySettingsFiles.get(file); if (xmlFile != null) { xmlFile.save(); @@ -439,7 +442,7 @@ public class ConversionContextImpl implements ConversionContext { return Collections.emptySet(); } - public SettingsXmlFile getOrCreateFile(File file) throws CannotConvertException { + public SettingsXmlFile getOrCreateFile(Path file) throws CannotConvertException { SettingsXmlFile settingsFile = mySettingsFiles.get(file); if (settingsFile == null) { settingsFile = new SettingsXmlFile(file); @@ -470,7 +473,7 @@ public class ConversionContextImpl implements ConversionContext { @NotNull private File[] getSettingsXmlFiles(@NotNull String dirName) { - final File librariesDir = new File(mySettingsBaseDir, dirName); - return ObjectUtils.notNull(librariesDir.listFiles(FileFilters.filesWithExtension("xml")), ArrayUtilRt.EMPTY_FILE_ARRAY); + Path librariesDir = mySettingsBaseDir.resolve(dirName); + return ObjectUtils.notNull(librariesDir.toFile().listFiles(FileFilters.filesWithExtension("xml")), ArrayUtilRt.EMPTY_FILE_ARRAY); } } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionRunner.java b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionRunner.java index 19e08091aca6..7adb37a64b8b 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionRunner.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionRunner.java @@ -1,25 +1,14 @@ -/* - * Copyright 2000-2009 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.conversion.impl; import com.intellij.conversion.*; import com.intellij.openapi.components.StorageScheme; +import com.intellij.util.containers.ContainerUtil; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -36,7 +25,7 @@ public class ConversionRunner { private boolean myProcessRunConfigurations; private boolean myProcessProjectLibraries; private boolean myArtifacts; - private final List myModulesFilesToProcess = new ArrayList<>(); + private final List myModulesFilesToProcess = new ArrayList<>(); private final ProjectConverter myConverter; private final ConversionProcessor myRunConfigurationsConverter; private final ConversionProcessor myProjectLibrariesConverter; @@ -56,18 +45,18 @@ public class ConversionRunner { public boolean isConversionNeeded() throws CannotConvertException { if (myContext.isConversionAlreadyPerformed(myProvider)) return false; - + myProcessProjectFile = myContext.getStorageScheme() == StorageScheme.DEFAULT && myProjectFileConverter != null && myProjectFileConverter.isConversionNeeded(myContext.getProjectSettings()); - myProcessWorkspaceFile = myWorkspaceConverter != null && myContext.getWorkspaceFile().exists() + myProcessWorkspaceFile = myWorkspaceConverter != null && Files.exists(myContext.getWorkspaceFile()) && myWorkspaceConverter.isConversionNeeded(myContext.getWorkspaceSettings()); myModulesFilesToProcess.clear(); if (myModuleFileConverter != null) { for (File moduleFile : myContext.getModuleFiles()) { if (moduleFile.exists() && myModuleFileConverter.isConversionNeeded(myContext.getModuleSettings(moduleFile))) { - myModulesFilesToProcess.add(moduleFile); + myModulesFilesToProcess.add(moduleFile.toPath()); } } } @@ -89,18 +78,18 @@ public class ConversionRunner { myConverter.isConversionNeeded(); } - public boolean isModuleConversionNeeded(File moduleFile) throws CannotConvertException { - return myModuleFileConverter != null && myModuleFileConverter.isConversionNeeded(myContext.getModuleSettings(moduleFile)); + public boolean isModuleConversionNeeded(Path moduleFile) throws CannotConvertException { + return myModuleFileConverter != null && myModuleFileConverter.isConversionNeeded(myContext.getModuleSettings(moduleFile.toFile())); } - public Collection getCreatedFiles() { - return myConverter.getCreatedFiles(); + public Collection getCreatedFiles() { + return ContainerUtil.map(myConverter.getCreatedFiles(), file -> file.toPath()); } - public Set getAffectedFiles() { - Set affectedFiles = new HashSet<>(); + public Set getAffectedFiles() { + Set affectedFiles = new HashSet<>(); if (myProcessProjectFile) { - affectedFiles.add(myContext.getProjectFile()); + affectedFiles.add(myContext.getProjectFile().toPath()); } if (myProcessWorkspaceFile) { affectedFiles.add(myContext.getWorkspaceFile()); @@ -123,11 +112,13 @@ public class ConversionRunner { if (!myProvider.canDetermineIfConversionAlreadyPerformedByProjectFiles()) { final ComponentManagerSettings settings = myContext.getProjectFileVersionSettings(); if (settings != null) { - affectedFiles.add(settings.getFile()); + affectedFiles.add(settings.getPath()); } } - - affectedFiles.addAll(myConverter.getAdditionalAffectedFiles()); + + for (File file : myConverter.getAdditionalAffectedFiles()) { + affectedFiles.add(file.toPath()); + } return affectedFiles; } @@ -140,8 +131,8 @@ public class ConversionRunner { myWorkspaceConverter.preProcess(myContext.getWorkspaceSettings()); } - for (File moduleFile : myModulesFilesToProcess) { - myModuleFileConverter.preProcess(myContext.getModuleSettings(moduleFile)); + for (Path moduleFile : myModulesFilesToProcess) { + myModuleFileConverter.preProcess(myContext.getModuleSettings(moduleFile.toFile())); } if (myProcessRunConfigurations) { @@ -167,8 +158,8 @@ public class ConversionRunner { myWorkspaceConverter.process(myContext.getWorkspaceSettings()); } - for (File moduleFile : myModulesFilesToProcess) { - myModuleFileConverter.process(myContext.getModuleSettings(moduleFile)); + for (Path moduleFile : myModulesFilesToProcess) { + myModuleFileConverter.process(myContext.getModuleSettings(moduleFile.toFile())); } if (myProcessRunConfigurations) { @@ -194,8 +185,8 @@ public class ConversionRunner { myWorkspaceConverter.postProcess(myContext.getWorkspaceSettings()); } - for (File moduleFile : myModulesFilesToProcess) { - myModuleFileConverter.postProcess(myContext.getModuleSettings(moduleFile)); + for (Path moduleFile : myModulesFilesToProcess) { + myModuleFileConverter.postProcess(myContext.getModuleSettings(moduleFile.toFile())); } if (myProcessRunConfigurations) { @@ -216,18 +207,18 @@ public class ConversionRunner { return myProvider; } - public static List getReadOnlyFiles(final Collection affectedFiles) { - List result = new ArrayList<>(); - for (File file : affectedFiles) { - if (!file.canWrite()) { + public static List getReadOnlyFiles(final Collection affectedFiles) { + List result = new ArrayList<>(); + for (Path file : affectedFiles) { + if (!Files.isWritable(file)) { result.add(file); } } return result; } - public void convertModule(File moduleFile) throws CannotConvertException { - final ModuleSettings settings = myContext.getModuleSettings(moduleFile); + public void convertModule(Path moduleFile) throws CannotConvertException { + final ModuleSettings settings = myContext.getModuleSettings(moduleFile.toFile()); myModuleFileConverter.preProcess(settings); myModuleFileConverter.process(settings); myModuleFileConverter.postProcess(settings); diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java index b71db804bbac..6a2cfa081ec9 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ModuleSettingsImpl.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.conversion.impl; @@ -26,7 +12,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -36,6 +22,7 @@ import org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer; import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer; import java.io.File; +import java.nio.file.Path; import java.util.*; /** @@ -44,13 +31,13 @@ import java.util.*; public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements ModuleSettings { private final String myModuleName; - public ModuleSettingsImpl(File moduleFile, ConversionContextImpl context) throws CannotConvertException { + public ModuleSettingsImpl(Path moduleFile, ConversionContextImpl context) throws CannotConvertException { super(moduleFile, context); myModuleName = getModuleName(moduleFile); } - public static String getModuleName(File moduleFile) { - return StringUtil.trimEnd(moduleFile.getName(), ModuleFileType.DOT_DEFAULT_EXTENSION); + public static String getModuleName(Path moduleFile) { + return StringUtil.trimEnd(moduleFile.getFileName().toString(), ModuleFileType.DOT_DEFAULT_EXTENSION); } @Override @@ -68,7 +55,7 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements @Override @NotNull public File getModuleFile() { - return mySettingsFile.getFile(); + return mySettingsFile.getFile().toFile(); } @Override @@ -149,7 +136,7 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements public Collection getContentRoots() { final List result = new ArrayList<>(); for (Element contentRoot : getContentRootElements()) { - String path = VfsUtil.urlToPath(contentRoot.getAttributeValue(JpsModuleRootModelSerializer.URL_ATTRIBUTE)); + String path = VfsUtilCore.urlToPath(contentRoot.getAttributeValue(JpsModuleRootModelSerializer.URL_ATTRIBUTE)); result.add(new File(FileUtil.toSystemDependentName(expandPath(path)))); } return result; @@ -255,10 +242,10 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements } } String path = ConversionContextImpl.collapsePath(FileUtil.toSystemIndependentName(directory.getAbsolutePath()), this); - contentRoot.addContent(new Element(JpsModuleRootModelSerializer.EXCLUDE_FOLDER_TAG).setAttribute(JpsModuleRootModelSerializer.URL_ATTRIBUTE, VfsUtil.pathToUrl(path))); + contentRoot.addContent(new Element(JpsModuleRootModelSerializer.EXCLUDE_FOLDER_TAG).setAttribute(JpsModuleRootModelSerializer.URL_ATTRIBUTE, VfsUtilCore.pathToUrl(path))); } private File getFile(String url) { - return new File(FileUtil.toSystemDependentName(expandPath(VfsUtil.urlToPath(url)))); + return new File(FileUtil.toSystemDependentName(expandPath(VfsUtilCore.urlToPath(url)))); } -} +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/MultiFilesSettings.java b/platform/lang-impl/src/com/intellij/conversion/impl/MultiFilesSettings.java index a8e21aebb69a..b1abe016ee77 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/MultiFilesSettings.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/MultiFilesSettings.java @@ -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.conversion.impl; import com.intellij.conversion.CannotConvertException; @@ -22,6 +8,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -33,20 +21,20 @@ class MultiFilesSettings { private SettingsXmlFile myProjectFile; private final List mySettingsFiles; - protected MultiFilesSettings(@Nullable File projectFile, @Nullable File[] settingsFiles, @NotNull ConversionContextImpl context) + protected MultiFilesSettings(@Nullable Path projectFile, @Nullable File[] settingsFiles, @NotNull ConversionContextImpl context) throws CannotConvertException { if (projectFile == null && settingsFiles == null) { throw new IllegalArgumentException("Either project file or settings files should be not null"); } - if (projectFile != null && projectFile.exists()) { + if (projectFile != null && Files.exists(projectFile)) { myProjectFile = context.getOrCreateFile(projectFile); } mySettingsFiles = new ArrayList<>(); if (settingsFiles != null) { for (File file : settingsFiles) { - mySettingsFiles.add(context.getOrCreateFile(file)); + mySettingsFiles.add(context.getOrCreateFile(file.toPath())); } } } @@ -65,8 +53,8 @@ class MultiFilesSettings { return result; } - public Collection getAffectedFiles() { - final List files = new ArrayList<>(); + public Collection getAffectedFiles() { + final List files = new ArrayList<>(); if (myProjectFile != null) { files.add(myProjectFile.getFile()); diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectConversionUtil.java b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectConversionUtil.java index f635badb3bb1..5b290d979f06 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectConversionUtil.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectConversionUtil.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.conversion.impl; @@ -22,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; /** @@ -34,23 +21,24 @@ public class ProjectConversionUtil { private ProjectConversionUtil() { } - public static File backupFile(File file) throws IOException { - final String fileName = FileUtil.createSequentFileName(file.getParentFile(), file.getName(), BACKUP_EXTENSION); - final File backup = new File(file.getParentFile(), fileName); - FileUtil.copy(file, backup); - return backup; + public static File backupFile(Path file) throws IOException { + final String fileName = FileUtil.createSequentFileName(file.getParent().toFile(), file.getFileName().toString(), BACKUP_EXTENSION); + final File backup = file.getParent().resolve(fileName).toFile(); + FileUtil.copy(file.toFile(), backup); + return backup; } @NotNull - public static File backupFiles(final Collection files, final File parentDir) throws IOException { + public static File backupFiles(final Collection files, final File parentDir) throws IOException { File backupDir = getBackupDir(parentDir); backupFiles(files, parentDir, backupDir); return backupDir; } - public static void backupFiles(Collection files, File parentDir, File backupDir) throws IOException { + public static void backupFiles(Collection files, File parentDir, File backupDir) throws IOException { backupDir.mkdirs(); - for (File file : files) { + for (Path path : files) { + File file = path.toFile(); final File target; if (FileUtil.isAncestor(parentDir, file, true)) { final String relativePath = FileUtil.getRelativePath(parentDir, file); diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectLibrariesSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectLibrariesSettingsImpl.java index 3d68042b4b78..80eff7516ab5 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectLibrariesSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectLibrariesSettingsImpl.java @@ -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 com.intellij.conversion.impl; @@ -24,11 +10,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; +import java.nio.file.Path; import java.util.Collection; public class ProjectLibrariesSettingsImpl extends MultiFilesSettings implements ProjectLibrariesSettings { - public ProjectLibrariesSettingsImpl(@Nullable File projectFile, @Nullable File[] librariesFiles, + public ProjectLibrariesSettingsImpl(@Nullable Path projectFile, @Nullable File[] librariesFiles, ConversionContextImpl context) throws CannotConvertException { super(projectFile, librariesFiles, context); } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectSettingsImpl.java index 9a1b35ff3065..9eb2c7d1c98d 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ProjectSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ProjectSettingsImpl.java @@ -1,31 +1,17 @@ -/* - * Copyright 2000-2009 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.conversion.impl; -import com.intellij.conversion.ProjectSettings; import com.intellij.conversion.CannotConvertException; +import com.intellij.conversion.ProjectSettings; -import java.io.File; +import java.nio.file.Path; /** * @author nik */ public class ProjectSettingsImpl extends ComponentManagerSettingsImpl implements ProjectSettings { - public ProjectSettingsImpl(File file, ConversionContextImpl context) throws CannotConvertException { + public ProjectSettingsImpl(Path file, ConversionContextImpl context) throws CannotConvertException { super(file, context); } } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/RunManagerSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/RunManagerSettingsImpl.java index 2a508a2c8b31..17671d5a02fd 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/RunManagerSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/RunManagerSettingsImpl.java @@ -10,6 +10,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -26,20 +28,20 @@ public class RunManagerSettingsImpl implements RunManagerSettings { private SettingsXmlFile myProjectFile; private final List mySharedConfigurationFiles; - public RunManagerSettingsImpl(@NotNull File workspaceFile, @Nullable File projectFile, @Nullable File[] sharedConfigurationFiles, + public RunManagerSettingsImpl(@NotNull Path workspaceFile, @Nullable Path projectFile, @Nullable File[] sharedConfigurationFiles, ConversionContextImpl context) throws CannotConvertException { - if (workspaceFile.exists()) { + if (Files.exists(workspaceFile)) { myWorkspaceFile = context.getOrCreateFile(workspaceFile); } - if (projectFile != null && projectFile.exists()) { + if (projectFile != null && Files.exists(projectFile)) { myProjectFile = context.getOrCreateFile(projectFile); } mySharedConfigurationFiles = new ArrayList<>(); if (sharedConfigurationFiles != null) { for (File file : sharedConfigurationFiles) { - mySharedConfigurationFiles.add(context.getOrCreateFile(file)); + mySharedConfigurationFiles.add(context.getOrCreateFile(file.toPath())); } } } @@ -63,8 +65,8 @@ public class RunManagerSettingsImpl implements RunManagerSettings { return result; } - public Collection getAffectedFiles() { - final List files = new ArrayList<>(); + public Collection getAffectedFiles() { + final List files = new ArrayList<>(); if (myWorkspaceFile != null) { files.add(myWorkspaceFile.getFile()); } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/SettingsXmlFile.java b/platform/lang-impl/src/com/intellij/conversion/impl/SettingsXmlFile.java index 719b20099371..8eea5505338b 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/SettingsXmlFile.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/SettingsXmlFile.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.conversion.impl; @@ -26,24 +12,24 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.serialization.JDomSerializationUtil; -import java.io.File; import java.io.IOException; +import java.nio.file.Path; /** * @author nik */ class SettingsXmlFile { - private final File myFile; + private final Path myFile; private final Document myDocument; private final Element myRootElement; - SettingsXmlFile(@NotNull File file) throws CannotConvertException { + SettingsXmlFile(@NotNull Path file) throws CannotConvertException { myFile = file; - myDocument = JDomConvertingUtil.loadDocument(file); + myDocument = JDomConvertingUtil.loadDocument(file.toFile()); myRootElement = myDocument.getRootElement(); } - public File getFile() { + public Path getFile() { return myFile; } @@ -52,10 +38,10 @@ class SettingsXmlFile { } public void save() throws IOException { - JDOMUtil.writeDocument(myDocument, myFile, SystemProperties.getLineSeparator()); + JDOMUtil.writeDocument(myDocument, myFile.toFile(), SystemProperties.getLineSeparator()); } - @Nullable + @Nullable public Element findComponent(String componentName) { return JDomSerializationUtil.findComponent(myRootElement, componentName); } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/WorkspaceSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/WorkspaceSettingsImpl.java index b02006212e54..10fba94e50b7 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/WorkspaceSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/WorkspaceSettingsImpl.java @@ -1,32 +1,17 @@ -/* - * Copyright 2000-2009 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.conversion.impl; import com.intellij.conversion.CannotConvertException; import com.intellij.conversion.WorkspaceSettings; -import java.io.File; +import java.nio.file.Path; /** * @author nik */ public class WorkspaceSettingsImpl extends ComponentManagerSettingsImpl implements WorkspaceSettings { - public WorkspaceSettingsImpl(File workspaceFile, ConversionContextImpl context) throws CannotConvertException { + public WorkspaceSettingsImpl(Path workspaceFile, ConversionContextImpl context) throws CannotConvertException { super(workspaceFile, context); } - } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/XmlBasedSettingsImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/XmlBasedSettingsImpl.java index 4239927cbd7b..76bf30c161ff 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/XmlBasedSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/XmlBasedSettingsImpl.java @@ -1,33 +1,18 @@ -/* - * Copyright 2000-2011 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.conversion.impl; import com.intellij.conversion.CannotConvertException; import com.intellij.conversion.XmlBasedSettings; -import org.jdom.Document; import org.jdom.Element; import org.jetbrains.annotations.NotNull; -import java.io.File; +import java.nio.file.Path; public class XmlBasedSettingsImpl implements XmlBasedSettings { protected final SettingsXmlFile mySettingsFile; protected final ConversionContextImpl myContext; - public XmlBasedSettingsImpl(File file, ConversionContextImpl context) throws CannotConvertException { + public XmlBasedSettingsImpl(Path file, ConversionContextImpl context) throws CannotConvertException { myContext = context; mySettingsFile = context.getOrCreateFile(file); } @@ -39,7 +24,7 @@ public class XmlBasedSettingsImpl implements XmlBasedSettings { } @Override - public File getFile() { + public Path getPath() { return mySettingsFile.getFile(); } } diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ui/ConvertProjectDialog.java b/platform/lang-impl/src/com/intellij/conversion/impl/ui/ConvertProjectDialog.java index 927ce5cb588a..a3193269f647 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ui/ConvertProjectDialog.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ui/ConvertProjectDialog.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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.conversion.impl.ui; @@ -36,6 +22,7 @@ import javax.swing.event.HyperlinkListener; import java.awt.*; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -52,7 +39,7 @@ public class ConvertProjectDialog extends DialogWrapper { private final ConversionContextImpl myContext; private final List myConversionRunners; private final File myBackupDir; - private final Set myAffectedFiles; + private final Set myAffectedFiles; private boolean myNonExistingFilesMessageShown; public ConvertProjectDialog(ConversionContextImpl context, final List conversionRunners) { @@ -103,7 +90,7 @@ public class ConvertProjectDialog extends DialogWrapper { @Override protected void doOKAction() { - final List nonexistentFiles = myContext.getNonExistingModuleFiles(); + final List nonexistentFiles = myContext.getNonExistingModuleFiles(); if (!nonexistentFiles.isEmpty() && !myNonExistingFilesMessageShown) { final String filesString = getFilesString(nonexistentFiles); final String message = IdeBundle.message("message.text.files.do.not.exist", filesString); @@ -141,16 +128,16 @@ public class ConvertProjectDialog extends DialogWrapper { } } - private static String getFilesString(List files) { + private static String getFilesString(List files) { StringBuilder buffer = new StringBuilder(); - for (File file : files) { - buffer.append(file.getAbsolutePath()).append("
"); + for (Path file : files) { + buffer.append(file.toAbsolutePath().toString()).append("
"); } return buffer.toString(); } - private boolean checkReadOnlyFiles() throws IOException { - List files = getReadOnlyFiles(); + private boolean checkReadOnlyFiles() { + List files = getReadOnlyFiles(); if (!files.isEmpty()) { final String message = IdeBundle.message("message.text.unlock.read.only.files", ApplicationNamesInfo.getInstance().getFullProductName(), @@ -170,13 +157,13 @@ public class ConvertProjectDialog extends DialogWrapper { return true; } - private List getReadOnlyFiles() { + private List getReadOnlyFiles() { return ConversionRunner.getReadOnlyFiles(myAffectedFiles); } - private static void unlockFiles(final List files) throws IOException { - for (File file : files) { - FileUtil.setReadOnlyAttribute(file.getAbsolutePath(), false); + private static void unlockFiles(final List files) { + for (Path file : files) { + FileUtil.setReadOnlyAttribute(file.toAbsolutePath().toString(), false); } } diff --git a/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java b/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java index 775e1b7d08cf..14696d4e5cc6 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/convert/JDomConvertingUtil.java @@ -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.ide.impl.convert; import com.intellij.conversion.CannotConvertException; @@ -6,7 +6,6 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.JDOMUtil; -import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; @@ -16,6 +15,7 @@ import org.jetbrains.jps.model.serialization.JDomSerializationUtil; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.*; /** @@ -25,6 +25,10 @@ public final class JDomConvertingUtil extends JDomSerializationUtil { private JDomConvertingUtil() { } + /** + * @deprecated Use {@link #load(Path)} + */ + @Deprecated public static Document loadDocument(File file) throws CannotConvertException { try { return JDOMUtil.loadDocument(file); @@ -34,25 +38,19 @@ public final class JDomConvertingUtil extends JDomSerializationUtil { } } + public static Element load(Path file) throws CannotConvertException { + try { + return JDOMUtil.load(file); + } + catch (JDOMException | IOException e) { + throw new CannotConvertException(file.toAbsolutePath() + ": " + e.getMessage(), e); + } + } + public static String getOptionValue(Element element, String optionName) { return JDOMExternalizerUtil.readField(element, optionName); } - @Nullable - public static String getSettingsValue(@Nullable Element element) { - return element != null ? element.getAttributeValue("value") : null; - } - - @Nullable - public static Element getSettingsElement(@Nullable Element element, String name) { - for (Element child : JDOMUtil.getChildren(element, "setting")) { - if (child.getAttributeValue("name").equals(name)) { - return child; - } - } - return null; - } - public static Condition createAttributeValueFilter(@NonNls final String name, @NonNls final String value) { return createAttributeValueFilter(name, Collections.singleton(value)); } @@ -61,37 +59,11 @@ public final class JDomConvertingUtil extends JDomSerializationUtil { return element -> value.contains(element.getAttributeValue(name)); } - public static Condition createOptionElementFilter(@NonNls final String optionName) { - return createElementWithAttributeFilter(OPTION_ELEMENT, NAME_ATTRIBUTE, optionName); - } - public static Condition createElementWithAttributeFilter(final String elementName, final String attributeName, final String attributeValue) { return Conditions.and(createElementNameFilter(elementName), createAttributeValueFilter(attributeName, attributeValue)); } - public static void copyAttributes(Element from, Element to) { - if (!from.hasAttributes()) { - return; - } - - for (Attribute attribute : from.getAttributes()) { - to.setAttribute(attribute.getName(), attribute.getValue()); - } - } - - public static void copyChildren(Element from, Element to) { - copyChildren(from, to, Conditions.alwaysTrue()); - } - - public static void copyChildren(Element from, Element to, Condition filter) { - for (Element element : from.getChildren()) { - if (filter.value(element)) { - to.addContent(element.clone()); - } - } - } - public static Condition createElementNameFilter(@NonNls final String elementName) { return element -> elementName.equals(element.getName()); } @@ -110,13 +82,6 @@ public final class JDomConvertingUtil extends JDomSerializationUtil { return toRemove; } - public static Element createOptionElement(String name, String value) { - final Element element = new Element(OPTION_ELEMENT); - element.setAttribute(NAME_ATTRIBUTE, name); - element.setAttribute(VALUE_ATTRIBUTE, value); - return element; - } - @Nullable public static Element findChild(Element parent, final Condition filter) { final List list = parent.getChildren(); diff --git a/platform/lang-impl/src/com/intellij/ide/impl/convert/ProjectFileVersionImpl.java b/platform/lang-impl/src/com/intellij/ide/impl/convert/ProjectFileVersionImpl.java index 0fd65a22dfda..13db89850d38 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/convert/ProjectFileVersionImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/convert/ProjectFileVersionImpl.java @@ -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.ide.impl.convert; @@ -9,12 +9,13 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.project.ProjectKt; import com.intellij.util.xmlb.XmlSerializerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import java.nio.file.Paths; + /** * @author nik */ @@ -40,7 +41,7 @@ public class ProjectFileVersionImpl extends ProjectFileVersion implements Dispos LOG.info("Cannot save conversion result: filePath == null"); } else { - ConversionService.getInstance().saveConversionResult(FileUtil.toSystemDependentName(path)); + ConversionService.getInstance().saveConversionResult(Paths.get(path)); } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java index 94a19263cab5..dc6559fe60e2 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java @@ -4,7 +4,6 @@ package com.intellij.ide.util.projectWizard; import com.intellij.ide.RecentProjectsManager; import com.intellij.ide.util.projectWizard.actions.ProjectSpecificAction; import com.intellij.idea.ActionsBundle; -import com.intellij.internal.statistic.beans.ConvertUsagesUtil; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; @@ -191,8 +190,6 @@ public abstract class AbstractNewProjectStep extends DefaultActionGroup imple } } - String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName()); - RecentProjectsManager.getInstance().setLastProjectCreationLocation(PathUtil.toSystemIndependentName(location.getParent())); ProjectOpenedCallback callback = null; diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java index 8423b496643e..d6e149a4bb1c 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java @@ -16,7 +16,6 @@ import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.impl.ProjectMacrosUtil; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMUtil; import org.jdom.Element; import org.jdom.JDOMException; @@ -25,6 +24,9 @@ import org.jetbrains.jps.model.serialization.PathMacroUtil; 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.Set; /** @@ -48,7 +50,7 @@ public class ExistingModuleLoader extends ModuleBuilder { @Override @NotNull public Module createModule(@NotNull ModifiableModuleModel moduleModel) - throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { + throws IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { LOG.assertTrue(getName() != null); final String moduleFilePath = getModuleFilePath(); @@ -69,8 +71,8 @@ public class ExistingModuleLoader extends ModuleBuilder { if (getName() == null) return false; String moduleFilePath = getModuleFilePath(); if (moduleFilePath == null) return false; - final File file = new File(moduleFilePath); - if (file.exists()) { + final Path file = Paths.get(moduleFilePath); + if (Files.exists(file)) { try { final ConversionResult result = ConversionService.getInstance().convertModule(dest, file); if (result.openingIsCanceled()) { diff --git a/platform/lang-impl/src/com/intellij/platform/ModuleAttachProcessor.kt b/platform/lang-impl/src/com/intellij/platform/ModuleAttachProcessor.kt index 60159010bcd5..c1c6d791233b 100644 --- a/platform/lang-impl/src/com/intellij/platform/ModuleAttachProcessor.kt +++ b/platform/lang-impl/src/com/intellij/platform/ModuleAttachProcessor.kt @@ -91,9 +91,8 @@ 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.fileName.toString(), projectDir.toString(), true, false) ?: return false - val baseDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(projectDir.systemIndependentPath)!! - PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(baseDir, newProject) + val newProject = ProjectManagerEx.getInstanceEx().newProject(projectDir, true, false) ?: return false + PlatformProjectOpenProcessor.runDirectoryProjectConfigurators(projectDir, newProject) StoreUtil.saveSettings(newProject) runWriteAction { Disposer.dispose(newProject) } } diff --git a/platform/lang-impl/src/com/intellij/platform/templates/TemplateModuleBuilder.java b/platform/lang-impl/src/com/intellij/platform/templates/TemplateModuleBuilder.java index e03f053bce64..470faa5bdcc3 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/TemplateModuleBuilder.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/TemplateModuleBuilder.java @@ -12,7 +12,6 @@ import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.FileTemplateUtil; import com.intellij.ide.util.projectWizard.*; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Attachment; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; @@ -51,6 +50,10 @@ import javax.swing.*; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -373,20 +376,20 @@ public class TemplateModuleBuilder extends ModuleBuilder { @Nullable @Override public Project createProject(String name, @NotNull String path) { - final File location = new File(FileUtil.toSystemDependentName(path)); - LOG.assertTrue(location.exists()); + Path baseDir = Paths.get(path); + LOG.assertTrue(Files.isDirectory(baseDir)); - final VirtualFile baseDir = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location)); - if (baseDir == null) { - LOG.error("Couldn't find path '" + path + "' in VFS"); - return null; + List children; + try (DirectoryStream childrenIterator = Files.newDirectoryStream(baseDir)) { + children = ContainerUtil.collect(childrenIterator.iterator()); } + catch (IOException e) { + throw new RuntimeException(e); + } + boolean isSomehowOverwriting = children.size() > 1 || + (children.size() == 1 && !PathMacroUtil.DIRECTORY_STORE_NAME.equals(children.get(0).getFileName().toString())); - VirtualFile[] children = baseDir.getChildren(); - boolean isSomehowOverwriting = children.length > 1 || - (children.length == 1 && !PathMacroUtil.DIRECTORY_STORE_NAME.equals(children[0].getName())); - - Task.WithResult task = new Task.WithResult(null, "Applying Template", true) { + return ProgressManager.getInstance().run(new Task.WithResult(null, "Applying Template", true) { @Override public Project compute(@NotNull ProgressIndicator indicator) { try { @@ -400,21 +403,16 @@ public class TemplateModuleBuilder extends ModuleBuilder { } finally { cleanup(); - if(indicator.isCanceled()){ - if (!isSomehowOverwriting) { - ApplicationManager.getApplication().invokeLater(() -> { - try { - WriteAction.run(() -> baseDir.delete(TemplateProjectDirectoryGenerator.class)); - } - catch (IOException e) { - LOG.error(e); - } - }); + if (indicator.isCanceled() && !isSomehowOverwriting) { + try { + FileUtil.delete(baseDir); + } + catch (IOException e) { + LOG.error(e); } } } } - }; - return ProgressManager.getInstance().run(task); + }); } } diff --git a/platform/platform-api/src/com/intellij/projectImport/ProjectOpenProcessor.java b/platform/platform-api/src/com/intellij/projectImport/ProjectOpenProcessor.java index 00462a762bf1..1cbe4d4348bf 100644 --- a/platform/platform-api/src/com/intellij/projectImport/ProjectOpenProcessor.java +++ b/platform/platform-api/src/com/intellij/projectImport/ProjectOpenProcessor.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.nio.file.Path; public abstract class ProjectOpenProcessor { public static final ExtensionPointName EXTENSION_POINT_NAME = @@ -82,6 +83,6 @@ public abstract class ProjectOpenProcessor { return false; } - public void refreshProjectFiles(@NotNull VirtualFile baseDir) { + public void refreshProjectFiles(@NotNull Path baseDir) { } } diff --git a/platform/platform-impl/src/com/intellij/conversion/ConversionListener.java b/platform/platform-impl/src/com/intellij/conversion/ConversionListener.java index 6f40ad52f11d..a7f17669c61c 100644 --- a/platform/platform-impl/src/com/intellij/conversion/ConversionListener.java +++ b/platform/platform-impl/src/com/intellij/conversion/ConversionListener.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.conversion; @@ -22,11 +8,14 @@ import java.io.File; import java.util.List; /** -* @author nik -*/ + * @author nik + */ public interface ConversionListener { void conversionNeeded(); + void successfullyConverted(@NotNull File backupDir); + void error(@NotNull String message); + void cannotWriteToFiles(@NotNull List readonlyFiles); } diff --git a/platform/platform-impl/src/com/intellij/conversion/ConversionService.java b/platform/platform-impl/src/com/intellij/conversion/ConversionService.java index 5a1cbc798294..761e3cfc7133 100644 --- a/platform/platform-impl/src/com/intellij/conversion/ConversionService.java +++ b/platform/platform-impl/src/com/intellij/conversion/ConversionService.java @@ -4,10 +4,9 @@ package com.intellij.conversion; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import java.io.File; +import java.nio.file.Path; /** * @author nik @@ -20,16 +19,16 @@ public abstract class ConversionService { } @NotNull - public abstract ConversionResult convertSilently(@NotNull String projectPath); + public abstract ConversionResult convertSilently(@NotNull Path projectPath); @NotNull - public abstract ConversionResult convertSilently(@NotNull String projectPath, @NotNull ConversionListener conversionListener); + public abstract ConversionResult convertSilently(@NotNull Path projectPath, @NotNull ConversionListener conversionListener); @NotNull - public abstract ConversionResult convert(@NotNull VirtualFile projectPath); + public abstract ConversionResult convert(@NotNull Path projectPath); @NotNull - public abstract ConversionResult convertModule(@NotNull Project project, @NotNull File moduleFile); + public abstract ConversionResult convertModule(@NotNull Project project, @NotNull Path moduleFile); - public abstract void saveConversionResult(@NotNull String projectPath); + public abstract void saveConversionResult(@NotNull Path projectPath); } diff --git a/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java b/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java index defd332044fc..94f29635ee00 100644 --- a/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java +++ b/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java @@ -2,10 +2,9 @@ package com.intellij.conversion; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import java.io.File; +import java.nio.file.Path; /** * @author Dmitry Avdeev @@ -29,29 +28,29 @@ public final class DummyConversionService extends ConversionService { @NotNull @Override - public ConversionResult convertSilently(@NotNull String projectPath) { + public ConversionResult convertSilently(@NotNull Path projectPath) { return CONVERSION_RESULT; } @NotNull @Override - public ConversionResult convertSilently(@NotNull String projectPath, @NotNull ConversionListener conversionListener) { + public ConversionResult convertSilently(@NotNull Path projectPath, @NotNull ConversionListener conversionListener) { return CONVERSION_RESULT; } @NotNull @Override - public ConversionResult convert(@NotNull VirtualFile projectPath) { + public ConversionResult convert(@NotNull Path projectPath) { return CONVERSION_RESULT; } @NotNull @Override - public ConversionResult convertModule(@NotNull Project project, @NotNull File moduleFile) { + public ConversionResult convertModule(@NotNull Project project, @NotNull Path moduleFile) { return CONVERSION_RESULT; } @Override - public void saveConversionResult(@NotNull String projectPath) { + public void saveConversionResult(@NotNull Path projectPath) { } } diff --git a/platform/platform-impl/src/com/intellij/ide/RecentDirectoryProjectsManager.java b/platform/platform-impl/src/com/intellij/ide/RecentDirectoryProjectsManager.java index 0d9b5d93a23a..cdbe0519927a 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentDirectoryProjectsManager.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentDirectoryProjectsManager.java @@ -5,26 +5,22 @@ import com.intellij.openapi.components.RoamingType; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.platform.ProjectBaseDirectory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.SystemIndependent; -// todo the only difference - usage of ProjectBaseDirectory Is it really make sense? +import java.nio.file.Path; + +// todo the only difference - usage of ProjectBaseDirectory Does it really make sense? @State(name = "RecentDirectoryProjectsManager", storages = @Storage(value = "recentProjectDirectories.xml", roamingType = RoamingType.DISABLED)) public class RecentDirectoryProjectsManager extends RecentProjectsManagerBase { @Override @Nullable @SystemIndependent protected String getProjectPath(@NotNull Project project) { - final ProjectBaseDirectory baseDir = ProjectBaseDirectory.getInstance(project); - if (baseDir.getBaseDir() == null) { - return project.getBasePath(); - } - else { - VirtualFile baseDirVFile = baseDir.getBaseDir(); - return baseDirVFile != null ? baseDirVFile.getPath() : null; - } + ProjectBaseDirectory baseDir = ProjectBaseDirectory.getInstance(project); + Path baseDirFile = baseDir.getBase(); + return baseDirFile == null ? project.getBasePath() : baseDirFile.toString(); } } diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index 5286f0e0249b..5f4eab3b7172 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -19,8 +19,6 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.impl.SystemDock; import com.intellij.openapi.wm.impl.welcomeScreen.RecentProjectPanel; import com.intellij.platform.PlatformProjectOpenProcessor; @@ -492,27 +490,25 @@ public class RecentProjectsManagerBase extends RecentProjectsManager implements @Nullable public Project doOpenProject(@NotNull @SystemIndependent String projectPath, @Nullable Project projectToClose, boolean forceOpenInNewFrame) { - VirtualFile dotIdea = LocalFileSystem.getInstance() - .refreshAndFindFileByPath(FileUtilRt.toSystemIndependentName(projectPath) + "/" + Project.DIRECTORY_STORE_FOLDER); - Project existing = ProjectUtil.findAndFocusExistingProjectForPath(projectPath); if (existing != null) { return existing; } - if (dotIdea != null) { + Path projectFile = Paths.get(projectPath); + if (Files.isDirectory(projectFile.resolve(Project.DIRECTORY_STORE_FOLDER))) { EnumSet options = EnumSet.of(PlatformProjectOpenProcessor.Option.REOPEN); if (forceOpenInNewFrame) { options.add(PlatformProjectOpenProcessor.Option.FORCE_NEW_FRAME); } - return PlatformProjectOpenProcessor.doOpenProject(dotIdea.getParent(), projectToClose, -1, null, options); + return PlatformProjectOpenProcessor.doOpenProject(projectFile, projectToClose, -1, null, options); } else { // If .idea is missing in the recent project's dir; this might mean, for instance, that 'git clean' was called. // Reopening such a project should be similar to opening the dir first time (and trying to import known project formats) // IDEA-144453 IDEA rejects opening recent project if there are no .idea subfolder // CPP-12106 Auto-load CMakeLists.txt on opening from Recent projects when .idea and cmake-build-debug were deleted - return ProjectUtil.openOrImport(projectPath, projectToClose, forceOpenInNewFrame); + return ProjectUtil.openOrImport(projectFile, projectToClose, forceOpenInNewFrame); } } diff --git a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java index c96e570ece73..294f3b2abfab 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java @@ -42,6 +42,7 @@ import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.List; /** @@ -84,6 +85,10 @@ public class ProjectUtil { return ProjectManagerEx.getInstanceEx().closeAndDispose(project); } + public static Project openOrImport(@NotNull Path path, Project projectToClose, boolean forceOpenInNewFrame) { + return openOrImport(FileUtil.toSystemIndependentName(path.toString()), projectToClose, forceOpenInNewFrame); + } + /** * @param path project file path * @param projectToClose currently active project diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 14e148417b56..e71e9d949962 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -25,8 +25,6 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryKeyBean; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.impl.SystemDock; @@ -48,7 +46,9 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -327,22 +327,19 @@ public final class IdeaApplication { if (args.length > 0) { String filename = args[0]; - File file = new File(currentDirectory, filename); - - if (file.exists()) { - VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); - if (virtualFile != null) { - int line = -1; - if (args.length > 2 && CustomProtocolHandler.LINE_NUMBER_ARG_NAME.equals(args[1])) { - try { - line = Integer.parseInt(args[2]); - } catch (NumberFormatException ex) { - LOG.error("Wrong line number:" + args[2]); - } + Path file = currentDirectory == null ? Paths.get(filename) : Paths.get(currentDirectory, filename); + if (Files.exists(file)) { + int line = -1; + if (args.length > 2 && CustomProtocolHandler.LINE_NUMBER_ARG_NAME.equals(args[1])) { + try { + line = Integer.parseInt(args[2]); + } + catch (NumberFormatException ex) { + LOG.error("Wrong line number:" + args[2]); } - EnumSet options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class); - PlatformProjectOpenProcessor.doOpenProject(virtualFile, null, line, null, options); } + EnumSet options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class); + PlatformProjectOpenProcessor.doOpenProject(file, null, line, null, options); } return CliResult.error(1, "Can't find file:" + file); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java index 8bb582b0f2cc..f131ba936d65 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java @@ -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.openapi.vfs.VirtualFile; import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -13,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; public abstract class ProjectManagerEx extends ProjectManager { @@ -26,6 +26,9 @@ public abstract class ProjectManagerEx extends ProjectManager { @Nullable 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) { @@ -100,7 +103,7 @@ public abstract class ProjectManagerEx extends ProjectManager { public abstract Project findOpenProjectByHash(@Nullable String locationHash); @Nullable - public abstract Project convertAndLoadProject(@NotNull VirtualFile path) throws IOException; + public abstract Project convertAndLoadProject(@NotNull Path path) throws IOException; @NotNull @ApiStatus.Internal diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index c4dbb547559a..2fe5e34f7591 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -39,7 +39,6 @@ import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.UserDataHolderEx; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.ZipHandler; @@ -55,6 +54,8 @@ import org.jetbrains.annotations.*; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -163,6 +164,11 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { private static long CHECK_START = System.currentTimeMillis(); private final Map 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); + } + @Override @Nullable public Project newProject(@Nullable String projectName, @NotNull String filePath, boolean useDefaultProjectSettings, boolean isDummy) { @@ -519,17 +525,17 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { @Override public Project loadAndOpenProject(@NotNull String originalFilePath) { String filePath = FileUtilRt.toSystemIndependentName(toCanonicalName(originalFilePath)); - return loadAndOpenProject(LocalFileSystem.getInstance().findFileByPath(filePath), filePath); + return loadAndOpenProject(Paths.get(filePath), filePath); } @Override public Project loadAndOpenProject(@NotNull File file) { - VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file); - return loadAndOpenProject(virtualFile, Objects.requireNonNull(virtualFile).getPath()); + Path path = file.toPath(); + return loadAndOpenProject(path, FileUtil.toSystemIndependentName(path.toString())); } - private Project loadAndOpenProject(@Nullable VirtualFile virtualFile, @NotNull @SystemIndependent String filePath) { - final ConversionResult conversionResult = virtualFile == null ? null : ConversionService.getInstance().convert(virtualFile); + private Project loadAndOpenProject(@Nullable Path file, @NotNull @SystemIndependent String filePath) { + final ConversionResult conversionResult = file == null ? null : ConversionService.getInstance().convert(file); ProjectImpl project; if (conversionResult != null && conversionResult.openingIsCanceled()) { project = null; @@ -584,7 +590,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { */ @Override @Nullable - public Project convertAndLoadProject(@NotNull VirtualFile path) { + public Project convertAndLoadProject(@NotNull Path path) { Activity activity = StartUpMeasurer.start(StartUpMeasurer.Phases.PROJECT_CONVERSION); final ConversionResult conversionResult = ConversionService.getInstance().convert(path); activity.end(); @@ -592,7 +598,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { return null; } - String filePath = path.getPath(); + String filePath = FileUtil.toSystemIndependentName(path.toString()); ProjectImpl project = doCreateProject(null, filePath); try { if (!ApplicationManager.getApplication().isDispatchThread() && ProgressManager.getInstance().getProgressIndicator() != null) { diff --git a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java index 8d4aa220e420..e4525fa61729 100644 --- a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java +++ b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java @@ -27,6 +27,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.IdeFrame; @@ -42,11 +43,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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.EnumSet; +import java.util.Objects; /** * @author max @@ -131,35 +133,48 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement return doOpenProject(virtualFile, projectToClose, line, callback, options); } + /** + * @deprecated Use Path instead of VirtualFile. + */ @Nullable + @Deprecated public static Project doOpenProject(@NotNull VirtualFile virtualFile, @Nullable Project projectToClose, int line, @Nullable ProjectOpenedCallback callback, @NotNull EnumSet