use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteConnection method delete.
/**
* Remote delete function. This method is recursive. If a remote directory
* is specified, the remote directory and all its contents are removed. A
* RemoteConnectionException is thrown if failure occurs for any reason.
*
* @param remotePath
* - the remote path of the file or folder to be deleted
* @param monitor
* - progress monitor
* @throws RemoteConnectionException If a problem while deleting occured.
*/
public void delete(IPath remotePath, IProgressMonitor monitor) throws RemoteConnectionException {
try {
IFileStore remoteFile = rmtFileProxy.getResource(remotePath.toString());
remoteFile.delete(0, monitor);
} catch (CoreException e) {
throw new RemoteConnectionException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteProxyCMainTab method checkWorkingDir.
private boolean checkWorkingDir(IProject project) {
String name = workingDirText.getText().trim();
if (name.length() == 0) {
// an empty working directory means, "use the default"
return true;
}
// changed (project).
if (name.equals(fPreviouslyCheckedWorkingDir)) {
if (fPreviouslyCheckedWorkingDirErrorMsg != null) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg);
}
return fPreviouslyCheckedWorkingDirIsValid;
}
fPreviouslyCheckedWorkingDir = name;
// we'll flip this below if
fPreviouslyCheckedWorkingDirIsValid = true;
// not true
// we'll set this below if
fPreviouslyCheckedWorkingDirErrorMsg = null;
// there's an error
IPath wdPath;
URI wdURI = null;
boolean passed = false;
try {
wdURI = new URI(name);
String wdPathStr = wdURI.getPath();
if (wdPathStr == null) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_working_directory_is_invalid);
fPreviouslyCheckedWorkingDirIsValid = false;
return false;
}
wdPath = Path.fromOSString(wdURI.getPath());
if (!wdPath.isAbsolute() && wdURI != null && !wdURI.isAbsolute()) {
URI projectURI = project.getLocationURI();
wdURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + wdPath.toString(), EMPTY_STRING);
}
if (wdURI != null) {
passed = true;
}
} catch (URISyntaxException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_working_directory_is_invalid);
fPreviouslyCheckedWorkingDirIsValid = false;
return false;
}
if (!passed) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_does_not_exist);
fPreviouslyCheckedWorkingDirIsValid = false;
return false;
}
passed = false;
IRemoteFileProxy wdFileProxy;
try {
wdFileProxy = RemoteProxyManager.getInstance().getFileProxy(wdURI);
if (wdFileProxy != null) {
IFileStore wdFS = wdFileProxy.getResource(wdURI.getPath());
if (wdFS != null) {
IFileInfo wdFI = wdFS.fetchInfo();
if (wdFI != null) {
if (wdFI.exists()) {
if (wdFI.isDirectory()) {
passed = true;
} else {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_is_not_a_directory);
}
} else {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_does_not_exist);
}
} else {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
}
} else {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
}
} else {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.scheme_error_in_working_directory);
}
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.connection_of_working_directory_cannot_be_opened);
}
if (!passed) {
fPreviouslyCheckedWorkingDirIsValid = false;
return false;
}
setErrorMessage(null);
return true;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteProxyCMainTab method checkCopyFromExe.
private boolean checkCopyFromExe(IProject project) {
if (!enableCopyFromExeButton.getSelection()) {
setErrorMessage(null);
return true;
}
String name = copyFromExeText.getText().trim();
if (name.length() == 0) {
setErrorMessage(ProxyLaunchMessages.copy_from_exe_is_not_specified);
return false;
}
// changed (binary or project name). See bug 277663.
if (name.equals(fPreviouslyCheckedCopyFromExe)) {
if (fPreviouslyCheckedCopyFromExeErrorMsg != null) {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg);
}
return fPreviouslyCheckedCopyFromExeIsValid;
}
fPreviouslyCheckedCopyFromExe = name;
// we'll flip this below if
fPreviouslyCheckedCopyFromExeIsValid = true;
// not true
// we'll set this below if
fPreviouslyCheckedCopyFromExeErrorMsg = null;
// there's an error
IPath exePath;
URI exeURI = null;
boolean passed = false;
try {
exeURI = new URI(name);
String exePathStr = exeURI.getPath();
if (exePathStr == null) {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
fPreviouslyCheckedCopyFromExeIsValid = false;
return false;
}
exePath = Path.fromOSString(exeURI.getPath());
if (!exePath.isAbsolute() && exeURI != null && !exeURI.isAbsolute()) {
URI projectURI = project.getLocationURI();
exeURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + exePath.toString(), EMPTY_STRING);
}
if (exeURI != null) {
passed = true;
}
} catch (URISyntaxException e) {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
fPreviouslyCheckedCopyFromExeIsValid = false;
return false;
}
if (!passed) {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
fPreviouslyCheckedCopyFromExeIsValid = false;
return false;
}
passed = false;
try {
IRemoteFileProxy exeFileProxy;
exeFileProxy = RemoteProxyManager.getInstance().getFileProxy(exeURI);
if (exeFileProxy != null) {
String exeFilePath = exeURI.getPath();
IFileStore exeFS = exeFileProxy.getResource(exeFilePath);
if (exeFS != null) {
IFileInfo exeFI = exeFS.fetchInfo();
if (exeFI != null) {
if (exeFI.exists()) {
if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
passed = true;
} else {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_have_execution_rights);
}
} else {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
}
} else {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
}
} else {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
}
} else {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.scheme_error_in_copy_from_exe);
}
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.connection_of_copy_from_exe_cannot_be_opened);
}
if (!passed) {
fPreviouslyCheckedCopyFromExeIsValid = false;
return false;
}
setErrorMessage(null);
return true;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Open a file in the Editor at the specified offset, highlighting the given length
*
* @param path : Absolute path pointing to the file which will be opened.
* @param offset : Offset of the function to be highlighted.
* @param length : Length of the function to be highlighted.
* @throws PartInitException if the editor could not be initialized
*/
public static void openEditorAndSelect(String path, int offset, int length) throws PartInitException {
Path p = new Path(path);
if (p.toFile().exists()) {
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IFileStore fileStore = EFS.getLocalFileSystem().getStore(p);
IEditorPart editor = IDE.openEditorOnFileStore(activePage, fileStore);
if (editor instanceof ITextEditor) {
ITextEditor text = (ITextEditor) editor;
text.selectAndReveal(offset, length);
}
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class FileProxyTest method testLocalFileProxy.
@Test
public void testLocalFileProxy() {
IRemoteFileProxy fileProxy = null;
try {
fileProxy = proxyManager.getFileProxy(localProject.getProject());
assertTrue("Should have returned a remote launcher", fileProxy instanceof LocalFileProxy);
} catch (CoreException e) {
fail("Should have returned a launcher: " + e.getCause());
}
/*
* Test getDirectorySeparator()
*/
String ds = fileProxy.getDirectorySeparator();
assertNotNull(ds);
/*
* Test getResource()
*/
IFileStore actualFileStore = fileProxy.getResource(localProject.getProject().getLocation().toOSString());
assertNotNull(actualFileStore);
IFileStore expectedFileStore = null;
try {
expectedFileStore = EFS.getStore(localProject.getLocationURI());
} catch (CoreException e) {
fail("Unabled to get FileStore to local project: " + e.getMessage());
}
assertEquals("FileStore to local project folder diverge", expectedFileStore, actualFileStore);
assertTrue(actualFileStore.fetchInfo().isDirectory());
actualFileStore = fileProxy.getResource("/filenotexits");
assertNotNull(actualFileStore);
IFileInfo fileInfo = actualFileStore.fetchInfo();
assertNotNull(fileInfo);
assertFalse(fileInfo.exists());
/*
* Test getWorkingDir()
*/
URI workingDir = fileProxy.getWorkingDir();
assertNotNull(workingDir);
assertEquals(localProject.getLocationURI(), workingDir);
/*
* Test toPath()
*/
assertEquals(localProject.getProject().getLocation().toOSString(), fileProxy.toPath(localProject.getLocationURI()));
}
Aggregations