use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testBug463258_05.
@Test
public void testBug463258_05() throws Exception {
IJavaProject project = createJavaProject("foo");
final Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar");
IPackageFragment foo = root.getPackageFragment("foo");
final JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
fileInJar.setParent(foo);
LoggingTester.captureLogging(Level.ERROR, Storage2UriMapperJavaImpl.class, new Runnable() {
@Override
public void run() {
URI uri = impl.getUri(fileInJar);
assertNull(uri);
}
}).assertNoLogEntries();
}
use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl 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.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testBug463258_01.
@Test
public void testBug463258_01() throws Exception {
IJavaProject project = createJavaProject("foo");
IFile file = project.getProject().getFile("foo.jar");
file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
addJarToClasspath(project, file);
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
IPackageFragment foo = root.getPackageFragment("foo");
JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
fileInJar.setParent(foo);
URI uri = impl.getUri(fileInJar);
assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.notindexed", uri.toString());
try (InputStream stream = new ResourceSetImpl().getURIConverter().createInputStream(uri)) {
byte[] bytes = ByteStreams.toByteArray(stream);
assertEquals("//empty", new String(bytes));
}
}
use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testJaredBundle.
@Test
public void testJaredBundle() 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"), new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: hubba.bubba\n")), true, monitor());
file.setLocalTimeStamp(678L);
addJarToClasspath(project, file);
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
Map<URI, IStorage> rootData = impl.getAllEntries(root);
assertEquals(1, rootData.size());
assertEquals("platform:/resource/hubba.bubba/foo/bar.indexed", rootData.keySet().iterator().next().toString());
// let's change the bundle name
file.setContents(jarInputStream(new TextFile("foo/bar.indexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty"), new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: other.bundle.name;singleton:=true\n")), IResource.FORCE, monitor());
rootData = impl.getAllEntries(root);
assertEquals(1, rootData.size());
assertEquals("platform:/resource/other.bundle.name/foo/bar.indexed", rootData.keySet().iterator().next().toString());
}
use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method getStorage2UriMapper.
protected Storage2UriMapperJavaImpl getStorage2UriMapper() {
Storage2UriMapperJavaImpl impl = new Storage2UriMapperJavaImpl();
impl.setUriValidator(new UriValidator() {
@Override
public boolean isPossiblyManaged(IStorage storage) {
return "indexed".equals(storage.getFullPath().getFileExtension());
}
@Override
public boolean isValid(URI uri, IStorage storage) {
return "indexed".equals(storage.getFullPath().getFileExtension());
}
});
impl.setLocator(new JarEntryLocator());
return impl;
}
Aggregations