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/Utils.java (-9 / +13 lines)
Lines 43-66 Link Here
43
 */
43
 */
44
package org.netbeans.modules.versioning.core;
44
package org.netbeans.modules.versioning.core;
45
45
46
import org.netbeans.modules.versioning.core.util.VCSSystemProvider;
47
import org.openide.filesystems.FileStateInvalidException;
48
import org.openide.util.RequestProcessor;
46
import org.openide.util.RequestProcessor;
49
import org.openide.util.Lookup;
47
import org.openide.util.Lookup;
50
import org.openide.util.actions.Presenter;
48
import org.openide.util.actions.Presenter;
51
import org.openide.awt.Actions;
49
import org.openide.awt.Actions;
52
import org.openide.filesystems.FileUtil;
53
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
54
import org.openide.nodes.Node;
51
import org.openide.nodes.Node;
55
import org.netbeans.modules.versioning.core.spi.VCSContext;
52
import org.netbeans.modules.versioning.core.spi.VCSContext;
56
import org.netbeans.api.fileinfo.NonRecursiveFolder;
53
import org.netbeans.api.fileinfo.NonRecursiveFolder;
57
54
58
import javax.swing.*;
55
import javax.swing.*;
59
import javax.swing.text.Document;
60
import java.io.File;
56
import java.io.File;
61
import java.io.Reader;
57
import java.net.MalformedURLException;
62
import java.io.StringReader;
58
import java.net.URI;
63
import java.io.IOException;
64
import java.util.*;
59
import java.util.*;
65
import java.util.logging.Logger;
60
import java.util.logging.Logger;
66
import java.util.logging.Level;
61
import java.util.logging.Level;
Lines 68-75 Link Here
68
import java.util.prefs.Preferences;
63
import java.util.prefs.Preferences;
69
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
64
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
70
import org.netbeans.modules.versioning.core.api.VersioningSupport;
65
import org.netbeans.modules.versioning.core.api.VersioningSupport;
71
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
66
import org.openide.filesystems.*;
72
import org.openide.filesystems.FileSystem;
73
import org.openide.util.Utilities;
67
import org.openide.util.Utilities;
74
68
75
/**
69
/**
Lines 388-391 Link Here
388
            Logger.getLogger(Utils.class.getName()).log(Level.INFO, sb.toString());
382
            Logger.getLogger(Utils.class.getName()).log(Level.INFO, sb.toString());
389
        }
383
        }
390
    }
384
    }
385
    
386
    public static VCSFileProxy toFileProxy(URI uri) {
387
        FileObject fo = null;
388
        try {
389
            fo = URLMapper.findFileObject(uri.toURL());
390
        } catch (MalformedURLException ex) {
391
            VersioningManager.LOG.log(Level.WARNING, uri != null ? uri.toString() : null, ex);
391
}
392
}
393
        return fo != null ? VCSFileProxy.createFileProxy(fo) : null;
394
    }    
395
}
(-)versioning.core/src/org/netbeans/modules/versioning/core/VcsCollocationQueryImplementation.java (-8 / +50 lines)
Lines 47-74 Link Here
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.io.File;
50
import java.net.URI;
51
import java.net.URISyntaxException;
52
import java.util.logging.Level;
50
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
53
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
54
import org.netbeans.spi.queries.CollocationQueryImplementation2;
51
55
52
/**
56
/**
53
 * Delegates the work to the owner of files in query.
57
 * Delegates the work to the owner of files in query.
54
 * 
58
 * 
55
 * @author Maros Sandor
59
 * @author Maros Sandor
60
 * @author Tomas Stupka
56
 */
61
 */
57
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.CollocationQueryImplementation.class, position=50)
62
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.CollocationQueryImplementation.class, position=50)
58
public class VcsCollocationQueryImplementation implements CollocationQueryImplementation {
63
public class VcsCollocationQueryImplementation implements CollocationQueryImplementation, CollocationQueryImplementation2 {
59
64
65
    @Override
60
    public boolean areCollocated(File a, File b) {
66
    public boolean areCollocated(File a, File b) {
61
        VersioningSystem vsa = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(a));
67
        URI aUri = a.toURI();
62
        VersioningSystem vsb = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(b));
68
        URI bUri = b.toURI();
69
        return areCollocated(bUri, bUri);
70
    }
71
72
    @Override
73
    public File findRoot(File file) {
74
        URI uri = findRoot(file.toURI());
75
        return uri != null ? new File(uri) : null;
76
    }
77
78
    @Override
79
    public boolean areCollocated(URI file1, URI file2) {
80
        VCSFileProxy proxy1 = Utils.toFileProxy(file1);
81
        VCSFileProxy proxy2 = Utils.toFileProxy(file2);
82
        
83
        if(proxy1 == null || proxy2 == null) return false;
84
        VersioningSystem vsa = VersioningManager.getInstance().getOwner(proxy1);
85
        VersioningSystem vsb = VersioningManager.getInstance().getOwner(proxy2);
63
        if (vsa == null || vsa != vsb) return false;
86
        if (vsa == null || vsa != vsb) return false;
64
        
87
        
65
        CollocationQueryImplementation cqi = vsa.getCollocationQueryImplementation();
88
        CollocationQueryImplementation2 cqi = vsa.getCollocationQueryImplementation();
66
        return cqi != null && cqi.areCollocated(a, b);
89
        return cqi != null && cqi.areCollocated(file1, file2);
67
    }
90
    }
68
91
69
    public File findRoot(File file) {
92
    @Override
70
        VersioningSystem system = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(file));
93
    public URI findRoot(URI file) {
71
        CollocationQueryImplementation cqi = system.getCollocationQueryImplementation();
94
        VCSFileProxy proxy = Utils.toFileProxy(file);
95
        if(proxy != null) {
96
            VersioningSystem system = VersioningManager.getInstance().getOwner(proxy);
97
            CollocationQueryImplementation2 cqi = system.getCollocationQueryImplementation();
72
        return cqi == null ? null : cqi.findRoot(file);
98
        return cqi == null ? null : cqi.findRoot(file);
99
        } else {
100
            String path = file.getPath();
101
            int idx = path.lastIndexOf("/");
102
            if(idx > 0) {
103
                path = path.substring(0, idx);
104
            } else {
105
                return null;
73
    }
106
    }
107
            try {
108
                file = new URI(file.getScheme(), file.getUserInfo(), file.getHost(), file.getPort(), path, file.getQuery(), file.getFragment());
109
            } catch (URISyntaxException ex) {
110
                VersioningManager.LOG.log(Level.WARNING, path, ex);
111
                return null;
74
}
112
}
113
            return findRoot(file);
114
        }
115
    }
116
}
(-)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 (+154 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 = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
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 = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
88
        folder.mkdirs();
89
        File file = new File(folder, "somefile");
90
        assertRoot(folder, file);
91
    }
92
    
93
    private void assertRoot(File root, File file) {
94
        assertEquals(root.toURI(), CollocationQuery.findRoot(file.toURI()));
95
    }
96
    
97
    public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
98
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
99
        folder.mkdirs();
100
101
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
102
        file1.createNewFile();
103
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
104
        file2.createNewFile();
105
        
106
        assertCollocated(true, file1, file2);
107
    }
108
    
109
    public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
110
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
111
        folder.mkdirs();
112
113
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
114
        file1.createNewFile();
115
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
116
        file2.createNewFile();
117
        
118
        assertCollocated(true, file1, file2);
119
    }
120
    
121
    
122
    public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
123
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
124
        folder.mkdirs();
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 = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
136
        folder.mkdirs();
137
138
        File file1 = new File(folder, "file1");
139
        file1.createNewFile();
140
        File file2 = new File(folder, "file2");
141
        file2.createNewFile();
142
        
143
        assertCollocated(false, file1, file2);
144
    }
145
    
146
    void assertCollocated(boolean expected, File file1, File file2) {
147
        if(expected) {
148
            assertTrue(CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
149
        } else {
150
            assertFalse(CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
151
        }
152
    }
153
    
154
}
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java (+8 lines)
Lines 49-54 Link Here
49
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
49
import org.netbeans.modules.versioning.core.spi.VCSInterceptor;
50
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
50
import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery;
51
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
51
import org.netbeans.modules.versioning.core.spi.VersioningSystem;
52
import org.netbeans.spi.queries.CollocationQueryImplementation2;
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 CollocationQueryImplementation2 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 VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) {
82
    public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) {
Lines 99-102 Link Here
99
        return vq;
102
        return vq;
100
}
103
}
101
104
105
    @Override
106
    public CollocationQueryImplementation2 getCollocationQueryImplementation() {
107
        return vcq;
102
}
108
}
109
110
}
(-)versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java (+76 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.net.URI;
45
import org.netbeans.modules.versioning.core.Utils;
46
import org.netbeans.modules.versioning.core.api.VCSFileProxy;
47
import org.netbeans.spi.queries.CollocationQueryImplementation2;
48
49
/**
50
 *
51
 * @author tomas
52
 */
53
public class TestVCSCollocationQuery implements CollocationQueryImplementation2 {
54
55
    public static String COLLOCATED_FILENAME_SUFFIX = "_iscollocated";
56
    @Override
57
    public boolean areCollocated(URI file1, URI file2) {
58
        String name1 = file1.getPath();
59
        String name2 = file2.getPath();
60
        
61
        return name1.endsWith(COLLOCATED_FILENAME_SUFFIX) && name2.endsWith(COLLOCATED_FILENAME_SUFFIX);
62
    }
63
64
    @Override
65
    public URI findRoot(URI file) {
66
        VCSFileProxy proxy = TestVCS.getInstance().getTopmostManagedAncestor(Utils.toFileProxy(file));
67
        try {
68
            return proxy.toFileObject().getURL().toURI();
69
        } catch (Exception ex) {
70
            ex.printStackTrace();
71
            assert false;
72
            return null;
73
        }
74
    }
75
    
76
}
(-)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 (+154 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
    private void assertRoot(File root, File file) {
93
        assertEquals(root, CollocationQuery.findRoot(file));
94
    }
95
    
96
    public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
97
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
98
        folder.mkdirs();
99
100
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
101
        file1.createNewFile();
102
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
103
        file2.createNewFile();
104
        
105
        assertCollocated(true, file1, file2);
106
    }
107
    
108
    public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
109
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
110
        folder.mkdirs();
111
112
        File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
113
        file1.createNewFile();
114
        File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX);
115
        file2.createNewFile();
116
        
117
        assertCollocated(true, file1, file2);
118
    }
119
    
120
    
121
    public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception {
122
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
123
        folder.mkdirs();
124
125
        File file1 = new File(folder, "file1");
126
        file1.createNewFile();
127
        File file2 = new File(folder, "file2");
128
        file2.createNewFile();
129
        
130
        assertCollocated(false, file1, file2);
131
    }
132
    
133
    public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception {
134
        File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX);
135
        folder.mkdirs();
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, file2));
148
        } else {
149
            assertFalse(CollocationQuery.areCollocated(file1, file2));
150
        }
151
    }
152
    
153
    
154
}
(-)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