Search in sources :

Example 1 with JarFileSystemImpl

use of com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl in project intellij-community by JetBrains.

the class LoaderFactory method createClassLoader.

private static ClassLoader createClassLoader(final String runClasspath, final String moduleName) {
    final ArrayList<URL> urls = new ArrayList<>();
    final VirtualFileManager manager = VirtualFileManager.getInstance();
    final JarFileSystemImpl fileSystem = (JarFileSystemImpl) JarFileSystem.getInstance();
    final StringTokenizer tokenizer = new StringTokenizer(runClasspath, File.pathSeparator);
    while (tokenizer.hasMoreTokens()) {
        final String s = tokenizer.nextToken();
        try {
            VirtualFile vFile = manager.findFileByUrl(VfsUtil.pathToUrl(s));
            final File realFile = fileSystem.getMirroredFile(vFile);
            urls.add(realFile != null ? realFile.toURI().toURL() : new File(s).toURI().toURL());
        } catch (Exception e) {
        // ignore ?
        }
    }
    try {
        urls.add(new File(PathUtil.getJarPathForClass(Spacer.class)).toURI().toURL());
    } catch (MalformedURLException ignored) {
    // ignore
    }
    final URL[] _urls = urls.toArray(new URL[urls.size()]);
    return new DesignTimeClassLoader(Arrays.asList(_urls), LoaderFactory.class.getClassLoader(), moduleName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) JarFileSystemImpl(com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with JarFileSystemImpl

use of com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl in project intellij-community by JetBrains.

the class JarFileSystemTest method testJarHandlerDoNotCreateCopyWhenListingArchive.

@Test
public void testJarHandlerDoNotCreateCopyWhenListingArchive() throws Exception {
    File jar = IoTestUtil.createTestJar(tempDir.newFile("test.jar"));
    JarHandler handler = new JarHandler(jar.getPath());
    FileAttributes attributes = handler.getAttributes(JarFile.MANIFEST_NAME);
    assertNotNull(attributes);
    assertEquals(0, attributes.length);
    assertTimestampsEqual(jar.lastModified(), attributes.lastModified);
    if (((JarFileSystemImpl) JarFileSystem.getInstance()).isMakeCopyOfJar(jar)) {
        // for performance reasons we create file copy on windows when we read contents and have the handle open to the copy
        Field resolved = handler.getClass().getDeclaredField("myFileWithMirrorResolved");
        resolved.setAccessible(true);
        assertTrue(resolved.get(handler) == null);
    }
}
Also used : Field(java.lang.reflect.Field) JarFileSystemImpl(com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl) JarFile(java.util.jar.JarFile) JarHandler(com.intellij.openapi.vfs.impl.jar.JarHandler) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Test(org.junit.Test)

Aggregations

JarFileSystemImpl (com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 JarHandler (com.intellij.openapi.vfs.impl.jar.JarHandler)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 JarFile (java.util.jar.JarFile)1 Test (org.junit.Test)1