Search in sources :

Example 21 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project titan.EclipsePlug-ins by eclipse.

the class MakefileGeneratorVisitor method visit.

@Override
public boolean visit(final IResource resource) throws CoreException {
    if (!resource.isAccessible()) {
        return false;
    }
    URI resourceURI = resource.getLocationURI();
    // Not having a location in the local file system is an
    // error, but should only be reported if the resource is
    // not excluded from build.
    String resourceName = new Path(resourceURI.getPath()).lastSegment();
    if (resourceName.startsWith(".")) {
        return false;
    }
    try {
        URI resolved = resource.getWorkspace().getPathVariableManager().resolveURI(resource.getLocationURI());
        IFileStore store = EFS.getStore(resolved);
        IFileInfo fileInfo = store.fetchInfo();
        if (!fileInfo.exists()) {
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    switch(resource.getType()) {
        case IResource.FILE:
            if (ResourceExclusionHelper.isDirectlyExcluded((IFile) resource) || helper.isExcludedByRegexp(resourceName)) {
                return false;
            }
            String folder = projectVisited == makefileGenerator.getProject() ? null : actualWorkingDirectory;
            for (URI centralStorage : getCentralStorages()) {
                if (resourceURI.getHost() == centralStorage.getHost() && resourceURI.getPath().startsWith(centralStorage.getPath())) {
                    folder = centralStorage.getPath();
                    for (BaseDirectoryStruct dir : makefileGenerator.getBaseDirectories()) {
                        if (dir.getDirectory() != null && dir.getDirectory().isPrefixOf(resource.getFullPath())) {
                            dir.setHasModules(true);
                            break;
                        }
                    }
                    break;
                }
            }
            if (resource.getLocation() == null && folder == null) {
                folder = actualWorkingDirectory;
            }
            IFile file = (IFile) resource;
            String extension = file.getFileExtension();
            if ("ttcn3".equals(extension) || "ttcn".equals(extension)) {
                makefileGenerator.addTTCN3Module(file, folder);
            } else if ("asn".equals(extension) || "asn1".equals(extension)) {
                makefileGenerator.addASN1Module(file, folder);
            } else if ("ttcnpp".equals(extension)) {
                makefileGenerator.addPreprocessingModule(file, folder);
            } else if ("ttcnin".equals(extension)) {
                makefileGenerator.addIncludeModule(file, folder);
            } else if ("c".equals(extension) || "cc".equals(extension)) {
                makefileGenerator.addUserSourceFile(file, folder);
            } else if ("h".equals(extension) || "hh".equals(extension)) {
                makefileGenerator.addUserHeaderFile(file, folder);
            } else {
                makefileGenerator.addOtherFiles(file, folder);
            }
            return false;
        case IResource.FOLDER:
            for (IContainer workingDirectory : workingDirectories) {
                if (workingDirectory.equals(resource)) {
                    if (projectVisited != makefileGenerator.getProject()) {
                        makefileGenerator.addBaseDirectory(resource.getLocation());
                    }
                    return false;
                }
            }
            if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) resource) || helper.isExcludedByRegexp(resourceName)) {
                return false;
            }
            if (ResourceUtils.getBooleanPersistentProperty(resource, FolderBuildPropertyData.QUALIFIER, FolderBuildPropertyData.CENTRAL_STORAGE_PROPERTY)) {
                makefileGenerator.addBaseDirectory(resource.getLocation());
                getCentralStorages().add(resourceURI);
            }
            break;
        default:
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) IContainer(org.eclipse.core.resources.IContainer) URI(java.net.URI) IFolder(org.eclipse.core.resources.IFolder)

Example 22 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project titan.EclipsePlug-ins by eclipse.

the class ReferencedProjectResourceVisitor method visit.

@Override
public boolean visit(final IResource resource) {
    if (resource == null || !resource.isAccessible()) {
        return false;
    }
    final URI resourceLocation = resource.getLocationURI();
    resourcename = resource.getName();
    if (resourcename == null || resourcename.startsWith(DOT)) {
        return false;
    }
    try {
        final URI resolved = resource.getWorkspace().getPathVariableManager().resolveURI(resourceLocation);
        final IFileStore store = EFS.getStore(resolved);
        final IFileInfo fileInfo = store.fetchInfo();
        if (!fileInfo.exists()) {
            ErrorReporter.logError("The resource `" + resource.getFullPath() + "' points to a non-existing location.");
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    switch(resource.getType()) {
        case IResource.FILE:
            if (!ResourceExclusionHelper.isDirectlyExcluded((IFile) resource) && !helper.isExcludedByRegexp(resourcename)) {
                boolean inExcluded = false;
                final IPath resourceFullPath = resource.getFullPath();
                for (int i = 0; i < excludedFolders.size(); i++) {
                    final IPath excludedFolder = excludedFolders.get(i);
                    if (excludedFolder.isPrefixOf(resourceFullPath)) {
                        inExcluded = true;
                        break;
                    }
                }
                IFile file = (IFile) resource;
                if (inExcluded) {
                    excludedFiles.put(resource.getName(), file);
                    return false;
                }
                boolean inCentralStorage = false;
                for (int i = 0; i < centralStorages.size(); i++) {
                    final URI centralFolder = centralStorages.get(i);
                    if (centralFolder.getHost() == resourceLocation.getHost() && resourceLocation.getPath().startsWith(centralFolder.getPath())) {
                        inCentralStorage = true;
                        break;
                    }
                }
                file = (IFile) resource;
                if (inCentralStorage) {
                    if (file.getLocation() == null) {
                        centralStorageFiles.put(file.getName(), file);
                    } else {
                        centralStorageFiles.put(file.getLocation().toOSString(), file);
                    }
                } else {
                    files.put(resourcename, file);
                }
            }
            return false;
        case IResource.FOLDER:
            for (IContainer workingDirectory : workingDirectories) {
                if (workingDirectory.equals(resource)) {
                    return false;
                }
            }
            try {
                if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) resource) || helper.isExcludedByRegexp(resourcename)) {
                    excludedFolders.add(resource.getFullPath());
                }
                if (TRUE.equals(resource.getPersistentProperty(new QualifiedName(FolderBuildPropertyData.QUALIFIER, FolderBuildPropertyData.CENTRAL_STORAGE_PROPERTY)))) {
                    centralStorages.add(resourceLocation);
                }
            } catch (CoreException e) {
                return false;
            }
            break;
        default:
    }
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) QualifiedName(org.eclipse.core.runtime.QualifiedName) IFileStore(org.eclipse.core.filesystem.IFileStore) IContainer(org.eclipse.core.resources.IContainer) URI(java.net.URI) IFolder(org.eclipse.core.resources.IFolder)

Example 23 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project titan.EclipsePlug-ins by eclipse.

the class TTCN3Analyzer method parse.

/**
 * Parse TTCN-3 file using ANTLR v4
 * @param aFile TTCN-3 file to parse, It cannot be null
 * @param aCode TTCN-3 code to parse in string format
 *              It can be null, in this case code is read from file
 */
public void parse(final IFile aFile, final String aCode) {
    Reader reader;
    int rootInt;
    if (aCode != null) {
        reader = new StringReader(aCode);
        rootInt = aCode.length();
    } else if (aFile != null) {
        try {
            InputStreamReader temp = new InputStreamReader(aFile.getContents());
            if (!aFile.getCharset().equals(temp.getEncoding())) {
                try {
                    temp.close();
                } catch (IOException e) {
                    ErrorReporter.logWarningExceptionStackTrace(e);
                }
                temp = new InputStreamReader(aFile.getContents(), aFile.getCharset());
            }
            reader = new BufferedReader(temp);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        } catch (UnsupportedEncodingException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        }
        IFileStore store;
        try {
            store = EFS.getStore(aFile.getLocationURI());
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        }
        IFileInfo fileInfo = store.fetchInfo();
        rootInt = (int) fileInfo.getLength();
    } else {
        return;
    }
    parse(reader, rootInt, aFile);
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 24 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project erlide_eclipse by erlang.

the class EditorUtility method resolveFile.

private static IFile resolveFile(final IFile file) {
    IFile result = file;
    if (file.getResourceAttributes().isSymbolicLink()) {
        try {
            final File f = new File(file.getLocation().toString());
            final IFileInfo info = EFS.getFileSystem(EFS.SCHEME_FILE).fromLocalFile(f).fetchInfo();
            final String target = info.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET);
            if (target != null) {
                // FIXME this is wrong in the general case
                // find the file in the externals!
                result = (IFile) file.getParent().findMember(target);
                if (result == null) {
                    result = file;
                }
            }
        } catch (final Exception e) {
            ErlLogger.warn(e);
        }
    }
    return result;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException)

Example 25 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project eclipse.jdt.ls by eclipse.

the class CreateFileChange method isValid.

@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);
    URI location = file.getLocationURI();
    if (location == null) {
        result.addFatalError(Messages.format(NLSChangesMessages.CreateFileChange_error_unknownLocation, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
        return result;
    }
    IFileInfo jFile = EFS.getStore(location).fetchInfo();
    if (jFile.exists()) {
        result.addFatalError(Messages.format(NLSChangesMessages.CreateFileChange_error_exists, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
        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