@Test public void verify_classpath_replication() { List<ClasspathEntry> cp = Classpath.getClasspath(getClass().getClassLoader()); System.out.println("Cached classpath"); for(ClasspathEntry entry: cp) { String path = console.cacheFile(entry); System.out.println(" - " + path); File file = new File(path); assertTrue(file.isFile()); assertEquals("File size should be same", entry.size(), file.length()); } }
@Override public String cacheFile(FileBlob blob) { ensureRunning(); try { File file = blob.getLocalFile(); if (file != null && file.isFile()) { return file.getCanonicalPath(); } else { synchronized(hashCache) { String hashKey = blob.getContentHash() + "___" + blob.getFileName(); if (hashCache.containsKey(hashKey)) { return hashCache.get(hashKey); } else { File f = new File(new File(cacheDir, blob.getContentHash()), blob.getFileName()); f.getParentFile().mkdirs(); File tmp = File.createTempFile(f.getName(), "", f.getParentFile()); FileOutputStream fos = new FileOutputStream(tmp); StreamHelper.copy(blob.getContent(), fos); fos.close(); tmp.renameTo(f); f.deleteOnExit(); String path = f.getCanonicalPath(); hashCache.put(hashKey, path); return path; } } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
LocalControlConsole implements HostControlConsole { @Override public String cacheFile(FileBlob blob) { ensureRunning(); try { File file = blob.getLocalFile(); if (file != null && file.isFile()) { return file.getCanonicalPath(); } else { synchronized(hashCache) { String hashKey = blob.getContentHash() + "___" + blob.getFileName(); if (hashCache.containsKey(hashKey)) { return hashCache.get(hashKey); } else { File f = new File(new File(cacheDir, blob.getContentHash()), blob.getFileName()); f.getParentFile().mkdirs(); File tmp = File.createTempFile(f.getName(), "", f.getParentFile()); FileOutputStream fos = new FileOutputStream(tmp); StreamHelper.copy(blob.getContent(), fos); fos.close(); tmp.renameTo(f); f.deleteOnExit(); String path = f.getCanonicalPath(); hashCache.put(hashKey, path); return path; } } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }
LocalControlConsole implements HostControlConsole { @Override public String cacheFile(FileBlob blob) { ensureRunning(); try { File file = blob.getLocalFile(); if (file != null && file.isFile()) { return file.getCanonicalPath(); } else { synchronized(hashCache) { String hashKey = blob.getContentHash() + "___" + blob.getFileName(); if (hashCache.containsKey(hashKey)) { return hashCache.get(hashKey); } else { File f = new File(new File(cacheDir, blob.getContentHash()), blob.getFileName()); f.getParentFile().mkdirs(); File tmp = File.createTempFile(f.getName(), "", f.getParentFile()); FileOutputStream fos = new FileOutputStream(tmp); StreamHelper.copy(blob.getContent(), fos); fos.close(); tmp.renameTo(f); f.deleteOnExit(); String path = f.getCanonicalPath(); hashCache.put(hashKey, path); return path; } } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } LocalControlConsole();  LocalControlConsole(String tmpDir); }
LocalControlConsole implements HostControlConsole { @Override public String cacheFile(FileBlob blob) { ensureRunning(); try { File file = blob.getLocalFile(); if (file != null && file.isFile()) { return file.getCanonicalPath(); } else { synchronized(hashCache) { String hashKey = blob.getContentHash() + "___" + blob.getFileName(); if (hashCache.containsKey(hashKey)) { return hashCache.get(hashKey); } else { File f = new File(new File(cacheDir, blob.getContentHash()), blob.getFileName()); f.getParentFile().mkdirs(); File tmp = File.createTempFile(f.getName(), "", f.getParentFile()); FileOutputStream fos = new FileOutputStream(tmp); StreamHelper.copy(blob.getContent(), fos); fos.close(); tmp.renameTo(f); f.deleteOnExit(); String path = f.getCanonicalPath(); hashCache.put(hashKey, path); return path; } } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } LocalControlConsole();  LocalControlConsole(String tmpDir); @Override boolean isLocalFileSystem(); @Override String cacheFile(FileBlob blob); @Override List<String> cacheFiles(List<? extends FileBlob> blobs); @Override Destroyable openSocket(SocketHandler handler); @Override Destroyable startProcess(String workingDir, String[] command, Map<String, String> env, ProcessHandler handler); @Override void terminate(); File getCacheDir(); }
LocalControlConsole implements HostControlConsole { @Override public String cacheFile(FileBlob blob) { ensureRunning(); try { File file = blob.getLocalFile(); if (file != null && file.isFile()) { return file.getCanonicalPath(); } else { synchronized(hashCache) { String hashKey = blob.getContentHash() + "___" + blob.getFileName(); if (hashCache.containsKey(hashKey)) { return hashCache.get(hashKey); } else { File f = new File(new File(cacheDir, blob.getContentHash()), blob.getFileName()); f.getParentFile().mkdirs(); File tmp = File.createTempFile(f.getName(), "", f.getParentFile()); FileOutputStream fos = new FileOutputStream(tmp); StreamHelper.copy(blob.getContent(), fos); fos.close(); tmp.renameTo(f); f.deleteOnExit(); String path = f.getCanonicalPath(); hashCache.put(hashKey, path); return path; } } } } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } LocalControlConsole();  LocalControlConsole(String tmpDir); @Override boolean isLocalFileSystem(); @Override String cacheFile(FileBlob blob); @Override List<String> cacheFiles(List<? extends FileBlob> blobs); @Override Destroyable openSocket(SocketHandler handler); @Override Destroyable startProcess(String workingDir, String[] command, Map<String, String> env, ProcessHandler handler); @Override void terminate(); File getCacheDir();  }