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

(-)apichanges.xml (+19 lines)
Lines 108-113 Link Here
108
        
108
        
109
        <change>
109
        <change>
110
            <api name="versioning_spi"/>
110
            <api name="versioning_spi"/>
111
            <summary>Added getVisibilityQueryImplementation() method to VersioningSystem</summary>
112
            <version major="1" minor="10"/>
113
            <date day="8" month="12" year="2009"/>
114
            <author login="tstupka"/>
115
            <compatibility addition="yes"/>
116
            <description>
117
                Some Versioning systems provide a VisibilityQueryImplementation. This API change has two purposes:
118
                1. There will be only one registered VQI (Versioning manager) that will delegate the query to the appropriate
119
                versioning system which will speed things up.
120
                2. It makes it clear and explicit that implementors of a VersioningSystem might want to provide the query.
121
                It would be possible for them to just implement and register their own VisibilityQueryImplementation but
122
                they could easily forget to do that.
123
            </description>
124
            <class package="org.netbeans.modules.versioning.spi" name="VersioningSystem"/>
125
            <issue number="146634"/>
126
        </change>
127
128
        <change>
129
            <api name="versioning_spi"/>
111
            <summary>Added getCollocationQueryImplementation() method to VersioningSystem</summary>
130
            <summary>Added getCollocationQueryImplementation() method to VersioningSystem</summary>
112
            <version major="1" minor="9"/>
131
            <version major="1" minor="9"/>
113
            <date day="12" month="5" year="2009"/>
132
            <date day="12" month="5" year="2009"/>
(-)src/org/netbeans/modules/versioning/VcsVisibilityQueryImplementation.java (+114 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.versioning;
42
43
import javax.swing.event.ChangeListener;
44
import org.netbeans.modules.versioning.spi.VersioningSystem;
45
46
import java.io.File;
47
import java.util.ArrayList;
48
import java.util.List;
49
import javax.swing.event.ChangeEvent;
50
import org.netbeans.modules.versioning.spi.VCSVisibilityQuery;
51
import org.netbeans.spi.queries.VisibilityQueryImplementation2;
52
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
54
55
/**
56
 * Delegates the work to the owner of files in query.
57
 * 
58
 * @author Tomas Stupka
59
 */
60
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.VisibilityQueryImplementation.class)
61
public class VcsVisibilityQueryImplementation implements VisibilityQueryImplementation2 {
62
63
    private List<ChangeListener> listeners = new ArrayList<ChangeListener>();
64
    private static VcsVisibilityQueryImplementation instance;
65
66
    public VcsVisibilityQueryImplementation() {
67
        instance = this;
68
    }
69
70
    public static VcsVisibilityQueryImplementation getInstance() {
71
        return instance;
72
    }
73
74
    public boolean isVisible(File file) {
75
        VersioningSystem system = VersioningManager.getInstance().getOwner(file);
76
        if(system == null) {
77
            return true;
78
        }
79
        VCSVisibilityQuery vqi = system.getVisibilityQuery();
80
        return vqi == null ? true : vqi.isVisible(file);
81
    }
82
83
    public boolean isVisible(FileObject fileObject) {
84
        File file = FileUtil.toFile(fileObject);
85
        if(file == null) {
86
            return true;
87
        }
88
        return isVisible(file);
89
    }
90
91
    public synchronized void addChangeListener(ChangeListener l) {
92
        ArrayList<ChangeListener> newList = new ArrayList<ChangeListener>(listeners);
93
        newList.add(l);
94
        listeners = newList;
95
    }
96
97
    public synchronized void removeChangeListener(ChangeListener l) {
98
        ArrayList<ChangeListener> newList = new ArrayList<ChangeListener>(listeners);
99
        newList.remove(l);
100
        listeners = newList;
101
    }
102
103
    public void fireVisibilityChanged() {
104
        ChangeListener[] ls;
105
        synchronized(this) {
106
            ls = listeners.toArray(new ChangeListener[listeners.size()]);
107
        }
108
        ChangeEvent event = new ChangeEvent(this);
109
        for (ChangeListener l : ls) {
110
            l.stateChanged(event);
111
        }
112
    }
113
114
}
(-)src/org/netbeans/modules/versioning/spi/VCSVisibilityQuery.java (+73 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.versioning.spi;
42
43
44
import java.io.File;
45
import org.netbeans.modules.versioning.VcsVisibilityQueryImplementation;
46
import org.netbeans.spi.queries.VisibilityQueryImplementation2;
47
48
/**
49
 * Provides the visibility servis according to {@link VisibilityQueryImplementation2}
50
 * for a particular VersioningSystem
51
 * 
52
 * @author Tomas Stupka
53
 */
54
public abstract class VCSVisibilityQuery {
55
56
    /**
57
     * Check whether a file is recommended to be visible.
58
     * @param file a file to considered
59
     * @return true if it is recommended to display this file
60
     */
61
    public abstract boolean isVisible(File file);
62
63
    /**
64
     * Notify a visibility change
65
     */
66
    protected final void fireVisibilityChanged() {
67
        VcsVisibilityQueryImplementation vq = VcsVisibilityQueryImplementation.getInstance();
68
        if(vq != null) {
69
            // was touched from outside - lets fire the change
70
            vq.fireVisibilityChanged();
71
        }
72
    }
73
}
(-)src/org/netbeans/modules/versioning/spi/VersioningSystem.java (+11 lines)
Lines 47-52 Link Here
47
import java.beans.PropertyChangeListener;
47
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeSupport;
48
import java.beans.PropertyChangeSupport;
49
import java.util.*;
49
import java.util.*;
50
import org.netbeans.spi.queries.VisibilityQueryImplementation2;
50
51
51
/**
52
/**
52
 * Base class for a versioning system that integrates into IDE.
53
 * Base class for a versioning system that integrates into IDE.
Lines 180-185 Link Here
180
    }    
181
    }    
181
182
182
    /**
183
    /**
184
     * Retrieves a VCSVisibilityQuery implementation if this versioning system provides one.
185
     *
186
     * @return VCSVisibilityQuery a VCSVisibilityQuery instance or null if the system does not provide the service
187
     * @since 1.10
188
     */
189
    public VCSVisibilityQuery getVisibilityQuery() {
190
        return null;
191
    }
192
193
    /**
183
     * Adds a listener for change events.
194
     * Adds a listener for change events.
184
     * 
195
     * 
185
     * @param listener a PropertyChangeListener 
196
     * @param listener a PropertyChangeListener 
(-)test/unit/src/org/netbeans/modules/versioning/spi/VCSVisibilityQueryTest.java (+87 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.versioning.spi;
42
43
import java.io.IOException;
44
import org.openide.filesystems.FileUtil;
45
import org.openide.filesystems.FileStateInvalidException;
46
import org.openide.filesystems.FileObject;
47
48
import java.io.File;
49
import org.netbeans.api.queries.VisibilityQuery;
50
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.modules.versioning.spi.testvcs.TestVCS;
52
import org.netbeans.modules.versioning.spi.testvcs.TestVCSVisibilityQuery;
53
54
/**
55
 * Versioning SPI unit tests of VCSVisibilityQuery.
56
 * 
57
 * @author Tomas Stupka
58
 */
59
public class VCSVisibilityQueryTest extends NbTestCase {
60
    
61
62
    public VCSVisibilityQueryTest(String testName) {
63
        super(testName);
64
    }
65
66
    protected void setUp() throws Exception {
67
        System.setProperty("netbeans.user", System.getProperty("data.root.dir") + "/userdir");
68
        super.setUp();
69
    }
70
71
    public void testVQ() throws FileStateInvalidException, IOException {
72
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
73
        folder.mkdirs();
74
        
75
        File visible = new File(folder, "this-file-is-visible");
76
        visible.createNewFile();
77
        FileObject visibleFO = FileUtil.toFileObject(visible);
78
        assertTrue(VisibilityQuery.getDefault().isVisible(visible));
79
        assertTrue(VisibilityQuery.getDefault().isVisible(visibleFO));
80
81
        File invisible = new File(folder, "this-file-is-" + TestVCSVisibilityQuery.INVISIBLE_FILE_SUFFIX);
82
        invisible.createNewFile();
83
        FileObject invisibleFO = FileUtil.toFileObject(invisible);
84
        assertFalse(VisibilityQuery.getDefault().isVisible(invisible));
85
        assertFalse(VisibilityQuery.getDefault().isVisible(invisibleFO));
86
    }
87
}
(-)test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java (-1 / +12 lines)
Lines 45-50 Link Here
45
import org.netbeans.modules.versioning.spi.VCSAnnotator;
45
import org.netbeans.modules.versioning.spi.VCSAnnotator;
46
46
47
import java.io.File;
47
import java.io.File;
48
import org.netbeans.modules.versioning.spi.VCSVisibilityQuery;
48
49
49
/**
50
/**
50
 * Test versioning system.
51
 * Test versioning system.
Lines 57-63 Link Here
57
    private static TestVCS instance;
58
    private static TestVCS instance;
58
    private VCSInterceptor interceptor;
59
    private VCSInterceptor interceptor;
59
    private VCSAnnotator annotator;
60
    private VCSAnnotator annotator;
61
    private VCSVisibilityQuery vq;
60
62
63
    public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned";
64
61
    public static TestVCS getInstance() {
65
    public static TestVCS getInstance() {
62
        return instance;
66
        return instance;
63
    }
67
    }
Lines 66-77 Link Here
66
        instance = this;
70
        instance = this;
67
        interceptor = new TestVCSInterceptor();
71
        interceptor = new TestVCSInterceptor();
68
        annotator = new TestVCSAnnotator();
72
        annotator = new TestVCSAnnotator();
73
        vq = new TestVCSVisibilityQuery();
69
    }
74
    }
70
75
71
    public File getTopmostManagedAncestor(File file) {
76
    public File getTopmostManagedAncestor(File file) {
72
        File topmost = null;
77
        File topmost = null;
73
        for (; file != null; file = file.getParentFile()) {
78
        for (; file != null; file = file.getParentFile()) {
74
            if (file.getName().endsWith("-test-versioned")) {
79
            if (file.getName().endsWith(VERSIONED_FOLDER_SUFFIX)) {
75
                topmost = file;
80
                topmost = file;
76
            }
81
            }
77
        }
82
        }
Lines 85-88 Link Here
85
    public VCSAnnotator getVCSAnnotator() {
90
    public VCSAnnotator getVCSAnnotator() {
86
        return annotator;
91
        return annotator;
87
    }
92
    }
93
94
    @Override
95
    public VCSVisibilityQuery getVisibilityQuery() {
96
        return vq;
88
}
97
}
98
99
}
(-)test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSVisibilityQuery.java (+58 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.versioning.spi.testvcs;
41
42
import java.io.File;
43
import org.netbeans.modules.versioning.spi.VCSVisibilityQuery;
44
45
/**
46
 *
47
 * @author Tomas Stupka
48
 */
49
public class TestVCSVisibilityQuery extends VCSVisibilityQuery {
50
51
    public static final String INVISIBLE_FILE_SUFFIX = "invisible";
52
53
    @Override
54
    public boolean isVisible(File file) {
55
        return !file.getName().endsWith(INVISIBLE_FILE_SUFFIX);
56
    }
57
58
}

Return to bug 146634