Search in sources :

Example 36 with IFileInfo

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

the class KernelBrowserView method validateProxy.

private boolean validateProxy(IRemoteFileProxy proxy, String kernelSource) {
    if (proxy == null) {
        return false;
    }
    IFileStore fs = proxy.getResource(kernelSource);
    if (fs == null) {
        return false;
    }
    IFileInfo info = fs.fetchInfo();
    if (info == null) {
        return false;
    }
    if (!info.exists()) {
        return false;
    }
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 37 with IFileInfo

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

the class RemoteProxyCMainTab method checkProgram.

private boolean checkProgram(IProject project) {
    String name = fProgText.getText().trim();
    if (name.length() == 0) {
        setErrorMessage(ProxyLaunchMessages.executable_is_not_specified);
        return false;
    }
    // changed (binary or project name). See bug 277663.
    if (name.equals(fPreviouslyCheckedProgram)) {
        if (fPreviouslyCheckedProgramErrorMsg != null) {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg);
        }
        return fPreviouslyCheckedProgramIsValid;
    }
    fPreviouslyCheckedProgram = name;
    // we'll flip this below if
    fPreviouslyCheckedProgramIsValid = true;
    // not true
    // we'll set this below if
    fPreviouslyCheckedProgramErrorMsg = null;
    // there's an error
    IPath exePath;
    URI exeURI = null;
    boolean passed = false;
    try {
        exeURI = new URI(name);
        String exePathStr = exeURI.getPath();
        if (exePathStr == null) {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
            fPreviouslyCheckedProgramIsValid = false;
            return false;
        }
        exePath = Path.fromOSString(exeURI.getPath());
        if (!exePath.isAbsolute() && exeURI != null && !exeURI.isAbsolute()) {
            URI projectURI = project.getLocationURI();
            exeURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + exePath.toString(), EMPTY_STRING);
        }
        if (exeURI != null) {
            passed = true;
        }
    } catch (URISyntaxException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_executable_is_invalid);
        fPreviouslyCheckedProgramIsValid = false;
        return false;
    }
    if (!passed) {
        setErrorMessage(fPreviouslyCheckedProgramErrorMsg = LaunchMessages.CMainTab_Program_does_not_exist);
        fPreviouslyCheckedProgramIsValid = false;
        return false;
    }
    passed = false;
    try {
        IRemoteFileProxy exeFileProxy;
        exeFileProxy = RemoteProxyManager.getInstance().getFileProxy(exeURI);
        if (exeFileProxy != null) {
            String exeFilePath = exeURI.getPath();
            IFileStore exeFS = exeFileProxy.getResource(exeFilePath);
            if (exeFS != null) {
                IFileInfo exeFI = exeFS.fetchInfo();
                if (exeFI != null) {
                    if (dontCheckProgram || enableCopyFromExeButton.getSelection()) {
                        // The program may not exist yet if we are copying it.
                        passed = true;
                    } else {
                        if (exeFI.exists()) {
                            if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
                                passed = true;
                            } else {
                                setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_have_execution_rights);
                            }
                        } else {
                            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.executable_does_not_exist);
                        }
                    }
                } else {
                    setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
                }
            } else {
                setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.error_accessing_executable);
            }
        } else {
            setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.scheme_error_in_executable);
        }
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedProgramErrorMsg = ProxyLaunchMessages.connection_of_executable_cannot_be_opened);
    }
    if (!passed) {
        fPreviouslyCheckedProgramIsValid = 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)

Example 38 with IFileInfo

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

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

the class PerfLaunchConfigDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    try {
        ConfigUtils configUtils = new ConfigUtils(config);
        project = configUtils.getProject();
        // Set the current project that will be profiled
        PerfPlugin.getDefault().setProfiledProject(project);
        // check if Perf exists in $PATH
        if (!PerfCore.checkPerfInPath(project)) {
            // $NON-NLS-1$
            IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, "Error: Perf was not found on PATH");
            throw new CoreException(status);
        }
        URI workingDirURI = new URI(config.getAttribute(RemoteProxyCMainTab.ATTR_REMOTE_WORKING_DIRECTORY_NAME, EMPTY_STRING));
        // Local project
        if (workingDirURI.toString().equals(EMPTY_STRING)) {
            workingDirURI = getWorkingDirectory(config).toURI();
            workingDirPath = Path.fromPortableString(workingDirURI.getPath());
            binPath = CDebugUtils.verifyProgramPath(config);
        } else {
            workingDirPath = Path.fromPortableString(workingDirURI.getPath() + IPath.SEPARATOR);
            URI binURI = new URI(configUtils.getExecutablePath());
            binPath = Path.fromPortableString(binURI.getPath().toString());
        }
        PerfPlugin.getDefault().setWorkingDir(workingDirPath);
        if (config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default)) {
            showStat(config, launch);
        } else {
            String perfPathString = RuntimeProcessFactory.getFactory().whichCommand(PerfPlugin.PERF_COMMAND, project);
            IFileStore workingDir;
            RemoteConnection workingDirRC = new RemoteConnection(workingDirURI);
            IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy();
            workingDir = workingDirRFP.getResource(workingDirURI.getPath());
            // Build the commandline string to run perf recording the given project
            // Program args from launch config.
            String[] arguments = getProgramArgumentsArray(config);
            ArrayList<String> command = new ArrayList<>(4 + arguments.length);
            // Get the base commandline string (with flags/options based on config)
            command.addAll(Arrays.asList(PerfCore.getRecordString(config)));
            // Add the path to the executable
            command.add(binPath.toPortableString());
            command.set(0, perfPathString);
            command.add(2, OUTPUT_STR + PerfPlugin.PERF_DEFAULT_DATA);
            // Compile string
            command.addAll(Arrays.asList(arguments));
            // Spawn the process
            String[] commandArray = command.toArray(new String[command.size()]);
            Process pProxy = RuntimeProcessFactory.getFactory().exec(commandArray, getEnvironment(config), workingDir, project);
            // $NON-NLS-1$
            MessageConsole console = new MessageConsole("Perf Console", null);
            console.activate();
            ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
            MessageConsoleStream stream = console.newMessageStream();
            if (pProxy != null) {
                try (BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream()))) {
                    String err = error.readLine();
                    while (err != null) {
                        stream.println(err);
                        err = error.readLine();
                    }
                }
            }
            /* This commented part is the basic method to run perf record without integrating into eclipse.
                        String binCall = exePath.toOSString();
                        for(String arg : arguments) {
                            binCall.concat(" " + arg);
                        }
                        PerfCore.Run(binCall);*/
            pProxy.destroy();
            PrintStream print = null;
            if (config.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true)) {
                // Get the console to output to.
                // This may not be the best way to accomplish this but it shall do for now.
                ConsolePlugin plugin = ConsolePlugin.getDefault();
                IConsoleManager conMan = plugin.getConsoleManager();
                IConsole[] existing = conMan.getConsoles();
                IOConsole binaryOutCons = null;
                // Find the console
                for (IConsole x : existing) {
                    if (x.getName().contains(renderProcessLabel(commandArray[0]))) {
                        binaryOutCons = (IOConsole) x;
                    }
                }
                if ((binaryOutCons == null) && (existing.length != 0)) {
                    // if can't be found get the most recent opened, this should probably never happen.
                    if (existing[existing.length - 1] instanceof IOConsole)
                        binaryOutCons = (IOConsole) existing[existing.length - 1];
                }
                // Get the printstream via the outputstream.
                // Get ouput stream
                OutputStream outputTo;
                if (binaryOutCons != null) {
                    outputTo = binaryOutCons.newOutputStream();
                    // Get the printstream for that console
                    print = new PrintStream(outputTo);
                }
                for (int i = 0; i < command.size(); i++) {
                    // $NON-NLS-1$
                    print.print(command.get(i) + " ");
                }
                // Print Message
                print.println();
                // $NON-NLS-1$
                print.println("Analysing recorded perf.data, please wait...");
            // Possibly should pass this (the console reference) on to PerfCore.Report if theres anything we ever want to spit out to user.
            }
            PerfCore.report(config, workingDirPath, monitor, null, print);
            URI perfDataURI = null;
            IRemoteFileProxy proxy = null;
            perfDataURI = new URI(workingDirURI.toString() + IPath.SEPARATOR + PerfPlugin.PERF_DEFAULT_DATA);
            proxy = RemoteProxyManager.getInstance().getFileProxy(perfDataURI);
            IFileStore perfDataFileStore = proxy.getResource(perfDataURI.getPath());
            IFileInfo info = perfDataFileStore.fetchInfo();
            info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
            perfDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
            PerfCore.refreshView(renderProcessLabel(binPath.toPortableString()));
            if (config.getAttribute(PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default)) {
                showSourceDisassembly(Path.fromPortableString(workingDirURI.toString() + IPath.SEPARATOR));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    } catch (RemoteConnectionException e) {
        e.printStackTrace();
        abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OutputStream(java.io.OutputStream) ConfigUtils(org.eclipse.linuxtools.profiling.launch.ConfigUtils) ArrayList(java.util.ArrayList) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) PrintStream(java.io.PrintStream) MessageConsole(org.eclipse.ui.console.MessageConsole) RemoteConnectionException(org.eclipse.linuxtools.profiling.launch.RemoteConnectionException) InputStreamReader(java.io.InputStreamReader) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) IConsoleManager(org.eclipse.ui.console.IConsoleManager) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) RemoteConnection(org.eclipse.linuxtools.profiling.launch.RemoteConnection) IOConsole(org.eclipse.ui.console.IOConsole)

Example 40 with IFileInfo

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

the class SSHFileStore method childInfos.

@Override
public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    try {
        monitor.beginTask(Messages.SSHFileStore_childInfoMonitor, 100);
        ChannelSftp channel = proxy.getChannelSftp();
        monitor.worked(25);
        Vector<?> v = channel.ls(uri.getPath());
        monitor.worked(50);
        LinkedList<IFileInfo> childs = new LinkedList<>();
        boolean isDir = false;
        for (int i = 0; i < v.size(); i++) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) v.get(i);
            if (!entry.getFilename().equals(".") && !entry.getFilename().equals("..")) {
                // $NON-NLS-1$ //$NON-NLS-2$
                childs.add(createFileInfo(entry.getAttrs()));
            } else {
                isDir = true;
            }
        }
        if (!isDir) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.SSHFileStore_childInfoFailedDirectory, getName())));
        }
        monitor.worked(100);
        monitor.done();
        return childs.toArray(new IFileInfo[0]);
    } catch (SftpException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_childInfoFailed + e.getMessage()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SftpException(com.jcraft.jsch.SftpException) LinkedList(java.util.LinkedList) ChannelSftp(com.jcraft.jsch.ChannelSftp) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException)

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