diff -r 846d1a231c05 core.startup/nbproject/project.xml --- a/core.startup/nbproject/project.xml Sun Jul 06 22:21:21 2008 +0200 +++ b/core.startup/nbproject/project.xml Mon Jul 07 14:39:46 2008 +0200 @@ -60,7 +60,7 @@ made subject to such option by the copyr - 7.2 + 7.10 diff -r 846d1a231c05 core.startup/src/org/netbeans/core/startup/layers/BinaryCacheManager.java --- a/core.startup/src/org/netbeans/core/startup/layers/BinaryCacheManager.java Sun Jul 06 22:21:21 2008 +0200 +++ b/core.startup/src/org/netbeans/core/startup/layers/BinaryCacheManager.java Mon Jul 07 14:39:46 2008 +0200 @@ -184,16 +184,19 @@ final class BinaryCacheManager extends P "methodvalue", // NOI18N "newvalue", // NOI18N "serialvalue", // NOI18N + "bundlevalue", // NOI18N }; private void writeAttribute(BinaryWriter bw, MemAttr attr) throws IOException { bw.writeString(attr.name); - int i = 0; - for(; i < ATTR_TYPES.length; i++) { - if(ATTR_TYPES[i].equals(attr.type)) break; + for (int i = 0; i < ATTR_TYPES.length; i++) { + if(ATTR_TYPES[i].equals(attr.type)) { + bw.writeByte((byte)i); + bw.writeString(attr.data); + return; + } } - bw.writeByte((byte)i); // XXX - may write wrong value if unknown type! - bw.writeString(attr.data); + throw new IOException("Wrong type: " + attr); } // this map is actually valid only during BFS regeneration, null otherwise diff -r 846d1a231c05 core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java --- a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Sun Jul 06 22:21:21 2008 +0200 +++ b/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Mon Jul 07 14:39:46 2008 +0200 @@ -48,7 +48,6 @@ import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.RandomAccessFile; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; @@ -56,8 +55,6 @@ import java.nio.ByteOrder; import java.nio.ByteOrder; import java.util.AbstractMap; import java.util.AbstractSet; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -71,7 +68,6 @@ import java.util.StringTokenizer; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; -import org.netbeans.Stamps; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; @@ -79,6 +75,7 @@ import org.openide.util.Enumerations; import org.openide.util.Enumerations; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.NbBundle; import org.openide.util.SharedClassObject; import org.openide.util.Union2; import org.openide.util.actions.SystemAction; @@ -100,7 +97,7 @@ public class BinaryFS extends FileSystem * FS data */ - static final byte[] MAGIC = "org.netbeans.core.projects.cache.BinaryV3".getBytes(); // NOI18N + static final byte[] MAGIC = "org.netbeans.core.projects.cache.BinaryV4".getBytes(); // NOI18N /** An empty array of SystemActions. */ static final SystemAction[] NO_ACTIONS = new SystemAction[0]; @@ -492,6 +489,9 @@ public class BinaryFS extends FileSystem case 12: // serialvalue return decodeValue(value); + case 13: // bundle value + String[] arr = value.split("#", 2); // NOI18N + return NbBundle.getBundle(arr[0]).getObject(arr[1]); default: throw new IllegalStateException("Bad index: " + index); // NOI18N } diff -r 846d1a231c05 core.startup/src/org/netbeans/core/startup/layers/ParsingLayerCacheManager.java --- a/core.startup/src/org/netbeans/core/startup/layers/ParsingLayerCacheManager.java Sun Jul 06 22:21:21 2008 +0200 +++ b/core.startup/src/org/netbeans/core/startup/layers/ParsingLayerCacheManager.java Mon Jul 07 14:39:46 2008 +0200 @@ -80,6 +80,7 @@ abstract class ParsingLayerCacheManager private final static String[] ATTR_TYPES = { "boolvalue", + "bundlevalue", "bytevalue", "charvalue", "doublevalue", @@ -91,7 +92,7 @@ abstract class ParsingLayerCacheManager "serialvalue", "shortvalue", "stringvalue", - "urlvalue" + "urlvalue", }; private final static String DTD_1_0 = "-//NetBeans//DTD Filesystem 1.0//EN"; diff -r 846d1a231c05 core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSTest.java Sun Jul 06 22:21:21 2008 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSTest.java Mon Jul 07 14:39:46 2008 +0200 @@ -41,11 +41,9 @@ package org.netbeans.core.startup.layers; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.net.URL; -import java.nio.ByteBuffer; import java.util.Arrays; import junit.framework.Test; import org.netbeans.junit.NbTestSuite; @@ -56,12 +54,14 @@ import org.openide.filesystems.FileSyste import org.openide.filesystems.FileSystemTestHid; import org.openide.filesystems.TestUtilHid; import org.openide.filesystems.XMLFileSystem; +import org.openide.filesystems.XMLFileSystemTestHid; /** * * @author Radek Matous */ -public class BinaryFSTest extends FileSystemFactoryHid { +public class BinaryFSTest extends FileSystemFactoryHid +implements XMLFileSystemTestHid.Factory { public BinaryFSTest(Test test) { super(test); } @@ -71,6 +71,7 @@ public class BinaryFSTest extends FileSy suite.addTestSuite(FileSystemTestHid.class); suite.addTestSuite(FileObjectTestHid.class); suite.addTestSuite(AttributesTestHidden.class); + suite.addTestSuite(XMLFileSystemTestHid.class); return new BinaryFSTest(suite); } @@ -88,5 +89,14 @@ public class BinaryFSTest extends FileSy String workDirProperty = System.getProperty("workdir");//NOI18N workDirProperty = (workDirProperty != null) ? workDirProperty : System.getProperty("java.io.tmpdir");//NOI18N return new File(workDirProperty); - } + } + + public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException { + LayerCacheManager bm = LayerCacheManager.manager(true); + return BinaryCacheManagerTest.store(bm, Arrays.asList(layers)); + } + + public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException { + return false; + } } diff -r 846d1a231c05 openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/apichanges.xml Mon Jul 07 14:39:46 2008 +0200 @@ -46,6 +46,22 @@ made subject to such option by the copyr Filesystems API + + + XMLFileSystem supports 'bundlevalue' attribute + + + + + +

+ It is possible to declare a value in layer.xml + files with <attr name="..." bundlevalue="org.yourpkg.Bundle#key"/>. +

+
+ + +
Added methods to interconvert URLs and traditional path entries diff -r 846d1a231c05 openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/manifest.mf Mon Jul 07 14:39:46 2008 +0200 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.openide.filesystems -OpenIDE-Module-Specification-Version: 7.9 +OpenIDE-Module-Specification-Version: 7.10 OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties diff -r 846d1a231c05 openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java Mon Jul 07 14:39:46 2008 +0200 @@ -89,7 +89,7 @@ import org.xml.sax.helpers.DefaultHandle * Mandatory attributes: * -for filesystem version=... (e.g. "1.0") * -for file,folder,attr name=.... (e.g.: <folder name="Config">) - * -for attr is mandatory one of bytevalue,shortvalue,intvalue,longvalue,floatvalue,doublevalue,boolvalue,charvalue,stringvalue,methodvalue,serialvalue,urlvalue + * -for attr is mandatory one of bytevalue,shortvalue,intvalue,longvalue,floatvalue,doublevalue,boolvalue,charvalue,stringvalue,methodvalue,serialvalue,urlvalue,bundlevalue * * Allowed atributes: * -for file: url=.... (e.g.: <file name="sample.xml" url="file:/c:/sample.xml">) @@ -109,7 +109,8 @@ import org.xml.sax.helpers.DefaultHandle * * This class implements virtual FileSystem. It is special case of FileSystem in XML format. * - * Description of this format best ilustrate DTD file that is showed in next lines: + * Description of this format best ilustrate DTD file + * that is showed in the following few lines: * < !ELEMENT filesystem (file | folder)*> * < !ATTLIST filesystem version CDATA #REQUIRED> //version not checkked yet * < !ELEMENT folder (file |folder | attr)*> @@ -131,6 +132,7 @@ import org.xml.sax.helpers.DefaultHandle * < !ATTLIST attr methodvalue CDATA #IMPLIED> * < !ATTLIST attr serialvalue CDATA #IMPLIED> * < !ATTLIST attr urlvalue CDATA #IMPLIED> + * < !ATTLIST attr bundlevalue CDATA #IMPLIED> <!-- since version 7.10 --> * * *

@@ -162,6 +164,7 @@ public final class XMLFileSystem extends static { DTD_MAP.put("-//NetBeans//DTD Filesystem 1.0//EN", "org/openide/filesystems/filesystem.dtd"); //NOI18N DTD_MAP.put("-//NetBeans//DTD Filesystem 1.1//EN", "org/openide/filesystems/filesystem1_1.dtd"); //NOI18N + DTD_MAP.put("-//NetBeans//DTD Filesystem 1.2//EN", "org/openide/filesystems/filesystem1_2.dtd"); //NOI18N } /** Url location of XML document */ diff -r 846d1a231c05 openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java --- a/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java Mon Jul 07 14:39:46 2008 +0200 @@ -53,6 +53,7 @@ import java.net.URL; import java.util.*; import org.openide.util.Exceptions; +import org.openide.util.NbBundle; /** @@ -338,6 +339,7 @@ final class XMLMapAttr implements Map { return map.containsValue(p1); } + @Override public synchronized int hashCode() { return map.hashCode(); } @@ -367,8 +369,13 @@ final class XMLMapAttr implements Map { return map.isEmpty(); } + @Override public synchronized boolean equals(Object p1) { - return map.equals(p1); + if (p1 instanceof Map) { + return map.equals(p1); + } else { + return false; + } } public synchronized int size() { @@ -384,7 +391,7 @@ final class XMLMapAttr implements Map { // static final long serialVersionUID = -62733358015297232L; private static final String[] ALLOWED_ATTR_KEYS = { "bytevalue", "shortvalue", "intvalue", "longvalue", "floatvalue", "doublevalue", "boolvalue", "charvalue", - "stringvalue", "methodvalue", "serialvalue", "urlvalue", "newvalue" + "stringvalue", "methodvalue", "serialvalue", "urlvalue", "newvalue", "bundlevalue" }; // NOI18N private String value; private int keyIndex; @@ -861,6 +868,9 @@ final class XMLMapAttr implements Map { } else { return cls.newInstance(); } + case 13: + String[] arr = value.split("#", 2); // NOI18N + return NbBundle.getBundle(arr[0]).getObject(arr[1]); } } catch (Exception exc) { ExternalUtil.annotate(exc, "value = " + value); //NOI18N @@ -982,6 +992,7 @@ final class XMLMapAttr implements Map { return index; } + @Override public boolean equals(Object obj) { if (obj instanceof Attr) { Attr other = (Attr)obj; @@ -995,6 +1006,7 @@ final class XMLMapAttr implements Map { return false; } + @Override public int hashCode() { return 743 + keyIndex << 8 + value.hashCode(); } @@ -1140,10 +1152,12 @@ final class XMLMapAttr implements Map { return fo.getAttribute(key); } + @Override public Object remove(Object key) { throw new UnsupportedOperationException(); } + @Override public Object put(String key, Object value) { throw new UnsupportedOperationException(); } @@ -1186,6 +1200,7 @@ final class XMLMapAttr implements Map { return cnt; } + @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } diff -r 846d1a231c05 openide.filesystems/src/org/openide/filesystems/filesystem1_2.dtd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.filesystems/src/org/openide/filesystems/filesystem1_2.dtd Mon Jul 07 14:39:46 2008 +0200 @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java Mon Jul 07 14:39:46 2008 +0200 @@ -41,12 +41,9 @@ package org.openide.filesystems; -import junit.framework.*; -//import org.openide.filesystems.hidden.*; import java.util.*; import java.io.*; -import java.net.URL; /** * @@ -55,6 +52,7 @@ import java.net.URL; * */ public class AttributesTestHidden extends TestBaseHid { + static final String TEST_ERR = "Not the tested code, but this test contains errors"; static final String COMMON_ATTR_STRING = "testAttribute"; @@ -245,55 +243,6 @@ public class AttributesTestHidden extend assertTrue ("There was not found expected key: " + COMMON_ATTR_STRING +" in .nbattrs",content.indexOf("name=\""+COMMON_ATTR_STRING) != -1 );// } - - public void testAttribute08 () throws Exception { - URL fsURLDef = this.getClass().getResource ("data/Attributes.xml"); - assertTrue ("Cannot create XML FS for testing purposes", fsURLDef != null); - FileSystem fs = new XMLFileSystem (fsURLDef); - FileObject fo = fs.findResource("testMethodValue"); - assertTrue ("Cannot acces FileObject named testMethodValue", fo != null); - - String testName = "test1"; - Object obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertTrue ("methodValue doesn't keep order ", - obj.equals(getObjectViaMethodValue1 (fo, testName))); - - testName = "test2"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertTrue ("methodValue doesn't keep order ", - obj.equals(getObjectViaMethodValue2 (testName, fo))); - - testName = "test3"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertTrue ("methodValue doesn't keep order ", - obj.equals(getObjectViaMethodValue3 (fo))); - - testName = "test4"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertTrue ("methodValue doesn't keep order ", - obj.equals(getObjectViaMethodValue4 (testName))); - - testName = "test5"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertTrue ("methodValue doesn't keep order ", - obj.equals(getObjectViaMethodValue5 ())); - - testName = "test6"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertEquals("even works for java.util.Map", "Ahoj1", obj); - - testName = "test7"; - obj = fo.getAttribute(testName); - assertTrue ("methodValue failed", obj != null); - assertEquals("works for map and string", "Ahoj1test7", obj); - } - public void testAttribute09 () throws IOException { assertTrue (TEST_ERR,testedFS != null); if (testedFS.isReadOnly ()) return; @@ -322,101 +271,6 @@ public class AttributesTestHidden extend } } - private static String getObjectViaMethodValue1 (FileObject fo, String testName) { - return fo.getPath()+testName; - } - - private static String getObjectViaMethodValue1 (String testName, FileObject fo) { - return testName+fo.getPath(); - } - - private static String getObjectViaMethodValue1 (FileObject fo) { - return fo.getPath(); - } - - private static String getObjectViaMethodValue1 (String testName) { - return testName; - } - - private static String getObjectViaMethodValue1 () { - return ""; - } -/// - private static String getObjectViaMethodValue2 (String testName, FileObject fo) { - return testName+fo.getPath(); - } - - private static String getObjectViaMethodValue2 (FileObject fo) { - return fo.getPath(); - } - - private static String getObjectViaMethodValue2 (String testName) { - return testName; - } - - private static String getObjectViaMethodValue2 () { - return ""; - } -/// - private static String getObjectViaMethodValue3 (FileObject fo) { - return fo.getPath(); - } - - private static String getObjectViaMethodValue3 (String testName) { - return testName; - } - - private static String getObjectViaMethodValue3 () { - return ""; - } -/// - private static String getObjectViaMethodValue4 (String testName) { - return testName; - } - - private static String getObjectViaMethodValue4 () { - return ""; - } -/// - private static String getObjectViaMethodValue5 () { - return ""; - } - - private static Object getObjectViaMethodValue6 (Map attrs) { - try { - attrs.keySet().iterator().remove(); - return "UnsupportedOperationException"; - } catch (UnsupportedOperationException ex) { - // ok - } - try { - attrs.put("value1", "nothing"); - return "UnsupportedOperationException"; - } catch (UnsupportedOperationException ex) { - // ok - } - try { - attrs.remove("value1"); - return "UnsupportedOperationException"; - } catch (UnsupportedOperationException ex) { - // ok - } - - - return attrs.get("value1"); - } - private static Object getObjectViaMethodValue7 (Map attrs, String attrName) { - assertEquals(8, attrs.keySet().size()); - try { - attrs.entrySet().remove(null); - return "UnsupportedOperationException"; - } catch (UnsupportedOperationException ex) { - // ok - } - - - return attrs.get("value1") + attrName; - } private String basicAttributeTest (String attrName, String attrValue) throws IOException { FileObject foTested = testedFS.getRoot (); diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/FileSystemFactoryHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/FileSystemFactoryHid.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/FileSystemFactoryHid.java Mon Jul 07 14:39:46 2008 +0200 @@ -45,9 +45,9 @@ import org.netbeans.junit.*; import org.netbeans.junit.*; import java.io.*; +import java.net.URL; import java.util.*; -import org.openide.filesystems.*; /** @@ -77,6 +77,27 @@ public abstract class FileSystemFactoryH * @return array of FileSystems that should be tested in test named: "testName"*/ final static FileSystem[] createFileSystem (String testName,String[] resources, Test test) throws IOException { return getInstance (test,true).createFileSystem(testName, resources); + } + + /** + * Intended to allow prepare tested environment for each individual test. + * @param testName name of test + * @return array of FileSystems that should be tested in test named: "testName"*/ + final static FileSystem createXMLSystem (String testName, Test test, URL... layers) throws IOException { + FileSystemFactoryHid factory = getInstance(test, false); + if (factory instanceof XMLFileSystemTestHid.Factory) { + XMLFileSystemTestHid.Factory f = (XMLFileSystemTestHid.Factory) factory; + return f.createLayerSystem(testName, layers); + } + throw new IllegalStateException("You need to implement XMLFileSystemTestHid.Factory to use the AttributesTestHidden!"); + } + final static boolean switchXMLSystem (FileSystem fs, Test test, URL... layers) throws IOException { + FileSystemFactoryHid factory = getInstance(test, false); + if (factory instanceof XMLFileSystemTestHid.Factory) { + XMLFileSystemTestHid.Factory f = (XMLFileSystemTestHid.Factory) factory; + return f.setXmlUrl(fs, layers); + } + throw new IllegalStateException("You need to implement XMLFileSystemTestHid.Factory to use the AttributesTestHidden!"); } final static void destroyFileSystem (String testName, Test test) throws IOException { diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/LocalFileSystemTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/LocalFileSystemTest.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/LocalFileSystemTest.java Mon Jul 07 14:39:46 2008 +0200 @@ -57,13 +57,6 @@ public class LocalFileSystemTest extends super(test); } - - public static void main(String args[]) { - junit.textui.TestRunner.run(suite()); - } - - - public static Test suite() { NbTestSuite suite = new NbTestSuite(); diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java Mon Jul 07 14:39:46 2008 +0200 @@ -97,7 +97,9 @@ public abstract class TestBaseHid extend clearWorkDir(); String[] resources = getResources (getName()); resourcePrefix = FileSystemFactoryHid.getResourcePrefix(this.getName(),this, resources); - allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this); + if (allTestedFS == null) { + allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this); + } if (allTestedFS != null) testedFS = allTestedFS[0]; // If not null, file accesses are counted through custom SecurityManager. if(accessMonitor != null) { diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTest.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTest.java Mon Jul 07 14:39:46 2008 +0200 @@ -41,30 +41,24 @@ package org.openide.filesystems; +import java.beans.PropertyVetoException; +import java.net.URL; import junit.framework.*; import java.io.*; -import java.util.*; -import java.util.jar.*; -import java.util.zip.*; -import java.net.*; import org.netbeans.junit.*; - -//import org.openide.filesystems.hidden.*; +import org.openide.util.Exceptions; /** * * @author rm111737 * @version */ -public class XMLFileSystemTest extends FileSystemFactoryHid { +public class XMLFileSystemTest extends FileSystemFactoryHid +implements XMLFileSystemTestHid.Factory { /** Creates new XMLFileSystemTest */ public XMLFileSystemTest(Test test) { super(test); - } - - public static void main(String args[]) { - junit.textui.TestRunner.run(suite()); } public static Test suite() { @@ -75,11 +69,32 @@ public class XMLFileSystemTest extends F return new XMLFileSystemTest(suite); } + protected void destroyFileSystem(String testName) throws IOException {} protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException{ return new FileSystem[] {TestUtilHid.createXMLFileSystem(testName, resources)}; } + + public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException { + XMLFileSystem xfs = new XMLFileSystem(); + try { + xfs.setXmlUrls(layers); + } catch (PropertyVetoException ex) { + throw (IOException)new IOException().initCause(ex); + } + return xfs; + } + + public boolean setXmlUrl(org.openide.filesystems.FileSystem fs, URL[] layers) throws IOException { + XMLFileSystem xfs = (XMLFileSystem)fs; + try { + xfs.setXmlUrls(layers); + } catch (PropertyVetoException ex) { + throw (IOException)new IOException().initCause(ex); + } + return true; + } diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java Mon Jul 07 14:39:46 2008 +0200 @@ -47,11 +47,31 @@ import java.net.URL; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class XMLFileSystemTestHid extends TestBaseHid { + /** Factory for all filesystems that want to use TCK in this class. + */ + public static interface Factory { + /** Creates a filesystem representing XML files at given URLs + * + * @param testName name of the test + * @param layers URLs of layers to parse + * @return new filesystem that represents those layers + */ + public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException; + + /** Assigns new URLs to existing filesystem. + * + * @param fs the filesystem produced by {@link #createLayerSystem(java.lang.String, java.net.URL[])} + * @param layers new URLs that the filesystem shall switch to + * @return true if successful, false if this operation is not supported + */ + public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException; + } private String[] resources = new String[] {"a/b/c"}; - XMLFileSystem xfs = null; + FileSystem xfs = null; public XMLFileSystemTestHid(String testName) { super(testName); @@ -70,21 +90,25 @@ public class XMLFileSystemTestHid extend FileChangeAdapter fcl = new FileChangeAdapter(); a.addFileChangeListener(fcl); - resources = new String[] {"a/b/c","a/b1/c"}; - xfs.setXmlUrl(createXMLLayer().toURL()); + resources = new String[] {"a/b/c","a/b1/c"}; + + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, createXMLLayer().toURL())) { + // OK, unsupported + return; + } FileObject b1 = xfs.findResource("a/b1"); assertNotNull(b1); assertTrue(b1.isFolder()); } + @Override protected void setUp() throws Exception { + File f = createXMLLayer(); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); + this.testedFS = xfs; + this.allTestedFS = new FileSystem[] { xfs }; super.setUp(); - - File f = createXMLLayer(); - xfs = new XMLFileSystem (); - xfs.setXmlUrl(f.toURL()); - this.testedFS = xfs; } private File createXMLLayer() throws IOException { @@ -113,13 +137,16 @@ public class XMLFileSystemTestHid extend - xfs = new XMLFileSystem (f.toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals ("Four bytes there", 4, fo.getSize ()); registerDefaultListener (fo); - xfs.setXmlUrl (f2.toURL ()); + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { + // OK, unsupported + return; + } assertEquals ("Six bytes there", 6, fo.getSize ()); @@ -149,13 +176,16 @@ public class XMLFileSystemTestHid extend - xfs = new XMLFileSystem (f.toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals ("Four bytes there", 4, fo.getSize ()); registerDefaultListener (fo); - xfs.setXmlUrl (f2.toURL ()); + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { + // OK, unsupported + return; + } assertEquals ("Six bytes there", 6, fo.getSize ()); @@ -186,13 +216,16 @@ public class XMLFileSystemTestHid extend - xfs = new XMLFileSystem (f.toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertEquals("Old value is in the attribute", "old", fo.getAttribute("value")); registerDefaultListener (fo); - xfs.setXmlUrl (f2.toURL ()); + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { + // OK, unsupported + return; + } assertEquals("New value is in the attribute", "new", fo.getAttribute("value")); fileAttributeChangedAssert("Change in the content", 1); @@ -217,13 +250,16 @@ public class XMLFileSystemTestHid extend - xfs = new XMLFileSystem(f.toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); FileObject fo = xfs.findResource("TestModule/sample.txt"); assertEquals("Four bytes there", 4, fo.getSize()); registerDefaultListener(fo); - xfs.setXmlUrl(f2.toURL()); + if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { + // OK, unsupported + return; + } assertFalse("Valid no more", fo.isValid()); assertEquals("Empty now", 0, fo.getSize()); @@ -246,7 +282,7 @@ public class XMLFileSystemTestHid extend Thread.sleep(3000); assertTrue(f2.createNewFile()); } - xfs = new XMLFileSystem(f.toURL()); + xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); FileObject fo = xfs.findResource ("TestModule/sample.txt"); assertNotNull(fo); assertEquals(fo.lastModified().getTime(), f.lastModified()); @@ -268,6 +304,60 @@ public class XMLFileSystemTestHid extend return f; } + + public void testAttribute08 () throws Exception { + URL fsURLDef = this.getClass().getResource ("data/Attributes.xml"); + assertTrue ("Cannot create XML FS for testing purposes", fsURLDef != null); + FileSystem fs = FileSystemFactoryHid.createXMLSystem(getName(), this, fsURLDef); + FileObject fo = fs.findResource("testMethodValue"); + assertTrue ("Cannot acces FileObject named testMethodValue", fo != null); + + String testName = "test1"; + Object obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertTrue ("methodValue doesn't keep order ", + obj.equals(getObjectViaMethodValue1 (fo, testName))); + + testName = "test2"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertTrue ("methodValue doesn't keep order ", + obj.equals(getObjectViaMethodValue2 (testName, fo))); + + testName = "test3"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertTrue ("methodValue doesn't keep order ", + obj.equals(getObjectViaMethodValue3 (fo))); + + testName = "test4"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertTrue ("methodValue doesn't keep order ", + obj.equals(getObjectViaMethodValue4 (testName))); + + testName = "test5"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertTrue ("methodValue doesn't keep order ", + obj.equals(getObjectViaMethodValue5 ())); + + testName = "test6"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertEquals("even works for java.util.Map", "Ahoj1", obj); + + testName = "test7"; + obj = fo.getAttribute(testName); + assertTrue ("methodValue failed", obj != null); + assertEquals("works for map and string", "Ahoj1test7", obj); + + testName = "testLoc"; + obj = fo.getAttribute(testName); + assertNotNull("Value returned", obj); + assertEquals("works for bundle key", "Hello World!", obj); + } + public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception { XMLFileSystem fs = new XMLFileSystem(); @@ -333,30 +423,131 @@ public class XMLFileSystemTestHid extend public List change = new ArrayList(); + @Override public void fileRenamed(FileRenameEvent fe) { events.add(fe); } + @Override public void fileAttributeChanged(FileAttributeEvent fe) { events.add(fe); } + @Override public void fileFolderCreated(FileEvent fe) { events.add(fe); } + @Override public void fileDeleted(FileEvent fe) { events.add(fe); } + @Override public void fileDataCreated(FileEvent fe) { events.add(fe); } + @Override public void fileChanged(FileEvent fe) { change.add(fe); } } + private static String getObjectViaMethodValue1 (FileObject fo, String testName) { + return fo.getPath()+testName; + } + + private static String getObjectViaMethodValue1 (String testName, FileObject fo) { + return testName+fo.getPath(); + } + + private static String getObjectViaMethodValue1 (FileObject fo) { + return fo.getPath(); + } + + private static String getObjectViaMethodValue1 (String testName) { + return testName; + } + + private static String getObjectViaMethodValue1 () { + return ""; + } +/// + private static String getObjectViaMethodValue2 (String testName, FileObject fo) { + return testName+fo.getPath(); + } + + private static String getObjectViaMethodValue2 (FileObject fo) { + return fo.getPath(); + } + + private static String getObjectViaMethodValue2 (String testName) { + return testName; + } + + private static String getObjectViaMethodValue2 () { + return ""; + } +/// + private static String getObjectViaMethodValue3 (FileObject fo) { + return fo.getPath(); + } + + private static String getObjectViaMethodValue3 (String testName) { + return testName; + } + + private static String getObjectViaMethodValue3 () { + return ""; + } +/// + private static String getObjectViaMethodValue4 (String testName) { + return testName; + } + + private static String getObjectViaMethodValue4 () { + return ""; + } +/// + private static String getObjectViaMethodValue5 () { + return ""; + } + + private static Object getObjectViaMethodValue6 (Map attrs) { + try { + attrs.keySet().iterator().remove(); + return "UnsupportedOperationException"; + } catch (UnsupportedOperationException ex) { + // ok + } + try { + attrs.put("value1", "nothing"); + return "UnsupportedOperationException"; + } catch (UnsupportedOperationException ex) { + // ok + } + try { + attrs.remove("value1"); + return "UnsupportedOperationException"; + } catch (UnsupportedOperationException ex) { + // ok + } + + + return attrs.get("value1"); + } + private static Object getObjectViaMethodValue7 (Map attrs, String attrName) { + assertEquals(9, attrs.keySet().size()); + try { + attrs.entrySet().remove(null); + return "UnsupportedOperationException"; + } catch (UnsupportedOperationException ex) { + // ok + } + + + return attrs.get("value1") + attrName; + } } diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml --- a/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml Sun Jul 06 22:21:21 2008 +0200 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml Mon Jul 07 14:39:46 2008 +0200 @@ -8,17 +8,17 @@ Purpose of the document: testing of attributes. --> - + - - - - - - - - + + + + + + + + diff -r 846d1a231c05 openide.filesystems/test/unit/src/org/openide/filesystems/data/TestBundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/data/TestBundle.properties Mon Jul 07 14:39:46 2008 +0200 @@ -0,0 +1,39 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2008 Sun Microsystems, Inc. + +AHOJ=Hello World! +