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

(-)masterfs/apichanges.xml (+14 lines)
Lines 49-54 Link Here
49
        <apidef name="masterfs">MasterFileSystem API</apidef>
49
        <apidef name="masterfs">MasterFileSystem API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="canWrite">
53
            <api name="masterfs"/>
54
            <summary>Determine if a ProvidedExtensions instance should be used to get a files canWrite() value</summary>
55
            <version major="2" minor="30"/>
56
            <date day="1" month="2" year="2011"/>
57
            <author login="tstupka"/>
58
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
59
            <description>
60
                Introduced a new constructor parameter <code>providesCanWrite</code> to specify if a 
61
                ProvidedExtensions instance is meant to provide the canWrite() value for a file.
62
            </description>
63
            <class package="org.netbeans.modules.masterfs.providers" name="ProvidedExtensions"/>
64
            <issue number="194683"/>
65
        </change>
52
        <change id="copy-handler">
66
        <change id="copy-handler">
53
            <api name="masterfs"/>
67
            <api name="masterfs"/>
54
            <summary>Delegate FileObject.copy() to ProvidedExtensions</summary>
68
            <summary>Delegate FileObject.copy() to ProvidedExtensions</summary>
(-)masterfs/manifest.mf (-1 / +1 lines)
Lines 2-8 Link Here
2
OpenIDE-Module: org.netbeans.modules.masterfs/2
2
OpenIDE-Module: org.netbeans.modules.masterfs/2
3
OpenIDE-Module-Install: org/netbeans/modules/masterfs/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/masterfs/Installer.class
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/masterfs/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/masterfs/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 2.29
5
OpenIDE-Module-Specification-Version: 2.30
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
8
8
(-)masterfs/src/org/netbeans/modules/masterfs/ProvidedExtensionsAccessor.java (+55 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
43
package org.netbeans.modules.masterfs;
44
45
import org.netbeans.modules.masterfs.providers.ProvidedExtensions;
46
47
/**
48
 *
49
 * @author Tomas Stupka
50
 */
51
public abstract class ProvidedExtensionsAccessor {
52
    public static ProvidedExtensionsAccessor IMPL;
53
    
54
    public abstract boolean providesCanWrite(ProvidedExtensions pe);
55
}
(-)masterfs/src/org/netbeans/modules/masterfs/ProvidedExtensionsProxy.java (+8 lines)
Lines 218-228 Link Here
218
            if (iListener instanceof ProvidedExtensions) {
218
            if (iListener instanceof ProvidedExtensions) {
219
                runCheckCode(new Runnable() {
219
                runCheckCode(new Runnable() {
220
                    public void run() {
220
                    public void run() {
221
                        ProvidedExtensions extension = (ProvidedExtensions)iListener;
222
                        if(ProvidedExtensionsAccessor.IMPL != null && 
223
                           ProvidedExtensionsAccessor.IMPL.providesCanWrite(extension)) 
224
                        {
221
                        ret[0] = ((ProvidedExtensions)iListener).canWrite(f);
225
                        ret[0] = ((ProvidedExtensions)iListener).canWrite(f);
222
                    }
226
                    }
227
                    }
223
                });                                                                                
228
                });                                                                                
229
                if(ret[0] != null && ret[0]) {
230
                    break;
224
            }
231
            }
225
        }
232
        }
233
        }
226
        return ret[0] != null ? ret[0] : super.canWrite(f);
234
        return ret[0] != null ? ret[0] : super.canWrite(f);
227
    }
235
    }
228
        
236
        
(-)masterfs/src/org/netbeans/modules/masterfs/providers/ProvidedExtensions.java (+33 lines)
Lines 48-53 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.util.List;
49
import java.util.List;
50
import java.util.concurrent.Callable;
50
import java.util.concurrent.Callable;
51
import org.netbeans.modules.masterfs.ProvidedExtensionsAccessor;
51
import org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager;
52
import org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager;
52
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
53
54
Lines 69-74 Link Here
69
public class ProvidedExtensions implements InterceptionListener {
70
public class ProvidedExtensions implements InterceptionListener {
70
71
71
    /**
72
    /**
73
     * true if this instance should be called to determine a files canWrite value, otherwise false
74
     */
75
    private final boolean providesCanWrite;
76
77
    /**
78
     * Creates a new ProvidedExtensions. 
79
     * 
80
     * @param providesCanWrite true if this instance is meant to 
81
     *        determine a files {@link #canWrite()} value, otherwise false. 
82
     * @since 2.29
83
     *          
84
     */
85
    public ProvidedExtensions(boolean providesCanWrite) {
86
        this.providesCanWrite = providesCanWrite;
87
        if(ProvidedExtensionsAccessor.IMPL == null) {
88
            ProvidedExtensionsAccessor.IMPL = new ProvidedExtensionsAccessor() {
89
                @Override
90
                public boolean providesCanWrite(ProvidedExtensions pe) {
91
                    return pe.providesCanWrite;
92
                }
93
            };
94
        }     
95
    }
96
97
    /**
98
     * Default constructor
99
     */
100
    public ProvidedExtensions() {
101
        this(false);
102
    }
103
    
104
    /**
72
     * Return instance of {@link ProvidedExtensions.IOHandler}
105
     * Return instance of {@link ProvidedExtensions.IOHandler}
73
     * that is responsible for copying the file or null.
106
     * that is responsible for copying the file or null.
74
     *
107
     *
(-)masterfs/test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java (-8 / +25 lines)
Lines 61-66 Link Here
61
import junit.framework.AssertionFailedError;
61
import junit.framework.AssertionFailedError;
62
import org.netbeans.junit.MockServices;
62
import org.netbeans.junit.MockServices;
63
import org.netbeans.junit.NbTestCase;
63
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.modules.masterfs.ProvidedExtensionsAccessor;
64
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
65
import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
65
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
66
import org.netbeans.modules.masterfs.filebasedfs.naming.NamingFactory;
66
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo;
67
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo;
Lines 83-91 Link Here
83
 */
84
 */
84
public class ProvidedExtensionsTest extends NbTestCase {
85
public class ProvidedExtensionsTest extends NbTestCase {
85
    private ProvidedExtensionsImpl iListener;
86
    private ProvidedExtensionsImpl iListener;
87
    private ProvidedExtensionsImpl iListenerNoCanWrite;
86
88
87
    static {
89
    static {
88
        MockServices.setServices(AnnotationProviderImpl.class);
90
        MockServices.setServices(AnnotationProviderImpl.class, AnnotationProviderImplNoCanWrite.class);
89
    }
91
    }
90
92
91
    @Override
93
    @Override
Lines 94-115 Link Here
94
        AnnotationProvider provider = (AnnotationProvider)Lookups.metaInfServices(
96
        AnnotationProvider provider = (AnnotationProvider)Lookups.metaInfServices(
95
                Thread.currentThread().getContextClassLoader()).lookup(AnnotationProvider.class);
97
                Thread.currentThread().getContextClassLoader()).lookup(AnnotationProvider.class);
96
        assertNotNull(provider);
98
        assertNotNull(provider);
97
        iListener = lookupImpl();
99
        iListener = lookupImpl(true);
98
        assertNotNull(iListener);
100
        assertNotNull(iListener);
101
        iListenerNoCanWrite = lookupImpl(false);
102
        assertNotNull(iListenerNoCanWrite);
99
        clearWorkDir();
103
        clearWorkDir();
100
    }
104
    }
101
    
105
    
102
    private ProvidedExtensionsImpl lookupImpl() {
106
    private ProvidedExtensionsImpl lookupImpl(boolean providesCanWrite) {
103
        Lookup.Result result = Lookups.metaInfServices(Thread.currentThread().getContextClassLoader()).
107
        Lookup.Result result = Lookups.metaInfServices(Thread.currentThread().getContextClassLoader()).
104
                lookup(new Lookup.Template(AnnotationProvider.class));
108
                lookup(new Lookup.Template(AnnotationProvider.class));
105
        Collection all = result.allInstances();
109
        Collection all = result.allInstances();
106
        for (Iterator it = all.iterator(); it.hasNext();) {
110
        for (Iterator it = all.iterator(); it.hasNext();) {
107
            AnnotationProvider ap = (AnnotationProvider) it.next();
111
            AnnotationProvider ap = (AnnotationProvider) it.next();
108
            InterceptionListener iil = ap.getInterceptionListener();
112
            InterceptionListener iil = ap.getInterceptionListener();
109
            if (iil instanceof ProvidedExtensions) {
113
            if (iil instanceof ProvidedExtensionsImpl) {
114
                ProvidedExtensionsImpl extension = (ProvidedExtensionsImpl)iil;
115
                if(ProvidedExtensionsAccessor.IMPL.providesCanWrite(extension) == providesCanWrite) {
110
                return (ProvidedExtensionsImpl)iil;
116
                return (ProvidedExtensionsImpl)iil;
111
            }
117
            }
112
        }
118
        }
119
        }
113
        return null;
120
        return null;
114
    }
121
    }
115
    
122
    
Lines 154-164 Link Here
154
        FileObject fo = FileUtil.toFileObject(getWorkDir());
161
        FileObject fo = FileUtil.toFileObject(getWorkDir());
155
        assertNotNull(fo);
162
        assertNotNull(fo);
156
        assertNotNull(iListener);
163
        assertNotNull(iListener);
164
        assertNotNull(iListenerNoCanWrite);
157
        int nCalls = iListener.implsCanWriteCalls;
165
        int nCalls = iListener.implsCanWriteCalls;
158
        FileObject toChange = fo.createData("cw");
166
        FileObject toChange = fo.createData("cw");
159
        assertNotNull(toChange);
167
        assertNotNull(toChange);
160
        boolean cw = toChange.canWrite();
168
        boolean cw = toChange.canWrite();
161
        assertEquals(nCalls + 1, iListener.implsCanWriteCalls);
169
        assertEquals(nCalls + 1, iListener.implsCanWriteCalls);
170
        assertEquals(0, iListenerNoCanWrite.implsCanWriteCalls);
162
    }
171
    }
163
    
172
    
164
    public void testImplsMove() throws IOException {
173
    public void testImplsMove() throws IOException {
Lines 570-577 Link Here
570
    }
579
    }
571
580
572
    
581
    
582
    public static class AnnotationProviderImplNoCanWrite extends InterceptionListenerTest.AnnotationProviderImpl  {
583
        private ProvidedExtensionsImpl impl = new ProvidedExtensionsImpl(this, false);
584
        public InterceptionListener getInterceptionListener() {
585
            return impl;
586
        }
587
    }
588
    
573
    public static class AnnotationProviderImpl extends InterceptionListenerTest.AnnotationProviderImpl  {
589
    public static class AnnotationProviderImpl extends InterceptionListenerTest.AnnotationProviderImpl  {
574
        private ProvidedExtensionsImpl impl = new ProvidedExtensionsImpl(this);
590
        private ProvidedExtensionsImpl impl = new ProvidedExtensionsImpl(this, true);
575
        public InterceptionListener getInterceptionListener() {
591
        public InterceptionListener getInterceptionListener() {
576
            return impl;
592
            return impl;
577
        }
593
        }
Lines 608-620 Link Here
608
        private static int cnt;
624
        private static int cnt;
609
        
625
        
610
        public static FileLock lock;
626
        public static FileLock lock;
611
        private final AnnotationProviderImpl provider;
627
        private final AnnotationProvider provider;
612
628
613
        public ProvidedExtensionsImpl() {
629
        public ProvidedExtensionsImpl() {
614
            this(null);
630
            this(null, false);
615
        }
631
        }
616
632
617
        public ProvidedExtensionsImpl(AnnotationProviderImpl p) {
633
        public ProvidedExtensionsImpl(AnnotationProvider p, boolean provideCanWrite) {
634
            super(provideCanWrite);
618
            this.provider = p;
635
            this.provider = p;
619
            cnt++;
636
            cnt++;
620
        }
637
        }

Return to bug 194683