use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class StartupManagerImpl method checkProjectRoots.
private void checkProjectRoots() {
VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots();
if (roots.length == 0)
return;
LocalFileSystem fs = LocalFileSystem.getInstance();
if (!(fs instanceof LocalFileSystemImpl))
return;
FileWatcher watcher = ((LocalFileSystemImpl) fs).getFileWatcher();
if (!watcher.isOperational())
return;
PooledThreadExecutor.INSTANCE.submit(() -> {
LOG.debug("FW/roots waiting started");
while (true) {
if (myProject.isDisposed())
return;
if (!watcher.isSettingRoots())
break;
TimeoutUtil.sleep(10);
}
LOG.debug("FW/roots waiting finished");
Collection<String> manualWatchRoots = watcher.getManualWatchRoots();
if (!manualWatchRoots.isEmpty()) {
List<String> nonWatched = new SmartList<>();
for (VirtualFile root : roots) {
if (!(root.getFileSystem() instanceof LocalFileSystem))
continue;
String rootPath = root.getPath();
for (String manualWatchRoot : manualWatchRoots) {
if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) {
nonWatched.add(rootPath);
}
}
}
if (!nonWatched.isEmpty()) {
String message = ApplicationBundle.message("watcher.non.watchable.project");
watcher.notifyOnFailure(message, null);
LOG.info("unwatched roots: " + nonWatched);
LOG.info("manual watches: " + manualWatchRoots);
}
}
});
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class ChangesUtil method getValidParentUnderReadAction.
@Nullable
private static VirtualFile getValidParentUnderReadAction(@NotNull FilePath filePath) {
return ReadAction.compute(() -> {
VirtualFile result = null;
FilePath parent = filePath;
LocalFileSystem lfs = LocalFileSystem.getInstance();
while (result == null && parent != null) {
result = lfs.findFileByPath(parent.getPath());
parent = parent.getParentPath();
}
return result;
});
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class ConfigFileFactoryImpl method createFileFromTemplate.
@Nullable
private VirtualFile createFileFromTemplate(@Nullable final Project project, String url, final String templateName, final boolean forceNew) {
final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
final File file = new File(VfsUtilCore.urlToPath(url));
VirtualFile existingFile = fileSystem.refreshAndFindFileByIoFile(file);
if (existingFile != null) {
existingFile.refresh(false, false);
if (!existingFile.isValid()) {
existingFile = null;
}
}
if (existingFile != null && !forceNew) {
return existingFile;
}
try {
String text = getText(templateName, project);
final VirtualFile childData;
if (existingFile == null || existingFile.isDirectory()) {
final VirtualFile virtualFile;
if (!FileUtil.createParentDirs(file) || (virtualFile = fileSystem.refreshAndFindFileByIoFile(file.getParentFile())) == null) {
throw new IOException(IdeBundle.message("error.message.unable.to.create.file", file.getPath()));
}
childData = virtualFile.createChildData(this, file.getName());
} else {
childData = existingFile;
}
VfsUtil.saveText(childData, text);
return childData;
} catch (final IOException e) {
LOG.info(e);
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("message.text.error.creating.deployment.descriptor", e.getLocalizedMessage()), IdeBundle.message("message.text.creating.deployment.descriptor")));
}
return null;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class SvnBranchConfigurationManager method resolveAllBranchPoints.
@NotNull
private Set<Pair<VirtualFile, SvnBranchConfigurationNew>> resolveAllBranchPoints() {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final UrlSerializationHelper helper = new UrlSerializationHelper(SvnVcs.getInstance(myProject));
final Set<Pair<VirtualFile, SvnBranchConfigurationNew>> branchPointsToLoad = ContainerUtil.newHashSet();
for (Map.Entry<String, SvnBranchConfiguration> entry : myConfigurationBean.myConfigurationMap.entrySet()) {
final SvnBranchConfiguration configuration = entry.getValue();
final VirtualFile root = lfs.refreshAndFindFileByIoFile(new File(entry.getKey()));
if (root == null) {
LOG.info("root not found: " + entry.getKey());
continue;
}
final SvnBranchConfiguration configToConvert;
if ((!myConfigurationBean.mySupportsUserInfoFilter) || configuration.isUserinfoInUrl()) {
configToConvert = helper.afterDeserialization(entry.getKey(), configuration);
} else {
configToConvert = configuration;
}
final SvnBranchConfigurationNew newConfig = new SvnBranchConfigurationNew();
newConfig.setTrunkUrl(configToConvert.getTrunkUrl());
newConfig.setUserinfoInUrl(configToConvert.isUserinfoInUrl());
for (String branchUrl : configToConvert.getBranchUrls()) {
List<SvnBranchItem> stored = getStored(branchUrl);
if (stored != null && !stored.isEmpty()) {
newConfig.addBranches(branchUrl, new InfoStorage<>(stored, InfoReliability.setByUser));
} else {
branchPointsToLoad.add(Pair.create(root, newConfig));
newConfig.addBranches(branchUrl, new InfoStorage<>(new ArrayList<>(), InfoReliability.empty));
}
}
myBunch.updateForRoot(root, new InfoStorage<>(newConfig, InfoReliability.setByUser), false);
}
return branchPointsToLoad;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class HgUtil method convertToLocalVirtualFile.
/**
* Convert {@link VcsVirtualFile} to the {@link LocalFileSystem local} Virtual File.
*
* TODO
* It is a workaround for the following problem: VcsVirtualFiles returned from the {@link FileHistoryPanelImpl} contain the current path
* of the file, not the path that was in certain revision. This has to be fixed by making {@link HgFileRevision} implement
* {@link VcsFileRevisionEx}.
*/
@Nullable
public static VirtualFile convertToLocalVirtualFile(@Nullable VirtualFile file) {
if (!(file instanceof AbstractVcsVirtualFile)) {
return file;
}
LocalFileSystem lfs = LocalFileSystem.getInstance();
VirtualFile resultFile = lfs.findFileByPath(file.getPath());
if (resultFile == null) {
resultFile = lfs.refreshAndFindFileByPath(file.getPath());
}
return resultFile;
}
Aggregations