Search in sources :

Example 6 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy 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()));
}
Also used : LocalFileProxy(org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 7 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class RuntimeProcessFactory method exec.

/**
 * Execute one command using the path selected in 'Linux Tools Path' preference page
 * in the informed project.
 * @param cmdarray An array with the command to be executed and its params.
 * @param envp An array with extra enviroment variables to be used when running
 * the command
 * @param dir The directory used as current directory to run the command.
 * @param project The current project. If null, only system path will be
 * used to look for the command.
 * @param pty PTY for use with Eclipse Console.
 * @return The process started by exec.
 * @throws IOException If problem executing the command occured.
 *
 * @since 3.0
 */
public Process exec(String[] cmdarray, String[] envp, IFileStore dir, IProject project, PTY pty) throws IOException {
    Process p = null;
    try {
        cmdarray = fillPathCommand(cmdarray, project);
        String command = cmdarray[0];
        URI uri = URI.create(command);
        IPath changeToDir = null;
        IPath path;
        IRemoteCommandLauncher launcher;
        envp = updateEnvironment(envp, project);
        if (project != null) {
            IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
            path = new Path(proxy.toPath(uri));
            launcher = RemoteProxyManager.getInstance().getLauncher(project);
            if (dir != null) {
                changeToDir = new Path(proxy.toPath(dir.toURI()));
            }
        } else {
            path = new Path(uri.getPath());
            launcher = RemoteProxyManager.getInstance().getLauncher(uri);
            if (dir != null) {
                changeToDir = new Path(dir.toURI().getPath());
            }
        }
        List<String> cmdlist = new ArrayList<>(Arrays.asList(cmdarray));
        cmdlist.remove(0);
        cmdlist.toArray(cmdarray);
        cmdarray = cmdlist.toArray(new String[0]);
        if (pty == null) {
            p = launcher.execute(path, cmdarray, envp, changeToDir, new NullProgressMonitor());
        } else {
            p = launcher.execute(path, cmdarray, envp, changeToDir, new NullProgressMonitor(), pty);
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return p;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 8 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class KernelBrowserView method refresh.

/**
 * Updates the kernel source displayed to the user with the new kernel source tree. Usually
 * a response to the user changing the preferences related to the kernel source location, requiring
 * that the application update the kernel source information.
 */
@Override
public void refresh() {
    displayLoadingMessage();
    IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore();
    String kernelSource = p.getString(IDEPreferenceConstants.P_KERNEL_SOURCE);
    if (kernelSource == null || kernelSource.length() < 1) {
        // $NON-NLS-1$
        displayMessage(Localization.getString("KernelBrowserView.NoKernelSourceFound"));
        return;
    }
    String localOrRemote = p.getString(IDEPreferenceConstants.P_REMOTE_LOCAL_KERNEL_SOURCE);
    URI kernelLocationURI = null;
    IRemoteFileProxy proxy = null;
    boolean remote = localOrRemote.equals(PathPreferencePage.REMOTE);
    if (remote) {
        boolean error = false;
        try {
            kernelLocationURI = IDEPlugin.getDefault().createRemoteUri(kernelSource);
            if (kernelLocationURI == null) {
                error = true;
            } else {
                proxy = RemoteProxyManager.getInstance().getFileProxy(kernelLocationURI);
                if (!validateProxy(proxy, kernelSource)) {
                    error = true;
                }
            }
        } catch (CoreException e2) {
            error = true;
        }
        if (error) {
            // $NON-NLS-1$
            displayMessage(Localization.getString("KernelBrowserView.KernelSourceDirNotFound"));
            return;
        }
    }
    KernelRefreshJob refreshJob = new KernelRefreshJob(remote, kernelLocationURI, proxy, kernelSource);
    refreshJob.setPriority(Job.SHORT);
    refreshJob.schedule();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) URI(java.net.URI)

Example 9 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class KernelSourceTree method buildKernelTree.

/**
 * Builds the kernel tree from file parameter direct and stores the excluded string array.
 *
 * @param direct The file to include into the tree.
 * @param excluded The string array to store as excluded.
 */
public void buildKernelTree(String direct, String[] excluded) {
    if (direct == null || direct.isEmpty()) {
        kernelTree = null;
        return;
    }
    try {
        URI locationURI = new URI(direct);
        IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(locationURI);
        this.buildKernelTree(locationURI, excluded, proxy, null);
    } catch (URISyntaxException e) {
        kernelTree = null;
    } catch (CoreException e) {
        kernelTree = null;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy 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 line - line number to select, 0 to not select a line
 * @param project - current project object
 * @throws BadLocationException - Line number not valid in file
 * @throws PartInitException if the editor could not be initialized
 * @throws CoreException if the proxy cannot be initialized
 * @since 3.1
 */
public static void openEditorAndSelect(String path, int line, IProject project) throws PartInitException, BadLocationException, CoreException {
    IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IRemoteFileProxy proxy = null;
    proxy = RemoteProxyManager.getInstance().getFileProxy(project);
    IFileStore file = proxy.getResource(path);
    if (file.fetchInfo().exists()) {
        IEditorPart editor = IDE.openEditorOnFileStore(activePage, file);
        if (editor instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) editor;
            if (line > 0) {
                IDocumentProvider provider = textEditor.getDocumentProvider();
                IDocument document = provider.getDocument(textEditor.getEditorInput());
                // zero-indexed
                int start = document.getLineOffset(line - 1);
                textEditor.selectAndReveal(start, 0);
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)25 CoreException (org.eclipse.core.runtime.CoreException)24 IFileStore (org.eclipse.core.filesystem.IFileStore)18 URI (java.net.URI)12 IOException (java.io.IOException)10 IPath (org.eclipse.core.runtime.IPath)10 BufferedReader (java.io.BufferedReader)9 InputStreamReader (java.io.InputStreamReader)9 URISyntaxException (java.net.URISyntaxException)7 ArrayList (java.util.ArrayList)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 IFileInfo (org.eclipse.core.filesystem.IFileInfo)6 InputStream (java.io.InputStream)3 IStatus (org.eclipse.core.runtime.IStatus)3 Path (org.eclipse.core.runtime.Path)3 Status (org.eclipse.core.runtime.Status)3 IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)3 RemoteConnectionException (org.eclipse.linuxtools.profiling.launch.RemoteConnectionException)3 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)3 Test (org.junit.Test)3