# HG changeset patch # User Jaroslav Tulach # Date 1230579740 -3600 # Node ID 61f814414c7dba57652aff4cec408c38d4737036 # Parent a62346c9de53424ded668b063f8754d88fd33e4b Calling getAttribute from methodvalue on different fileobject could result in bad behaviour diff --git a/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSBehindMultiFSTest.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSBehindMultiFSTest.java new file mode 100644 --- /dev/null +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSBehindMultiFSTest.java @@ -0,0 +1,105 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.netbeans.core.startup.layers; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Arrays; +import junit.framework.Test; +import org.netbeans.junit.NbTestSuite; +import org.openide.filesystems.AttributesTestHidden; +import org.openide.filesystems.FileObjectTestHid; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileSystemFactoryHid; +import org.openide.filesystems.FileSystemTestHid; +import org.openide.filesystems.MultiFileSystem; +import org.openide.filesystems.TestUtilHid; +import org.openide.filesystems.XMLFileSystem; +import org.openide.filesystems.XMLFileSystemTestHid; + +/** + * + * @author Radek Matous + */ +public class BinaryFSBehindMultiFSTest extends FileSystemFactoryHid +implements XMLFileSystemTestHid.Factory { + public BinaryFSBehindMultiFSTest(Test test) { + super(test); + } + + public static Test suite() { + NbTestSuite suite = new NbTestSuite(); + suite.addTestSuite(FileSystemTestHid.class); + suite.addTestSuite(FileObjectTestHid.class); + suite.addTestSuite(AttributesTestHidden.class); + suite.addTestSuite(XMLFileSystemTestHid.class); + + return new BinaryFSBehindMultiFSTest(suite); + } + + protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException { + XMLFileSystem xfs = (XMLFileSystem)TestUtilHid.createXMLFileSystem(testName, resources); + LayerCacheManager bm = LayerCacheManager.manager(true); + return new FileSystem[] {BinaryCacheManagerTest.store(bm, Arrays.asList(xfs.getXmlUrls()))}; + } + + protected void destroyFileSystem(String testName) throws IOException { + } + + private File getWorkDir() { + 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 new MultiFileSystem(new FileSystem[] { + BinaryCacheManagerTest.store(bm, Arrays.asList(layers)) + }); + } + + public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException { + return false; + } +} diff --git a/openide.filesystems/src/org/openide/filesystems/MultiFileObject.java b/openide.filesystems/src/org/openide/filesystems/MultiFileObject.java --- a/openide.filesystems/src/org/openide/filesystems/MultiFileObject.java +++ b/openide.filesystems/src/org/openide/filesystems/MultiFileObject.java @@ -814,9 +814,9 @@ private Object getAttribute(FileObject fo, String attrName, String path) { Object o; - FileObject topFO = attrAskedFileObject.get(); + FileObject previousFO = attrAskedFileObject.get(); - if (topFO == null) { + if (previousFO == null || !previousFO.getPath().equals(getPath())) { attrAskedFileObject.set(this); } @@ -829,9 +829,7 @@ o = fo.getAttribute(attrName); } } finally { - if (topFO == null) { - attrAskedFileObject.set(null); - } + attrAskedFileObject.set(previousFO); } if (o != null) { diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileSystemXMLTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileSystemXMLTest.java new file mode 100644 --- /dev/null +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/MultiFileSystemXMLTest.java @@ -0,0 +1,110 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.openide.filesystems; + +import java.beans.PropertyVetoException; +import java.io.IOException; +import java.net.URL; +import junit.framework.Test; +import org.netbeans.junit.*; + +/** + * + * @author rm111737 + * @version + */ +public class MultiFileSystemXMLTest extends FileSystemFactoryHid +implements XMLFileSystemTestHid.Factory { + + /** Creates new XMLFileSystemTest */ + public MultiFileSystemXMLTest(Test test) { + super(test); + } + + public static Test suite() { + NbTestSuite suite = new NbTestSuite(); + suite.addTestSuite(FileSystemTestHid.class); + suite.addTestSuite(FileObjectTestHid.class); + suite.addTestSuite(XMLFileSystemTestHid.class); + + return new MultiFileSystemXMLTest(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 { + MFS mfs = new MFS(); + try { + mfs.xfs.setXmlUrls(layers); + } catch (PropertyVetoException ex) { + throw (IOException)new IOException().initCause(ex); + } + return mfs; + } + + public boolean setXmlUrl(org.openide.filesystems.FileSystem fs, URL[] layers) throws IOException { + MFS mfs = (MFS)fs; + try { + mfs.xfs.setXmlUrls(layers); + } catch (PropertyVetoException ex) { + throw (IOException)new IOException().initCause(ex); + } + return true; + } + + + private static final class MFS extends MultiFileSystem { + private XMLFileSystem xfs; + public MFS() { + this(new XMLFileSystem()); + } + + private MFS(XMLFileSystem fs) { + super(new FileSystem[] { fs }); + this.xfs = fs; + } + } +} diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java @@ -487,6 +487,19 @@ assertNotNull("Value returned", obj); assertEquals("works for bundle key", "Hello World!", obj); } + public void testPeerAttribute() throws Exception { + URL fsURLDef = XMLFileSystemTestHid.class.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"); + FileObject peer = fs.findResource("peer"); + assertTrue ("Cannot acces FileObject named testMethodValue", fo != null); + + Object obj = fo.getAttribute("testPeer"); + assertTrue ("methodValue failed", obj != null); + assertEquals("it is the top most fileobject", peer, obj); + + } public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception { @@ -719,7 +732,7 @@ return attrs.get("value1"); } private static Object getObjectViaMethodValue7 (Map attrs, String attrName) { - assertEquals(9, attrs.keySet().size()); + assertEquals(10, attrs.keySet().size()); try { attrs.entrySet().remove(null); return "UnsupportedOperationException"; @@ -730,5 +743,13 @@ return attrs.get("value1") + attrName; } + private static Object getReadOtherFileObjectAttribute(FileObject fo) { + FileObject peer = fo.getParent().getFileObject("peer"); + assertNotNull("Peer exists", peer); + return peer.getAttribute("testPeer"); + } + private static Object getFO(FileObject fo) { + return fo; + } } diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml b/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml --- a/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml @@ -18,7 +18,11 @@ + + + +