Search in sources :

Example 1 with FileReplicator

use of org.apache.commons.vfs2.provider.FileReplicator in project spoofax by metaborg.

the class ResourceService method close.

@Override
public void close() throws Exception {
    if (fileSystemManager instanceof DefaultFileSystemManager) {
        final DefaultFileSystemManager defaultFileSystemManager = (DefaultFileSystemManager) fileSystemManager;
        final FileReplicator replicator = defaultFileSystemManager.getReplicator();
        if (replicator instanceof DefaultFileReplicator) {
            final DefaultFileReplicator defaultFileReplicator = (DefaultFileReplicator) replicator;
            defaultFileReplicator.close();
        } else {
            logger.warn("File replicator {} does not support cleaning up generated temporary files", replicator);
        }
    } else {
        logger.warn("File system manager {} does not support cleaning up generated temporary files", fileSystemManager);
    }
}
Also used : DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileReplicator(org.apache.commons.vfs2.provider.FileReplicator) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator)

Example 2 with FileReplicator

use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.

the class AccumuloVFSClassLoader method close.

public static void close() {
    for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) {
        DefaultFileSystemManager ref = vfsInstance.get();
        if (ref != null) {
            FileReplicator replicator;
            try {
                replicator = ref.getReplicator();
                if (replicator instanceof UniqueFileReplicator) {
                    ((UniqueFileReplicator) replicator).close();
                }
            } catch (FileSystemException e) {
                log.error("FileSystemException", e);
            }
            ref.close();
        }
    }
    try {
        FileUtils.deleteDirectory(computeTopCacheDir());
    } catch (IOException e) {
        log.error("IOException", e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) IOException(java.io.IOException) FileReplicator(org.apache.commons.vfs2.provider.FileReplicator)

Example 3 with FileReplicator

use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.

the class AccumuloVFSClassLoaderTest method testDefaultCacheDirectory.

@Test
public void testDefaultCacheDirectory() throws Exception {
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>general.vfs.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();
    Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    AccumuloVFSClassLoader.getClassLoader();
    FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
    String tempDirParent = tempDir.getParent();
    String tempDirName = tempDir.getName();
    String javaIoTmpDir = System.getProperty("java.io.tmpdir");
    // trim off any final separator, because java.io.File does the same.
    if (javaIoTmpDir.endsWith(File.separator)) {
        javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length());
    }
    Assert.assertTrue(javaIoTmpDir.equals(tempDirParent));
    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with FileReplicator

use of org.apache.commons.vfs2.provider.FileReplicator in project accumulo by apache.

the class AccumuloVFSClassLoaderTest method testCacheDirectoryConfigured.

@Test
public void testCacheDirectoryConfigured() throws Exception {
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
    String cacheDir = "/some/random/cache/dir";
    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>" + AccumuloVFSClassLoader.VFS_CACHE_DIR + "</name>\n");
    out.append("<value>" + cacheDir + "</value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();
    Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    AccumuloVFSClassLoader.getClassLoader();
    FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
    String tempDirParent = tempDir.getParent();
    String tempDirName = tempDir.getName();
    Assert.assertTrue(cacheDir.equals(tempDirParent));
    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

File (java.io.File)2 FileWriter (java.io.FileWriter)2 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)2 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)2 FileReplicator (org.apache.commons.vfs2.provider.FileReplicator)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IOException (java.io.IOException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)1