Search in sources :

Example 51 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 52 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)

Example 53 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class GitRepositoryFiles method getMainGitDirForWorktree.

/**
   * Checks if the given .git directory is actually a worktree's git directory, and returns the main .git directory if it is true.
   * If it is not a worktree, returns null.
   * <p/>
   * Worktree's ".git" file references {@code <main-project>/.git/worktrees/<worktree-name>}
   */
@Nullable
private static VirtualFile getMainGitDirForWorktree(@NotNull VirtualFile gitDir) {
    File gitDirFile = virtualToIoFile(gitDir);
    File commonDir = new File(gitDirFile, "commondir");
    if (!commonDir.exists())
        return null;
    String pathToMain;
    try {
        pathToMain = FileUtil.loadFile(commonDir).trim();
    } catch (IOException e) {
        LOG.error("Couldn't load " + commonDir, e);
        return null;
    }
    String mainDir = FileUtil.toCanonicalPath(gitDirFile.getPath() + File.separator + pathToMain, true);
    LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile mainDirVF = lfs.refreshAndFindFileByPath(mainDir);
    if (mainDirVF != null)
        return mainDirVF;
    // absolute path is also possible
    return lfs.refreshAndFindFileByPath(pathToMain);
}
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) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with LocalFileSystem

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Change(com.intellij.openapi.vcs.changes.Change) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) SvnDiffProvider(org.jetbrains.idea.svn.SvnDiffProvider) Test(org.junit.Test)

Example 55 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class EclipseUserLibrariesHelper method readProjectLibrariesContent.

public static void readProjectLibrariesContent(@NotNull VirtualFile exportedFile, Project project, Collection<String> unknownLibraries) throws IOException, JDOMException {
    if (!exportedFile.isValid()) {
        return;
    }
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    Element element = JDOMUtil.load(exportedFile.getInputStream());
    WriteAction.run(() -> {
        for (Element libElement : element.getChildren("library")) {
            String libName = libElement.getAttributeValue("name");
            Library libraryByName = libraryTable.getLibraryByName(libName);
            if (libraryByName == null) {
                LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
                libraryByName = model.createLibrary(libName);
                model.commit();
            }
            if (libraryByName != null) {
                Library.ModifiableModel model = libraryByName.getModifiableModel();
                for (Element a : libElement.getChildren("archive")) {
                    String rootPath = a.getAttributeValue("path");
                    // IDEA-138039 Eclipse import: Unix file system: user library gets wrong paths
                    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
                    VirtualFile localFile = fileSystem.findFileByPath(rootPath);
                    if (rootPath.startsWith("/") && (localFile == null || !localFile.isValid())) {
                        // relative to workspace root
                        rootPath = project.getBaseDir().getPath() + rootPath;
                        localFile = fileSystem.findFileByPath(rootPath);
                    }
                    String url = localFile == null ? VfsUtilCore.pathToUrl(rootPath) : localFile.getUrl();
                    if (localFile != null) {
                        VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
                        if (jarFile != null) {
                            url = jarFile.getUrl();
                        }
                    }
                    model.addRoot(url, OrderRootType.CLASSES);
                }
                model.commit();
            }
            //ignore finally found libraries
            unknownLibraries.remove(libName);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Element(org.jdom.Element) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 File (java.io.File)32 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)7 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 Library (com.intellij.openapi.roots.libraries.Library)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 PsiFile (com.intellij.psi.PsiFile)4 Application (com.intellij.openapi.application.Application)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2