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;
}
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);
}
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();
}
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;
}
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;
}
Aggregations