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

(-)versioning.core/src/org/netbeans/modules/versioning/core/DelegatingVCS.java (-2 / +2 lines)
Lines 60-66 Link Here
60
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
60
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
61
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
61
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
62
import org.netbeans.modules.versioning.core.api.VersioningSupport;
62
import org.netbeans.modules.versioning.core.api.VersioningSupport;
63
import org.netbeans.spi.queries.CollocationQueryImplementation;
63
import org.netbeans.spi.queries.CollocationQueryImplementation2;
64
import org.openide.util.ContextAwareAction;
64
import org.openide.util.ContextAwareAction;
65
import org.openide.util.Utilities;
65
import org.openide.util.Utilities;
66
import org.openide.util.lookup.Lookups;
66
import org.openide.util.lookup.Lookups;
Lines 137-143 Link Here
137
    }
137
    }
138
138
139
    @Override
139
    @Override
140
    public CollocationQueryImplementation getCollocationQueryImplementation() {
140
    public CollocationQueryImplementation2 getCollocationQueryImplementation() {
141
        return getDelegate().getCollocationQueryImplementation();
141
        return getDelegate().getCollocationQueryImplementation();
142
    }
142
    }
143
143
(-)versioning.core/src/org/netbeans/modules/versioning/core/VcsCollocationQueryImplementation.java (-13 / +59 lines)
Lines 43-74 Link Here
43
 */
43
 */
44
package org.netbeans.modules.versioning.core;
44
package org.netbeans.modules.versioning.core;
45
45
46
import org.netbeans.spi.queries.CollocationQueryImplementation;
46
import java.net.MalformedURLException;
47
import org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem;
47
import org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem;
48
48
49
import java.io.File;
49
import java.net.URI;
50
import java.net.URISyntaxException;
51
import java.util.logging.Level;
50
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
52
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
53
import org.netbeans.spi.queries.CollocationQueryImplementation2;
54
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.URLMapper;
51
56
52
/**
57
/**
53
 * Delegates the work to the owner of files in query.
58
 * Delegates the work to the owner of files in query.
54
 * 
59
 * 
55
 * @author Maros Sandor
60
 * @author Maros Sandor
61
 * @author Tomas Stupka
56
 */
62
 */
57
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.CollocationQueryImplementation.class, position=50)
63
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.CollocationQueryImplementation2.class, position=50)
58
public class VcsCollocationQueryImplementation implements CollocationQueryImplementation {
64
public class VcsCollocationQueryImplementation implements CollocationQueryImplementation2 {
59
65
60
    public boolean areCollocated(File a, File b) {
66
    @Override
61
        VersioningSystem vsa = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(a));
67
    public boolean areCollocated(URI file1, URI file2) {
62
        VersioningSystem vsb = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(b));
68
        VCSFileProxy proxy1 = toFileProxy(file1);
69
        VCSFileProxy proxy2 = toFileProxy(file2);
70
        
71
        if(proxy1 == null || proxy2 == null) return false;
72
        VersioningSystem vsa = VersioningManager.getInstance().getOwner(proxy1);
73
        VersioningSystem vsb = VersioningManager.getInstance().getOwner(proxy2);
63
        if (vsa == null || vsa != vsb) return false;
74
        if (vsa == null || vsa != vsb) return false;
64
        
75
        
65
        CollocationQueryImplementation cqi = vsa.getCollocationQueryImplementation();
76
        CollocationQueryImplementation2 cqi = vsa.getCollocationQueryImplementation();
66
        return cqi != null && cqi.areCollocated(a, b);
77
        return cqi != null && cqi.areCollocated(file1, file2);
67
    }
78
    }
68
79
69
    public File findRoot(File file) {
80
    @Override
70
        VersioningSystem system = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(file));
81
    public URI findRoot(URI file) {
71
        CollocationQueryImplementation cqi = system.getCollocationQueryImplementation();
82
        VCSFileProxy proxy = toFileProxy(file);
72
        return cqi == null ? null : cqi.findRoot(file);
83
        if(proxy != null) {
84
            VersioningSystem system = VersioningManager.getInstance().getOwner(proxy);
85
            CollocationQueryImplementation2 cqi = system != null ? system.getCollocationQueryImplementation() : null;
86
            return cqi != null ? cqi.findRoot(file) : null;
73
    }
87
    }
88
        return null;
74
}
89
}
90
    
91
    private static VCSFileProxy toFileProxy(URI uri) {
92
        FileObject fo = getFileObject(uri);
93
        return fo != null ? VCSFileProxy.createFileProxy(fo) : null;
94
    }        
95
    
96
    private static FileObject getFileObject(URI uri) {
97
        FileObject fo = null;
98
        try {
99
            fo = URLMapper.findFileObject(uri.toURL());
100
        } catch (MalformedURLException ex) {
101
            VersioningManager.LOG.log(Level.WARNING, uri != null ? uri.toString() : null, ex);
102
        }
103
        if(fo == null) {
104
            // file doesn't exists? use parent for the query then.
105
            // By the means of VCS it has to be collocated in the same way.
106
            String path = uri.getPath();
107
            URI parent;
108
            try {
109
                parent = new URI(path.endsWith("/") ? path : path + "/").resolve(".."); // NOI18N
110
                path = parent.getPath();
111
                uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment());
112
            } catch (URISyntaxException ex) {
113
                VersioningManager.LOG.log(Level.WARNING, path, ex);
114
                return null;
115
            }
116
            fo = getFileObject(uri);
117
        }
118
        return fo;
119
    }
120
}
(-)versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java (-2 / +2 lines)
Lines 69-75 Link Here
69
import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationEvent;
69
import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationEvent;
70
import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationListener;
70
import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationListener;
71
import org.netbeans.modules.versioning.core.util.VCSSystemProvider;
71
import org.netbeans.modules.versioning.core.util.VCSSystemProvider;
72
import org.netbeans.spi.queries.CollocationQueryImplementation;
72
import org.netbeans.spi.queries.CollocationQueryImplementation2;
73
import org.openide.util.*;
73
import org.openide.util.*;
74
import org.openide.util.Lookup.Result;
74
import org.openide.util.Lookup.Result;
75
75
Lines 191-197 Link Here
191
        @Override public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) { throw new IllegalStateException(); }
191
        @Override public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) { throw new IllegalStateException(); }
192
        @Override public VCSInterceptor getInterceptor() { throw new IllegalStateException(); }
192
        @Override public VCSInterceptor getInterceptor() { throw new IllegalStateException(); }
193
        @Override public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { throw new IllegalStateException(); }
193
        @Override public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { throw new IllegalStateException(); }
194
        @Override public CollocationQueryImplementation getCollocationQueryImplementation() { throw new IllegalStateException(); }
194
        @Override public CollocationQueryImplementation2 getCollocationQueryImplementation() { throw new IllegalStateException(); }
195
        @Override public void addPropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); }
195
        @Override public void addPropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); }
196
        @Override public void removePropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); }
196
        @Override public void removePropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); }
197
        @Override public boolean isExcluded(VCSFileProxy file) { throw new IllegalStateException(); }
197
        @Override public boolean isExcluded(VCSFileProxy file) { throw new IllegalStateException(); }
(-)versioning.core/src/org/netbeans/modules/versioning/core/spi/VersioningSystem.java (-2 / +2 lines)
Lines 44-50 Link Here
44
package org.netbeans.modules.versioning.core.spi;
44
package org.netbeans.modules.versioning.core.spi;
45
45
46
import org.netbeans.modules.versioning.core.VersioningManager;
46
import org.netbeans.modules.versioning.core.VersioningManager;
47
import org.netbeans.spi.queries.CollocationQueryImplementation;
48
47
49
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeSupport;
49
import java.beans.PropertyChangeSupport;
Lines 54-59 Link Here
54
import java.lang.annotation.Target;
53
import java.lang.annotation.Target;
55
import java.util.*;
54
import java.util.*;
56
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
55
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
56
import org.netbeans.spi.queries.CollocationQueryImplementation2;
57
import org.openide.awt.ActionID;
57
import org.openide.awt.ActionID;
58
import org.openide.awt.ActionReference;
58
import org.openide.awt.ActionReference;
59
import org.openide.awt.ActionRegistration;
59
import org.openide.awt.ActionRegistration;
Lines 130-136 Link Here
130
     * 
130
     * 
131
     * @return CollocationQueryImplementation a CollocationQueryImplementation instance or null if the system does not provide the service
131
     * @return CollocationQueryImplementation a CollocationQueryImplementation instance or null if the system does not provide the service
132
     */
132
     */
133
    public CollocationQueryImplementation getCollocationQueryImplementation() {
133
    public CollocationQueryImplementation2 getCollocationQueryImplementation() {
134
        return null;
134
        return null;
135
    }    
135
    }    
136
136
(-)versioning.core/src/org/netbeans/modules/versioning/core/util/VCSSystemProvider.java (-2 / +2 lines)
Lines 49-55 Link Here
49
import org.netbeans.modules.versioning.core.spi.VCSContext;
49
import org.netbeans.modules.versioning.core.spi.VCSContext;
50
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
50
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
51
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
51
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
52
import org.netbeans.spi.queries.CollocationQueryImplementation;
52
import org.netbeans.spi.queries.CollocationQueryImplementation2;
53
53
54
/**
54
/**
55
 * Warning: VCS internal use only. Not to be implemented by clients.
55
 * Warning: VCS internal use only. Not to be implemented by clients.
Lines 103-109 Link Here
103
103
104
        public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile);
104
        public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile);
105
105
106
        public CollocationQueryImplementation getCollocationQueryImplementation();
106
        public CollocationQueryImplementation2 getCollocationQueryImplementation();
107
107
108
        public VCSVisibilityQuery getVisibility();
108
        public VCSVisibilityQuery getVisibility();
109
109
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/core/ConnectDisconnectTest.java (-2 / +2 lines)
Lines 54-60 Link Here
54
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
54
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
55
import org.netbeans.modules.versioning.core.api.VersioningSupport;
55
import org.netbeans.modules.versioning.core.api.VersioningSupport;
56
import org.netbeans.modules.versioning.core.spi.VCSContext;
56
import org.netbeans.modules.versioning.core.spi.VCSContext;
57
import org.netbeans.spi.queries.CollocationQueryImplementation;
57
import org.netbeans.spi.queries.CollocationQueryImplementation2;
58
import org.openide.util.NbPreferences;
58
import org.openide.util.NbPreferences;
59
import org.openide.util.test.MockLookup;
59
import org.openide.util.test.MockLookup;
60
60
Lines 269-275 Link Here
269
        public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { }
269
        public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { }
270
270
271
        @Override
271
        @Override
272
        public CollocationQueryImplementation getCollocationQueryImplementation() {
272
        public CollocationQueryImplementation2 getCollocationQueryImplementation() {
273
            return null;
273
            return null;
274
        }
274
        }
275
275
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/core/spi/VCSCollocationQueryTest.java (+159 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.versioning.core.spi;
45
46
import java.io.IOException;
47
import org.openide.filesystems.FileStateInvalidException;
48
49
import java.io.File;
50
import org.netbeans.api.queries.CollocationQuery;
51
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.modules.versioning.spi.testvcs.TestVCS;
53
import org.netbeans.modules.versioning.spi.testvcs.TestVCSCollocationQuery;
54
import org.openide.util.test.MockLookup;
55
56
/**
57
 * Versioning SPI unit tests of VCSVisibilityQuery.
58
 * 
59
 * @author Tomas Stupka
60
 */
61
public class VCSCollocationQueryTest extends NbTestCase {
62
    
63
64
    public VCSCollocationQueryTest(String testName) {
65
        super(testName);
66
        MockLookup.setLayersAndInstances();
67
    }
68
69
    protected void setUp() throws Exception {
70
        MockLookup.setLayersAndInstances();
71
        File userdir = new File(getWorkDir() + "userdir");
72
        userdir.mkdirs();
73
        System.setProperty("netbeans.user", userdir.getAbsolutePath());
74
        super.setUp();
75
    }
76
77
    public void testFindRootExisting() throws FileStateInvalidException, IOException, Exception {
78
        File folder = createVersionedFolder();
79
        folder.mkdirs();
80
        File file = new File(folder, "somefile");
81
        file.createNewFile();
82
        
83
        assertRoot(folder, file);
84
    }
85
86
    public void testFindRootNotExisting() throws FileStateInvalidException, IOException, Exception {
87
        File folder = createVersionedFolder();
88
        File file = new File(folder, "dontexist");
89
        assertRoot(folder, file);
90
    }
91
    
92
    public void testFindRootBogusFile() throws FileStateInvalidException, IOException, Exception {
93
        assertNull(CollocationQuery.findRoot(new File("/a/b/c").toURI()));
94
    }
95
    
96
    private void assertRoot(File root, File file) {
97
        assertEquals(root.toURI(), CollocationQuery.findRoot(file.toURI()));
98
    }
99
    
100
    public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
101
        File folder = createVersionedFolder();
102
103
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
104
        file1.createNewFile();
105
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
106
        file2.createNewFile();
107
        
108
        assertCollocated(true, file1, file2);
109
    }
110
    
111
    public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
112
        File folder = createVersionedFolder();
113
114
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
115
        file1.createNewFile();
116
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
117
        file2.createNewFile();
118
        
119
        assertCollocated(true, file1, file2);
120
    }
121
    
122
    
123
    public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
124
        File folder = createVersionedFolder();
125
126
        File file1 = new File(folder, "file1");
127
        file1.createNewFile();
128
        File file2 = new File(folder, "file2");
129
        file2.createNewFile();
130
        
131
        assertCollocated(false, file1, file2);
132
    }
133
    
134
    public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
135
        File folder = createVersionedFolder();
136
137
        File file1 = new File(folder, "file1");
138
        file1.createNewFile();
139
        File file2 = new File(folder, "file2");
140
        file2.createNewFile();
141
        
142
        assertCollocated(false, file1, file2);
143
    }
144
    
145
    void assertCollocated(boolean expected, File file1, File file2) {
146
        if(expected) {
147
            assertTrue(CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
148
        } else {
149
            assertFalse(CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
150
        }
151
    }
152
153
    private File createVersionedFolder() throws IOException {
154
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
155
        new File(folder, TestVCS.TEST_VCS_METADATA).mkdirs();
156
        return folder;
157
    }
158
    
159
}
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java (+9 lines)
Lines 46-56 Link Here
46
46
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
48
import java.awt.event.ActionListener;
49
import org.netbeans.modules.versioning.core.VcsCollocationQueryImplementation;
49
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
50
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
50
import org.netbeans.modules.versioning.core.spi.VCSAnnotator;
51
import org.netbeans.modules.versioning.core.spi.VCSAnnotator;
51
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
52
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
52
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
53
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
53
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
54
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
55
import org.netbeans.spi.queries.CollocationQueryImplementation2;
54
import org.openide.awt.ActionID;
56
import org.openide.awt.ActionID;
55
import org.openide.awt.ActionReference;
57
import org.openide.awt.ActionReference;
56
import org.openide.awt.ActionReferences;
58
import org.openide.awt.ActionReferences;
Lines 79-84 Link Here
79
    private VCSInterceptor interceptor;
81
    private VCSInterceptor interceptor;
80
    private VCSAnnotator annotator;
82
    private VCSAnnotator annotator;
81
    private VCSVisibilityQuery vq;
83
    private VCSVisibilityQuery vq;
84
    private TestVCSCollocationQuery vcq;
82
85
83
    public static final String TEST_VCS_METADATA = ".testvcs";
86
    public static final String TEST_VCS_METADATA = ".testvcs";
84
    public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned";
87
    public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned";
Lines 96-101 Link Here
96
        interceptor = new TestVCSInterceptor();
99
        interceptor = new TestVCSInterceptor();
97
        annotator = new TestVCSAnnotator();
100
        annotator = new TestVCSAnnotator();
98
        vq = new TestVCSVisibilityQuery();
101
        vq = new TestVCSVisibilityQuery();
102
        vcq = new TestVCSCollocationQuery();
99
    }
103
    }
100
104
101
    public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) {
105
    public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) {
Lines 121-126 Link Here
121
        return vq;
125
        return vq;
122
    }
126
    }
123
127
128
    @Override
129
    public CollocationQueryImplementation2 getCollocationQueryImplementation() {
130
        return vcq;
131
    }
132
124
    public void fire() {
133
    public void fire() {
125
        VCSFileProxy file = null;
134
        VCSFileProxy file = null;
126
        super.fireStatusChanged(file);
135
        super.fireStatusChanged(file);
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java (+79 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.versioning.spi.testvcs;
43
44
import java.io.File;
45
import java.net.URI;
46
import org.netbeans.spi.queries.CollocationQueryImplementation2;
47
48
/**
49
 *
50
 * @author tomas
51
 */
52
public class TestVCSCollocationQuery implements CollocationQueryImplementation2 {
53
54
    public static String COLLOCATED_FILENAME_SUFFIX = "_iscollocated";
55
    @Override
56
    public boolean areCollocated(URI file1, URI file2) {
57
        String name1 = file1.getPath();
58
        String name2 = file2.getPath();
59
        
60
        return name1.endsWith(COLLOCATED_FILENAME_SUFFIX) && name2.endsWith(COLLOCATED_FILENAME_SUFFIX);
61
    }
62
63
    @Override
64
    public URI findRoot(URI uri) {
65
        File root = getRoot(new File(uri));
66
        return root != null ? root.toURI() : null;
67
    }
68
    
69
    private File getRoot(File file) {
70
        File topmost = null;
71
        for (; file != null; file = file.getParentFile()) {
72
            if (file.getName().endsWith(TestVCS.VERSIONED_FOLDER_SUFFIX)) {
73
                topmost = file;
74
            }
75
        }
76
        return topmost;
77
    }
78
    
79
}
(-)versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java (-2 / +19 lines)
Lines 47-52 Link Here
47
import java.beans.PropertyChangeSupport;
47
import java.beans.PropertyChangeSupport;
48
import java.io.File;
48
import java.io.File;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.net.URI;
50
import java.util.*;
51
import java.util.*;
51
import java.util.logging.Level;
52
import java.util.logging.Level;
52
import java.util.logging.Logger;
53
import java.util.logging.Logger;
Lines 59-64 Link Here
59
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
60
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
60
import org.netbeans.modules.versioning.spi.VersioningSupport;
61
import org.netbeans.modules.versioning.spi.VersioningSupport;
61
import org.netbeans.spi.queries.CollocationQueryImplementation;
62
import org.netbeans.spi.queries.CollocationQueryImplementation;
63
import org.netbeans.spi.queries.CollocationQueryImplementation2;
62
import org.openide.util.ContextAwareAction;
64
import org.openide.util.ContextAwareAction;
63
import org.openide.util.Utilities;
65
import org.openide.util.Utilities;
64
import org.openide.util.lookup.Lookups;
66
import org.openide.util.lookup.Lookups;
Lines 87-92 Link Here
87
    private VCSAnnotator annotator;
89
    private VCSAnnotator annotator;
88
    private VCSVisibilityQuery visibilityQuery;
90
    private VCSVisibilityQuery visibilityQuery;
89
    private VCSInterceptor interceptor;
91
    private VCSInterceptor interceptor;
92
    private CollocationQueryImplementation2 collocationQuery;
90
    
93
    
91
    private DelegatingVCS(Map<?, ?> map) {
94
    private DelegatingVCS(Map<?, ?> map) {
92
        this.map = map;
95
        this.map = map;
Lines 146-154 Link Here
146
    }
149
    }
147
150
148
    @Override
151
    @Override
149
    public CollocationQueryImplementation getCollocationQueryImplementation() {
152
    public CollocationQueryImplementation2 getCollocationQueryImplementation() {
150
        return getDelegate().getCollocationQueryImplementation();
153
        if(collocationQuery == null) {
154
            collocationQuery = new CollocationQueryImplementation2() {
155
                private CollocationQueryImplementation cqi = getDelegate().getCollocationQueryImplementation();
156
                @Override
157
                public boolean areCollocated(URI uri1, URI uri2) {
158
                    return cqi != null && cqi.areCollocated(new File(uri1), new File(uri2));
151
    }
159
    }
160
                @Override
161
                public URI findRoot(URI uri) {
162
                    File file = cqi != null ? cqi.findRoot(new File(uri)) : null;
163
                    return file != null ? file.toURI() : null;
164
                }
165
            };
166
        } 
167
        return collocationQuery;        
168
    }
152
169
153
    @Override
170
    @Override
154
    public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy proxy) {
171
    public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy proxy) {
(-)versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSCollocationQueryTest.java (+158 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.versioning.spi;
45
46
import java.io.IOException;
47
import org.openide.filesystems.FileStateInvalidException;
48
49
import java.io.File;
50
import org.netbeans.api.queries.CollocationQuery;
51
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.modules.versioning.spi.testvcs.TestVCS;
53
import org.netbeans.modules.versioning.spi.testvcs.TestVCSCollocationQuery;
54
import org.openide.util.test.MockLookup;
55
56
/**
57
 * Versioning SPI unit tests of VCSVisibilityQuery.
58
 * 
59
 * @author Tomas Stupka
60
 */
61
public class VCSCollocationQueryTest extends NbTestCase {
62
    
63
64
    public VCSCollocationQueryTest(String testName) {
65
        super(testName);
66
    }
67
68
    protected void setUp() throws Exception {
69
        MockLookup.setLayersAndInstances();
70
        File userdir = new File(getWorkDir() + "userdir");
71
        userdir.mkdirs();
72
        System.setProperty("netbeans.user", userdir.getAbsolutePath());
73
        super.setUp();
74
    }
75
76
    public void testFindRootExisting() throws FileStateInvalidException, IOException, Exception {
77
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
78
        folder.mkdirs();
79
        File file = new File(folder, "somefile");
80
        file.createNewFile();
81
        
82
        assertRoot(folder, file);
83
    }
84
    
85
    public void testFindRootNotExisting() throws FileStateInvalidException, IOException, Exception {
86
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
87
        folder.mkdirs();
88
        File file = new File(folder, "somefile");
89
        assertRoot(folder, file);
90
    }
91
    
92
    public void testFindRootBogusFile() throws FileStateInvalidException, IOException, Exception {
93
        assertNull(CollocationQuery.findRoot(new File("/a/b/c")));
94
    }
95
    
96
    private void assertRoot(File root, File file) {
97
        assertEquals(root, CollocationQuery.findRoot(file));
98
    }
99
    
100
    public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
101
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
102
        folder.mkdirs();
103
104
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
105
        file1.createNewFile();
106
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
107
        file2.createNewFile();
108
        
109
        assertCollocated(true, file1, file2);
110
    }
111
    
112
    public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
113
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
114
        folder.mkdirs();
115
116
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
117
        file1.createNewFile();
118
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
119
        file2.createNewFile();
120
        
121
        assertCollocated(true, file1, file2);
122
    }
123
    
124
    
125
    public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
126
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
127
        folder.mkdirs();
128
129
        File file1 = new File(folder, "file1");
130
        file1.createNewFile();
131
        File file2 = new File(folder, "file2");
132
        file2.createNewFile();
133
        
134
        assertCollocated(false, file1, file2);
135
    }
136
    
137
    public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
138
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
139
        folder.mkdirs();
140
141
        File file1 = new File(folder, "file1");
142
        file1.createNewFile();
143
        File file2 = new File(folder, "file2");
144
        file2.createNewFile();
145
        
146
        assertCollocated(false, file1, file2);
147
    }
148
    
149
    void assertCollocated(boolean expected, File file1, File file2) {
150
        if(expected) {
151
            assertTrue(CollocationQuery.areCollocated(file1, file2));
152
        } else {
153
            assertFalse(CollocationQuery.areCollocated(file1, file2));
154
        }
155
    }
156
    
157
    
158
}
(-)versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java (+9 lines)
Lines 49-54 Link Here
49
49
50
import java.io.File;
50
import java.io.File;
51
import org.netbeans.modules.versioning.spi.VCSVisibilityQuery;
51
import org.netbeans.modules.versioning.spi.VCSVisibilityQuery;
52
import org.netbeans.spi.queries.CollocationQueryImplementation;
52
53
53
/**
54
/**
54
 * Test versioning system.
55
 * Test versioning system.
Lines 62-67 Link Here
62
    private VCSInterceptor interceptor;
63
    private VCSInterceptor interceptor;
63
    private VCSAnnotator annotator;
64
    private VCSAnnotator annotator;
64
    private VCSVisibilityQuery vq;
65
    private VCSVisibilityQuery vq;
66
    private TestVCSCollocationQuery vcq;
65
67
66
    public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned";
68
    public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned";
67
69
Lines 74-79 Link Here
74
        interceptor = new TestVCSInterceptor();
76
        interceptor = new TestVCSInterceptor();
75
        annotator = new TestVCSAnnotator();
77
        annotator = new TestVCSAnnotator();
76
        vq = new TestVCSVisibilityQuery();
78
        vq = new TestVCSVisibilityQuery();
79
        vcq = new TestVCSCollocationQuery();
77
    }
80
    }
78
81
79
    public File getTopmostManagedAncestor(File file) {
82
    public File getTopmostManagedAncestor(File file) {
Lines 99-102 Link Here
99
        return vq;
102
        return vq;
100
}
103
}
101
104
105
    @Override
106
    public CollocationQueryImplementation getCollocationQueryImplementation() {
107
        return vcq;
102
}
108
}
109
    
110
    
111
}
(-)versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java (+67 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.versioning.spi.testvcs;
43
44
import java.io.File;
45
import org.netbeans.spi.queries.CollocationQueryImplementation;
46
47
/**
48
 *
49
 * @author tomas
50
 */
51
public class TestVCSCollocationQuery implements CollocationQueryImplementation {
52
53
    public static String COLLOCATED_FILENAME_SUFFIX = "_iscollocated";
54
    @Override
55
    public boolean areCollocated(File file1, File file2) {
56
        String name1 = file1.getName();
57
        String name2 = file2.getName();
58
        
59
        return name1.endsWith(COLLOCATED_FILENAME_SUFFIX) && name2.endsWith(COLLOCATED_FILENAME_SUFFIX);
60
    }
61
62
    @Override
63
    public File findRoot(File file) {
64
        return TestVCS.getInstance().getTopmostManagedAncestor(file);
65
    }
66
    
67
}

Return to bug 207340