# HG changeset patch # User Jaroslav Tulach # Date 1213430216 -7200 # Node ID 6a66df28018c8ed1c67dde890c4b82f880f847ed # Parent df21e222a7815b8e0b3a2bdd03ddef520733c8f7 Sample code to work with filesystem layers diff -r df21e222a781 -r 6a66df28018c samples/libs/build.xml --- a/samples/libs/build.xml Sat Jun 14 09:56:36 2008 +0200 +++ b/samples/libs/build.xml Sat Jun 14 09:56:56 2008 +0200 @@ -11,6 +11,11 @@ + + + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/build.xml Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project unionfs. + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/nbproject/build-impl.xml Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,627 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/nbproject/genfiles.properties Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=31076a65 +build.xml.script.CRC32=977a9029 +build.xml.stylesheet.CRC32=be360661 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=31076a65 +nbproject/build-impl.xml.script.CRC32=3625d6eb +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r df21e222a781 -r 6a66df28018c samples/unionfs/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/nbproject/project.properties Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,63 @@ +application.title=unionfs +application.vendor=jarda +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/unionfs.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.junit-4.4.jar=../libs/dist/junit-4.4.jar +file.reference.org-openide-filesystems.jar=../libs/dist/org-openide-filesystems.jar +file.reference.org-openide-util.jar=../libs/dist/org-openide-util.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.org-openide-util.jar}:\ + ${file.reference.org-openide-filesystems.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${file.reference.junit-4.4.jar} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r df21e222a781 -r 6a66df28018c samples/unionfs/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/nbproject/project.xml Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + unionfs + 1.6.5 + + + + + + + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/src/org/apidesign/unionfs/UnionFS.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/src/org/apidesign/unionfs/UnionFS.java Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,20 @@ +package org.apidesign.unionfs; + +import java.net.URL; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.MultiFileSystem; +import org.openide.filesystems.XMLFileSystem; +import org.xml.sax.SAXException; + +public final class UnionFS { + private UnionFS() { + } + + public static FileSystem union(FileSystem... toUnion) { + return new MultiFileSystem(toUnion); + } + + public static FileSystem fromResource(URL stream) throws SAXException { + return new XMLFileSystem(stream); + } +} diff -r df21e222a781 -r 6a66df28018c samples/unionfs/src/org/apidesign/unionfs/fs-one.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/src/org/apidesign/unionfs/fs-one.xml Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,10 @@ + + + + + + + + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/src/org/apidesign/unionfs/fs-two.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/src/org/apidesign/unionfs/fs-two.xml Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,7 @@ + + + + + + + diff -r df21e222a781 -r 6a66df28018c samples/unionfs/test/org/apidesign/unionfs/UnionFSTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/unionfs/test/org/apidesign/unionfs/UnionFSTest.java Sat Jun 14 09:56:56 2008 +0200 @@ -0,0 +1,65 @@ +package org.apidesign.unionfs; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openide.filesystems.FileObject; +import static org.junit.Assert.*; +import org.openide.filesystems.FileSystem; +import org.xml.sax.SAXException; + +public class UnionFSTest { + + public UnionFSTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void union() throws SAXException { + FileSystem one = UnionFS.fromResource(UnionFSTest.class.getResource("fs-one.xml")); + assertChildren("There is just one file in the folder", one, "Menu", "Open.instance"); + + FileSystem two = UnionFS.fromResource(UnionFSTest.class.getResource("fs-two.xml")); + assertChildren("There is just one file in the other folder", two, "Menu", "Close.instance"); + + FileSystem union = UnionFS.union(one, two); + assertChildren("There both in the union", union, "Menu", "Open.instance", "Close.instance"); + } + + private static void assertChildren(String msg, FileSystem fs, String folder, String... expect) { + Set names = new HashSet(); + names.addAll(Arrays.asList(expect)); + + FileObject fo = fs.getRoot().getFileObject(folder); + assertNotNull(msg + " folder " + folder + " has to exist", fo); + + for (FileObject ch : fo.getChildren()) { + names.remove(ch.getNameExt()); + } + + if (!names.isEmpty()) { + fail(msg + " - expected files not found " + names); + } + } + +} \ No newline at end of file