This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 26338
Collapse All | Expand All

(-)openide/fs/apichanges.xml (+21 lines)
Lines 23-28 Link Here
23
        <apidef name="filesystems">Filesystems API</apidef>
23
        <apidef name="filesystems">Filesystems API</apidef>
24
    </apidefs>
24
    </apidefs>
25
    <changes>
25
    <changes>
26
        <change id="add-content-to-sfs">
27
            <api name="filesystems"/>
28
            <summary>Allow modules to dynamically add/remove layer content</summary>
29
            <version major="7" minor="1"/>
30
            <date day="12" month="3" year="2007"/>
31
            <author login="jtulach"/>
32
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
33
            <description>
34
                <p>
35
                    Repository.getDefaultFileSystem's content can now be 
36
                    influenced by adding own 
37
                    <a href="@TOP@/org/openide/filesystems/FileSystem.html">FileSystem</a>s
38
                    into global 
39
                    <a href="@org-openide-util@/org/openide/util/Lookup.html">Lookup.getDefault()</a>.
40
                    This is supposed to work in a standalone mode as well 
41
                    as inside NetBeans Platform.
42
                </p>
43
            </description>
44
            <class package="org.openide.filesystems" name="Repository"/>
45
            <issue number="26338"/>
46
        </change>
26
        <change id="createData-and-createFolder-take-File-as-parameter">
47
        <change id="createData-and-createFolder-take-File-as-parameter">
27
            <api name="filesystems"/>
48
            <api name="filesystems"/>
28
            <summary>Added additional methods <code>FileUtil.createData</code>
49
            <summary>Added additional methods <code>FileUtil.createData</code>
(-)openide/fs/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Specification-Version: 7.0
3
OpenIDE-Module-Specification-Version: 7.1
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
5
5
(-)openide/fs/src/org/openide/filesystems/ExternalUtil.java (-1 / +27 lines)
Lines 18-27 Link Here
18
 */
18
 */
19
package org.openide.filesystems;
19
package org.openide.filesystems;
20
20
21
import java.util.ArrayList;
22
import java.util.List;
21
import java.util.logging.Level;
23
import java.util.logging.Level;
22
import java.util.logging.Logger;
24
import java.util.logging.Logger;
23
import org.openide.util.Exceptions;
25
import org.openide.util.Exceptions;
24
import org.openide.util.Lookup;
26
import org.openide.util.Lookup;
27
import org.openide.util.LookupEvent;
28
import org.openide.util.LookupListener;
25
29
26
30
27
/** Contains utility methods to deal with repository and error manager,
31
/** Contains utility methods to deal with repository and error manager,
Lines 120-126 Link Here
120
124
121
        if (repository == null) {
125
        if (repository == null) {
122
            // if not provided use default one
126
            // if not provided use default one
123
            repository = new Repository(FileUtil.createMemoryFileSystem());
127
            repository = new Repository(new MainFS());
124
        }
128
        }
125
    }
129
    }
130
    
131
    private static final class MainFS extends MultiFileSystem implements LookupListener {
132
        private static final Lookup.Result<FileSystem> ALL = Lookup.getDefault().lookupResult(FileSystem.class);
133
        private static final FileSystem MEMORY = FileUtil.createMemoryFileSystem();
134
        
135
        public MainFS() {
136
            super(computeDelegates());
137
            ALL.addLookupListener(this);
138
        }
139
        
140
        private static FileSystem[] computeDelegates() {
141
            List<FileSystem> arr = new ArrayList<FileSystem>();
142
            arr.add(MEMORY);
143
            arr.addAll(ALL.allInstances());
144
            return arr.toArray(new FileSystem[0]);
145
        }
146
        
147
    
148
        public void resultChanged(LookupEvent ev) {
149
            setDelegates(computeDelegates());
150
        }
151
    } // end of MainFS
126
}
152
}
(-)openide/fs/test/unit/src/org/openide/filesystems/RepositoryTest.java (+65 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.openide.filesystems;
21
22
import junit.framework.TestCase;
23
import org.openide.util.lookup.AbstractLookup;
24
import org.openide.util.lookup.InstanceContent;
25
26
/**
27
 *
28
 * @author Jaroslav Tulach
29
 */
30
public class RepositoryTest extends TestCase {
31
    static {
32
        System.setProperty("org.openide.util.Lookup", MainLookup.class.getName());
33
    }
34
    
35
    
36
    public RepositoryTest(String testName) {
37
        super(testName);
38
    }
39
40
    
41
    public void testContentOfFileSystemIsInfluencedByLookup () throws Exception {
42
        FileSystem mem = FileUtil.createMemoryFileSystem();
43
        String dir = "/yarda/own/file";
44
        org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir);
45
        
46
        assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
47
        MainLookup.ic.add(mem);
48
        try {
49
            assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
50
        } finally {
51
            MainLookup.ic.remove(mem);
52
        }
53
        assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
54
    }
55
    
56
    
57
    public static final class MainLookup extends AbstractLookup {
58
        static final InstanceContent ic = new InstanceContent();
59
        
60
        
61
        public MainLookup() {
62
            super(ic);
63
        }
64
    }
65
}
(-)core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java (-13 / +44 lines)
Lines 29-34 Link Here
29
import java.io.ObjectStreamException;
29
import java.io.ObjectStreamException;
30
import java.io.Serializable;
30
import java.io.Serializable;
31
import java.net.URL;
31
import java.net.URL;
32
import java.util.ArrayList;
33
import java.util.Arrays;
32
import java.util.HashSet;
34
import java.util.HashSet;
33
import java.util.Iterator;
35
import java.util.Iterator;
34
import java.util.MissingResourceException;
36
import java.util.MissingResourceException;
Lines 42-54 Link Here
42
import org.openide.filesystems.LocalFileSystem;
44
import org.openide.filesystems.LocalFileSystem;
43
import org.openide.filesystems.MultiFileSystem;
45
import org.openide.filesystems.MultiFileSystem;
44
import org.openide.filesystems.Repository;
46
import org.openide.filesystems.Repository;
47
import org.openide.util.Lookup;
45
import org.openide.util.NbBundle;
48
import org.openide.util.NbBundle;
46
49
47
/** The system FileSystem - represents system files under $NETBEANS_HOME/system.
50
/** The system FileSystem - represents system files under $NETBEANS_HOME/system.
48
*
51
*
49
* @author Jan Jancura, Ian Formanek, Petr Hamernik
52
* @author Jan Jancura, Ian Formanek, Petr Hamernik
50
*/
53
*/
51
public final class SystemFileSystem extends MultiFileSystem implements FileSystem.Status {
54
public final class SystemFileSystem extends MultiFileSystem 
55
implements FileSystem.Status, org.openide.util.LookupListener {
52
    // Must be public for BeanInfo to work: #11186.
56
    // Must be public for BeanInfo to work: #11186.
53
57
54
    /** generated Serialized Version UID */
58
    /** generated Serialized Version UID */
Lines 65-70 Link Here
65
    /** name of file attribute with URL to 32x32 color icon */
69
    /** name of file attribute with URL to 32x32 color icon */
66
    private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
70
    private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
67
71
72
    /** lookup result we listen on */
73
    private static Lookup.Result<FileSystem> result = Lookup.getDefault().lookupResult(FileSystem.class);
74
    /** the set of layers provided by the system */
75
    private static FileSystem[] layers;
76
68
    /** user fs */
77
    /** user fs */
69
    private ModuleLayeredFileSystem user;
78
    private ModuleLayeredFileSystem user;
70
    /** home fs */
79
    /** home fs */
Lines 73-85 Link Here
73
    /** @param fss list of file systems to delegate to
82
    /** @param fss list of file systems to delegate to
74
    */
83
    */
75
    @SuppressWarnings("deprecation")
84
    @SuppressWarnings("deprecation")
76
    private SystemFileSystem (FileSystem[] fss) throws PropertyVetoException {
85
    private SystemFileSystem() throws PropertyVetoException {
77
        super (fss);
86
        super(computeLayers());
78
        user = (ModuleLayeredFileSystem) fss[0];
87
        user = (ModuleLayeredFileSystem) layers[0];
79
        home = fss.length > 2 ? (ModuleLayeredFileSystem) fss[1] : null;
88
        home = layers.length > 2 ? (ModuleLayeredFileSystem) layers[1] : null;
80
89
        
81
        setSystemName (SYSTEM_NAME);
90
        setSystemName(SYSTEM_NAME);
82
        setHidden (true);
91
        setHidden(true);
92
        
93
        result.addLookupListener(this);
83
    }
94
    }
84
95
85
96
Lines 113-120 Link Here
113
            else
124
            else
114
                s.add (arr[i]);
125
                s.add (arr[i]);
115
126
127
        layers = (FileSystem[])arr.clone();
116
        // create own internal copy of passed filesystems
128
        // create own internal copy of passed filesystems
117
        setDelegates(arr.clone());
129
        setDelegates(computeLayers());
118
        firePropertyChange ("layers", null, null); // NOI18N
130
        firePropertyChange ("layers", null, null); // NOI18N
119
    }
131
    }
120
    
132
    
Lines 127-132 Link Here
127
        // don't return reference to internal buffer
139
        // don't return reference to internal buffer
128
        return getDelegates().clone();
140
        return getDelegates().clone();
129
    }
141
    }
142
    
143
    private synchronized static FileSystem[] computeLayers () {
144
        FileSystem[] fromLookup = (FileSystem[])result.allInstances ().toArray (new FileSystem[0]);
145
        
146
        if (fromLookup.length > 0) {
147
            ArrayList<FileSystem> arr = new ArrayList<FileSystem>(layers.length + fromLookup.length);
148
            arr.addAll (Arrays.asList (layers));
149
            arr.addAll (Arrays.asList (fromLookup));
150
            return (FileSystem[])arr.toArray (new FileSystem[0]);
151
        }
152
        
153
        return layers;
154
    }
130
155
131
    protected FileSystem createWritableOnForRename (String oldName, String newName) throws IOException {        
156
    protected FileSystem createWritableOnForRename (String oldName, String newName) throws IOException {        
132
        return createWritableOn (oldName);
157
        return createWritableOn (oldName);
Lines 280-286 Link Here
280
            ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N
305
            ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N
281
        arr[home == null ? 1 : 2] = FixedFileSystem.deflt;
306
        arr[home == null ? 1 : 2] = FixedFileSystem.deflt;
282
307
283
        return new SystemFileSystem (arr);
308
        layers = arr;
309
        return new SystemFileSystem ();
284
    }
310
    }
285
311
286
    /** Notification that a file has migrated from one file system
312
    /** Notification that a file has migrated from one file system
Lines 297-305 Link Here
297
    }
323
    }
298
324
299
    // --- SAFETY ---
325
    // --- SAFETY ---
300
    private Object writeReplace () throws ObjectStreamException {
326
    private Object writeReplace() throws ObjectStreamException {
301
        new NotSerializableException ("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace (); // NOI18N
327
        new NotSerializableException("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace(); // NOI18N
302
        return new SingletonSerializer ();
328
        return new SingletonSerializer();
329
    }
330
    
331
    /** Refresh layers */
332
    public synchronized void resultChanged(org.openide.util.LookupEvent ev) {
333
        setDelegates(computeLayers());
303
    }
334
    }
304
    
335
    
305
    private static final class SingletonSerializer extends Object implements Serializable {
336
    private static final class SingletonSerializer extends Object implements Serializable {
(-)core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java (-3 / +18 lines)
Lines 20-31 Link Here
20
package org.netbeans.core.projects;
20
package org.netbeans.core.projects;
21
21
22
import org.netbeans.junit.*;
22
import org.netbeans.junit.*;
23
import junit.textui.TestRunner;
24
import org.netbeans.Module;
23
import org.netbeans.Module;
25
import org.netbeans.ModuleManager;
24
import org.netbeans.ModuleManager;
26
import org.netbeans.core.startup.ModuleHistory;
25
import org.netbeans.core.startup.ModuleHistory;
27
26
28
import org.netbeans.core.NbTopManager;
29
import org.openide.util.Mutex;
27
import org.openide.util.Mutex;
30
import org.openide.util.MutexException;
28
import org.openide.util.MutexException;
31
import org.openide.filesystems.FileObject;
29
import org.openide.filesystems.FileObject;
Lines 36-46 Link Here
36
import java.util.Collections;
34
import java.util.Collections;
37
import java.awt.Toolkit;
35
import java.awt.Toolkit;
38
import java.awt.Image;
36
import java.awt.Image;
39
import java.awt.image.BufferedImage;
40
import java.net.URL;
37
import java.net.URL;
41
import java.beans.BeanInfo;
38
import java.beans.BeanInfo;
42
import java.awt.image.PixelGrabber;
39
import java.awt.image.PixelGrabber;
43
import java.awt.image.ImageObserver;
40
import java.awt.image.ImageObserver;
41
import org.netbeans.core.startup.MainLookup;
42
import org.openide.filesystems.FileSystem;
43
import org.openide.filesystems.FileUtil;
44
44
45
/** Test operation of the SystemFileSystem.
45
/** Test operation of the SystemFileSystem.
46
 * For now, just display attributes.
46
 * For now, just display attributes.
Lines 93-98 Link Here
93
        FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt");
93
        FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt");
94
        Node n = DataObject.find(bar).getNodeDelegate();
94
        Node n = DataObject.find(bar).getNodeDelegate();
95
        assertEquals("correct localized data object name", "Localized Name", n.getDisplayName());
95
        assertEquals("correct localized data object name", "Localized Name", n.getDisplayName());
96
    }
97
    
98
    public void testContentOfFileSystemIsInfluencedByLookup () throws Exception {
99
        FileSystem mem = FileUtil.createMemoryFileSystem();
100
        String dir = "/yarda/own/file";
101
        org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir);
102
        
103
        assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
104
        MainLookup.register (mem);
105
        try {
106
            assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
107
        } finally {
108
            MainLookup.unregister (mem);
109
        }
110
        assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
96
    }
111
    }
97
    
112
    
98
    public void testIconFromURL() throws Exception {
113
    public void testIconFromURL() throws Exception {

Return to bug 26338