Search in sources :

Example 11 with IRemoteFileProxy

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

the class FileProxyTest method testRemoteFileProxyOnSyncProject.

@Test
public void testRemoteFileProxyOnSyncProject() {
    IRemoteFileProxy fileProxy = null;
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", fileProxy instanceof RDTFileProxy);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);
    SyncConfig config = getSyncConfig(syncProject.getProject());
    String projectLocation = config.getLocation();
    assertNotNull(projectLocation);
    IRemoteConnection conn = null;
    String connScheme = null;
    try {
        conn = config.getRemoteConnection();
        connScheme = conn.getConnectionType().getScheme();
    } catch (MissingConnectionException e) {
        fail("Unabled to get remote connection: " + e.getMessage());
    }
    /*
		 *  Test getResource()
		 */
    IFileStore fs = fileProxy.getResource(projectLocation);
    assertNotNull(fs);
    assertEquals("Remote connection and FileStore schemes diverge", connScheme, fs.toURI().getScheme());
    // assertTrue(fs.fetchInfo().isDirectory());
    fs = fileProxy.getResource("/filenotexits");
    assertNotNull(fs);
    IFileInfo fileInfo = fs.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());
    /*
		 * Test getWorkingDir()
		 */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals("Remote connection and URI schemes diverge", connScheme, workingDir.getScheme());
    /*
		 * Test toPath()
		 */
    URI uri = null;
    try {
        uri = new URI(connScheme, conn.getName(), projectLocation, null, null);
    } catch (URISyntaxException e) {
        fail("Failed to build URI for the test: " + e.getMessage());
    }
    assertEquals(projectLocation, fileProxy.toPath(uri));
    /*
		 * Test it opens connection
		 */
    assertNotNull(conn);
    conn.close();
    assertFalse(conn.isOpen());
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertNotNull(fileProxy);
    } catch (CoreException e) {
        fail("Failed to obtain file proxy when connection is closed: " + e.getMessage());
    }
    fs = fileProxy.getResource("/tmp/somedir");
    assertNotNull(fs);
    assertFalse(fs.fetchInfo().exists());
    try {
        fs.mkdir(EFS.SHALLOW, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("should be able to create a directory when connection is closed: " + e.getMessage());
    }
    assertTrue(fs.fetchInfo().exists());
    try {
        fs.delete(EFS.NONE, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("Failed to delete file: " + e.getMessage());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SyncConfig(org.eclipse.ptp.rdt.sync.core.SyncConfig) URISyntaxException(java.net.URISyntaxException) MissingConnectionException(org.eclipse.ptp.rdt.sync.core.exceptions.MissingConnectionException) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 12 with IRemoteFileProxy

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

the class RemoteProxyManagerTest method testGetFileProxy.

@Test
public void testGetFileProxy() {
    IRemoteFileProxy fp;
    try {
        /*
			 * Test the proxy for local URIs and project
			 */
        fp = proxyManager.getFileProxy(URI.create("/path/to/file"));
        assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
        fp = proxyManager.getFileProxy(URI.create("file:/path/to/file"));
        assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
        fp = proxyManager.getFileProxy(localProject.getLocationURI());
        assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
        fp = proxyManager.getFileProxy(localProject.getProject());
        assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
        /*
			 * Test the proxy for remote URIs and project
			 */
        fp = proxyManager.getFileProxy(URI.create("ssh://" + CONNECTION_NAME + "/path/to/file"));
        assertTrue("Should have returned a remote file proxy", fp instanceof RDTFileProxy);
        fp = proxyManager.getFileProxy(syncProject.getProject());
        assertTrue("Should have returned a remote file proxy", fp instanceof RDTFileProxy);
        /*
			 * Test the proxy for jsch connection scheme
			 */
        fp = proxyManager.getFileProxy(URI.create("jsch://" + USERNAME + "@" + HOST + ":22/path/to/file"));
        assertTrue("Should have returned a remote file proxy", fp instanceof SSHFileProxy);
    } catch (CoreException e) {
        fail("Should have returned a file proxy: " + e.getCause());
    }
    /*
		 * Test the proxy for unsupported URIs
		 */
    try {
        // As of org.eclipse.remote 2.0, remotetools scheme is no longer
        // support
        fp = proxyManager.getFileProxy(URI.create("remotetools://MyConnection/path/to/file"));
        fail("remotetools scheme should not be recognized");
    } catch (CoreException e) {
        assertTrue(e.getMessage(), true);
    }
}
Also used : LocalFileProxy(org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy) CoreException(org.eclipse.core.runtime.CoreException) SSHFileProxy(org.eclipse.linuxtools.internal.ssh.proxy.SSHFileProxy) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 13 with IRemoteFileProxy

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

the class AbstractDataManipulator method performCommand.

public void performCommand(String[] cmd, String file) {
    Process proc = null;
    IRemoteFileProxy fileProxy;
    try {
        try {
            fileProxy = RemoteProxyManager.getInstance().getFileProxy(project);
        } catch (RemoteConnectionException e) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
            return;
        }
        IFileStore workDirStore = getWorkingDirStore();
        proc = RuntimeProcessFactory.getFactory().exec(cmd, null, workDirStore, project, new PTY());
        // $NON-NLS-1$
        DebugPlugin.newProcess(launch, proc, "");
        proc.waitFor();
        StringBuffer data = new StringBuffer();
        try (BufferedReader buffData = new BufferedReader(new InputStreamReader(fileProxy.getResource(file).openInputStream(EFS.NONE, null)))) {
            readStream(buffData, data);
            joinAll();
        }
        text = data.toString();
    } catch (IOException | CoreException e) {
        // $NON-NLS-1$
        text = "";
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        text = "";
    }
}
Also used : RemoteConnectionException(org.eclipse.linuxtools.profiling.launch.RemoteConnectionException) PTY(org.eclipse.cdt.utils.pty.PTY) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 14 with IRemoteFileProxy

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

the class PerfPlugin method getWorkingDirURI.

/**
 * Get the working directory.
 * @return the URI of the working directory or null.
 */
public URI getWorkingDirURI() {
    try {
        IRemoteFileProxy fileProxy = RemoteProxyManager.getInstance().getFileProxy(getProfiledProject());
        IPath wd = getWorkingDir();
        if (wd == null || fileProxy == null) {
            return null;
        }
        IFileStore fs = fileProxy.getResource(wd.toOSString());
        return fs.toURI();
    } catch (CoreException e) {
        return null;
    }
}
Also used : 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)

Example 15 with IRemoteFileProxy

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

the class StatComparisonData method collectStats.

/**
 * Collect statistics entries from the specified stat data file.
 *
 * @param file file to collect from
 * @return List containing statistics entries from the given file.
 */
private static ArrayList<PMStatEntry> collectStats(IPath file) {
    ArrayList<PMStatEntry> result = new ArrayList<>();
    BufferedReader statReader = null;
    URI fileURI = null;
    try {
        fileURI = new URI(file.toPortableString());
        IRemoteFileProxy proxy = null;
        proxy = RemoteProxyManager.getInstance().getFileProxy(fileURI);
        IFileStore newDataFileStore = proxy.getResource(fileURI.getPath());
        statReader = new BufferedReader(new InputStreamReader(newDataFileStore.openInputStream(EFS.NONE, null)));
        // pattern for a valid perf stat entry
        Pattern entryPattern = Pattern.compile(PMStatEntry.getString(Type.ENTRY_PATTERN));
        // pattern for last stat entry (seconds elapsed):
        Pattern totalTimePattern = Pattern.compile(PMStatEntry.getString(Type.TIME_PATTERN));
        String line;
        while ((line = statReader.readLine()) != null) {
            line = line.trim();
            Matcher match = entryPattern.matcher(line);
            String samples, event, usage, units, delta, scale;
            PMStatEntry statEntry;
            if (match.find()) {
                // extract information from groups
                samples = match.group(1);
                event = match.group(2);
                usage = match.group(7);
                units = match.group(8);
                delta = match.group(10);
                scale = match.group(14);
                // create stat entry
                statEntry = new PMStatEntry(toFloat(samples), event, toFloat(usage), units, toFloat(delta), toFloat(scale));
                // add stat entry to results list
                result.add(statEntry);
            } else if (line.contains(PMStatEntry.TIME)) {
                // match seconds elapsed pattern
                match = totalTimePattern.matcher(line);
                if (match.find()) {
                    samples = match.group(1);
                    event = match.group(2);
                    delta = match.group(4);
                    // create stat entry
                    statEntry = new PMStatEntry(toFloat(samples), event, 0, null, toFloat(delta), 0);
                    result.add(statEntry);
                }
            }
        }
        return result;
    } catch (IOException | CoreException | URISyntaxException e) {
        PerfPlugin.getDefault().openError(e, Messages.MsgError);
    } finally {
        try {
            if (statReader != null) {
                statReader.close();
            }
        } catch (IOException e) {
            PerfPlugin.getDefault().openError(e, Messages.PerfResourceLeak_title);
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore)

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