Search in sources :

Example 41 with IFileInfo

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

the class SSHFileStore method createFileInfo.

private IFileInfo createFileInfo(SftpATTRS attrs) {
    FileInfo f = new FileInfo();
    f.setExists(true);
    f.setLastModified(attrs.getMTime());
    f.setLength(attrs.getSize());
    f.setName(getName());
    f.setDirectory(attrs.isDir());
    int p = attrs.getPermissions();
    if ((p & USER_READ) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OWNER_READ, true);
    }
    if ((p & USER_WRITE) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OWNER_WRITE, true);
    }
    if ((p & USER_EXEC) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OWNER_EXECUTE, true);
    }
    if ((p & GROUP_READ) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_GROUP_READ, true);
    }
    if ((p & GROUP_WRITE) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_GROUP_WRITE, true);
    }
    if ((p & GROUP_EXEC) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_GROUP_EXECUTE, true);
    }
    if ((p & OTHER_READ) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OTHER_READ, true);
    }
    if ((p & OTHER_WRITE) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OTHER_WRITE, true);
    }
    if ((p & OTHER_EXEC) != 0) {
        f.setAttribute(EFS.ATTRIBUTE_OTHER_EXECUTE, true);
    }
    return f;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) FileInfo(org.eclipse.core.filesystem.provider.FileInfo)

Example 42 with IFileInfo

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

the class ValgrindRemoteProxyLaunchDelegate method launch.

@Override
public void launch(final ILaunchConfiguration config, String mode, final ILaunch launch, IProgressMonitor m) throws CoreException {
    if (m == null) {
        m = new NullProgressMonitor();
    }
    // Clear process as we wait on it to be instantiated
    process = null;
    SubMonitor monitor = SubMonitor.convert(m, Messages.getString("ValgrindRemoteLaunchDelegate.task_name"), // $NON-NLS-1$
    10);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    this.config = config;
    this.launch = launch;
    try {
        // remove any output from previous run
        ValgrindUIPlugin.getDefault().resetView();
        // reset stored launch data
        getPlugin().setCurrentLaunchConfiguration(null);
        getPlugin().setCurrentLaunch(null);
        this.configUtils = new ConfigUtils(config);
        IProject project = configUtils.getProject();
        ValgrindUIPlugin.getDefault().setProfiledProject(project);
        URI exeURI = new URI(configUtils.getExecutablePath());
        RemoteConnection exeRC = new RemoteConnection(exeURI);
        monitor.worked(1);
        String valgrindPathString = RuntimeProcessFactory.getFactory().whichCommand(VALGRIND_CMD, project);
        IPath valgrindFullPath = Path.fromOSString(valgrindPathString);
        boolean copyExecutable = configUtils.getCopyExecutable();
        if (copyExecutable) {
            URI copyExeURI = new URI(configUtils.getCopyFromExecutablePath());
            RemoteConnection copyExeRC = new RemoteConnection(copyExeURI);
            IRemoteFileProxy copyExeRFP = copyExeRC.getRmtFileProxy();
            IFileStore copyExeFS = copyExeRFP.getResource(copyExeURI.getPath());
            IRemoteFileProxy exeRFP = exeRC.getRmtFileProxy();
            IFileStore exeFS = exeRFP.getResource(exeURI.getPath());
            IFileInfo exeFI = exeFS.fetchInfo();
            if (exeFI.isDirectory()) {
                // Assume the user wants to copy the file to the given directory, using
                // the same filename as the "copy from" executable.
                IPath copyExePath = Path.fromOSString(copyExeURI.getPath());
                IPath newExePath = Path.fromOSString(exeURI.getPath()).append(copyExePath.lastSegment());
                // update the exeURI with the new path.
                exeURI = new URI(exeURI.getScheme(), exeURI.getAuthority(), newExePath.toString(), exeURI.getQuery(), exeURI.getFragment());
                exeFS = exeRFP.getResource(exeURI.getPath());
            }
            copyExeFS.copy(exeFS, EFS.OVERWRITE | EFS.SHALLOW, SubMonitor.convert(monitor, 1));
        // Note: assume that we don't need to create a new exeRC since the
        // scheme and authority remain the same between the original exeURI and the new one.
        }
        valgrindVersion = getValgrindVersion(project);
        IPath remoteBinFile = Path.fromOSString(exeURI.getPath());
        String configWorkingDir = configUtils.getWorkingDirectory();
        IFileStore workingDir;
        if (configWorkingDir == null) {
            // If no working directory was provided, use the directory containing the
            // the executable as the working directory.
            IPath workingDirPath = remoteBinFile.removeLastSegments(1);
            IRemoteFileProxy workingDirRFP = exeRC.getRmtFileProxy();
            workingDir = workingDirRFP.getResource(workingDirPath.toOSString());
        } else {
            URI workingDirURI = new URI(configUtils.getWorkingDirectory());
            RemoteConnection workingDirRC = new RemoteConnection(workingDirURI);
            IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy();
            workingDir = workingDirRFP.getResource(workingDirURI.getPath());
        }
        // $NON-NLS-1$
        IPath remoteLogDir = Path.fromOSString("/tmp/");
        // $NON-NLS-1$
        outputPath = remoteLogDir.append("eclipse-valgrind-" + System.currentTimeMillis());
        exeRC.createFolder(outputPath, SubMonitor.convert(monitor, 1));
        // create/empty local output directory
        IValgrindOutputDirectoryProvider provider = getPlugin().getOutputDirectoryProvider();
        setOutputPath(config, provider.getOutputPath());
        IPath localOutputDir = null;
        try {
            localOutputDir = provider.getOutputPath();
            createDirectory(localOutputDir);
        } catch (IOException e2) {
            throw new CoreException(new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, IStatus.OK, "", // $NON-NLS-1$
            e2));
        }
        // tool that was launched
        toolID = getTool(config);
        // ask tool extension for arguments
        dynamicDelegate = getDynamicDelegate(toolID);
        String[] valgrindArgs = getValgrindArgumentsArray(config);
        String[] executableArgs = getProgramArgumentsArray(config);
        String[] allArgs = new String[executableArgs.length + valgrindArgs.length + 2];
        int idx = 0;
        allArgs[idx++] = VALGRIND_CMD;
        for (String valgrindArg : valgrindArgs) {
            allArgs[idx++] = valgrindArg;
        }
        allArgs[idx++] = remoteBinFile.toOSString();
        for (String executableArg : executableArgs) {
            allArgs[idx++] = executableArg;
        }
        Process p = RuntimeProcessFactory.getFactory().exec(allArgs, new String[0], workingDir, project);
        int state = p.waitFor();
        if (state != IRemoteCommandLauncher.OK) {
            abort(// $NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ValgrindLaunchConfigurationDelegate.Launch_exited_status") + " " + state + ". " + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            NLS.bind(Messages.getString("ValgrindRemoteProxyLaunchDelegate.see_reference"), "IRemoteCommandLauncher") + // $NON-NLS-1$
            "\n", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
        }
        if (p.exitValue() != 0) {
            String line = null;
            StringBuilder valgrindOutSB = new StringBuilder();
            BufferedReader valgrindOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = valgrindOut.readLine()) != null) {
                valgrindOutSB.append(line);
            }
            StringBuilder valgrindErrSB = new StringBuilder();
            BufferedReader valgrindErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            while ((line = valgrindErr.readLine()) != null) {
                valgrindErrSB.append(line);
            }
            abort(// $NON-NLS-1$
            NLS.bind("ValgrindRemoteProxyLaunchDelegate.Stdout", valgrindOutSB.toString()) + "\n" + // $NON-NLS-1$ //$NON-NLS-2$
            NLS.bind("ValgrindRemoteProxyLaunchDelegate.Stderr", valgrindErrSB.toString()), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
        }
        // move remote log files to local directory
        exeRC.download(outputPath, localOutputDir, SubMonitor.convert(monitor, 1));
        // remove remote log dir and all files under it
        exeRC.delete(outputPath, SubMonitor.convert(monitor, 1));
        // store these for use by other classes
        getPlugin().setCurrentLaunchConfiguration(config);
        getPlugin().setCurrentLaunch(launch);
        // parse Valgrind logs
        IValgrindMessage[] messages = parseLogs(localOutputDir);
        // create launch summary string to distinguish this launch
        launchStr = createLaunchStr(valgrindFullPath);
        // create view
        ValgrindUIPlugin.getDefault().createView(launchStr, toolID);
        // set log messages
        ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
        view.setMessages(messages);
        monitor.worked(1);
        // pass off control to extender
        dynamicDelegate.handleLaunch(config, launch, localOutputDir, monitor.newChild(2));
        // initialize tool-specific part of view
        dynamicDelegate.initializeView(view.getDynamicView(), launchStr, monitor.newChild(1));
        // refresh view
        ValgrindUIPlugin.getDefault().refreshView();
        // show view
        ValgrindUIPlugin.getDefault().showView();
        monitor.worked(1);
    } catch (URISyntaxException | IOException | RemoteConnectionException | InterruptedException e) {
        abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    } finally {
        monitor.done();
        m.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConfigUtils(org.eclipse.linuxtools.profiling.launch.ConfigUtils) 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) RemoteConnectionException(org.eclipse.linuxtools.profiling.launch.RemoteConnectionException) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IValgrindOutputDirectoryProvider(org.eclipse.linuxtools.valgrind.launch.IValgrindOutputDirectoryProvider) CoreException(org.eclipse.core.runtime.CoreException) ValgrindViewPart(org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) RemoteConnection(org.eclipse.linuxtools.profiling.launch.RemoteConnection)

Example 43 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project polymap4-core by Polymap4.

the class Folder method create.

/* (non-Javadoc)
	 * @see IFolder#create(int, boolean, IProgressMonitor)
	 */
public void create(int updateFlags, boolean local, IProgressMonitor monitor) throws CoreException {
    final boolean force = (updateFlags & IResource.FORCE) != 0;
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_creating, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        checkValidPath(path, FOLDER, true);
        final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            IFileStore store = getStore();
            IFileInfo localInfo = store.fetchInfo();
            assertCreateRequirements(store, localInfo, updateFlags);
            workspace.beginOperation(true);
            if (force && !Workspace.caseSensitive && localInfo.exists()) {
                String name = getLocalManager().getLocalName(store);
                if (name == null || localInfo.getName().equals(name)) {
                    delete(true, null);
                } else {
                    // The file system is not case sensitive and a case variant exists at this location
                    String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                    throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null);
                }
            }
            internalCreate(updateFlags, local, Policy.subMonitorFor(monitor, Policy.opWork));
            workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_ZERO, monitor);
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 44 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project xtext-eclipse by eclipse.

the class Storage2UriMapperImpl method getStorages.

private Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */
URI uri, IFile file) {
    if (file == null || !file.isAccessible()) {
        Iterable<Pair<IStorage, IProject>> result = contribution.getStorages(uri);
        if (result == null || !result.iterator().hasNext()) {
            // Handle files external to the workspace. But check contribution first to be backwards compatible.
            if (uri.isFile()) {
                Path filePath = new Path(uri.toFileString());
                IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath);
                IFileInfo fileInfo = fileStore.fetchInfo();
                if (fileInfo.exists() && !fileInfo.isDirectory()) {
                    return Collections.singletonList(Tuples.<IStorage, IProject>create(new FileStoreStorage(fileStore, fileInfo, filePath), (IProject) null));
                }
            }
        }
        return result;
    }
    return Collections.singleton(Tuples.<IStorage, IProject>create(file, file.getProject()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 45 with IFileInfo

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

the class CreateFileChange method isValid.

@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    URI location = file.getLocationURI();
    if (location == null) {
        result.addFatalError(String.format("The location for file %s is unknown", path));
        return result;
    }
    IFileInfo jFile = EFS.getStore(location).fetchInfo();
    if (jFile.exists()) {
        result.addFatalError(String.format("File %s already exists", path));
        return result;
    }
    return result;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) 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