use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class FileDropHandler method openFiles.
private void openFiles(final Project project, final List<File> fileList, EditorWindow editorWindow) {
if (editorWindow == null && myEditor != null) {
editorWindow = findEditorWindow(project);
}
final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
for (File file : fileList) {
final VirtualFile vFile = fileSystem.refreshAndFindFileByIoFile(file);
final FileEditorManagerEx fileEditorManager = (FileEditorManagerEx) FileEditorManager.getInstance(project);
if (vFile != null) {
NonProjectFileWritingAccessProvider.allowWriting(vFile);
if (editorWindow != null) {
fileEditorManager.openFileWithProviders(vFile, true, editorWindow);
} else {
new OpenFileDescriptor(project, vFile).navigate(true);
}
}
}
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class RootFileElement method getFileSystemRoots.
private static VirtualFile[] getFileSystemRoots() {
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final Set<VirtualFile> roots = new HashSet<>();
final File[] ioRoots = File.listRoots();
if (ioRoots != null) {
for (final File root : ioRoots) {
final String path = FileUtil.toSystemIndependentName(root.getAbsolutePath());
final VirtualFile file = localFileSystem.findFileByPath(path);
if (file != null) {
roots.add(file);
}
}
}
return VfsUtilCore.toVirtualFileArray(roots);
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class EclipseImportBuilder method commit.
@Override
public List<Module> commit(final Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) {
final Collection<String> unknownLibraries = new TreeSet<>();
final Collection<String> unknownJdks = new TreeSet<>();
final Set<String> refsToModules = new HashSet<>();
final List<Module> result = new ArrayList<>();
final Map<Module, Set<String>> module2NatureNames = new HashMap<>();
try {
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
final ModifiableRootModel[] rootModels = new ModifiableRootModel[getParameters().projectsToConvert.size()];
final Set<File> files = new HashSet<>();
final Set<String> moduleNames = new THashSet<>(getParameters().projectsToConvert.size());
for (String path : getParameters().projectsToConvert) {
String modulesDirectory = getParameters().converterOptions.commonModulesDirectory;
if (modulesDirectory == null) {
modulesDirectory = path;
}
final String moduleName = EclipseProjectFinder.findProjectName(path);
moduleNames.add(moduleName);
final File imlFile = new File(modulesDirectory + File.separator + moduleName + ModuleManagerImpl.IML_EXTENSION);
if (imlFile.isFile()) {
files.add(imlFile);
}
final File emlFile = new File(modulesDirectory + File.separator + moduleName + EclipseXml.IDEA_SETTINGS_POSTFIX);
if (emlFile.isFile()) {
files.add(emlFile);
}
}
if (!files.isEmpty()) {
final int resultCode = Messages.showYesNoCancelDialog(ApplicationNamesInfo.getInstance().getFullProductName() + " module files found:\n" + StringUtil.join(files, file -> file.getPath(), "\n") + ".\n Would you like to reuse them?", "Module Files Found", Messages.getQuestionIcon());
if (resultCode != Messages.YES) {
if (resultCode == Messages.NO) {
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
for (File file : files) {
final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file);
if (virtualFile != null) {
ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Void, IOException>() {
@Override
public Void compute() throws IOException {
virtualFile.delete(this);
return null;
}
});
} else {
FileUtil.delete(file);
}
}
} else {
return result;
}
}
}
int idx = 0;
for (String path : getParameters().projectsToConvert) {
String modulesDirectory = getParameters().converterOptions.commonModulesDirectory;
if (modulesDirectory == null) {
modulesDirectory = path;
}
final Module module = moduleModel.newModule(modulesDirectory + "/" + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId());
result.add(module);
final Set<String> natures = collectNatures(path);
if (natures.size() > 0) {
module2NatureNames.put(module, natures);
}
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
rootModels[idx++] = rootModel;
final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, getParameters().projectsToConvert, moduleNames);
classpathReader.init(rootModel);
if (classpathFile.exists()) {
Element classpathElement = JDOMUtil.load(classpathFile);
classpathReader.readClasspath(rootModel, unknownLibraries, unknownJdks, refsToModules, getParameters().converterOptions.testPattern, classpathElement);
} else {
EclipseClasspathReader.setOutputUrl(rootModel, path + "/bin");
}
ClasspathStorage.setStorageType(rootModel, getParameters().linkConverted ? JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID : ClassPathStorageUtil.DEFAULT_STORAGE);
if (model != null) {
ApplicationManager.getApplication().runWriteAction(() -> rootModel.commit());
}
}
if (model == null) {
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(rootModels, moduleModel));
}
} catch (Exception e) {
LOG.error(e);
}
scheduleNaturesImporting(project, module2NatureNames);
createEclipseLibrary(project, unknownLibraries, IdeaXml.ECLIPSE_LIBRARY);
StringBuilder message = new StringBuilder();
refsToModules.removeAll(getParameters().existingModuleNames);
for (String path : getParameters().projectsToConvert) {
final String projectName = EclipseProjectFinder.findProjectName(path);
if (projectName != null) {
refsToModules.remove(projectName);
getParameters().existingModuleNames.add(projectName);
}
}
if (!refsToModules.isEmpty()) {
message.append("Unknown modules detected");
for (String module : refsToModules) {
message.append("\n").append(module);
}
}
if (!unknownJdks.isEmpty()) {
if (message.length() > 0) {
message.append("\nand jdks");
} else {
message.append("Imported project refers to unknown jdks");
}
for (String unknownJdk : unknownJdks) {
message.append("\n").append(unknownJdk);
}
}
if (!unknownLibraries.isEmpty()) {
final StringBuilder buf = new StringBuilder();
buf.append("<html><body>");
buf.append(EclipseBundle.message("eclipse.import.warning.undefinded.libraries"));
for (String name : unknownLibraries) {
buf.append("<br>").append(name);
}
if (model == null) {
buf.append("<br><b>Please export Eclipse user libraries and import them now from resulted .userlibraries file</b>");
buf.append("</body></html>");
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
return super.isFileSelectable(file) && Comparing.strEqual(file.getExtension(), "userlibraries");
}
};
descriptor.setDescription(buf.toString());
descriptor.setTitle(getTitle());
final VirtualFile selectedFile = FileChooser.chooseFile(descriptor, project, project.getBaseDir());
if (selectedFile != null) {
try {
EclipseUserLibrariesHelper.readProjectLibrariesContent(selectedFile, project, unknownLibraries);
} catch (Exception e) {
LOG.error(e);
}
}
}
}
if (message.length() > 0) {
Messages.showErrorDialog(project, message.toString(), getTitle());
}
return result;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class SvnAnnotationIsClosedTest method testClosedByUpdateWithExternals.
@Test
public void testClosedByUpdateWithExternals() throws Exception {
prepareExternal();
final File sourceFile = new File(myWorkingCopyDir.getPath(), "source" + File.separator + "s1.txt");
final File externalFile = new File(myWorkingCopyDir.getPath(), "source" + File.separator + "external" + File.separator + "t12.txt");
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final VirtualFile vf1 = lfs.refreshAndFindFileByIoFile(sourceFile);
final VirtualFile vf2 = lfs.refreshAndFindFileByIoFile(externalFile);
Assert.assertNotNull(vf1);
Assert.assertNotNull(vf2);
VcsTestUtil.editFileInCommand(myProject, vf1, "test externals 123" + System.currentTimeMillis());
VcsTestUtil.editFileInCommand(myProject, vf2, "test externals 123" + System.currentTimeMillis());
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
myChangeListManager.ensureUpToDate(false);
final Change change1 = myChangeListManager.getChange(vf1);
final Change change2 = myChangeListManager.getChange(vf2);
Assert.assertNotNull(change1);
Assert.assertNotNull(change2);
final File sourceDir = new File(myWorkingCopyDir.getPath(), "source");
final File externalDir = new File(myWorkingCopyDir.getPath(), "source/external");
// #3
runInAndVerifyIgnoreOutput("ci", "-m", "test", sourceDir.getPath());
// #4
runInAndVerifyIgnoreOutput("ci", "-m", "test", externalDir.getPath());
VcsTestUtil.editFileInCommand(myProject, vf2, "test externals 12344444" + System.currentTimeMillis());
// #5
runInAndVerifyIgnoreOutput("ci", "-m", "test", externalDir.getPath());
final SvnDiffProvider diffProvider = (SvnDiffProvider) myVcs.getDiffProvider();
assertRevision(vf1, diffProvider, 3);
assertRevision(vf2, diffProvider, 5);
runInAndVerifyIgnoreOutput("up", "-r", "4", sourceDir.getPath());
runInAndVerifyIgnoreOutput("up", "-r", "4", externalDir.getPath());
assertRevision(vf1, diffProvider, 3);
assertRevision(vf2, diffProvider, 4);
// then annotate both
final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), vf1);
annotation.setCloser(() -> {
myIsClosed = true;
listener.unregisterAnnotation(vf1, annotation);
});
listener.registerAnnotation(vf1, annotation);
final FileAnnotation annotation1 = createTestAnnotation(myVcs.getAnnotationProvider(), vf2);
annotation1.setCloser(() -> {
myIsClosed1 = true;
listener.unregisterAnnotation(vf1, annotation1);
});
listener.registerAnnotation(vf1, annotation1);
//up
runInAndVerifyIgnoreOutput("up", sourceDir.getPath());
imitateEvent(lfs.refreshAndFindFileByIoFile(sourceDir));
imitateEvent(lfs.refreshAndFindFileByIoFile(externalDir));
myChangeListManager.ensureUpToDate(false);
// wait for after-events like annotations recalculation
myChangeListManager.ensureUpToDate(false);
// zipper updater
sleep(100);
//verify(runSvn("up", "-r", "3", externalDir.getPath()));
assertRevision(vf1, diffProvider, 3);
assertRevision(vf2, diffProvider, 5);
Assert.assertTrue(myIsClosed1);
// in source is not closed..
Assert.assertFalse(myIsClosed);
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class SvnExternalTest method simpleExternalStatusImpl.
private void simpleExternalStatusImpl() {
final File sourceFile = new File(myWorkingCopyDir.getPath(), "source" + File.separator + "s1.txt");
final File externalFile = new File(myWorkingCopyDir.getPath(), "source" + File.separator + "external" + File.separator + "t12.txt");
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final VirtualFile vf1 = lfs.refreshAndFindFileByIoFile(sourceFile);
final VirtualFile vf2 = lfs.refreshAndFindFileByIoFile(externalFile);
Assert.assertNotNull(vf1);
Assert.assertNotNull(vf2);
VcsTestUtil.editFileInCommand(myProject, vf1, "test externals 123" + System.currentTimeMillis());
VcsTestUtil.editFileInCommand(myProject, vf2, "test externals 123" + System.currentTimeMillis());
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
clManager.ensureUpToDate(false);
final Change change1 = clManager.getChange(vf1);
final Change change2 = clManager.getChange(vf2);
Assert.assertNotNull(change1);
Assert.assertNotNull(change2);
Assert.assertNotNull(change1.getBeforeRevision());
Assert.assertNotNull(change2.getBeforeRevision());
Assert.assertNotNull(change1.getAfterRevision());
Assert.assertNotNull(change2.getAfterRevision());
}
Aggregations