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 198508
Collapse All | Expand All

(-)a/core.startup/nbproject/project.xml (-1 / +1 lines)
Lines 63-69 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <specification-version>7.35</specification-version>
66
                        <specification-version>7.49</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
(-)a/core.startup/src/org/netbeans/core/startup/NbInstaller.java (-1 lines)
Lines 92-98 Link Here
92
import org.openide.util.NbCollections;
92
import org.openide.util.NbCollections;
93
import org.openide.util.SharedClassObject;
93
import org.openide.util.SharedClassObject;
94
import org.openide.util.NbBundle;
94
import org.openide.util.NbBundle;
95
import org.openide.util.Utilities;
96
import org.openide.util.lookup.InstanceContent;
95
import org.openide.util.lookup.InstanceContent;
97
import org.xml.sax.SAXException;
96
import org.xml.sax.SAXException;
98
97
(-)a/core.startup/src/org/netbeans/core/startup/NbRepository.java (-1 / +26 lines)
Lines 47-59 Link Here
47
import java.beans.PropertyVetoException;
47
import java.beans.PropertyVetoException;
48
import java.io.File;
48
import java.io.File;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.net.URL;
50
import java.util.ArrayList;
51
import java.util.ArrayList;
51
import java.util.List;
52
import java.util.List;
52
import java.util.StringTokenizer;
53
import java.util.StringTokenizer;
54
import java.util.concurrent.ExecutionException;
55
import java.util.concurrent.Future;
56
import java.util.concurrent.TimeUnit;
57
import java.util.concurrent.TimeoutException;
58
import org.netbeans.core.startup.layers.ModuleLayeredFileSystem;
53
59
54
import org.openide.filesystems.*;
60
import org.openide.filesystems.*;
55
61
56
import org.netbeans.core.startup.layers.SessionManager;
62
import org.netbeans.core.startup.layers.SessionManager;
63
import org.openide.util.Exceptions;
64
import org.openide.util.Lookup;
57
import org.openide.util.NbBundle;
65
import org.openide.util.NbBundle;
58
66
59
/** Default repository.
67
/** Default repository.
Lines 162-166 Link Here
162
    private static void doExit (int value) {
170
    private static void doExit (int value) {
163
        TopLogging.exit(value);
171
        TopLogging.exit(value);
164
    }
172
    }
165
    
173
174
    public List<URL> additionalLayers(List<URL> urls) {
175
        for (LayersProvider p : Lookup.getDefault().lookupAll(LayersProvider.class)) {
176
            List<URL> mix = new ArrayList<URL>(urls);
177
            mix.addAll(findLayers(p));
178
            urls = mix;
179
        }
180
        return urls;
181
    }
182
183
    @Override
184
    protected void refreshAdditionalLayers() {
185
        try {
186
            ModuleLayeredFileSystem.getInstallationModuleLayer().setURLs(null);
187
        } catch (Exception ex) {
188
            Exceptions.printStackTrace(ex);
189
        }
190
    }
166
}
191
}
(-)a/core.startup/src/org/netbeans/core/startup/layers/ModuleLayeredFileSystem.java (-11 / +42 lines)
Lines 54-65 Link Here
54
import java.util.jar.Manifest;
54
import java.util.jar.Manifest;
55
import java.util.logging.Level;
55
import java.util.logging.Level;
56
import java.util.logging.Logger;
56
import java.util.logging.Logger;
57
import org.netbeans.core.startup.NbRepository;
57
import org.netbeans.core.startup.StartLog;
58
import org.netbeans.core.startup.StartLog;
58
import org.openide.filesystems.FileStateInvalidException;
59
import org.openide.filesystems.FileStateInvalidException;
59
import org.openide.filesystems.FileSystem;
60
import org.openide.filesystems.FileSystem;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.MultiFileSystem;
62
import org.openide.filesystems.MultiFileSystem;
63
import org.openide.filesystems.Repository.LayersProvider;
62
import org.openide.filesystems.XMLFileSystem;
64
import org.openide.filesystems.XMLFileSystem;
65
import org.openide.util.Exceptions;
63
import org.openide.util.Lookup;
66
import org.openide.util.Lookup;
64
import org.openide.util.LookupEvent;
67
import org.openide.util.LookupEvent;
65
import org.openide.util.LookupListener;
68
import org.openide.util.LookupListener;
Lines 77-87 Link Here
77
    
80
    
78
    static final Logger err = Logger.getLogger("org.netbeans.core.projects"); // NOI18N
81
    static final Logger err = Logger.getLogger("org.netbeans.core.projects"); // NOI18N
79
82
80
    /** lookup result we listen on */
83
    /** lookup result for registered filesystems */
81
    private static Lookup.Result<FileSystem> result = Lookup.getDefault().lookupResult(FileSystem.class);
84
    private static Lookup.Result<FileSystem> fsResult = Lookup.getDefault().lookupResult(FileSystem.class);
85
    private static Lookup.Result<LayersProvider> layerResult = Lookup.getDefault().lookupResult(LayersProvider.class);
82
    
86
    
83
    /** current list of URLs - r/o; or null if not yet set */
87
    /** current list of URLs - r/o; or null if not yet set */
84
    private List<URL> urls;
88
    private List<URL> urls;
89
    private List<URL> prevs;
85
    /** cache manager */
90
    /** cache manager */
86
    private LayerCacheManager manager;
91
    private LayerCacheManager manager;
87
    /** writable layer */
92
    /** writable layer */
Lines 129-143 Link Here
129
        
134
        
130
        urls = null;
135
        urls = null;
131
136
132
        result.addLookupListener(this);
137
        fsResult.addLookupListener(this);
133
        result.allItems();
138
        layerResult.addLookupListener(this);
134
    }
139
    }
135
    
140
    
136
    private static FileSystem[] appendLayers(FileSystem fs1, boolean addLookupBefore, FileSystem[] fs2s, FileSystem fs3, boolean addClasspathLayers) {
141
    private static FileSystem[] appendLayers(FileSystem fs1, boolean addLookupBefore, FileSystem[] fs2s, FileSystem fs3, boolean addClasspathLayers) {
137
        List<FileSystem> l = new ArrayList<FileSystem>(fs2s.length + 2);
142
        List<FileSystem> l = new ArrayList<FileSystem>(fs2s.length + 2);
138
        l.add(fs1);
143
        l.add(fs1);
139
        if (addLookupBefore) {
144
        if (addLookupBefore) {
140
            for (FileSystem f : result.allInstances()) {
145
            for (FileSystem f : fsResult.allInstances()) {
141
                if (Boolean.TRUE.equals(f.getRoot().getAttribute("fallback"))) { // NOI18N
146
                if (Boolean.TRUE.equals(f.getRoot().getAttribute("fallback"))) { // NOI18N
142
                    continue;
147
                    continue;
143
                }
148
                }
Lines 180-186 Link Here
180
            }
185
            }
181
        }
186
        }
182
        if (!addLookupBefore) {
187
        if (!addLookupBefore) {
183
            for (FileSystem f : result.allInstances()) {
188
            for (FileSystem f : fsResult.allInstances()) {
184
                if (Boolean.TRUE.equals(f.getRoot().getAttribute("fallback"))) { // NOI18N
189
                if (Boolean.TRUE.equals(f.getRoot().getAttribute("fallback"))) { // NOI18N
185
                    l.add(f);
190
                    l.add(f);
186
                }
191
                }
Lines 238-248 Link Here
238
    /** Change the list of module layers URLs.
243
    /** Change the list of module layers URLs.
239
     * @param urls the urls describing module layers to use. List<URL>
244
     * @param urls the urls describing module layers to use. List<URL>
240
     */
245
     */
241
    public void setURLs (final List<URL> urls) throws Exception {
246
    public void setURLs (List<URL> urls) throws Exception {
247
        if (urls == null) {
248
            urls = this.prevs;
249
        }
250
        if (urls == null) {
251
            return;
252
        }
242
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
253
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
243
        if (err.isLoggable(Level.FINE)) {
254
        if (err.isLoggable(Level.FINE)) {
244
            err.fine("setURLs: " + urls);
255
            err.fine("setURLs: " + urls);
245
        }
256
        }
257
        List<URL> orig = urls;
258
        if (this == ModuleLayeredFileSystem.getInstallationModuleLayer()) {
259
            urls = ((NbRepository)NbRepository.getDefault()).additionalLayers(urls);
260
        }
261
        
246
        if (this.urls != null && urls.equals(this.urls)) {
262
        if (this.urls != null && urls.equals(this.urls)) {
247
            err.fine("no-op");
263
            err.fine("no-op");
248
            return;
264
            return;
Lines 262-267 Link Here
262
        }
278
        }
263
        
279
        
264
        this.urls = urls;
280
        this.urls = urls;
281
        this.prevs = orig;
265
        firePropertyChange ("layers", null, null); // NOI18N
282
        firePropertyChange ("layers", null, null); // NOI18N
266
        
283
        
267
        StartLog.logEnd("setURLs"); // NOI18N
284
        StartLog.logEnd("setURLs"); // NOI18N
Lines 273-279 Link Here
273
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
290
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
274
        // Add to the front: #23609.
291
        // Add to the front: #23609.
275
        ArrayList<URL> arr = new ArrayList<URL>(urls);
292
        ArrayList<URL> arr = new ArrayList<URL>(urls);
276
        if (this.urls != null) arr.addAll(this.urls);
293
        if (this.prevs != null) arr.addAll(this.prevs);
277
        setURLs(arr);
294
        setURLs(arr);
278
    }
295
    }
279
    
296
    
Lines 282-295 Link Here
282
    public void removeURLs(Collection<URL> urls) throws Exception {
299
    public void removeURLs(Collection<URL> urls) throws Exception {
283
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
300
        if (urls.contains(null)) throw new NullPointerException("urls=" + urls); // NOI18N
284
        ArrayList<URL> arr = new ArrayList<URL>();
301
        ArrayList<URL> arr = new ArrayList<URL>();
285
        if (this.urls != null) arr.addAll(this.urls);
302
        if (this.prevs != null) arr.addAll(this.prevs);
286
        arr.removeAll(urls);
303
        arr.removeAll(urls);
287
        setURLs(arr);
304
        setURLs(arr);
288
    }
305
    }
289
    
306
    
290
    /** Refresh layers */
307
    @Override
291
    public void resultChanged(LookupEvent ev) {
308
    public void resultChanged(LookupEvent ev) {
292
        setDelegates(appendLayers(writableLayer, addLookupBefore, otherLayers, cacheLayer, false));
309
        if (ev.getSource() == fsResult) {
310
            setDelegates(appendLayers(writableLayer, addLookupBefore, otherLayers, cacheLayer, false));
311
            return;
312
        }
313
        if (ev.getSource() == layerResult) {
314
            if (prevs != null) {
315
                try {
316
                    setURLs(prevs);
317
                } catch (Exception ex) {
318
                    Exceptions.printStackTrace(ex);
319
                }
320
            }
321
            return;
322
        }
323
        throw new IllegalStateException("Unknown source: " + ev.getSource());
293
    }
324
    }
294
    
325
    
295
    private static void setStatusText (String msg) {
326
    private static void setStatusText (String msg) {
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/layers/ContentProviderTest.java (+119 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core.startup.layers;
43
44
import java.net.URL;
45
import java.util.Collections;
46
import java.util.List;
47
import java.util.concurrent.Future;
48
import junit.framework.Test;
49
import org.netbeans.core.startup.MainLookup;
50
import org.netbeans.core.startup.NbRepository;
51
import org.netbeans.junit.NbModuleSuite;
52
import org.netbeans.junit.NbTestCase;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.filesystems.Repository;
56
import org.openide.filesystems.Repository.LayersProvider;
57
import org.openide.util.Lookup;
58
59
/**
60
 *
61
 * @author Jaroslav Tulach <jtulach@netbeans.org>
62
 */
63
public class ContentProviderTest extends NbTestCase {
64
    public ContentProviderTest(String name) {
65
        super(name);
66
    }
67
    
68
    public static Test suite() {
69
        return NbModuleSuite.createConfiguration(ContentProviderTest.class)
70
            .gui(false).suite();
71
    }
72
    
73
    public void testBeforeRest() {
74
        FileObject fo = FileUtil.getConfigFile("foo/bar");
75
        assertNull("no foo/bar provided", fo);
76
    }
77
    
78
    public void testUsingNbRepositoryAndInit() {
79
        if (Repository.getDefault() instanceof NbRepository) {
80
            MainLookup.register(new MyProvider());
81
            return;
82
        }
83
        fail("Wrong repository: " + Repository.getDefault());
84
    }
85
    
86
    public void testCheckAFileFromOurLayer() {
87
        FileObject fo = FileUtil.getConfigFile("foo/bar");
88
        assertNotNull("foo/bar is provided", fo);
89
        assertEquals("value is val", "val", fo.getAttribute("x"));
90
    }
91
    
92
    public void testReturnEmptyLayers() throws Exception {
93
        MyProvider my = Lookup.getDefault().lookup(MyProvider.class);
94
        my.makeEmpty();
95
        FileObject fo = FileUtil.getConfigFile("foo/bar");
96
        assertNull("no foo/bar is provided anymore", fo);
97
        
98
    }
99
100
    public static final class MyProvider extends LayersProvider {
101
        private boolean empty;
102
        
103
        final void makeEmpty() {
104
            empty = true;
105
            refresh();
106
        }
107
        
108
        @Override
109
        public List<? extends URL> layers() {
110
            if (empty) {
111
                return Collections.emptyList();
112
            }
113
            final URL res = ContentProviderTest.class.getResource("ContentProviderTest.xml");
114
            assertNotNull("Layer found", res);
115
            return Collections.nCopies(1, res);
116
        }
117
    }
118
    
119
}
(-)a/ide.ergonomics/nbproject/project.xml (-1 / +1 lines)
Lines 115-121 Link Here
115
                    <build-prerequisite/>
115
                    <build-prerequisite/>
116
                    <compile-dependency/>
116
                    <compile-dependency/>
117
                    <run-dependency>
117
                    <run-dependency>
118
                        <specification-version>7.19</specification-version>
118
                        <specification-version>7.49</specification-version>
119
                    </run-dependency>
119
                    </run-dependency>
120
                </dependency>
120
                </dependency>
121
                <dependency>
121
                <dependency>
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/Installer.java (-2 lines)
Lines 43-49 Link Here
43
43
44
import org.netbeans.api.project.ui.OpenProjects;
44
import org.netbeans.api.project.ui.OpenProjects;
45
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
45
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
46
import org.netbeans.modules.ide.ergonomics.fod.FoDFileSystem;
47
import org.openide.modules.ModuleInstall;
46
import org.openide.modules.ModuleInstall;
48
import org.openide.util.Exceptions;
47
import org.openide.util.Exceptions;
49
48
Lines 57-63 Link Here
57
    @Override
56
    @Override
58
    public void restored() {
57
    public void restored() {
59
        WarmUp.init();
58
        WarmUp.init();
60
        FoDFileSystem.getInstance().initListener();
61
    }
59
    }
62
    
60
    
63
    @Override
61
    @Override
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/debugger/AttachTypeProxy.java (-2 / +2 lines)
Lines 49-55 Link Here
49
import org.netbeans.api.debugger.DebuggerManager;
49
import org.netbeans.api.debugger.DebuggerManager;
50
import org.netbeans.modules.ide.ergonomics.fod.ConfigurationPanel;
50
import org.netbeans.modules.ide.ergonomics.fod.ConfigurationPanel;
51
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
51
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
52
import org.netbeans.modules.ide.ergonomics.fod.FoDFileSystem;
52
import org.netbeans.modules.ide.ergonomics.fod.FoDLayersProvider;
53
import org.netbeans.spi.debugger.ui.AttachType;
53
import org.netbeans.spi.debugger.ui.AttachType;
54
import org.netbeans.spi.debugger.ui.Controller;
54
import org.netbeans.spi.debugger.ui.Controller;
55
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
Lines 74-80 Link Here
74
    }
74
    }
75
75
76
    public static AttachType create(FileObject fob) {
76
    public static AttachType create(FileObject fob) {
77
        FeatureInfo whichProvides = FoDFileSystem.getInstance().whichProvides(fob);
77
        FeatureInfo whichProvides = FoDLayersProvider.getInstance().whichProvides(fob);
78
        String displayName = (String) fob.getAttribute("displayName");
78
        String displayName = (String) fob.getAttribute("displayName");
79
        if (displayName == null) {
79
        if (displayName == null) {
80
            throw new IllegalArgumentException("No displayName attribute: " + fob);
80
            throw new IllegalArgumentException("No displayName attribute: " + fob);
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FeatureAction.java (-1 / +1 lines)
Lines 68-74 Link Here
68
    }
68
    }
69
69
70
    public void actionPerformed(ActionEvent e) {
70
    public void actionPerformed(ActionEvent e) {
71
        FeatureInfo info = FoDFileSystem.getInstance().whichProvides(fo);
71
        FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(fo);
72
        String n = Actions.cutAmpersand((String)fo.getAttribute("displayName")); // NOI18N
72
        String n = Actions.cutAmpersand((String)fo.getAttribute("displayName")); // NOI18N
73
        boolean success = Utilities.featureDialog(info, n, n);
73
        boolean success = Utilities.featureDialog(info, n, n);
74
        if (!success) {
74
        if (!success) {
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FeatureInfo.java (-2 / +2 lines)
Lines 187-193 Link Here
187
                        fs = new XMLFileSystem(url);
187
                        fs = new XMLFileSystem(url);
188
                        return fs;
188
                        return fs;
189
                    } catch (SAXException ex) {
189
                    } catch (SAXException ex) {
190
                        FoDFileSystem.LOG.log(Level.SEVERE, "Cannot parse: " + url, ex);
190
                        FoDLayersProvider.LOG.log(Level.SEVERE, "Cannot parse: " + url, ex);
191
                        Exceptions.printStackTrace(ex);
191
                        Exceptions.printStackTrace(ex);
192
                    }
192
                    }
193
                }
193
                }
Lines 223-229 Link Here
223
                                try {
223
                                try {
224
                                    required[1] = e = XPathFactory.newInstance().newXPath().compile((String) r1);
224
                                    required[1] = e = XPathFactory.newInstance().newXPath().compile((String) r1);
225
                                } catch (XPathExpressionException ex) {
225
                                } catch (XPathExpressionException ex) {
226
                                    FoDFileSystem.LOG.log(Level.WARNING, "Cannot parse " + r1, ex);
226
                                    FoDLayersProvider.LOG.log(Level.WARNING, "Cannot parse " + r1, ex);
227
                                    continue;
227
                                    continue;
228
                                }
228
                                }
229
                            } else {
229
                            } else {
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FeatureManager.java (-9 / +9 lines)
Lines 163-169 Link Here
163
     * @return
163
     * @return
164
     */
164
     */
165
    public static int dumpModules(Level withLevel, Level detailsLevel) {
165
    public static int dumpModules(Level withLevel, Level detailsLevel) {
166
        if (!FoDFileSystem.LOG.isLoggable(withLevel)) {
166
        if (!FoDLayersProvider.LOG.isLoggable(withLevel)) {
167
            return -1;
167
            return -1;
168
        }
168
        }
169
        int cnt = 0;
169
        int cnt = 0;
Lines 181-206 Link Here
181
                }
181
                }
182
            }
182
            }
183
            if (enabled.isEmpty() && disabled.isEmpty()) {
183
            if (enabled.isEmpty() && disabled.isEmpty()) {
184
                FoDFileSystem.LOG.log(withLevel, info.clusterName + " not present"); // NOTICES
184
                FoDLayersProvider.LOG.log(withLevel, info.clusterName + " not present"); // NOTICES
185
                continue;
185
                continue;
186
            }
186
            }
187
            if (enabled.isEmpty()) {
187
            if (enabled.isEmpty()) {
188
                FoDFileSystem.LOG.log(withLevel, info.clusterName + " disabled"); // NOTICES
188
                FoDLayersProvider.LOG.log(withLevel, info.clusterName + " disabled"); // NOTICES
189
                continue;
189
                continue;
190
            }
190
            }
191
            if (disabled.isEmpty()) {
191
            if (disabled.isEmpty()) {
192
                FoDFileSystem.LOG.log(withLevel, info.clusterName + " enabled"); // NOTICES
192
                FoDLayersProvider.LOG.log(withLevel, info.clusterName + " enabled"); // NOTICES
193
                cnt++;
193
                cnt++;
194
                continue;
194
                continue;
195
            }
195
            }
196
            FoDFileSystem.LOG.log(withLevel,
196
            FoDLayersProvider.LOG.log(withLevel,
197
                info.clusterName + " enabled " + enabled.size() + " disabled " + disabled.size()); // NOTICES
197
                info.clusterName + " enabled " + enabled.size() + " disabled " + disabled.size()); // NOTICES
198
            cnt++;
198
            cnt++;
199
            for (String cnb : disabled) {
199
            for (String cnb : disabled) {
200
                FoDFileSystem.LOG.log(detailsLevel, "- " + cnb); // NOI18N
200
                FoDLayersProvider.LOG.log(detailsLevel, "- " + cnb); // NOI18N
201
            }
201
            }
202
            for (String cnb : enabled) {
202
            for (String cnb : enabled) {
203
                FoDFileSystem.LOG.log(detailsLevel, "+ " + cnb); // NOI18N
203
                FoDLayersProvider.LOG.log(detailsLevel, "+ " + cnb); // NOI18N
204
            }
204
            }
205
        }
205
        }
206
        return cnt;
206
        return cnt;
Lines 293-304 Link Here
293
    }
293
    }
294
294
295
    private void fireChange() {
295
    private void fireChange() {
296
        FoDFileSystem.LOG.fine("Firing FeatureManager change"); // NOI18N
296
        FoDLayersProvider.LOG.fine("Firing FeatureManager change"); // NOI18N
297
        for (FeatureInfo f : features()) {
297
        for (FeatureInfo f : features()) {
298
            f.clearCache();
298
            f.clearCache();
299
        }
299
        }
300
        support.fireChange();
300
        support.fireChange();
301
        FoDFileSystem.LOG.fine("FeatureManager change delivered"); // NOI18N
301
        FoDLayersProvider.LOG.fine("FeatureManager change delivered"); // NOI18N
302
    }
302
    }
303
303
304
    /** Useful for testing */
304
    /** Useful for testing */
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FindComponentModules.java (-2 / +2 lines)
Lines 165-171 Link Here
165
            }
165
            }
166
        }
166
        }
167
        if (res.size() > 1) {
167
        if (res.size() > 1) {
168
            FoDFileSystem.LOG.warning("No prefCNB found " + prefCNB + " using multiple " + res);
168
            FoDLayersProvider.LOG.warning("No prefCNB found " + prefCNB + " using multiple " + res);
169
        }
169
        }
170
        return res;
170
        return res;
171
    }
171
    }
Lines 261-267 Link Here
261
                        all.add (el);
261
                        all.add (el);
262
                        all.addAll (reqs);
262
                        all.addAll (reqs);
263
//                    } else {
263
//                    } else {
264
//                        FoDFileSystem.LOG.fine("Cannot enable " + el.getCodeName() + " broken deps: " + breaks); // NOI18N
264
//                        FoDLayersProvider.LOG.fine("Cannot enable " + el.getCodeName() + " broken deps: " + breaks); // NOI18N
265
//                        ignore.add(el.getCodeName());
265
//                        ignore.add(el.getCodeName());
266
//                    }
266
//                    }
267
                } else {
267
                } else {
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FoDEditorOpened.java (-1 / +1 lines)
Lines 58-64 Link Here
58
    public void annotate(Set set, Lookup context) {
58
    public void annotate(Set set, Lookup context) {
59
        if (!anEditorIsOpened) {
59
        if (!anEditorIsOpened) {
60
            anEditorIsOpened = true;
60
            anEditorIsOpened = true;
61
            FoDFileSystem.getInstance().resultChanged(null);
61
            FoDLayersProvider.getInstance().resultChanged(null);
62
        }
62
        }
63
    }
63
    }
64
64
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FoDFileSystem.java (-75 / +21 lines)
Lines 41-47 Link Here
41
 */
41
 */
42
package org.netbeans.modules.ide.ergonomics.fod;
42
package org.netbeans.modules.ide.ergonomics.fod;
43
43
44
import java.io.IOException;
45
import java.net.URL;
44
import java.net.URL;
46
import java.util.ArrayList;
45
import java.util.ArrayList;
47
import java.util.Arrays;
46
import java.util.Arrays;
Lines 50-68 Link Here
50
import java.util.Set;
49
import java.util.Set;
51
import java.util.logging.Level;
50
import java.util.logging.Level;
52
import java.util.logging.Logger;
51
import java.util.logging.Logger;
53
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.core.startup.layers.LayerCacheManager;
56
import org.netbeans.spi.project.ProjectFactory;
52
import org.netbeans.spi.project.ProjectFactory;
57
import org.netbeans.spi.project.support.ant.AntBasedProjectType;
53
import org.netbeans.spi.project.support.ant.AntBasedProjectType;
58
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileSystem;
55
import org.openide.filesystems.Repository;
60
import org.openide.filesystems.MultiFileSystem;
61
import org.openide.util.Lookup;
56
import org.openide.util.Lookup;
62
import org.openide.util.LookupEvent;
57
import org.openide.util.LookupEvent;
63
import org.openide.util.LookupListener;
58
import org.openide.util.LookupListener;
64
import org.openide.util.RequestProcessor;
59
import org.openide.util.RequestProcessor;
65
import org.openide.util.WeakListeners;
66
import org.openide.util.lookup.ServiceProvider;
60
import org.openide.util.lookup.ServiceProvider;
67
import org.openide.util.lookup.ServiceProviders;
61
import org.openide.util.lookup.ServiceProviders;
68
62
Lines 71-135 Link Here
71
 * @author Jirka Rechtacek
65
 * @author Jirka Rechtacek
72
 */
66
 */
73
@ServiceProviders({
67
@ServiceProviders({
74
    @ServiceProvider(service=FileSystem.class),
68
    @ServiceProvider(service=Repository.LayersProvider.class),
75
    @ServiceProvider(service=FoDFileSystem.class)
69
    @ServiceProvider(service=FoDLayersProvider.class)
76
})
70
})
77
public final class FoDFileSystem extends MultiFileSystem
71
public final class FoDLayersProvider extends Repository.LayersProvider
78
implements Runnable, ChangeListener, LookupListener {
72
implements LookupListener, Runnable {
79
    private static final LayerCacheManager manager = LayerCacheManager.create("all-ergonomics.dat"); // NOI18N
73
    final static Logger LOG = Logger.getLogger (FoDLayersProvider.class.getPackage().getName());
80
    final static Logger LOG = Logger.getLogger (FoDFileSystem.class.getPackage().getName());
81
    private static RequestProcessor RP = new RequestProcessor("Ergonomics"); // NOI18N
74
    private static RequestProcessor RP = new RequestProcessor("Ergonomics"); // NOI18N
82
    private RequestProcessor.Task refresh = RP.create(this, true);
75
    private RequestProcessor.Task refresh = RP.create(this, true);
83
    private Lookup.Result<ProjectFactory> factories;
76
    private Lookup.Result<ProjectFactory> factories;
84
    private Lookup.Result<?> ants;
77
    private Lookup.Result<?> ants;
85
    private boolean forcedRefresh;
86
    private final ChangeListener weakL;
87
78
88
    public FoDFileSystem() {
79
    public static FoDLayersProvider getInstance() {
89
        setPropagateMasks(true);
80
        return Lookup.getDefault().lookup(FoDLayersProvider.class);
90
        weakL = WeakListeners.change(this, FeatureManager.getInstance());
91
        FileSystem fs;
92
        try {
93
            fs = manager.loadCache();
94
            if (fs != null) {
95
                LOG.fine("Using cached layer"); // NOI18N
96
                setDelegates(fs);
97
                return;
98
            }
99
        } catch (IOException ex) {
100
            LOG.log(Level.WARNING, "Cannot read cache", ex); // NOI18N
101
        }
102
        refresh();
103
    }
104
105
    public static FoDFileSystem getInstance() {
106
        return Lookup.getDefault().lookup(FoDFileSystem.class);
107
    }
81
    }
108
    
82
    
109
    public void initListener() {
110
        FeatureManager.getInstance().addChangeListener(weakL);
111
    }
112
113
    public void refresh() {
114
        refresh.schedule(0);
115
        refresh.waitFinished();
116
    }
117
    public void refreshForce() {
118
        forcedRefresh = true;
119
        refresh.schedule(0);
120
        refresh.waitFinished();
121
    }
122
123
    public void waitFinished() {
124
        refresh.waitFinished();
125
    }
126
127
    @Override
83
    @Override
128
    public void run() {
84
    public List<URL> layers() {
129
        boolean empty = true;
85
        boolean empty = true;
130
        LOG.fine("collecting layers"); // NOI18N
86
        LOG.fine("collecting layers"); // NOI18N
131
        List<URL> urls = new ArrayList<URL>();
87
        List<URL> urls = new ArrayList<URL>();
132
        urls.add(0, FoDFileSystem.class.getResource("common.xml")); // NOI18N
88
        urls.add(0, FoDLayersProvider.class.getResource("common.xml")); // NOI18N
133
        for (FeatureInfo info : FeatureManager.features()) {
89
        for (FeatureInfo info : FeatureManager.features()) {
134
            if (!info.isPresent()) {
90
            if (!info.isPresent()) {
135
                continue;
91
                continue;
Lines 144-171 Link Here
144
        }
100
        }
145
        if (empty && noAdditionalProjects() && !FoDEditorOpened.anEditorIsOpened) {
101
        if (empty && noAdditionalProjects() && !FoDEditorOpened.anEditorIsOpened) {
146
            LOG.fine("adding default layer"); // NOI18N
102
            LOG.fine("adding default layer"); // NOI18N
147
            urls.add(0, FoDFileSystem.class.getResource("default.xml")); // NOI18N
103
            urls.add(0, FoDLayersProvider.class.getResource("default.xml")); // NOI18N
148
        }
149
        if (forcedRefresh) {
150
            forcedRefresh = false;
151
            LOG.log(Level.INFO, "Forced refresh. Setting delegates to empty"); // NOI18N
152
            setDelegates();
153
            LOG.log(Level.INFO, "New delegates count: {0}", urls.size()); // NOI18N
154
            LOG.log(Level.INFO, "{0}", urls); // NOI18N
155
        }
104
        }
156
        LOG.log(Level.FINE, "delegating to {0} layers", urls.size()); // NOI18N
105
        LOG.log(Level.FINE, "delegating to {0} layers", urls.size()); // NOI18N
157
        LOG.log(Level.FINEST, "{0}", urls); // NOI18N
106
        LOG.log(Level.FINEST, "{0}", urls); // NOI18N
158
159
        try {
160
            FileSystem fs = getDelegates().length == 0 ?
161
                manager.createEmptyFileSystem() : getDelegates()[0];
162
            fs = manager.store(fs, urls);
163
            setDelegates(fs);
164
        } catch (IOException ex) {
165
            LOG.log(Level.WARNING, "Cannot save cache", ex);
166
        }
167
        LOG.fine("done");
107
        LOG.fine("done");
168
        FeatureManager.dumpModules();
108
        FeatureManager.dumpModules();
109
        return urls;
169
    }
110
    }
170
111
171
    public FeatureInfo whichProvides(FileObject template) {
112
    public FeatureInfo whichProvides(FileObject template) {
Lines 192-204 Link Here
192
    }
133
    }
193
134
194
    @Override
135
    @Override
195
    public void stateChanged(ChangeEvent e) {
136
    public void resultChanged(LookupEvent ev) {
196
        refresh.schedule(500);
137
        refresh.schedule(500);
197
    }
138
    }
198
139
    public void refreshForce() {
140
        super.refresh();
141
    }
199
    @Override
142
    @Override
200
    public void resultChanged(LookupEvent ev) {
143
    public void run() {
201
        refresh.schedule(0);
144
        super.refresh();
145
    }
146
    public void waitFinished() {
147
        refresh.waitFinished();
202
    }
148
    }
203
149
204
    private boolean noAdditionalProjects() {
150
    private boolean noAdditionalProjects() {
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FodDataObjectFactory.java (-6 / +6 lines)
Lines 82-88 Link Here
82
    
82
    
83
    private FodDataObjectFactory(FileObject fo) {
83
    private FodDataObjectFactory(FileObject fo) {
84
        this.definition = fo;
84
        this.definition = fo;
85
        this.info = FoDFileSystem.getInstance().whichProvides(definition);
85
        this.info = FoDLayersProvider.getInstance().whichProvides(definition);
86
    }
86
    }
87
87
88
88
Lines 154-163 Link Here
154
        }
154
        }
155
155
156
        private void delegate(boolean open) {
156
        private void delegate(boolean open) {
157
            FeatureInfo info = FoDFileSystem.getInstance().whichProvides(definition);
157
            FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(definition);
158
            String msg = NbBundle.getMessage(FodDataObjectFactory.class, "MSG_Opening_File", fo.getNameExt());
158
            String msg = NbBundle.getMessage(FodDataObjectFactory.class, "MSG_Opening_File", fo.getNameExt());
159
159
160
            FoDFileSystem.LOG.log(Level.FINER, "Opening file {0}", this);
160
            FoDLayersProvider.LOG.log(Level.FINER, "Opening file {0}", this);
161
            this.open = open;
161
            this.open = open;
162
            boolean success = Utilities.featureDialog(info, msg, msg);
162
            boolean success = Utilities.featureDialog(info, msg, msg);
163
            if (success) {
163
            if (success) {
Lines 170-176 Link Here
170
            ignore.add(getPrimaryFile());
170
            ignore.add(getPrimaryFile());
171
            try {
171
            try {
172
                DataObject obj = DataObject.find(fo);
172
                DataObject obj = DataObject.find(fo);
173
                FoDFileSystem.LOG.log(Level.FINER, "finishOpen {0}", obj);
173
                FoDLayersProvider.LOG.log(Level.FINER, "finishOpen {0}", obj);
174
                Class<?> what = open ? OpenCookie.class : EditCookie.class;
174
                Class<?> what = open ? OpenCookie.class : EditCookie.class;
175
                Object oc = obj.getLookup().lookup(what);
175
                Object oc = obj.getLookup().lookup(what);
176
                if (oc == this) {
176
                if (oc == this) {
Lines 193-200 Link Here
193
193
194
        @Override
194
        @Override
195
        public void stateChanged(ChangeEvent e) {
195
        public void stateChanged(ChangeEvent e) {
196
            FeatureInfo info = FoDFileSystem.getInstance().whichProvides(definition);
196
            FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(definition);
197
            FoDFileSystem.LOG.log(Level.FINER, "Refresh state of {0}", this);
197
            FoDLayersProvider.LOG.log(Level.FINER, "Refresh state of {0}", this);
198
            ignore.add(getPrimaryFile());
198
            ignore.add(getPrimaryFile());
199
            if (info == null || info.isEnabled()) {
199
            if (info == null || info.isEnabled()) {
200
                dispose();
200
                dispose();
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesActivator.java (-1 / +1 lines)
Lines 111-117 Link Here
111
            progressMonitor.onError(ex.getLocalizedMessage());
111
            progressMonitor.onError(ex.getLocalizedMessage());
112
            Logger.getLogger(ModulesActivator.class.getName()).warning(ex.getMessage());
112
            Logger.getLogger(ModulesActivator.class.getName()).warning(ex.getMessage());
113
        } finally {
113
        } finally {
114
            FoDFileSystem.getInstance().refresh();
114
            FoDLayersProvider.getInstance().refreshForce();
115
        }
115
        }
116
    }
116
    }
117
    
117
    
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesInstaller.java (-2 / +2 lines)
Lines 128-134 Link Here
128
        }
128
        }
129
        
129
        
130
        if (success) {
130
        if (success) {
131
            FoDFileSystem.getInstance().refresh();
131
            FoDLayersProvider.getInstance().refreshForce();
132
        }
132
        }
133
        
133
        
134
        return success;
134
        return success;
Lines 193-199 Link Here
193
                    );
193
                    );
194
            DialogDisplayer.getDefault ().notifyLater (nd);
194
            DialogDisplayer.getDefault ().notifyLater (nd);
195
        } finally {
195
        } finally {
196
            FoDFileSystem.getInstance().refresh();
196
            FoDLayersProvider.getInstance().refreshForce();
197
        }
197
        }
198
    }
198
    }
199
    
199
    
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/OpenAdvancedAction.java (-1 / +1 lines)
Lines 78-84 Link Here
78
        if (mimeDefinition == null) {
78
        if (mimeDefinition == null) {
79
            return;
79
            return;
80
        }
80
        }
81
        final FeatureInfo info = FoDFileSystem.getInstance().whichProvides(mimeDefinition);
81
        final FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(mimeDefinition);
82
        if (info == null || info.isEnabled()) {
82
        if (info == null || info.isEnabled()) {
83
            return;
83
            return;
84
        }
84
        }
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/newproject/DescriptionStep.java (-7 / +11 lines)
Lines 43-48 Link Here
43
 */
43
 */
44
package org.netbeans.modules.ide.ergonomics.newproject;
44
package org.netbeans.modules.ide.ergonomics.newproject;
45
45
46
import java.util.concurrent.ExecutionException;
46
import org.netbeans.modules.ide.ergonomics.fod.FindComponentModules;
47
import org.netbeans.modules.ide.ergonomics.fod.FindComponentModules;
47
import org.netbeans.modules.ide.ergonomics.fod.ModulesInstaller;
48
import org.netbeans.modules.ide.ergonomics.fod.ModulesInstaller;
48
import java.awt.Component;
49
import java.awt.Component;
Lines 67-73 Link Here
67
import org.netbeans.api.autoupdate.UpdateElement;
68
import org.netbeans.api.autoupdate.UpdateElement;
68
import org.netbeans.api.progress.ProgressHandle;
69
import org.netbeans.api.progress.ProgressHandle;
69
import org.netbeans.modules.ide.ergonomics.fod.ConfigurationPanel;
70
import org.netbeans.modules.ide.ergonomics.fod.ConfigurationPanel;
70
import org.netbeans.modules.ide.ergonomics.fod.FoDFileSystem;
71
import org.netbeans.modules.ide.ergonomics.fod.FoDLayersProvider;
71
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
72
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
72
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
73
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
73
import org.openide.WizardDescriptor;
74
import org.openide.WizardDescriptor;
Lines 106-112 Link Here
106
            configPanel = new ConfigurationPanel(new Callable<JComponent>() {
107
            configPanel = new ConfigurationPanel(new Callable<JComponent>() {
107
                @Override
108
                @Override
108
                public JComponent call() throws Exception {
109
                public JComponent call() throws Exception {
109
                    FoDFileSystem.getInstance().refresh();
110
                    FoDLayersProvider.getInstance().refreshForce();
110
                    waitForDelegateWizard();
111
                    waitForDelegateWizard();
111
                    return new JLabel(" ");
112
                    return new JLabel(" ");
112
                }
113
                }
Lines 179-185 Link Here
179
            forEnable = elems;
180
            forEnable = elems;
180
            fireChange ();
181
            fireChange ();
181
        } else {
182
        } else {
182
            FoDFileSystem.getInstance().refresh();
183
            FoDLayersProvider.getInstance().refreshForce();
183
            waitForDelegateWizard ();
184
            waitForDelegateWizard ();
184
            SwingUtilities.invokeLater(new Runnable() {
185
            SwingUtilities.invokeLater(new Runnable() {
185
                public void run() {
186
                public void run() {
Lines 204-210 Link Here
204
        Object o = settings.getProperty (FeatureOnDemandWizardIterator.CHOSEN_TEMPLATE);
205
        Object o = settings.getProperty (FeatureOnDemandWizardIterator.CHOSEN_TEMPLATE);
205
        assert o != null && o instanceof FileObject : o + " is not null and instanceof FileObject.";
206
        assert o != null && o instanceof FileObject : o + " is not null and instanceof FileObject.";
206
        FileObject fileObject = (FileObject) o;
207
        FileObject fileObject = (FileObject) o;
207
        info = FoDFileSystem.getInstance ().whichProvides(fileObject);
208
        info = FoDLayersProvider.getInstance ().whichProvides(fileObject);
208
        finder = new FindComponentModules(info);
209
        finder = new FindComponentModules(info);
209
    }
210
    }
210
211
Lines 224-231 Link Here
224
        WizardDescriptor.InstantiatingIterator<?> iterator = null;
225
        WizardDescriptor.InstantiatingIterator<?> iterator = null;
225
        int i = 0;
226
        int i = 0;
226
        while (fo == null || iterator == null) {
227
        while (fo == null || iterator == null) {
227
            FoDFileSystem.getInstance().refresh();
228
            try {
228
            FoDFileSystem.getInstance().waitFinished();
229
                FoDLayersProvider.getInstance().refreshForce();
230
            } catch (Exception ex) {
231
                Exceptions.printStackTrace(ex);
232
            }
229
            // hot-fixed wizard providers - temporary
233
            // hot-fixed wizard providers - temporary
230
            if (templateResource.startsWith("Servers/WizardProvider")) {
234
            if (templateResource.startsWith("Servers/WizardProvider")) {
231
                try {
235
                try {
Lines 268-274 Link Here
268
                }
272
                }
269
                LOG.info("Forcing refresh"); // NOI18N
273
                LOG.info("Forcing refresh"); // NOI18N
270
                // force refresh for the filesystem
274
                // force refresh for the filesystem
271
                FoDFileSystem.getInstance().refreshForce();
275
                FoDLayersProvider.getInstance().refreshForce();
272
                LOG.info("Done with refresh"); // NOI18N
276
                LOG.info("Done with refresh"); // NOI18N
273
277
274
                FileObject fake = FileUtil.getConfigFile(templateResource);
278
                FileObject fake = FileUtil.getConfigFile(templateResource);
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/newproject/EnableStep.java (-3 / +3 lines)
Lines 61-67 Link Here
61
import org.netbeans.api.progress.ProgressHandleFactory;
61
import org.netbeans.api.progress.ProgressHandleFactory;
62
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
62
import org.netbeans.modules.ide.ergonomics.fod.FeatureInfo;
63
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
63
import org.netbeans.modules.ide.ergonomics.fod.FeatureManager;
64
import org.netbeans.modules.ide.ergonomics.fod.FoDFileSystem;
64
import org.netbeans.modules.ide.ergonomics.fod.FoDLayersProvider;
65
import org.openide.WizardDescriptor;
65
import org.openide.WizardDescriptor;
66
import org.openide.WizardDescriptor.Panel;
66
import org.openide.WizardDescriptor.Panel;
67
import org.openide.filesystems.FileObject;
67
import org.openide.filesystems.FileObject;
Lines 125-131 Link Here
125
                    RequestProcessor.Task enable = activator.getEnableTask ();
125
                    RequestProcessor.Task enable = activator.getEnableTask ();
126
                    enable.schedule (0);
126
                    enable.schedule (0);
127
                    enable.waitFinished ();
127
                    enable.waitFinished ();
128
                    FoDFileSystem.getInstance().refresh();
128
                    FoDLayersProvider.getInstance().refreshForce();
129
                    waitForDelegateWizard ();
129
                    waitForDelegateWizard ();
130
                }
130
                }
131
            }
131
            }
Lines 153-159 Link Here
153
        Object templateO = settings.getProperty (FeatureOnDemandWizardIterator.CHOSEN_TEMPLATE);
153
        Object templateO = settings.getProperty (FeatureOnDemandWizardIterator.CHOSEN_TEMPLATE);
154
        assert templateO != null && templateO instanceof FileObject : templateO + " is not null and instanceof FileObject.";
154
        assert templateO != null && templateO instanceof FileObject : templateO + " is not null and instanceof FileObject.";
155
        FileObject templateFO = (FileObject) templateO;
155
        FileObject templateFO = (FileObject) templateO;
156
        FeatureInfo info = FoDFileSystem.getInstance().whichProvides(templateFO);
156
        FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(templateFO);
157
        RequestProcessor.Task t = FeatureManager.getInstance().create(doEnable(info));
157
        RequestProcessor.Task t = FeatureManager.getInstance().create(doEnable(info));
158
        t.schedule(0);
158
        t.schedule(0);
159
    }
159
    }
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/newproject/FeatureOnDemandWizardIterator.java (-2 / +2 lines)
Lines 53-59 Link Here
53
import javax.swing.JComponent;
53
import javax.swing.JComponent;
54
import javax.swing.event.ChangeListener;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.progress.ProgressHandle;
55
import org.netbeans.api.progress.ProgressHandle;
56
import org.netbeans.modules.ide.ergonomics.fod.FoDFileSystem;
56
import org.netbeans.modules.ide.ergonomics.fod.FoDLayersProvider;
57
import org.openide.WizardDescriptor;
57
import org.openide.WizardDescriptor;
58
import org.openide.WizardDescriptor.InstantiatingIterator;
58
import org.openide.WizardDescriptor.InstantiatingIterator;
59
import org.openide.WizardDescriptor.ProgressInstantiatingIterator;
59
import org.openide.WizardDescriptor.ProgressInstantiatingIterator;
Lines 95-101 Link Here
95
    
95
    
96
    private static WizardDescriptor.InstantiatingIterator getRealNewMakeProjectWizardIterator (FileObject template) {
96
    private static WizardDescriptor.InstantiatingIterator getRealNewMakeProjectWizardIterator (FileObject template) {
97
        WizardDescriptor.InstantiatingIterator res = null;
97
        WizardDescriptor.InstantiatingIterator res = null;
98
        if (FoDFileSystem.getInstance().getDelegateFileSystem (template) != null) {
98
        if (FoDLayersProvider.getInstance().getDelegateFileSystem (template) != null) {
99
            return null;
99
            return null;
100
        }
100
        }
101
        FileObject fo = FileUtil.getConfigFile(template.getPath ());
101
        FileObject fo = FileUtil.getConfigFile(template.getPath ());
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/AdditionalAntBasedTest.java (-1 / +1 lines)
Lines 120-126 Link Here
120
120
121
        assertNotNull("Ant found", f);
121
        assertNotNull("Ant found", f);
122
        LOG.info("waiting for FoDFileSystem to be updated");
122
        LOG.info("waiting for FoDFileSystem to be updated");
123
        FoDFileSystem.getInstance().waitFinished();
123
        FoDLayersProvider.getInstance().waitFinished();
124
        LOG.info("waiting for FoDFileSystem to be waitFinished is over");
124
        LOG.info("waiting for FoDFileSystem to be waitFinished is over");
125
125
126
        for (int cnt = 0; cnt < 5; cnt++) {
126
        for (int cnt = 0; cnt < 5; cnt++) {
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/AdditionalProjectFactoryTest.java (-1 / +1 lines)
Lines 103-109 Link Here
103
        Factory f = Lookup.getDefault().lookup(Factory.class);
103
        Factory f = Lookup.getDefault().lookup(Factory.class);
104
        assertNotNull("Factory found", f);
104
        assertNotNull("Factory found", f);
105
        LOG.info("Factory found");
105
        LOG.info("Factory found");
106
        FoDFileSystem.getInstance().waitFinished();
106
        FoDLayersProvider.getInstance().waitFinished();
107
        LOG.info("Refresh finished");
107
        LOG.info("Refresh finished");
108
        
108
        
109
        for (int i = 0; i < 100; i++) {
109
        for (int i = 0; i < 100; i++) {
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/EnablingAutoloadLeavesFeatureDisabledTest.java (-2 / +1 lines)
Lines 155-162 Link Here
155
            ParseXMLContentTest.class.getResource("TestBundle4.properties")
155
            ParseXMLContentTest.class.getResource("TestBundle4.properties")
156
        );
156
        );
157
        ic.add(info);
157
        ic.add(info);
158
        FoDFileSystem.getInstance().refresh();
158
        FoDLayersProvider.getInstance().refreshForce();
159
        FoDFileSystem.getInstance().waitFinished();
160
    }
159
    }
161
160
162
161
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/FodDataObjectFactoryTest.java (-2 / +1 lines)
Lines 154-161 Link Here
154
            ParseXMLContentTest.class.getResource("TestBundle.properties")
154
            ParseXMLContentTest.class.getResource("TestBundle.properties")
155
        );
155
        );
156
        ic.add(info);
156
        ic.add(info);
157
        FoDFileSystem.getInstance().refresh();
157
        FoDLayersProvider.getInstance().refreshForce();
158
        FoDFileSystem.getInstance().waitFinished();
159
    }
158
    }
160
159
161
160
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/FodDataObjectXMLFactoryTest.java (-2 / +1 lines)
Lines 160-167 Link Here
160
            ParseXMLContentTest.class.getResource("TestBundle.properties")
160
            ParseXMLContentTest.class.getResource("TestBundle.properties")
161
        );
161
        );
162
        ic.add(info);
162
        ic.add(info);
163
        FoDFileSystem.getInstance().refresh();
163
        FoDLayersProvider.getInstance().refreshForce();
164
        FoDFileSystem.getInstance().waitFinished();
165
    }
164
    }
166
165
167
166
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/GeneralActionTest.java (-1 / +1 lines)
Lines 122-128 Link Here
122
        root = FileUtil.toFileObject(getWorkDir());
122
        root = FileUtil.toFileObject(getWorkDir());
123
        assertNotNull("fileobject found", root);
123
        assertNotNull("fileobject found", root);
124
        
124
        
125
        FoDFileSystem.getInstance().refresh();
125
        FoDLayersProvider.getInstance().refreshForce();
126
126
127
        actionFile = FileUtil.getConfigFile("Actions/System/org-netbeans-modules-autoupdate-ui-actions-PluginManagerAction.instance");
127
        actionFile = FileUtil.getConfigFile("Actions/System/org-netbeans-modules-autoupdate-ui-actions-PluginManagerAction.instance");
128
        assertNotNull("testing layer is loaded: ", actionFile);
128
        assertNotNull("testing layer is loaded: ", actionFile);
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/OpenEditorEnablesEditMenuFactoryTest.java (-1 / +1 lines)
Lines 139-145 Link Here
139
                assertEquals("One component is open", 1, arr.length);
139
                assertEquals("One component is open", 1, arr.length);
140
            }
140
            }
141
        });
141
        });
142
        FoDFileSystem.getInstance().waitFinished();
142
        FoDLayersProvider.getInstance().waitFinished();
143
143
144
        FileObject fo = null;
144
        FileObject fo = null;
145
        for (int i = 0; i < 100; i++) {
145
        for (int i = 0; i < 100; i++) {
(-)a/openide.filesystems/apichanges.xml (+17 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="repository.content.provide">
53
            <api name="filesystems"/>
54
            <summary>Ability to provide additional layers</summary>
55
            <version major="7" minor="49"/>
56
            <date day="6" month="6" year="2011"/>
57
            <author login="jtulach"/>
58
            <compatibility addition="yes"/>
59
            <description>
60
                <p>
61
                Providers of implementation of
62
                <a href="@TOP@org/openide/filesystems/Repository.ContentProvider.html">ContentProvider</a>
63
                interface can contribute to the content of system file system.
64
                </p>
65
            </description>
66
            <class package="org.openide.filesystems" name="Repository"/>
67
            <issue number="198508"/>
68
        </change>
52
        <change id="to.parent">
69
        <change id="to.parent">
53
            <api name="filesystems"/>
70
            <api name="filesystems"/>
54
            <summary>FileObject.getFileObject accepts ".."</summary>
71
            <summary>FileObject.getFileObject accepts ".."</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 7.48
5
OpenIDE-Module-Specification-Version: 7.49
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/Repository.java (-21 / +93 lines)
Lines 57-68 Link Here
57
import java.io.Serializable;
57
import java.io.Serializable;
58
import java.net.URL;
58
import java.net.URL;
59
import java.util.ArrayList;
59
import java.util.ArrayList;
60
import java.util.Collections;
60
import java.util.Enumeration;
61
import java.util.Enumeration;
61
import java.util.HashSet;
62
import java.util.HashSet;
62
import java.util.Hashtable;
63
import java.util.Hashtable;
63
import java.util.Iterator;
64
import java.util.Iterator;
64
import java.util.List;
65
import java.util.List;
66
import java.util.Set;
65
import java.util.Vector;
67
import java.util.Vector;
68
import java.util.concurrent.Future;
66
import java.util.concurrent.atomic.AtomicReference;
69
import java.util.concurrent.atomic.AtomicReference;
67
import java.util.jar.Manifest;
70
import java.util.jar.Manifest;
68
import java.util.logging.Level;
71
import java.util.logging.Level;
Lines 72-77 Link Here
72
import org.openide.util.LookupListener;
75
import org.openide.util.LookupListener;
73
import org.openide.util.NbCollections;
76
import org.openide.util.NbCollections;
74
import org.openide.util.io.NbMarshalledObject;
77
import org.openide.util.io.NbMarshalledObject;
78
import org.openide.util.lookup.ServiceProvider;
75
79
76
/**
80
/**
77
 * Holder for NetBeans default (system, configuration) filesystem, used for most
81
 * Holder for NetBeans default (system, configuration) filesystem, used for most
Lines 143-148 Link Here
143
147
144
        return repository;
148
        return repository;
145
    }
149
    }
150
    
151
    /** Contributes to content of {@link #getDefaultFileSystem() system file system} 
152
     * (which influences structure under {@link FileUtil#getConfigRoot()}). The
153
     * method is called during initialization of {@link Repository} and 
154
     * implementors (registered via {@link ServiceProvider} annontation) may
155
     * add their <em>layers</em> (processed via {@link XMLFileSystem}) into
156
     * the general collection of existing providers.
157
     * <p class="non-normative">
158
     * The list of <em>layers</em> as well as their content may be cached.
159
     * In a typical NetBeans Platform application, the cache remains until
160
     * list of <a href="@org-openide-modules@/org/openide/modules/ModuleInfo.html">modules</a>
161
     * and their enablement state remain the same. While it does, the {@link LayersProvider}s
162
     * are not queried again.
163
     * </p>
164
     * @since 7.49
165
     */
166
    public static abstract class LayersProvider {
167
        /** Ordered list of {@link URL}s to with {@link XMLFileSystem}-like 
168
         * definitions to process
169
         * @return list of URLs
170
         */
171
        protected abstract List<? extends URL> layers();
172
        
173
        /** Method to call when set of URLs returned from the {@link #layers()}
174
         * method changed and there is a need to refresh it. Refresh is very likely 
175
         * a time consuming task - consider invoking it on a background thread and
176
         * don't hold any locks while calling the method
177
         */
178
        protected final void refresh() {
179
            Repository.getDefault().refreshAdditionalLayers();
180
        }
181
    }
182
183
    /** Methods that tells {@link Repository} subclasses to refresh list of
184
     * URLs provided by {@link LayersProvider}s.
185
     * @since 7.49
186
     */
187
    protected void refreshAdditionalLayers() {
188
        if (getDefaultFileSystem() instanceof MainFS) {
189
            ((MainFS)getDefaultFileSystem()).refreshLayers();
190
        }
191
    }
192
    
193
    /** Allows subclasses registered as {@link Repository#getDefault()} to 
194
     * find out list of URLs for a given provider. The method just calls
195
     * {@link LayersProvider#layers()}.
196
     * 
197
     * @param p the provider.
198
     * @return ordered list of URLs
199
     * @since 7.49
200
     */
201
    protected final List<? extends URL> findLayers(LayersProvider p) {
202
        if (this != Repository.getDefault()) {
203
            return Collections.emptyList();
204
        }
205
        return p.layers();
206
    }
146
207
147
    private static final class MainFS extends MultiFileSystem implements LookupListener {
208
    private static final class MainFS extends MultiFileSystem implements LookupListener {
148
        private static final Lookup.Result<FileSystem> ALL = Lookup.getDefault().lookupResult(FileSystem.class);
209
        private static final Lookup.Result<FileSystem> ALL = Lookup.getDefault().lookupResult(FileSystem.class);
Lines 151-179 Link Here
151
212
152
        public MainFS() {
213
        public MainFS() {
153
            ALL.addLookupListener(this);
214
            ALL.addLookupListener(this);
215
            refreshLayers();
216
        }
217
        
218
        final void refreshLayers() {
154
            List<URL> layerUrls = new ArrayList<URL>();
219
            List<URL> layerUrls = new ArrayList<URL>();
155
            ClassLoader l = Thread.currentThread().getContextClassLoader();
156
            try {
220
            try {
157
                for (URL manifest : NbCollections.iterable(l.getResources("META-INF/MANIFEST.MF"))) { // NOI18N
221
                provideLayer(layerUrls);
158
                    InputStream is = manifest.openStream();
159
                    try {
160
                        Manifest mani = new Manifest(is);
161
                        String layerLoc = mani.getMainAttributes().getValue("OpenIDE-Module-Layer"); // NOI18N
162
                        if (layerLoc != null) {
163
                            URL layer = l.getResource(layerLoc);
164
                            if (layer != null) {
165
                                layerUrls.add(layer);
166
                            } else {
167
                                LOG.warning("No such layer: " + layerLoc);
168
                            }
169
                        }
170
                    } finally {
171
                        is.close();
172
                    }
173
                }
174
                for (URL generatedLayer : NbCollections.iterable(l.getResources("META-INF/generated-layer.xml"))) { // NOI18N
175
                    layerUrls.add(generatedLayer);
176
                }
177
                layers.setXmlUrls(layerUrls.toArray(new URL[layerUrls.size()]));
222
                layers.setXmlUrls(layerUrls.toArray(new URL[layerUrls.size()]));
178
                LOG.log(Level.FINE, "Loading classpath layers: {0}", layerUrls);
223
                LOG.log(Level.FINE, "Loading classpath layers: {0}", layerUrls);
179
            } catch (Exception x) {
224
            } catch (Exception x) {
Lines 182-187 Link Here
182
            resultChanged(null); // run after add listener - see PN1 in #26338
227
            resultChanged(null); // run after add listener - see PN1 in #26338
183
        }
228
        }
184
229
230
        private void provideLayer(List<URL> layerUrls) throws IOException {
231
            ClassLoader l = Thread.currentThread().getContextClassLoader();
232
            for (URL manifest : NbCollections.iterable(l.getResources("META-INF/MANIFEST.MF"))) { // NOI18N
233
                InputStream is = manifest.openStream();
234
                try {
235
                    Manifest mani = new Manifest(is);
236
                    String layerLoc = mani.getMainAttributes().getValue("OpenIDE-Module-Layer"); // NOI18N
237
                    if (layerLoc != null) {
238
                        URL layer = l.getResource(layerLoc);
239
                        if (layer != null) {
240
                            layerUrls.add(layer);
241
                        } else {
242
                            LOG.warning("No such layer: " + layerLoc);
243
                        }
244
                    }
245
                } finally {
246
                    is.close();
247
                }
248
            }
249
            for (URL generatedLayer : NbCollections.iterable(l.getResources("META-INF/generated-layer.xml"))) { // NOI18N
250
                layerUrls.add(generatedLayer);
251
            }
252
            for (LayersProvider p : Lookup.getDefault().lookupAll(LayersProvider.class)) {
253
                layerUrls.addAll(p.layers());
254
            }
255
        }
256
185
        private static FileSystem[] computeDelegates() {
257
        private static FileSystem[] computeDelegates() {
186
            List<FileSystem> arr = new ArrayList<FileSystem>();
258
            List<FileSystem> arr = new ArrayList<FileSystem>();
187
            arr.add(MEMORY);
259
            arr.add(MEMORY);
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/ContentProviderTest.java (+97 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.openide.filesystems;
43
44
import java.net.URL;
45
import java.util.Collections;
46
import java.util.List;
47
import org.netbeans.junit.MockServices;
48
import org.netbeans.junit.NbTestCase;
49
import org.openide.filesystems.Repository.LayersProvider;
50
import org.openide.util.Lookup;
51
52
public class ContentProviderTest extends NbTestCase {
53
    static {
54
        MockServices.setServices(MyProvider.class);
55
    }
56
57
    public ContentProviderTest(String name) {
58
        super(name);
59
    }
60
61
    public void testCheckAFileFromOurLayer() {
62
        FileObject fo = FileUtil.getConfigFile("foo/bar");
63
        assertNotNull("foo/bar is provided", fo);
64
        assertEquals("value is val", "val", fo.getAttribute("x"));
65
    }
66
    
67
    public void testRefreshTheProvider() throws Exception {
68
        MyProvider my = Lookup.getDefault().lookup(MyProvider.class);
69
        assertNotNull("My provider found", my);
70
        
71
        my.clear();
72
        
73
        FileObject fo = FileUtil.getConfigFile("foo/bar");
74
        assertNull("foo/bar is no longer available", fo);
75
        
76
    }
77
    
78
    public static final class MyProvider extends LayersProvider {
79
        private boolean empty;
80
        
81
        @Override
82
        public List<? extends URL> layers() {
83
            if (empty) {
84
                return Collections.emptyList();
85
            }
86
            return Collections.nCopies(1,
87
                ContentProviderTest.class.getResource("test-layer-attribs.xml")
88
            );
89
        }
90
91
        final void clear() throws Exception {
92
            empty = true;
93
            refresh();
94
        }
95
        
96
    }
97
}

Return to bug 198508