use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testResourceInJar.
@Test
public void testResourceInJar() throws Exception {
IJavaProject project = createJavaProject("foo");
IFile file = project.getProject().getFile("foo.jar");
file.create(jarInputStream(new TextFile("foo/bar.indexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty")), true, monitor());
// we do cache per timestamp - test is to fast and tries to update the file content in the very same millisecond
// that's why we fake the timestamp here
file.setLocalTimeStamp(123L);
addJarToClasspath(project, file);
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
Map<URI, IStorage> rootData = impl.getAllEntries(root);
assertEquals(1, rootData.size());
assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.indexed", rootData.keySet().iterator().next().toString());
file.setContents(jarInputStream(new TextFile("foo/bar.notindexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty")), IResource.FORCE, monitor());
rootData = impl.getAllEntries(root);
assertTrue(rootData.isEmpty());
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testResourceInExternalFolder.
@Test
public void testResourceInExternalFolder() throws Exception {
IFolder externalFolder = createExternalFolder("externalFolder");
IJavaProject project = createJavaProject("foo");
IFile file = externalFolder.getFile("a.indexed");
file.create(new StringInputStream("content"), true, monitor());
IFile file2 = externalFolder.getFile("b.nonindexed");
file2.create(new StringInputStream("content"), true, monitor());
IClasspathEntry classpathEntry = addExternalFolderToClasspath(project, externalFolder);
IPackageFragmentRoot packageFragmentRoot = project.findPackageFragmentRoots(classpathEntry)[0];
Assert.assertTrue(packageFragmentRoot.getPath().toFile().setLastModified(456L));
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder);
Map<URI, IStorage> rootData = impl.getAllEntries(root);
assertEquals(rootData.toString(), 1, rootData.size());
assertEquals("platform:/resource/.org.eclipse.jdt.core.external.folders/externalFolder/a.indexed", rootData.keySet().iterator().next().toString());
IFile file3 = externalFolder.getFile("c.indexed");
file3.create(new StringInputStream("content"), true, monitor());
rootData = impl.getAllEntries(root);
assertEquals(rootData.toString(), 2, rootData.size());
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class ResourceAccess method readOnly.
@Override
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
URI resourceURI = targetURI.trimFragment();
Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI);
Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
ResourceSet resourceSet = fallBackResourceSet;
while (iterator.hasNext()) {
Pair<IStorage, IProject> pair = iterator.next();
IProject project = pair.getSecond();
if (project != null) {
resourceSet = getResourceSet(project);
break;
}
}
if (resourceSet != null) {
resourceSet.getResource(resourceURI, true);
try {
return work.exec(resourceSet);
} catch (Exception e) {
throw new WrappedException(e);
}
}
return null;
}
use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.
the class DerivedResourceMarkerBasedOpenerContributor method collectGeneratedFileOpeners.
@Override
public boolean collectGeneratedFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
IStorage storage = getStorage(editor);
if (storage != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
try {
List<IFile> resources = derivedResourceMarkers.findDerivedResources(root, uri.toString());
for (IFile file : resources) acceptor.accept(createOpener(file));
return true;
} catch (CoreException e) {
LOG.error(e.getMessage(), e);
}
}
return false;
}
use of org.eclipse.core.resources.IStorage in project jbosstools-hibernate by jbosstools.
the class HQLEditorInputFactory method saveState.
public static void saveState(IMemento memento, HQLEditorInput input) {
// Save the editor input type.
memento.putString(KEY_EDITOR_INPUT_TYPE, ID_STORAGE_EDITOR_INPUT);
String storageName = null;
// $NON-NLS-1$
String storageContent = "";
// $NON-NLS-1$
String configurationName = "";
IStorage storage = input.getStorage();
if (storage != null) {
storageName = storage.getName();
if (storage instanceof HQLEditorStorage) {
HQLEditorStorage sqlEditorStorage = (HQLEditorStorage) storage;
storageContent = sqlEditorStorage.getContentsString();
configurationName = sqlEditorStorage.getConfigurationName();
}
}
// Save the storage content name in the memento.
memento.putString(KEY_STORAGE_NAME, storageName);
// Save the storage content string in the memento.
memento.putString(KEY_STORAGE_CONTENT, storageContent);
memento.putString(KEY_CONFIGURATION_NAME, configurationName);
}
Aggregations