Java Code Examples for org.openide.filesystems.FileObject#move()

The following examples show how to use org.openide.filesystems.FileObject#move() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMoveWithAttributes() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    FileObject target = workDirFo.createFolder("target");
    FileObject folder = workDirFo.createFolder("a");
    folder.createData("non.empty");
    folder.setAttribute("name", "jmeno");
    assertEquals("jmeno", folder.getAttribute("name"));
    FileLock lock = folder.lock();
    FileObject newF = folder.move(lock, target, "b", null);
    assertFalse("Invalidated", folder.isValid());
    lock.releaseLock();
    assertEquals("Name is not b", "b", newF.getNameExt());
    WeakReference<?> ref = new WeakReference<FileObject>(newF);
    newF = null;
    assertGC("Folder can disappear", ref);
    folder = target.getFileObject("b");
    assertNotNull("Folder b found", folder);
    assertEquals("The attribute remains even after rename", "jmeno", folder.getAttribute("name"));
    assertEquals("One children", 1, folder.getChildren().length);
}
 
Example 2
Source File: ProjectManagerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRenameProjectFolder() throws Exception { // #194046
    FileObject p1 = scratch.createFolder("p1");
    p1.createFolder("testproject");
    Project project1 = pm.findProject(p1);
    FileObject p2;
    FileLock lock = p1.lock();
    try {
        p2 = p1.move(lock, scratch, "p2", null);
    } finally {
        lock.releaseLock();
    }
    assertEquals(p1, p2);
    Project project2 = pm.findProject(p2);
    TestUtil.notifyDeleted(project1);
    assertEquals(project2, pm.findProject(p2));
}
 
Example 3
Source File: InterceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void moveFO (File from, File to) throws DataObjectNotFoundException, IOException {
    FileObject foFrom = FileUtil.toFileObject(from);
    assertNotNull(foFrom);
    FileObject foTarget = FileUtil.toFileObject(to.getParentFile());
    assertNotNull(foTarget);
    FileLock lock = foFrom.lock();
    try {
        foFrom.move(lock, foTarget, to.getName(), null);
    } finally {
        lock.releaseLock();
    }
}
 
Example 4
Source File: JavaCustomIndexerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMoveClassLivingElseWhere() throws Exception {
    FileObject testFile = FileUtil.createData(src, "test/Test.java");
    TestUtilities.copyStringToFile(testFile, "package test2; public class Test {}");
    SourceUtilsTestUtil.compileRecursively(src);
    FileObject test2Package = FileUtil.createFolder(src, "test2");
    FileLock lock = testFile.lock();
    testFile.move(lock, test2Package, "Test", "java");
    lock.releaseLock();
    SourceUtilsTestUtil.compileRecursively(src);
    assertFalse(ErrorsCache.isInError(src, true));
}
 
Example 5
Source File: HgCommandTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDisableIBInFSEvents () throws Exception {
    CommandHandler handler = new CommandHandler();
    Mercurial.LOG.addHandler(handler);
    Mercurial.LOG.setLevel(Level.ALL);
    File file = createFile(getWorkTreeDir(), "aaa");
    commit(file);

    FileObject fo = FileUtil.toFileObject(file);

    fo.delete();
    assertEquals(FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file).getStatus());
    assertFalse(handler.commandInvoked);

    fo.getParent().createData(file.getName());
    assertNull(HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file));
    assertFalse(handler.commandInvoked);

    File copy = new File(file.getParentFile(), "copy");
    fo.copy(fo.getParent(), copy.getName(), "");
    assertEquals(FileInformation.STATUS_VERSIONED_ADDEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(copy), null, null).get(copy).getStatus());
    assertFalse(handler.commandInvoked);

    File renamed = new File(file.getParentFile(), "renamed");
    FileLock lock = fo.lock();
    fo.move(lock, fo.getParent(), renamed.getName(), "");
    lock.releaseLock();
    assertEquals(FileInformation.STATUS_VERSIONED_ADDEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(renamed), null, null).get(renamed).getStatus());
    assertEquals(FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file).getStatus());
    assertFalse(handler.commandInvoked);
}
 
Example 6
Source File: PropertiesFileEntry.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Moves entry to folder. Overrides superclass method. 
 * @param folder folder where copy
 * @param suffix suffix to use 
 * @exception IOException when error happens */
@Override
public FileObject move(FileObject folder, String suffix) throws IOException {
    if (LOG.isLoggable(FINER)) {
        LOG.finer("move("                                           //NOI18N
                  + FileUtil.getFileDisplayName(folder) + ", "      //NOI18N
                  + (suffix != null ? '"' + suffix + '"' : "<null>")//NOI18N
                  + ')');
    }
    String pasteSuffix = ((PropertiesDataObject)getDataObject()).getPasteSuffix();

    if(pasteSuffix == null)
        return super.move(folder, suffix);

    boolean wasLocked = isLocked();

    FileObject fileObject = getFile();
    FileLock lock = takeLock ();

    try {
        String basicName = getDataObject().getPrimaryFile().getName();
        String newName = basicName + pasteSuffix + Util.getLocaleSuffix(this);

        detachListener();
        FileObject fo = fileObject.move (lock, folder, newName, fileObject.getExt());
        attachListener(fo);
        return fo;
    } finally {
        if (!wasLocked) {
            lock.releaseLock ();
        }
    }
}
 
Example 7
Source File: AfterDeleteAfterMoveEndsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testExternalyMoved() throws IOException {
    FileObject fo = getVersionedFolder();
    FileObject fromFile = fo.createData("move.txt");
    FileObject toFolder = fo.createFolder("toFolder");
    
    fo.addFileChangeListener(new FileChangeAdapter());
    inteceptor.startAcceptingEvents = true;
    FileObject toFile = fromFile.move(fromFile.lock(), toFolder, fromFile.getName(), fromFile.getExt());
    
    VCSFileProxy fromProxy = VCSFileProxy.createFileProxy(fromFile);
    VCSFileProxy toProxy = VCSFileProxy.createFileProxy(toFile);
    assertEquals(ExternalyMovedInterceptor.DO_MOVE  + " from " + fromProxy + " " + toProxy, inteceptor.events.get(0));
    assertEquals(ExternalyMovedInterceptor.TIMEDOUT + " from " + fromProxy + " " + toProxy, inteceptor.events.get(1));
    
}
 
Example 8
Source File: VCSInterceptorTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFolderTreeMoved() throws IOException {
    inteceptor.moveHandler = moveHandler;
    FileObject fo = getVersionedFolder();
    FileObject fromFolder = fo.createFolder("fromFolder");
    FileObject movedChild = fromFolder.createData("movedChild");
    FileObject targetFolder = fo.createFolder("targetFolder");
    VCSFileProxy fromProxy = VCSFileProxy.createFileProxy(fromFolder);
    
    logHandler.clear();
    logHandler.ignoredMessages.add(createdExternalyFormat);
    logHandler.ignoredMessages.add(deletedExternalyFormat);
    FileObject toFile = fromFolder.move(fromFolder.lock(), targetFolder, fromFolder.getName(), fromFolder.getExt());
    VCSFileProxy toProxy = VCSFileProxy.createFileProxy(toFile);

    assertTrue(inteceptor.getBeforeMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getBeforeMoveFiles().contains(toProxy));
    assertTrue(inteceptor.getDoMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getDoMoveFiles().contains(toProxy));
    assertTrue(inteceptor.getAfterMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getAfterMoveFiles().contains(toProxy));
    
    assertInterceptedCalls(
//        f(fileLockedFormat, fromProxy); // no lock on folder
        f(getMoveHandlerFormat, fromProxy, toProxy),
        f(moveHandleFormat, fromProxy, toProxy),
//        f(deletedExternalyFormat, toProxy); // XXX can we avoid this? sometimes deleted or created externaly 
        f(afterMoveFormat, fromProxy, toProxy)
    );
}
 
Example 9
Source File: VCSInterceptorTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFileMoved() throws IOException {
    inteceptor.moveHandler = moveHandler;
    FileObject fo = getVersionedFolder();
    FileObject fromFile = fo.createData("move.txt");
    FileObject toFolder = fo.createFolder("toFolder");
    VCSFileProxy fromProxy = VCSFileProxy.createFileProxy(fromFile);
    
    logHandler.clear();
    logHandler.ignoredMessages.add(createdExternalyFormat);
    logHandler.ignoredMessages.add(deletedExternalyFormat);
    
    FileObject toFile = fromFile.move(fromFile.lock(), toFolder, fromFile.getName(), fromFile.getExt());
    VCSFileProxy toProxy = VCSFileProxy.createFileProxy(toFile);

    assertTrue(inteceptor.getBeforeMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getBeforeMoveFiles().contains(toProxy));
    assertTrue(inteceptor.getDoMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getDoMoveFiles().contains(toProxy));
    assertTrue(inteceptor.getAfterMoveFiles().contains(fromProxy));
    assertTrue(inteceptor.getAfterMoveFiles().contains(toProxy));
    
    assertInterceptedCalls(
        f(fileLockedFormat, fromProxy),
        f(getMoveHandlerFormat, fromProxy, toProxy),
        f(moveHandleFormat, fromProxy, toProxy),
//        f(deletedExternalyFormat, toProxy); // XXX can we avoid this? sometimes deleted or created externaly 
        f(afterMoveFormat, fromProxy, toProxy)
    );

}
 
Example 10
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void moveFO(File from, File to) throws DataObjectNotFoundException, IOException {
    FileObject foFrom = FileUtil.toFileObject(from);
    assertNotNull(foFrom);
    FileObject foTarget = FileUtil.toFileObject(to.getParentFile());
    assertNotNull(foTarget);
    FileLock lock = foFrom.lock();
    try {
        foFrom.move(lock, foTarget, to.getName(), null);
    } finally {
        lock.releaseLock();
    }        
}
 
Example 11
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void moveFO(File from, File to) throws DataObjectNotFoundException, IOException {
    FileObject foFrom = FileUtil.toFileObject(from);
    assertNotNull(foFrom);
    FileObject foTarget = FileUtil.toFileObject(to.getParentFile());
    assertNotNull(foTarget);
    FileLock lock = foFrom.lock();
    try {
        foFrom.move(lock, foTarget, to.getName(), null);
    } finally {
        lock.releaseLock();
    }
}
 
Example 12
Source File: GitClientTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDisableIBInFSEvents () throws Exception {
    File file = new File(repositoryLocation, "aaa");
    file.createNewFile();
    final GitClient client = Git.getInstance().getClient(repositoryLocation);
    client.add(new File[] { file }, GitUtils.NULL_PROGRESS_MONITOR);
    client.commit(new File[] { file }, "msg", null, null, GitUtils.NULL_PROGRESS_MONITOR);

    FileObject fo = FileUtil.toFileObject(file);
    Git.LOG.setLevel(Level.ALL);
    LogHandler handler = new LogHandler();
    Git.LOG.addHandler(handler);

    assertTrue(client.getStatus(new File[] { file }, GitUtils.NULL_PROGRESS_MONITOR).get(file).getStatusHeadIndex() == GitStatus.Status.STATUS_NORMAL);
    fo.delete();
    assertTrue(client.getStatus(new File[] { file }, GitUtils.NULL_PROGRESS_MONITOR).get(file).getStatusHeadIndex() == GitStatus.Status.STATUS_REMOVED);
    assertFalse(handler.indexingBridgeCalled);

    fo.getParent().createData(file.getName());
    assertTrue(client.getStatus(new File[] { file }, GitUtils.NULL_PROGRESS_MONITOR).get(file).getStatusHeadIndex() == GitStatus.Status.STATUS_NORMAL);
    assertFalse(handler.indexingBridgeCalled);

    File copy = new File(repositoryLocation, "copy");
    fo.copy(fo.getParent(), copy.getName(), "");
    assertTrue(client.getStatus(new File[] { copy }, GitUtils.NULL_PROGRESS_MONITOR).get(copy).getStatusHeadIndex() == GitStatus.Status.STATUS_ADDED);
    assertFalse(handler.indexingBridgeCalled);

    File renamed = new File(repositoryLocation, "renamed");
    FileLock lock = fo.lock();
    fo.move(lock, fo.getParent(), renamed.getName(), "");
    lock.releaseLock();
    assertTrue(client.getStatus(new File[] { file }, GitUtils.NULL_PROGRESS_MONITOR).get(file).getStatusHeadIndex() == GitStatus.Status.STATUS_REMOVED);
    assertTrue(client.getStatus(new File[] { renamed }, GitUtils.NULL_PROGRESS_MONITOR).get(renamed).getStatusHeadIndex() == GitStatus.Status.STATUS_ADDED);
    assertFalse(handler.indexingBridgeCalled);
}
 
Example 13
Source File: ProvidedExtensionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMove_BeforeSuccessFailure() throws IOException {
    FileObject fromFolder = FileUtil.toFileObject(getWorkDir()).createFolder("moveFrom");
    FileObject toFolder = FileUtil.toFileObject(getWorkDir()).createFolder("moveTo");
    assertNotNull(fromFolder);
    assertNotNull(toFolder);
    FileObject toMove = fromFolder.createData("aa");
    assertNotNull(toMove);
    iListener.clear();

    assertNotNull(iListener);
    assertEquals(0,iListener.beforeMoveCalls);
    assertEquals(0,iListener.moveSuccessCalls);
    assertEquals(0,iListener.moveFailureCalls);

    // move
    FileLock lock = toMove.lock();
    toMove.move(lock, toFolder, toMove.getName(), toMove.getExt());
    assertFalse(toMove.isValid());
    assertEquals(1,iListener.beforeMoveCalls);
    assertEquals(1,iListener.moveSuccessCalls);

    iListener.clear();
    try {
        // success
        assertEquals(0,iListener.moveSuccessCalls);
        assertEquals(0,iListener.moveFailureCalls);

        // move to itself => failure
        toMove.move(lock, toFolder, toMove.getName(), toMove.getExt());
        fail();
    } catch (IOException ex) {
        // failure
        assertEquals(0,iListener.moveSuccessCalls);
        assertEquals(1,iListener.moveFailureCalls);
    }
}
 
Example 14
Source File: MoveUnlocksWatcherTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMovedUnlocks() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    FileObject fromFile = fo.createData("move.txt");
    FileObject toFolder = fo.createFolder("toFolder");
    
    FileObject toFile = fromFile.move(fromFile.lock(), toFolder, fromFile.getName(), fromFile.getExt());

    assertFalse("Not locked anymore: " + fo, Watcher.isLocked(fo));
    assertFalse("Not locked anymore: " + fromFile, Watcher.isLocked(fromFile));
    assertFalse("Not locked anymore: " + toFolder, Watcher.isLocked(toFolder));
    assertFalse("Not locked anymore: " + toFile, Watcher.isLocked(toFile));
}
 
Example 15
Source File: Deadlock73332Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDeadLock() throws Exception {
    assertNotNull(folder);
    assertTrue(folder instanceof BaseFileObj);
    FileObject data = FileUtil.createData(folder, "/a/b/c/data.txt");
    assertNotNull(data);
    FileLock lock = data.lock();
    try {
        data.move(lock,folder, data.getName(), data.getExt());
    } finally {
        lock.releaseLock();
    }
}
 
Example 16
Source File: BaseFileObjectTestHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMoveOfAFolderDoesNotTouchSubhierarchy() throws Exception {
    FileObjectFactory fs = FileObjectFactory.getInstance(getWorkDir());
    assertNotNull(fs);
    FileObject root1 = fs.getValidFileObject(getWorkDir(), FileObjectFactory.Caller.Others);

    FileObject where = root1.createFolder("else").createFolder("sub").createFolder("subsub");
    FileObject fo = root1.createFolder("something");
    FileObject kidTxt = fo.createData("kid.txt");
    FileObject kid = fo.createFolder("kid");
    File kidFile = FileUtil.toFile(kid);
    File kidTxtFile = FileUtil.toFile(kidTxt);

    accessMonitor = new StatFiles();
    FileLock lock = fo.lock();
    FileObject newFolder;
    try {
        newFolder = fo.move(lock, where, fo.getNameExt(), null);
    } finally {
        lock.releaseLock();
    }
    assertEquals("Subfolder", where, newFolder.getParent());

    assertNotNull("Folder found", newFolder.getFileObject("kid"));
    assertNotNull("File found", newFolder.getFileObject("kid.txt"));
    assertFalse("No longer valid file", kidTxt.isValid());
    assertFalse("No longer valid dir", kid.isValid());

    String msg = 
        accessMonitor.getResults().statResultStack(kidFile, StatFiles.ALL) + "\n" +
        accessMonitor.getResults().statResultStack(kidTxtFile, StatFiles.ALL) + "\n";
    final Set<File> files = accessMonitor.getResults().getFiles();
    if (files.contains(kidFile) || files.contains(kidTxtFile)) {
        fail(msg);
    }
}
 
Example 17
Source File: BaseFileObjectTestHid.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testMoveKeepsLastModifiedDate() throws Exception {
    FileObjectFactory fs = FileObjectFactory.getInstance(getWorkDir());
    assertNotNull(fs);
    FileObject root1 = fs.getValidFileObject(getWorkDir(),
            FileObjectFactory.Caller.Others);

    FileObject where = root1.createFolder("else").createFolder("sub").createFolder(
            "subsub");
    FileObject fo = root1.createFolder("something");
    FileObject nestedTxt = fo.createData("nested.txt");
    FileObject simpleTxt = root1.createData("simple.txt");
    File nestedTxtFile = FileUtil.toFile(nestedTxt);
    File simpleTxtFile = FileUtil.toFile(simpleTxt);

    long origLastModifiedNested = nestedTxtFile.lastModified();
    long origLastModifiedSimple = simpleTxtFile.lastModified();

    Thread.sleep(1100);

    FileLock folderLock = fo.lock();
    try {
        fo.move(folderLock, where, fo.getNameExt(), null);
    } finally {
        folderLock.releaseLock();
    }
    FileLock simpleLock = simpleTxt.lock();
    try {
        simpleTxt.move(simpleLock, where, simpleTxt.getNameExt(), null);
    } finally {
        simpleLock.releaseLock();
    }

    FileObject nestedTarget = root1.getFileObject(
            "else/sub/subsub/something/nested.txt");
    FileObject simpleTarget = root1.getFileObject(
            "else/sub/subsub/simple.txt");

    assertEquals("LastModified date should be kept", origLastModifiedNested,
            FileUtil.toFile(nestedTarget).lastModified());
    assertEquals("LastModified date should be kept", origLastModifiedSimple,
            FileUtil.toFile(simpleTarget).lastModified());
}