public void assertRemoveSource(String name) { try { I path = strategy.sourcePath.getPath(name); if (path == null) { throw AbstractTestCase.failure("Cannot remove path " + Tools.join('/', name)); } strategy.sourcePath.removePath(path); } catch (Exception e) { throw AbstractTestCase.failure(e); } } }
public FileResource<I> assertAddSource(String name, String ext, String content) { try { ReadWriteFileSystem<I> fs = strategy.sourcePath; String[] atoms = Tools.split(name, '.'); I path; if (atoms.length > 1) { path = fs.makePath(Tools.iterable(atoms, 0, atoms.length - 1)); fs.createDir(path); } else { path = fs.getRoot(); } path = fs.makePath(path, atoms[atoms.length - 1] + "." + ext); fs.updateResource(path, new Resource(content)); return new FileResource<I>(fs, path); } catch (IOException e) { throw AbstractTestCase.failure(e); } }
public Compiler assertCompile() { try { strategy.compile(); ArrayList<URL> urls = new ArrayList<URL>(); urls.add(strategy.classOutput.getURL()); Iterator<ReadFileSystem<?>> i = strategy.classPath.iterator(); // Skip the first one that is the context classloader i.next(); while (i.hasNext()) { urls.add(i.next().getURL()); } classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); return strategy.compiler; } catch (Exception e) { throw AbstractTestCase.failure(e); } }
private <D> int kind(P srcPath, ReadWriteFileSystem<D> dst, D dstPath) throws IOException { if (isDir(srcPath)) { if (dst.isDir(dstPath)) { return 1; } else if (dst.isFile(dstPath)) { return 2; } else { return 1; } } else if (isFile(srcPath)) { if (dst.isFile(dstPath)) { return 0; } else if (dst.isDir(dstPath)) { return 3; } else { return 0; } } else { return 4; } }
public FileResource<I> assertSource(String name, String ext) { I path; try { String[] atoms = Tools.split(name, '.'); atoms[atoms.length - 1] += "." + ext; path = strategy.sourcePath.getPath(atoms); if (path == null) { throw AbstractTestCase.failure("Was not expecting " + Arrays.asList(name) + " to be null file"); } return new FileResource<I>(strategy.sourcePath, path); } catch (IOException e) { throw AbstractTestCase.failure(e); } }
File foo = output.makePath(output.getRoot(), "foo.txt"); output.updateResource(foo, new Resource("foo_value")); File root = output.getRoot(); Map<String, File> children = new HashMap<String, File>(); for (Iterator<File> i = output.getChildren(root);i.hasNext();) { File path = i.next(); if (output.isFile(path)) { children.put(output.getName(path), path); assertEquals("new_foo_value", output.getResource(foo).getObject().getCharSequence(Charset.defaultCharset())); File juu = children.get("juu.txt"); assertEquals("juu_value", output.getResource(juu).getObject().getCharSequence(Charset.defaultCharset()).toString());
case 0: { if (filter.acceptFile(srcPath, srcName)) { dst.updateResource(dstPath, getResource(srcPath).getObject()); for (Iterator<D> i = dst.getChildren(dstPath);i.hasNext();) { D next = i.next(); String name = dst.getName(next); P a = getChild(srcPath, name); P next = i.next(); String name = getName(next); D a = dst.getChild(dstPath, name); if (a == null) { boolean dir = isDir(next); boolean accept = dir ? filter.acceptDir(next, name) : filter.acceptFile(next, name); if (accept) { a = dst.makePath(dstPath, name); copy(next, filter, dst, a);
@Test public void testIncremental() throws IOException, CompilationException { CompilerAssert<File, File> compiler = compiler(true, Name.parse("compiler.incremental"), ""). with(compilerProvider). with((Provider<? extends Processor>)null); compiler.assertCompile(); // ReadWriteFileSystem<File> classOutput = compiler.getClassOutput(); assertEquals(1, classOutput.size(ReadFileSystem.FILE)); // ReadWriteFileSystem<File> sourcePath = (ReadWriteFileSystem<File>)compiler.getSourcePath(); File b = sourcePath.makePath(sourcePath.getPath("compiler", "incremental"), "B.java"); sourcePath.updateResource(b, new Resource("package compiler.incremental; public class B extends A {}")); compiler.assertCompile(); assertEquals(2, classOutput.size(ReadFileSystem.FILE)); }
String path = matcher.group(1) + ".class"; String[] names = Tools.split(path, '/'); O clazz = classOutput.getPath(names); if (clazz != null) { classOutput.removePath(clazz); if (classOutput.size(ReadFileSystem.FILE) > 0) { File root = File.createTempFile("juzu", ""); Assert.assertTrue(root.delete()); root.deleteOnExit(); ReadWriteFileSystem classes = new DiskFileSystem(root); classOutput.copy(new Filter.Default<O>() { @Override public boolean acceptFile(O file, String name) throws IOException {
public <D> void copy(Filter<P> filter, ReadWriteFileSystem<D> dst) throws IOException { copy(getRoot(), filter, dst, dst.getRoot()); }
@Test public void testGetNames() throws IOException { ReadWriteFileSystem<P> fs = create(); assertFalse(fs.getNames(fs.getRoot()).iterator().hasNext()); List<String> expected = Tools.list("a", "b", "c"); P path = fs.makePath(expected); List<String> test = Tools.list(fs.getNames(path)); assertEquals(expected, test); }
@Test public void testLifeCycle() throws Exception { ReadWriteFileSystem<P> fs = create(); // The root exist P foo = fs.makePath(Collections.singleton("foo")); P bar = fs.makePath(foo, "bar"); assertEquals(1, fs.size(ReadFileSystem.PATH)); // Now create fs.updateResource(bar, new Resource("FOO")); // assertEquals(3, fs.size(ReadFileSystem.PATH)); assertEquals(2, fs.size(ReadFileSystem.DIR)); assertEquals(1, fs.size(ReadFileSystem.FILE)); } }
@Override public void close() throws IOException { Resource content = new Resource(toByteArray(), null); long lastModified = fs.updateResource(file, content); JavaFileObjectImpl.this.content = new Timestamped<Resource>(lastModified, content); JavaFileObjectImpl.this.writing = false; } };
public void assertTouch() { try { Resource content = sourcePath.getResource(path).getObject(); sourcePath.updateResource(path, content); } catch (Exception e) { throw AbstractTestCase.failure(e); } }
public boolean delete() { if (fs instanceof ReadWriteFileSystem) { try { return ((ReadWriteFileSystem<P>)fs).removePath(file); } catch (IOException ignore) { return false; } } else { return false; } }
public JavaFileObjectImpl getWritable(FileKey key) throws IOException { JavaFileObjectImpl entry = getReadable(key); if (entry == null) { if (fs instanceof ReadWriteFileSystem<?>) { ReadWriteFileSystem<P> rwFS = (ReadWriteFileSystem<P>)fs; P file = rwFS.makePath(key.names); entries.put(key, entry = new JavaFileObjectImpl<P>(location, key, fs, file)); } else { throw new IOException("File system is not writable"); } } return entry; }
public FileResource<I> assertSource(String name, String ext) { I path; try { String[] atoms = Tools.split(name, '.'); atoms[atoms.length - 1] += "." + ext; path = strategy.sourcePath.getPath(atoms); if (path == null) { throw AbstractTestCase.failure("Was not expecting " + Arrays.asList(name) + " to be null file"); } return new FileResource<I>(strategy.sourcePath, path); } catch (IOException e) { throw AbstractTestCase.failure(e); } }
File foo = output.makePath(output.getRoot(), "foo.txt"); output.updateResource(foo, new Resource("foo_value")); File root = output.getRoot(); Map<String, File> children = new HashMap<String, File>(); for (Iterator<File> i = output.getChildren(root);i.hasNext();) { File path = i.next(); if (output.isFile(path)) { children.put(output.getName(path), path); assertEquals("new_foo_value", output.getResource(foo).getObject().getCharSequence(Charset.defaultCharset())); File juu = children.get("juu.txt"); assertEquals("juu_value", output.getResource(juu).getObject().getCharSequence(Charset.defaultCharset()).toString());