Search in sources :

Example 16 with IFileInfo

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

the class RemoteProxyCMainTab method checkCopyFromExe.

private boolean checkCopyFromExe(IProject project) {
    if (!enableCopyFromExeButton.getSelection()) {
        setErrorMessage(null);
        return true;
    }
    String name = copyFromExeText.getText().trim();
    if (name.length() == 0) {
        setErrorMessage(ProxyLaunchMessages.copy_from_exe_is_not_specified);
        return false;
    }
    // changed (binary or project name). See bug 277663.
    if (name.equals(fPreviouslyCheckedCopyFromExe)) {
        if (fPreviouslyCheckedCopyFromExeErrorMsg != null) {
            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg);
        }
        return fPreviouslyCheckedCopyFromExeIsValid;
    }
    fPreviouslyCheckedCopyFromExe = name;
    // we'll flip this below if
    fPreviouslyCheckedCopyFromExeIsValid = true;
    // not true
    // we'll set this below if
    fPreviouslyCheckedCopyFromExeErrorMsg = 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(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
            fPreviouslyCheckedCopyFromExeIsValid = 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(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
        fPreviouslyCheckedCopyFromExeIsValid = false;
        return false;
    }
    if (!passed) {
        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
        fPreviouslyCheckedCopyFromExeIsValid = 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 (exeFI.exists()) {
                        if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
                            passed = true;
                        } else {
                            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_have_execution_rights);
                        }
                    } else {
                        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
                    }
                } else {
                    setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
                }
            } else {
                setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
            }
        } else {
            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.scheme_error_in_copy_from_exe);
        }
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.connection_of_copy_from_exe_cannot_be_opened);
    }
    if (!passed) {
        fPreviouslyCheckedCopyFromExeIsValid = 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 17 with IFileInfo

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

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

the class ImageBuildPage method validate.

private void validate() {
    boolean complete = true;
    boolean error = false;
    setMessage(null);
    String name = nameText.getText();
    if (name.length() > 0 && name.charAt(name.length() - 1) == ':') {
        setErrorMessage(WizardMessages.getString(INVALID_ID));
        error = true;
    } else {
        if (name.contains(":")) {
            // $NON-NLS-1$
            if (name.substring(name.indexOf(':') + 1).contains(":")) {
                // $NON-NLS-1$
                setErrorMessage(WizardMessages.getString(INVALID_ID));
                error = true;
            }
        } else if (name.isEmpty()) {
            setMessage(WizardMessages.getString(IMAGE_NAME_EMPTY), WARNING);
        }
    }
    if (!error) {
        String dir = directoryText.getText();
        if (dir.length() == 0) {
            editButton.setEnabled(false);
            complete = false;
        } else {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(dir));
            IFileInfo info = fileStore.fetchInfo();
            if (!info.exists()) {
                error = true;
                setErrorMessage(WizardMessages.getString(NONEXISTENT_DIRECTORY));
            } else if (!info.isDirectory()) {
                error = true;
                setErrorMessage(WizardMessages.getString(INVALID_DIRECTORY));
            } else if (!Files.isReadable(Paths.get(dir))) {
                error = true;
                setErrorMessage(WizardMessages.getString(UNREADABLE_DIRECTORY));
            } else {
                editButton.setEnabled(true);
                // $NON-NLS-1$
                IFileStore dockerStore = fileStore.getChild("Dockerfile");
                if (!dockerStore.fetchInfo().exists()) {
                    complete = false;
                    setMessage(WizardMessages.getString(NO_DOCKER_FILE), IMessageProvider.INFORMATION);
                } else {
                    lastDirectoryPath = dir;
                }
            }
        }
    }
    if (!error) {
        setErrorMessage(null);
    } else {
        editButton.setEnabled(false);
    }
    setPageComplete(complete && !error);
}
Also used : Path(org.eclipse.core.runtime.Path) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 19 with IFileInfo

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

the class EditMetaInfoAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    boolean isWorkflow = false;
    if (m_parent.getChild(WorkflowPersistor.WORKFLOW_FILE).fetchInfo().exists()) {
        isWorkflow = true;
    }
    // if no meta file is available
    IFileStore metaFileTest = m_parent.getChild(WorkflowPersistor.METAINFO_FILE);
    IFileInfo fetchInfo = metaFileTest.fetchInfo();
    if (!fetchInfo.exists() || (fetchInfo.getLength() == 0)) {
        // create one
        File parentFile;
        try {
            parentFile = m_parent.toLocalFile(EFS.NONE, null);
        } catch (CoreException e) {
            throw new RuntimeException("Meta Info files can only be created" + " for local workflows or groups. " + m_parent.getName() + " doesn't provide a local file.");
        }
        if (parentFile == null) {
            throw new RuntimeException("Meta Info files can only be created" + " for local workflows or groups. " + m_parent.getName() + " doesn't provide a local file.");
        }
        MetaInfoFile.createMetaInfoFile(parentFile, isWorkflow);
    }
    IFileStore metaFile = m_parent.getChild(WorkflowPersistor.METAINFO_FILE);
    try {
        IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), metaFile);
    } catch (PartInitException e) {
        String m = e.getMessage() == null ? "<no details>" : e.getMessage();
        throw new RuntimeException("Unable to initialize editor for Meta Info file of " + m_parent.getName() + ": " + m, e);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) MetaInfoFile(org.knime.workbench.ui.metainfo.model.MetaInfoFile)

Example 20 with IFileInfo

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

the class FileStoreBrowser method runRequest.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.filetransfer.browse.LocalFileSystemBrowser#runDirectoryRequest()
	 */
protected void runRequest() throws Exception {
    final IFileInfo fileStoreInfo = fileStore.fetchInfo();
    if (fileStoreInfo.isDirectory()) {
        final IFileInfo[] fileInfos = fileStore.childInfos(EFS.NONE, null);
        remoteFiles = new IRemoteFile[fileInfos.length];
        for (int i = 0; i < fileInfos.length; i++) {
            // $NON-NLS-1$
            remoteFiles[i] = new EFSRemoteFile(FileIDFactory.getDefault().createFileID(fileID.getNamespace(), new URL(directoryOrFile + "/" + fileInfos[i].getName())), fileInfos[i]);
        }
    } else {
        remoteFiles = new IRemoteFile[1];
        remoteFiles[0] = new EFSRemoteFile(fileID, fileStoreInfo);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) URL(java.net.URL)

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