Search in sources :

Example 11 with IFileInfo

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);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 12 with IFileInfo

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;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 13 with IFileInfo

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;
}
Also used : PerfProfileView(org.eclipse.linuxtools.internal.perf.ui.PerfProfileView) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) PartInitException(org.eclipse.ui.PartInitException) URI(java.net.URI)

Example 14 with IFileInfo

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;
}
Also used : IPerfData(org.eclipse.linuxtools.internal.perf.IPerfData) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 15 with IFileInfo

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;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

IFileInfo (org.eclipse.core.filesystem.IFileInfo)49 IFileStore (org.eclipse.core.filesystem.IFileStore)32 CoreException (org.eclipse.core.runtime.CoreException)22 IOException (java.io.IOException)13 URI (java.net.URI)13 IFile (org.eclipse.core.resources.IFile)11 IPath (org.eclipse.core.runtime.IPath)11 Test (org.junit.Test)8 URISyntaxException (java.net.URISyntaxException)7 OutputStream (java.io.OutputStream)6 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)6 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)5 IStatus (org.eclipse.core.runtime.IStatus)5 IDocument (org.eclipse.jface.text.IDocument)5 InputStream (java.io.InputStream)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 Reader (java.io.Reader)3