use of org.eclipse.core.filesystem.IFileInfo in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method test2.
/*
* Tests isSynchronized.
*/
@Test
public void test2() throws Exception {
fManager.connectFileStore(fFileStore, null);
try {
ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
assertTrue(fileBuffer.isSynchronized());
IFileStore fileStore = fFileStore;
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
if (fileInfo.exists())
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
long lastModified = fileStore.fetchInfo().getLastModified();
assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized());
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
}
use of org.eclipse.core.filesystem.IFileInfo in project eclipse.platform.text by eclipse.
the class FileStoreFileBuffersForWorkspaceFiles method modifyUnderlyingFile.
@Override
protected boolean modifyUnderlyingFile() throws Exception {
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
assertTrue(fileStore.fetchInfo().exists());
OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
try {
out.write("Changed content of workspace file".getBytes());
out.flush();
} catch (IOException x) {
fail();
} finally {
out.close();
}
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
IFile iFile = FileBuffers.getWorkspaceFileAtLocation(getPath());
assertTrue(iFile.exists() && iFile.getFullPath().equals(getPath()));
iFile.refreshLocal(IResource.DEPTH_INFINITE, null);
return true;
}
use of org.eclipse.core.filesystem.IFileInfo in project linuxtools by eclipse.
the class PerfSaveSessionHandler method saveData.
@Override
public IPath saveData(String filename) {
// get paths
IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData();
URI newDataLocURI = null;
URI defaultDataLocURI = null;
// get files
IRemoteFileProxy proxy = null;
try {
newDataLocURI = new URI(newDataLoc.toPortableString());
defaultDataLocURI = new URI(defaultDataLoc.toPortableString());
proxy = RemoteProxyManager.getInstance().getFileProxy(newDataLocURI);
} catch (URISyntaxException e) {
openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
} catch (CoreException e) {
openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
}
IFileStore newDataFileStore = proxy.getResource(newDataLocURI.getPath());
IFileStore defaultDataFileStore = proxy.getResource(defaultDataLocURI.getPath());
if (canSave(newDataLoc)) {
// copy default data into new location
try {
defaultDataFileStore.copy(newDataFileStore, EFS.OVERWRITE, null);
PerfPlugin.getDefault().setPerfProfileData(newDataLoc);
try {
PerfProfileView view = (PerfProfileView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PerfPlugin.VIEW_ID);
view.setContentDescription(newDataLoc.toOSString());
} catch (PartInitException e) {
// fail silently
}
IFileInfo info = newDataFileStore.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
return newDataLoc;
} catch (CoreException e) {
openErroDialog(Messages.PerfSaveSession_failure_title, Messages.PerfSaveSession_failure_msg, newDataLoc.lastSegment());
}
}
return null;
}
use of org.eclipse.core.filesystem.IFileInfo in project linuxtools by eclipse.
the class PerfSaveStatsHandler method saveData.
@Override
public IPath saveData(String filename) {
IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
IPerfData statData = PerfPlugin.getDefault().getStatData();
BufferedWriter writer = null;
OutputStreamWriter osw = null;
try {
IRemoteFileProxy proxy = null;
proxy = RemoteProxyManager.getInstance().getFileProxy(getWorkingDirURI());
if (proxy == null) {
openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
return null;
}
IFileStore newDataFileStore = proxy.getResource(newDataLoc.toOSString());
osw = new OutputStreamWriter(newDataFileStore.openOutputStream(EFS.NONE, null));
writer = new BufferedWriter(osw);
writer.write(statData.getPerfData());
closeResource(writer);
IFileInfo info = newDataFileStore.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
return newDataLoc;
} catch (IOException | CoreException e) {
openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
} finally {
closeResource(writer);
}
return null;
}
use of org.eclipse.core.filesystem.IFileInfo 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;
}
Aggregations