use Path instead of VFS to open/import/create project

GitOrigin-RevId: aa9e1585ab96f3dbc5e83ae62d5aa7b31ad93d64
This commit is contained in:
Vladimir Krivosheev
2019-07-10 17:06:00 +03:00
committed by intellij-monorepo-bot
parent d2d72c7d66
commit 57eb7d80b3
41 changed files with 460 additions and 673 deletions
@@ -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"));
@@ -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();
}
}
@@ -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);
@@ -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);
}
@@ -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<File, SettingsXmlFile> mySettingsFiles = new HashMap<>();
private final Map<Path, SettingsXmlFile> 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<File> myNonExistingModuleFiles = new ArrayList<>();
private final List<Path> myNonExistingModuleFiles = new ArrayList<>();
private final Map<File, ModuleSettingsImpl> myFile2ModuleSettings = new HashMap<>();
private final Map<String, ModuleSettingsImpl> 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<String> 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<File> getAllProjectFiles() {
final HashSet<File> files = new HashSet<>(Arrays.asList(myModuleFiles));
Set<File> 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<File> getNonExistingModuleFiles() {
public List<Path> 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<? extends File> files, List<? extends ConversionRunner> usedRunners) throws IOException {
public void saveFiles(Collection<? extends Path> files, List<? extends ConversionRunner> usedRunners) throws IOException {
Set<String> 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);
}
}
@@ -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<File> myModulesFilesToProcess = new ArrayList<>();
private final List<Path> myModulesFilesToProcess = new ArrayList<>();
private final ProjectConverter myConverter;
private final ConversionProcessor<RunManagerSettings> myRunConfigurationsConverter;
private final ConversionProcessor<ProjectLibrariesSettings> 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<File> getCreatedFiles() {
return myConverter.getCreatedFiles();
public Collection<Path> getCreatedFiles() {
return ContainerUtil.map(myConverter.getCreatedFiles(), file -> file.toPath());
}
public Set<File> getAffectedFiles() {
Set<File> affectedFiles = new HashSet<>();
public Set<Path> getAffectedFiles() {
Set<Path> 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<File> getReadOnlyFiles(final Collection<? extends File> affectedFiles) {
List<File> result = new ArrayList<>();
for (File file : affectedFiles) {
if (!file.canWrite()) {
public static List<Path> getReadOnlyFiles(final Collection<? extends Path> affectedFiles) {
List<Path> 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);
@@ -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<File> getContentRoots() {
final List<File> 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))));
}
}
}
@@ -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<SettingsXmlFile> 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<File> getAffectedFiles() {
final List<File> files = new ArrayList<>();
public Collection<Path> getAffectedFiles() {
final List<Path> files = new ArrayList<>();
if (myProjectFile != null) {
files.add(myProjectFile.getFile());
@@ -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<? extends File> files, final File parentDir) throws IOException {
public static File backupFiles(final Collection<? extends Path> files, final File parentDir) throws IOException {
File backupDir = getBackupDir(parentDir);
backupFiles(files, parentDir, backupDir);
return backupDir;
}
public static void backupFiles(Collection<? extends File> files, File parentDir, File backupDir) throws IOException {
public static void backupFiles(Collection<? extends Path> 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);
@@ -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);
}
@@ -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);
}
}
@@ -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<SettingsXmlFile> 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<File> getAffectedFiles() {
final List<File> files = new ArrayList<>();
public Collection<Path> getAffectedFiles() {
final List<Path> files = new ArrayList<>();
if (myWorkspaceFile != null) {
files.add(myWorkspaceFile.getFile());
}
@@ -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);
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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<? extends ConversionRunner> myConversionRunners;
private final File myBackupDir;
private final Set<File> myAffectedFiles;
private final Set<Path> myAffectedFiles;
private boolean myNonExistingFilesMessageShown;
public ConvertProjectDialog(ConversionContextImpl context, final List<? extends ConversionRunner> conversionRunners) {
@@ -103,7 +90,7 @@ public class ConvertProjectDialog extends DialogWrapper {
@Override
protected void doOKAction() {
final List<File> nonexistentFiles = myContext.getNonExistingModuleFiles();
final List<Path> 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<? extends File> files) {
private static String getFilesString(List<? extends Path> files) {
StringBuilder buffer = new StringBuilder();
for (File file : files) {
buffer.append(file.getAbsolutePath()).append("<br>");
for (Path file : files) {
buffer.append(file.toAbsolutePath().toString()).append("<br>");
}
return buffer.toString();
}
private boolean checkReadOnlyFiles() throws IOException {
List<File> files = getReadOnlyFiles();
private boolean checkReadOnlyFiles() {
List<Path> 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<File> getReadOnlyFiles() {
private List<Path> getReadOnlyFiles() {
return ConversionRunner.getReadOnlyFiles(myAffectedFiles);
}
private static void unlockFiles(final List<? extends File> files) throws IOException {
for (File file : files) {
FileUtil.setReadOnlyAttribute(file.getAbsolutePath(), false);
private static void unlockFiles(final List<? extends Path> files) {
for (Path file : files) {
FileUtil.setReadOnlyAttribute(file.toAbsolutePath().toString(), false);
}
}
@@ -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<Element> 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<Element> createOptionElementFilter(@NonNls final String optionName) {
return createElementWithAttributeFilter(OPTION_ELEMENT, NAME_ATTRIBUTE, optionName);
}
public static Condition<Element> 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<? super Element> filter) {
for (Element element : from.getChildren()) {
if (filter.value(element)) {
to.addContent(element.clone());
}
}
}
public static Condition<Element> 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<? super Element> filter) {
final List<Element> list = parent.getChildren();
@@ -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));
}
}
@@ -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<T> extends DefaultActionGroup imple
}
}
String generatorName = generator == null ? "empty" : ConvertUsagesUtil.ensureProperKey(generator.getName());
RecentProjectsManager.getInstance().setLastProjectCreationLocation(PathUtil.toSystemIndependentName(location.getParent()));
ProjectOpenedCallback callback = null;
@@ -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()) {
@@ -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) }
}
@@ -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<Path> children;
try (DirectoryStream<Path> 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<Project, RuntimeException> task = new Task.WithResult<Project, RuntimeException>(null, "Applying Template", true) {
return ProgressManager.getInstance().run(new Task.WithResult<Project, RuntimeException>(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);
});
}
}
@@ -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<ProjectOpenProcessor> 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) {
}
}
@@ -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<? extends File> readonlyFiles);
}
@@ -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);
}
@@ -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) {
}
}
@@ -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();
}
}
@@ -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<PlatformProjectOpenProcessor.Option> 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);
}
}
@@ -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
@@ -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<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
PlatformProjectOpenProcessor.doOpenProject(virtualFile, null, line, null, options);
}
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
PlatformProjectOpenProcessor.doOpenProject(file, null, line, null, options);
}
return CliResult.error(1, "Can't find file:" + file);
}
@@ -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
@@ -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<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);
}
@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) {
@@ -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<Option> options) {
VirtualFile baseDir = virtualFile;
return doOpenProject(Paths.get(virtualFile.getPath()), projectToClose, line, callback, options);
}
@Nullable
public static Project doOpenProject(@NotNull Path file,
@Nullable Project projectToClose,
int line,
@Nullable ProjectOpenedCallback callback,
@NotNull EnumSet<Option> options) {
boolean dummyProject = false;
String dummyProjectName = null;
boolean forceOpenInNewFrame = options.contains(Option.FORCE_NEW_FRAME);
boolean tempProject = options.contains(Option.TEMP_PROJECT);
if (!baseDir.isDirectory()) {
Path baseDir = file;
if (!Files.isDirectory(baseDir)) {
if (tempProject) {
baseDir = null;
}
else {
baseDir = virtualFile.getParent();
while (baseDir != null && !com.intellij.openapi.project.ProjectUtil.isProjectDirectoryExistsUsingIo(baseDir)) {
baseDir = file.getParent();
while (baseDir != null && !Files.exists(baseDir)) {
baseDir = baseDir.getParent();
}
}
// no reasonable directory -> create new temp one or use parent
if (baseDir == null) {
if (tempProject || Registry.is("ide.open.file.in.temp.project.dir")) {
try {
dummyProjectName = virtualFile.getName();
File directory = FileUtil.createTempDirectory(dummyProjectName, null, true);
baseDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(directory);
dummyProjectName = file.getFileName().toString();
baseDir = FileUtil.createTempDirectory(dummyProjectName, null, true).toPath();
dummyProject = true;
}
catch (IOException ex) {
@@ -167,7 +182,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
}
}
if (baseDir == null) {
baseDir = virtualFile.getParent();
baseDir = file.getParent();
}
}
}
@@ -190,15 +205,15 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
Pair<Project, Module> result = null;
if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
result = prepareAndOpenProject(virtualFile, options, baseDir, dummyProject, dummyProjectName);
result = prepareAndOpenProject(file, options, baseDir, dummyProject, dummyProjectName);
}
else {
IdeFrameImpl frame = showFrame();
Ref<Pair<Project, Module>> refResult = Ref.create();
VirtualFile finalBaseDir = baseDir;
Path finalBaseDir = baseDir;
boolean finalDummyProject = dummyProject;
String finalDummyProjectName = dummyProjectName;
Runnable process = () -> refResult.set(prepareAndOpenProject(virtualFile, options, finalBaseDir, finalDummyProject, finalDummyProjectName));
Runnable process = () -> refResult.set(prepareAndOpenProject(file, options, finalBaseDir, finalDummyProject, finalDummyProjectName));
TransactionGuard.getInstance().submitTransactionAndWait(() -> {
boolean progressCompleted = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, "Loading Project...", true, null, frame.getComponent());
if (!progressCompleted) {
@@ -213,8 +228,8 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
return null;
}
if (!virtualFile.isDirectory()) {
openFileFromCommandLine(result.first, virtualFile, line);
if (!Files.isDirectory(file)) {
openFileFromCommandLine(result.first, file, line);
}
if (callback != null) {
@@ -247,20 +262,20 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
}
@Nullable
private static Pair<Project, Module> prepareAndOpenProject(@NotNull VirtualFile virtualFile,
private static Pair<Project, Module> prepareAndOpenProject(@NotNull Path file,
@NotNull EnumSet<Option> options,
VirtualFile baseDir,
Path baseDir,
boolean dummyProject,
String dummyProjectName) {
boolean newProject = false;
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
Project project;
VirtualFile dotIdeaDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER);
if (dotIdeaDir != null && dotIdeaDir.isDirectory()) {
Path dotIdeaDir = baseDir.resolve(Project.DIRECTORY_STORE_FOLDER);
if (Files.isDirectory(dotIdeaDir)) {
project = tryLoadProject(baseDir);
}
else {
project = projectManager.newProject(dummyProject ? dummyProjectName : baseDir.getName(), baseDir.getPath(), !options.contains(Option.DO_NOT_USE_DEFAULT_PROJECT), dummyProject);
project = projectManager.newProject(dummyProject ? dummyProjectName : baseDir.getFileName().toString(), baseDir.toString(), !options.contains(Option.DO_NOT_USE_DEFAULT_PROJECT), dummyProject);
newProject = true;
}
@@ -270,7 +285,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
ProjectBaseDirectory.getInstance(project).setBaseDir(baseDir);
Module module = configureNewProject(project, baseDir, virtualFile, dummyProject, newProject);
Module module = configureNewProject(project, baseDir, file, dummyProject, newProject);
if (newProject) {
project.save();
@@ -279,7 +294,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
}
@Nullable
private static Project tryLoadProject(VirtualFile baseDir) {
private static Project tryLoadProject(@NotNull Path baseDir) {
try {
for (ProjectOpenProcessor processor : ProjectOpenProcessor.EXTENSION_POINT_NAME.getExtensionList()) {
processor.refreshProjectFiles(baseDir);
@@ -292,8 +307,11 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
}
}
private static Module configureNewProject(Project project, VirtualFile baseDir, @NotNull VirtualFile dummyFileContentRoot,
boolean dummyProject, boolean newProject) {
private static Module configureNewProject(@NotNull Project project,
@NotNull Path baseDir,
@NotNull Path dummyFileContentRoot,
boolean dummyProject,
boolean newProject) {
boolean runConfigurators = newProject || ModuleManager.getInstance(project).getModules().length == 0;
final Ref<Module> module = new Ref<>();
if (runConfigurators) {
@@ -303,17 +321,21 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
module.set(ModuleManager.getInstance(project).getModules()[0]);
}
if (runConfigurators && dummyProject) { // add content root for chosen (single) file
if (runConfigurators && dummyProject) {
// add content root for chosen (single) file
ModuleRootModificationUtil.updateModel(module.get(), model -> {
ContentEntry[] entries = model.getContentEntries();
if (entries.length == 1) model.removeContentEntry(entries[0]); // remove custom content entry created for temp directory
model.addContentEntry(dummyFileContentRoot);
// remove custom content entry created for temp directory
if (entries.length == 1) {
model.removeContentEntry(entries[0]);
}
model.addContentEntry(VfsUtilCore.pathToUrl(dummyFileContentRoot.toString()));
});
}
return module.get();
}
private static boolean checkExistingProjectOnOpen(@NotNull Project projectToClose, @Nullable ProjectOpenedCallback callback, VirtualFile baseDir) {
private static boolean checkExistingProjectOnOpen(@NotNull Project projectToClose, @Nullable ProjectOpenedCallback callback, Path baseDir) {
if (ProjectAttachProcessor.canAttachToProject() && GeneralSettings.getInstance().getConfirmOpenNewProject() == GeneralSettings.OPEN_PROJECT_ASK) {
final int exitCode = ProjectUtil.confirmOpenOrAttachProject();
if (exitCode == -1) {
@@ -325,7 +347,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
}
}
else if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW_ATTACH) {
if (attachToProject(projectToClose, Paths.get(FileUtil.toSystemDependentName(baseDir.getPath())), callback)) {
if (attachToProject(projectToClose, baseDir, callback)) {
return true;
}
}
@@ -348,11 +370,20 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
return false;
}
/**
* @deprecated Use {@link #runDirectoryProjectConfigurators(Path, Project)}
*/
@Deprecated
public static Module runDirectoryProjectConfigurators(@NotNull VirtualFile baseDir, @NotNull Project project) {
return runDirectoryProjectConfigurators(Paths.get(baseDir.getPath()), project);
}
public static Module runDirectoryProjectConfigurators(@NotNull Path baseDir, @NotNull Project project) {
final Ref<Module> moduleRef = new Ref<>();
VirtualFile virtualFile = getFileAndRefresh(baseDir);
for (DirectoryProjectConfigurator configurator: DirectoryProjectConfigurator.EP_NAME.getIterable()) {
try {
configurator.configureProject(project, baseDir, moduleRef);
configurator.configureProject(project, virtualFile, moduleRef);
}
catch (Exception e) {
LOG.error(e);
@@ -370,15 +401,23 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor implement
return false;
}
private static void openFileFromCommandLine(Project project, VirtualFile file, int line) {
private static void openFileFromCommandLine(Project project, Path file, int line) {
StartupManager.getInstance(project).registerPostStartupActivity(
(DumbAwareRunnable)() -> ApplicationManager.getApplication().invokeLater(() -> {
if (!project.isDisposed() && file.isValid()) {
(line > 0 ? new OpenFileDescriptor(project, file, line - 1, 0) : PsiNavigationSupport.getInstance().createNavigatable(project, file, -1)).navigate(true);
if (!project.isDisposed() && Files.exists(file)) {
VirtualFile virtualFile = getFileAndRefresh(file);
(line > 0 ? new OpenFileDescriptor(project, virtualFile, line - 1, 0) : PsiNavigationSupport.getInstance().createNavigatable(project, virtualFile, -1)).navigate(true);
}
}, ModalityState.NON_MODAL));
}
@NotNull
private static VirtualFile getFileAndRefresh(Path file) {
VirtualFile virtualFile = Objects.requireNonNull(LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(file.toString())));
virtualFile.refresh(false, false);
return virtualFile;
}
@Nullable
@Override
public Icon getIcon() {
@@ -1,47 +1,58 @@
/*
* 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.platform;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* @author yole
*/
public class ProjectBaseDirectory {
public final class ProjectBaseDirectory {
public static ProjectBaseDirectory getInstance(@NotNull Project project) {
return ServiceManager.getService(project, ProjectBaseDirectory.class);
}
private VirtualFile BASE_DIR;
private Path baseDir;
public VirtualFile getBaseDir(final VirtualFile baseDir) {
if (getBaseDir() != null) {
return getBaseDir();
public Path getBaseDir(Path baseDir) {
return ObjectUtils.chooseNotNull(getBase(), baseDir);
}
/**
* @deprecated Use {@link #getBase()}
*/
@Nullable
@Deprecated
public VirtualFile getBaseDir() {
if (baseDir == null) {
return null;
}
return LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(baseDir.toString()));
}
@Nullable
public Path getBase() {
return baseDir;
}
public VirtualFile getBaseDir() {
return BASE_DIR;
public void setBaseDir(Path baseDir) {
this.baseDir = baseDir;
}
public void setBaseDir(final VirtualFile baseDir) {
BASE_DIR = baseDir;
/**
* @deprecated Use {@link #setBaseDir(Path)}
*/
@Deprecated
public void setBaseDir(VirtualFile baseDir) {
this.baseDir = Paths.get(baseDir.getPath());
}
}
@@ -1,24 +1,11 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.jetbrains.annotations.NotNull;
import org.junit.Assert;
import java.io.File;
import java.nio.file.Path;
import java.util.List;
/**
@@ -28,7 +15,7 @@ public class ProjectConversionTestUtil {
private ProjectConversionTestUtil() {
}
public static void assertNoConversionNeeded(String projectPath) {
public static void assertNoConversionNeeded(@NotNull Path projectPath) {
final MyConversionListener listener = new MyConversionListener();
final ConversionResult result = ConversionService.getInstance().convertSilently(projectPath, listener);
Assert.assertTrue(result.conversionNotNeeded());
@@ -36,7 +23,7 @@ public class ProjectConversionTestUtil {
Assert.assertFalse(listener.isConverted());
}
public static void convert(String projectPath) {
public static void convert(@NotNull Path projectPath) {
final MyConversionListener listener = new MyConversionListener();
final ConversionResult result = ConversionService.getInstance().convertSilently(projectPath, listener);
Assert.assertFalse(result.conversionNotNeeded());
@@ -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.impl;
import com.intellij.conversion.ConversionResult;
@@ -20,6 +6,7 @@ import com.intellij.conversion.impl.ConversionRunner;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.AbstractVcsHelper;
import com.intellij.openapi.vcs.VcsShowConfirmationOptionImpl;
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
@@ -30,7 +17,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.nio.file.Path;
import java.util.*;
/**
@@ -43,8 +30,8 @@ public class ConversionResultImpl implements ConversionResult {
private final boolean myConversionNeeded;
private final boolean myConversionCanceled;
private final boolean myErrorOccurred;
private final Set<File> myChangedFiles = new HashSet<>();
private final Set<File> myCreatedFiles = new HashSet<>();
private final Set<Path> myChangedFiles = new HashSet<>();
private final Set<Path> myCreatedFiles = new HashSet<>();
public ConversionResultImpl(boolean conversionNeeded, boolean conversionCanceled, boolean errorOccurred) {
myConversionNeeded = conversionNeeded;
@@ -103,10 +90,10 @@ public class ConversionResultImpl implements ConversionResult {
return false;
}
private static List<VirtualFile> findVirtualFiles(Collection<? extends File> ioFiles) {
private static List<VirtualFile> findVirtualFiles(Collection<? extends Path> ioFiles) {
List<VirtualFile> files = new ArrayList<>();
for (File file : ioFiles) {
ContainerUtil.addIfNotNull(files, LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));
for (Path file : ioFiles) {
ContainerUtil.addIfNotNull(files, LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(file.toString())));
}
return files;
}
@@ -16,9 +16,9 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PathUtil;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.graph.*;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.Tag;
@@ -29,6 +29,9 @@ import org.jetbrains.annotations.NotNull;
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.*;
/**
@@ -39,7 +42,7 @@ public class ConversionServiceImpl extends ConversionService {
@NotNull
@Override
public ConversionResult convertSilently(@NotNull String projectPath) {
public ConversionResult convertSilently(@NotNull Path projectPath) {
return convertSilently(projectPath, new ConversionListener() {
@Override
public void conversionNeeded() {
@@ -61,7 +64,7 @@ public class ConversionServiceImpl extends ConversionService {
@NotNull
@Override
public ConversionResult convertSilently(@NotNull String projectPath, @NotNull ConversionListener listener) {
public ConversionResult convertSilently(@NotNull Path projectPath, @NotNull ConversionListener listener) {
try {
if (!isConversionNeeded(projectPath)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
@@ -71,14 +74,14 @@ public class ConversionServiceImpl extends ConversionService {
ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = getConversionRunners(context);
Set<File> affectedFiles = new HashSet<>();
Set<Path> affectedFiles = new HashSet<>();
for (ConversionRunner runner : runners) {
affectedFiles.addAll(runner.getAffectedFiles());
}
final List<File> readOnlyFiles = ConversionRunner.getReadOnlyFiles(affectedFiles);
final List<Path> readOnlyFiles = ConversionRunner.getReadOnlyFiles(affectedFiles);
if (!readOnlyFiles.isEmpty()) {
listener.cannotWriteToFiles(readOnlyFiles);
listener.cannotWriteToFiles(ContainerUtil.map(readOnlyFiles, path -> path.toFile()));
return ConversionResultImpl.ERROR_OCCURRED;
}
final File backupDir = ProjectConversionUtil.backupFiles(affectedFiles, context.getProjectBaseDir());
@@ -104,13 +107,13 @@ public class ConversionServiceImpl extends ConversionService {
@NotNull
@Override
public ConversionResult convert(@NotNull VirtualFile projectPath) {
public ConversionResult convert(@NotNull Path projectPath) {
try {
if (!projectPath.isValid() || ApplicationManager.getApplication().isHeadlessEnvironment()) {
if (!Files.exists(projectPath) || ApplicationManager.getApplication().isHeadlessEnvironment()) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
}
final ConversionContextImpl context = new ConversionContextImpl(projectPath.getPath());
final ConversionContextImpl context = new ConversionContextImpl(projectPath);
if (!isConversionNeeded(context)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
}
@@ -159,7 +162,7 @@ public class ConversionServiceImpl extends ConversionService {
return converters;
}
private static boolean isConversionNeeded(String projectPath) throws CannotConvertException {
private static boolean isConversionNeeded(@NotNull Path projectPath) throws CannotConvertException {
return isConversionNeeded(new ConversionContextImpl(projectPath));
}
@@ -243,7 +246,7 @@ public class ConversionServiceImpl extends ConversionService {
}
@Override
public void saveConversionResult(@NotNull String projectPath) {
public void saveConversionResult(@NotNull Path projectPath) {
try {
saveConversionResult(new ConversionContextImpl(projectPath));
}
@@ -290,10 +293,10 @@ public class ConversionServiceImpl extends ConversionService {
@Override
@NotNull
public ConversionResult convertModule(@NotNull final Project project, @NotNull final File moduleFile) {
public ConversionResult convertModule(@NotNull final Project project, @NotNull final Path moduleFile) {
final String url = project.getPresentableUrl();
assert url != null : project;
final String projectPath = FileUtil.toSystemDependentName(url);
final Path projectPath = Paths.get(url);
if (!isConversionNeeded(projectPath, moduleFile)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
@@ -304,8 +307,8 @@ public class ConversionServiceImpl extends ConversionService {
if (res != Messages.YES) {
return ConversionResultImpl.CONVERSION_CANCELED;
}
if (!moduleFile.canWrite()) {
Messages.showErrorDialog(project, IdeBundle.message("error.message.cannot.modify.file.0", moduleFile.getAbsolutePath()),
if (!Files.isWritable(moduleFile)) {
Messages.showErrorDialog(project, IdeBundle.message("error.message.cannot.modify.file.0", moduleFile.toAbsolutePath().toString()),
IdeBundle.message("dialog.title.convert.module"));
return ConversionResultImpl.ERROR_OCCURRED;
}
@@ -337,7 +340,7 @@ public class ConversionServiceImpl extends ConversionService {
}
}
private static boolean isConversionNeeded(String projectPath, File moduleFile) {
private static boolean isConversionNeeded(Path projectPath, Path moduleFile) {
try {
ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = createConversionRunners(context, Collections.emptySet());
@@ -1,14 +1,14 @@
// 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.checkout;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.platform.PlatformProjectOpenProcessor;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;
/**
@@ -17,21 +17,20 @@ import java.util.EnumSet;
public class ProjectDirCheckoutListener implements CheckoutListener {
@Override
public boolean processCheckedOutDirectory(Project project, File directory) {
File ioDotIdea = new File(directory, Project.DIRECTORY_STORE_FOLDER);
VirtualFile dotIdea = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioDotIdea);
Path dotIdea = directory.toPath().resolve(Project.DIRECTORY_STORE_FOLDER);
// todo Rider project layout - several.idea.solution-name names
if (dotIdea == null) return false;
if (!Files.exists(dotIdea)) {
return false;
}
String message = VcsBundle.message("checkout.open.project.dir.prompt",
ProjectCheckoutListener.getProductNameWithArticle(), directory.getPath());
if (Messages.showYesNoDialog(project, message, VcsBundle.message("checkout.title"), Messages.getQuestionIcon()) == Messages.YES) {
PlatformProjectOpenProcessor.doOpenProject(dotIdea.getParent(), project, -1, null,
PlatformProjectOpenProcessor.doOpenProject(dotIdea.getParent(), project, -1, null,
EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class));
return true;
}
return false;
}
@@ -1,26 +0,0 @@
// 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.impl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.platform.ProjectBaseDirectory;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class BasicDefaultVcsRootPolicy extends DefaultVcsRootPolicy {
public BasicDefaultVcsRootPolicy(@NotNull Project project) {
super(project);
}
@Override
@NotNull
public Collection<VirtualFile> getDefaultVcsRoots() {
List<VirtualFile> result = new ArrayList<>();
final VirtualFile baseDir = ProjectBaseDirectory.getInstance(myProject).getBaseDir(myProject.getBaseDir());
if (baseDir != null) result.add(baseDir);
return result;
}
}
@@ -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.platform;
import com.intellij.openapi.application.ApplicationManager;
@@ -6,17 +6,22 @@ import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.VcsDirectoryMapping;
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.util.Collections.singletonList;
/**
* @author yole
*/
public class PlatformVcsDetector implements ProjectComponent {
public final class PlatformVcsDetector implements ProjectComponent {
private final Project myProject;
private final ProjectLevelVcsManagerImpl myVcsManager;
@@ -27,17 +32,27 @@ public class PlatformVcsDetector implements ProjectComponent {
@Override
public void projectOpened() {
//noinspection CodeBlock2Expr
StartupManager.getInstance(myProject).runWhenProjectIsInitialized((DumbAwareRunnable)() -> {
final Runnable runnable = () -> {
VirtualFile file = ProjectBaseDirectory.getInstance(myProject).getBaseDir(myProject.getBaseDir());
if (myVcsManager.needAutodetectMappings()) {
AbstractVcs vcs = myVcsManager.findVersioningVcs(file);
if (vcs != null && vcs != myVcsManager.getVcsFor(file)) {
myVcsManager.setAutoDirectoryMappings(singletonList(new VcsDirectoryMapping(file.getPath(), vcs.getName())));
ApplicationManager.getApplication().invokeLater(() -> {
String projectBasePath = myProject.getBasePath();
if (projectBasePath == null) {
return;
}
Path file = ProjectBaseDirectory.getInstance(myProject).getBaseDir(Paths.get(projectBasePath));
if (!myVcsManager.needAutodetectMappings()) {
return;
}
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(file.toString()));
if (virtualFile != null) {
AbstractVcs vcs = myVcsManager.findVersioningVcs(virtualFile);
if (vcs != null && vcs != myVcsManager.getVcsFor(virtualFile)) {
myVcsManager.setAutoDirectoryMappings(singletonList(new VcsDirectoryMapping(virtualFile.getPath(), vcs.getName())));
}
}
};
ApplicationManager.getApplication().invokeLater(runnable, o -> (!myProject.isOpen()) || myProject.isDisposed());
}, o -> (!myProject.isOpen()) || myProject.isDisposed());
});
}
}
@@ -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.appengine.converter;
import com.intellij.conversion.ProjectConversionTestUtil;
@@ -20,8 +6,6 @@ import com.intellij.conversion.impl.ProjectConversionUtil;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
@@ -37,15 +21,10 @@ public class AppEngineFacetConverterTest extends PlatformTestCase {
File testData = PathManagerEx.findFileUnderProjectHome(testDataPath + "before", getClass());
File tempDir = FileUtil.createTempDirectory("app-engine-project", null);
FileUtil.copyDir(testData, tempDir);
ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());
ProjectConversionTestUtil.convert(tempDir.toPath().toAbsolutePath());
File expectedDataDir = PathManagerEx.findFileUnderProjectHome(testDataPath + "after", getClass());
PlatformTestUtil.assertDirectoriesEqual(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
new VirtualFileFilter() {
@Override
public boolean accept(VirtualFile file) {
return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
}
});
file -> !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP));
}
}