Search in sources :

Example 41 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with LocalFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with LocalFileSystem

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Change(com.intellij.openapi.vcs.changes.Change) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Test(org.junit.Test)

Example 45 with LocalFileSystem

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)52 File (java.io.File)27 Nullable (org.jetbrains.annotations.Nullable)9 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)6 Project (com.intellij.openapi.project.Project)5 Change (com.intellij.openapi.vcs.changes.Change)5 Test (org.junit.Test)5 Module (com.intellij.openapi.module.Module)4 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 PsiFile (com.intellij.psi.PsiFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2