Search in sources :

Example 66 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class IssuesProvider method getPersistedIssues.

public List<Issue> getPersistedIssues(URI uri) {
    List<Issue> result = Lists.newArrayList();
    Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(uri);
    for (Pair<IStorage, IProject> storageToProject : storages) {
        IStorage iStorage = storageToProject.getFirst();
        if (iStorage instanceof IFile) {
            try {
                IMarker[] markers;
                markers = ((IFile) iStorage).findMarkers(EValidator.MARKER, true, 1);
                for (IMarker iMarker : markers) {
                    Issue issue = issueUtil.createIssue(iMarker);
                    if (issue != null)
                        result.add(issue);
                }
            } catch (CoreException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return result;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IStorage(org.eclipse.core.resources.IStorage) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Example 67 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class AbstractJavaProjectsStateTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    javaProject1 = makeJavaProject(project1);
    addSourceFolder(javaProject1, "src2");
    uri1 = createFileAndRegisterResource(project1, "src/file1");
    uri2 = createFileAndRegisterResource(project1, "src/file2");
    uri3 = createFileAndRegisterResource(project2, "src2/file3");
    IResource member = javaProject1.getProject().findMember("src");
    srcRoot = javaProject1.getPackageFragmentRoot(member);
    Storage2UriMapperImpl mapper = new Storage2UriMapperImpl() {

        @Override
        public boolean isValidUri(URI uri, IStorage storage) {
            return uri != null && !uri.toString().endsWith("/.project") && !uri.toString().endsWith("/.classpath");
        }
    };
    UriValidator uriValidator = new UriValidator() {

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "name".equals(uri.fileExtension());
        }

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "name".equals(storage.getFullPath().getFileExtension());
        }
    };
    mapper.setUriValidator(uriValidator);
    Storage2UriMapperJavaImpl contribution = new Storage2UriMapperJavaImpl();
    contribution.setUriValidator(uriValidator);
    contribution.setJdtHelper(new JdtHelper());
    contribution.setWorkspaceLockAccess(new WorkspaceLockAccess());
    contribution.setLocator(new JarEntryLocator());
    contribution.setHost(mapper);
    mapper.setContribution(contribution);
    projectsState = createProjectsState(mapper);
}
Also used : WorkspaceLockAccess(org.eclipse.xtext.ui.workspace.WorkspaceLockAccess) Storage2UriMapperImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperImpl) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JdtHelper(org.eclipse.xtext.ui.shared.JdtHelper) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Example 68 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class WorkspaceProjectsStateHelper method initContainedURIs.

public Collection<URI> initContainedURIs(String containerHandle) {
    try {
        IPath projectPath = new Path(null, containerHandle).makeAbsolute();
        if (projectPath.segmentCount() != 1)
            return Collections.emptySet();
        IProject project = getWorkspaceRoot().getProject(containerHandle);
        if (project != null && isAccessibleXtextProject(project)) {
            Map<URI, IStorage> entries = getMapper().getAllEntries(project);
            return entries.keySet();
        }
    } catch (IllegalArgumentException e) {
        if (log.isDebugEnabled())
            log.debug("Cannot init contained URIs for containerHandle '" + containerHandle + "'", e);
    }
    return Collections.emptyList();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 69 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class JavaProjectResourceSetInitializer method computePlatformURIMap.

protected Map<URI, URI> computePlatformURIMap(IJavaProject javaProject) {
    HashMap<URI, URI> hashMap = newHashMap();
    if (isUseLegacyPlatformUriMap()) {
        try {
            hashMap.putAll(EcorePlugin.computePlatformURIMap(false));
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
    if (!javaProject.exists())
        return hashMap;
    try {
        IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
        for (IPackageFragmentRoot root : roots) {
            Pair<URI, URI> uriMapping = storage2UriMapper.getURIMapping(root);
            if (uriMapping != null) {
                // we could just install the prefix mapping, i.e. platform:resource/my.project/ -> file:/my/path/to/my.project/
                // but then we wouldn't be able to load resources when using hosted bundles, because the target path points to the bin folder.
                // so instead we install qualified file mappings, which also makes normalization faster (i.e. just a lookup in a map instead of testing prefix URIs)
                // 
                Map<URI, IStorage> mapping = storage2UriMapper.getAllEntries(root);
                for (URI key : mapping.keySet()) {
                    IStorage storage = mapping.get(key);
                    URI physicalURI = null;
                    if (storage instanceof IFile) {
                        physicalURI = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
                    } else {
                        physicalURI = key.replacePrefix(uriMapping.getFirst(), uriMapping.getSecond());
                    }
                    hashMap.put(key, physicalURI);
                    if (key.isPlatformResource()) {
                        URI pluginURI = URI.createPlatformPluginURI(key.toPlatformString(false), false);
                        hashMap.put(pluginURI, physicalURI);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        LOG.error(e.getMessage(), e);
    } catch (NoClassDefFoundError e) {
        // guard against broken Eclipse installations / bogus project configuration
        LOG.error(e.getMessage(), e);
    }
    return hashMap;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 70 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class DefaultResourceUIServiceProvider method isSource.

/**
 * @since 2.9
 */
@Override
public boolean isSource(URI uri) {
    if (delegate instanceof IResourceServiceProviderExtension) {
        if (!((IResourceServiceProviderExtension) delegate).isSource(uri))
            return false;
    }
    if (workspace != null) {
        if (uri.isPlatformResource()) {
            String projectName = URI.decode(uri.segment(1));
            IProject project = workspace.getRoot().getProject(projectName);
            return project.isAccessible();
        }
        if (uri.isPlatformPlugin()) {
            return false;
        }
    }
    Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(uri);
    for (Pair<IStorage, IProject> pair : storages) {
        IStorage storage = pair.getFirst();
        if (storage instanceof IFile) {
            return ((IFile) storage).isAccessible();
        } else {
            return false;
        }
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IStorage(org.eclipse.core.resources.IStorage) IResourceServiceProviderExtension(org.eclipse.xtext.resource.IResourceServiceProviderExtension) IProject(org.eclipse.core.resources.IProject) Pair(org.eclipse.xtext.util.Pair)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6