Search in sources :

Example 26 with IFileStore

use of org.eclipse.core.filesystem.IFileStore 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 27 with IFileStore

use of org.eclipse.core.filesystem.IFileStore 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 28 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class LaunchOptions method isValid.

/**
 * Determines whether the global oprofile options represented by this
 * object are valid
 * @return whether the options are valid
 */
public boolean isValid() {
    IRemoteFileProxy proxy = null;
    try {
        proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
    } catch (CoreException e) {
        e.printStackTrace();
    }
    // The only point of contention is whether the specified vmlinux *file* exists.
    String fn = options.getKernelImageFile();
    if (fn != null && fn.length() > 0) {
        IFileStore fileStore = proxy.getResource(options.getKernelImageFile());
        return (fileStore.fetchInfo().exists() && !fileStore.fetchInfo().isDirectory());
    }
    return true;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 29 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class OprofileSetupTab method handleKernelImageFileTextModify.

// handles text modification events for all text boxes in this tab
private void handleKernelImageFileTextModify(Text text) {
    String errorMessage = null;
    String filename = text.getText();
    if (filename.length() > 0) {
        try {
            proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
        } catch (CoreException e) {
            e.printStackTrace();
        }
        IFileStore fileStore = proxy.getResource(filename);
        if (!fileStore.fetchInfo().exists() || fileStore.fetchInfo().isDirectory()) {
            // $NON-NLS-1$
            String msg = OprofileLaunchMessages.getString("tab.global.kernelImage.kernel.nonexistent");
            errorMessage = MessageFormat.format(msg, filename);
        }
        // seems odd, but must set it even if it is invalid so that performApply
        // and isValid work properly
        options.setKernelImageFile(filename);
    } else {
        // no kernel image file
        // $NON-NLS-1$
        options.setKernelImageFile("");
    }
    // Update dialog and error message
    setErrorMessage(errorMessage);
    updateLaunchConfigurationDialog();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 30 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class OprofileSetupTab method showFileDialog.

// Displays a file dialog to allow the user to select the kernel image file
private void showFileDialog(Shell shell) {
    try {
        proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
    } catch (CoreException e) {
        e.printStackTrace();
    }
    FileDialog d = new FileDialog(shell, SWT.OPEN);
    IFileStore kernel = proxy.getResource(options.getKernelImageFile());
    if (!kernel.fetchInfo().exists()) {
        // $NON-NLS-1$
        kernel = proxy.getResource("/boot");
        if (!kernel.fetchInfo().exists()) {
            // $NON-NLS-1$
            kernel = proxy.getResource("/");
        }
    }
    d.setFileName(kernel.toString());
    // $NON-NLS-1$
    d.setText(OprofileLaunchMessages.getString("tab.global.selectKernelDialog.text"));
    String newKernel = d.open();
    if (newKernel != null) {
        kernel = proxy.getResource(newKernel);
        if (!kernel.fetchInfo().exists()) {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.RETRY | SWT.CANCEL);
            // $NON-NLS-1$
            mb.setMessage(OprofileLaunchMessages.getString("tab.global.selectKernelDialog.error.kernelDoesNotExist.text"));
            switch(mb.open()) {
                case SWT.RETRY:
                    // Ok, it's recursive, but it shouldn't matter
                    showFileDialog(shell);
                    break;
                default:
                case SWT.CANCEL:
                    break;
            }
        } else {
            kernelImageFileText.setText(newKernel);
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) FileDialog(org.eclipse.swt.widgets.FileDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)178 CoreException (org.eclipse.core.runtime.CoreException)80 IOException (java.io.IOException)49 IPath (org.eclipse.core.runtime.IPath)42 IFileInfo (org.eclipse.core.filesystem.IFileInfo)33 URI (java.net.URI)30 Path (org.eclipse.core.runtime.Path)30 IFile (org.eclipse.core.resources.IFile)28 PartInitException (org.eclipse.ui.PartInitException)25 File (java.io.File)22 InputStream (java.io.InputStream)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)21 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 InputStreamReader (java.io.InputStreamReader)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)14 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)14 BufferedInputStream (java.io.BufferedInputStream)13 BufferedReader (java.io.BufferedReader)13 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)11 IStatus (org.eclipse.core.runtime.IStatus)11