Java Code Examples for org.eclipse.core.resources.IFile#move()
The following examples show how to use
org.eclipse.core.resources.IFile#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: StandardImportAndReadSmokeTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Test import from a nested empty archive. This should not import anything. * * @throws Exception * on error */ @Test public void testNestedEmptyArchive() throws Exception { IProject project = getProjectResource(); // Create the empty archive from an empty folder String testArchivePath = createEmptyArchive(); // Rename archive so that we can create a new one with the same name project.refreshLocal(IResource.DEPTH_ONE, null); IFile[] files = project.getWorkspace().getRoot().findFilesForLocationURI(new File(testArchivePath).toURI()); IFile archiveFile = files[0]; String newEmptyArchiveName = "nested" + archiveFile.getName(); IPath dest = archiveFile.getFullPath().removeLastSegments(1).append(newEmptyArchiveName); archiveFile.move(dest, true, null); IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest); createArchive(renamedArchiveFile); renamedArchiveFile.delete(true, null); openImportWizard(); SWTBotImportWizardUtils.selectImportFromArchive(fBot, testArchivePath); selectFolder(ARCHIVE_ROOT_ELEMENT_NAME); SWTBotImportWizardUtils.setOptions(fBot, 0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); importFinish(); assertNoTraces(); SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); Files.delete(Paths.get(testArchivePath)); }
Example 2
Source File: BuilderParticipantPluginUITest.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * * 01. Class0 uses Class1 in require statement and in isa function * 02. Class1 file is renamed * 05. Class0 should get error marker at require statement and at isa function * 06. Class1 is renamed back * 07. Class0 should have no error markers */ //@formatter:on @Test public void testSuperClassRenamed() throws Exception { logger.info("BuilderParticipantPluginUITest.testSuperClassRenamed"); // create project and test files final IProject project = createJSProject("testSuperClassRenamed"); IFolder folder = configureProjectWithXtext(project); IFolder moduleFolder = createFolder(folder, InheritanceTestFiles.inheritanceModule()); IFile parentFile = createTestFile(moduleFolder, "Parent", InheritanceTestFiles.Parent()); assertMarkers("Parent file should have no errors", parentFile, 0); IFile childFile = createTestFile(moduleFolder, "Child", InheritanceTestFiles.Child()); assertMarkers("Child file should have no errors", childFile, 0); // open editors of test files IWorkbenchPage page = EclipseUIUtils.getActivePage(); XtextEditor parentFileXtextEditor = openAndGetXtextEditor(parentFile, page); List<Resource.Diagnostic> errors = getEditorErrors(parentFileXtextEditor); assertEquals("Editor of parent should have no errors", 0, errors.size()); XtextEditor childFileXtextEditor = openAndGetXtextEditor(childFile, page); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have no errors", 0, errors.size()); parentFileXtextEditor.close(true); parentFile.move(new Path("Parent2" + "." + N4JSGlobals.N4JS_FILE_EXTENSION), true, true, monitor()); moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor()); waitForAutoBuild(); waitForUpdateEditorJob(); assertFalse("Parent.n4js doesn't exist anymore", moduleFolder.getFile(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION)).exists()); IFile movedParentFile = moduleFolder.getFile("Parent2" + "." + N4JSGlobals.N4JS_FILE_EXTENSION); assertTrue("Parent2.n4js does exist", movedParentFile.exists()); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have got error markers", Sets.newHashSet( "line 1: Cannot resolve plain module specifier (without project name as first segment): no matching module found.", "line 2: Couldn't resolve reference to Type 'ParentObjectLiteral'."), toSetOfStrings(errors)); movedParentFile.move(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION), true, true, monitor()); moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor()); waitForAutoBuild(); waitForUpdateEditorJob(); assertTrue("Parent.n4js does exist", moduleFolder.getFile(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION)).exists()); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have no errors", 0, errors.size()); }
Example 3
Source File: OutputFileManager.java From texlipse with Eclipse Public License 1.0 | 4 votes |
/** * Moves a file to the output directory with a new name. * * @param project the current project * @param sourceFile output file to be moved * @param destDir the destination directory of the file * @param destName the new name of the file * @param monitor progress monitor * @throws CoreException if an error occurs * @return file in the new location */ private static IFile moveFile(IProject project, IFile sourceFile, IContainer destContainer, String destName, IProgressMonitor monitor) throws CoreException { if (sourceFile != null && sourceFile.exists() && destName != null) { final IPath destRelPath = new Path(destName); final IFile dest = destContainer.getFile(destRelPath); if (dest.exists()) { File outFile = new File(sourceFile.getLocationURI()); File destFile = new File(dest.getLocationURI()); try { // Try to move the content instead of deleting the old file // and replace it by the new one. This is better for some // viewers like Sumatrapdf FileOutputStream out = new FileOutputStream(destFile); out.getChannel().tryLock(); BufferedInputStream in = new BufferedInputStream(new FileInputStream(outFile)); byte[] buf = new byte[4096]; int l; while ((l = in.read(buf)) != -1) { out.write(buf, 0, l); } in.close(); out.close(); sourceFile.delete(true, monitor); } catch (IOException e) { // try to delete and move the file dest.delete(true, monitor); sourceFile.move(dest.getFullPath(), true, monitor); } } else { // move the file sourceFile.move(dest.getFullPath(), true, monitor); } monitor.worked(1); return dest; } else { return null; } }
Example 4
Source File: XMLPersistenceProvider.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * A utility operation for processing tasks in the event loop. * * @param currentTask * The current task to be processed. */ private void processTask(QueuedTask currentTask) { // Local Declarations String name = null; IFile file = null; try { // Handle the task if it is available if (currentTask != null) { // Get the file name if this is a persist or delete if ("persist".equals(currentTask.task) || "delete".equals(currentTask.task)) { // Setup the file name name = currentTask.item.getName().replaceAll("\\s+", "_") + ".xml"; // Get the file from the project registered with the Item. // This may change depending on whether or not this Item was // created in the default project. file = currentTask.item.getProject().getFile(name); } // Process persists if ("persist".equals(currentTask.task)) { // Send the Item off to be written to the file writeFile(currentTask.item, file); // Update the item id map itemIdMap.put(currentTask.item.getId(), file.getName()); } else if ("delete".equals(currentTask.task)) { // Handle deletes // Make sure it exists, the platform may have deleted it // first // Sleep for a bit to let the platform delete if it wants Thread.currentThread(); Thread.sleep(100); if (file.exists()) { file.delete(true, null); } // Update the item id map itemIdMap.remove(currentTask.item.getId()); } else if ("write".equals(currentTask.task)) { // Deal with simple Form write requests from the IWriter // interface. writeFile(currentTask.form, currentTask.file); } else if ("rename".equals(currentTask.task)) { String oldFile = itemIdMap.get(currentTask.item.getId()); if (oldFile != null) { itemIdMap.put(currentTask.item.getId(), currentTask.file.getName()); // Sleep for a bit to let the platform delete if it // wants Thread.currentThread(); Thread.sleep(1000); IProject project = currentTask.item.getProject(); IFile oldFileHandle = project.getFile(oldFile); if (oldFileHandle.exists()) { oldFileHandle.move( currentTask.file.getProjectRelativePath(), true, null); } } } } else { // Otherwise sleep for a bit Thread.currentThread(); Thread.sleep(1000); } } catch (InterruptedException | CoreException e) { // Complain logger.error(getClass().getName() + " Exception!", e); } return; }