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;
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class SvnExternalTest method testSimpleExternalsStatus.
@Test
public void testSimpleExternalsStatus() 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();
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());
}
use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.
the class GitCheckoutProvider method doCheckout.
public void doCheckout(@NotNull final Project project, @Nullable final Listener listener, @Nullable String predefinedRepositoryUrl) {
BasicAction.saveAll();
GitCloneDialog dialog = new GitCloneDialog(project, predefinedRepositoryUrl);
if (!dialog.showAndGet()) {
return;
}
dialog.rememberSettings();
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final File parent = new File(dialog.getParentDirectory());
VirtualFile destinationParent = lfs.findFileByIoFile(parent);
if (destinationParent == null) {
destinationParent = lfs.refreshAndFindFileByIoFile(parent);
}
if (destinationParent == null) {
return;
}
final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
final String directoryName = dialog.getDirectoryName();
final String parentDirectory = dialog.getParentDirectory();
clone(project, myGit, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory);
}
Aggregations