# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /data/work/src/netbeans-cm # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: versioning.core/src/org/netbeans/modules/versioning/core/DelegatingVCS.java --- versioning.core/src/org/netbeans/modules/versioning/core/DelegatingVCS.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/DelegatingVCS.java Locally Modified (Based On LOCAL) @@ -60,7 +60,7 @@ import org.netbeans.modules.versioning.core.spi.VersioningSystem; import org.netbeans.modules.versioning.core.api.VCSFileProxy; import org.netbeans.modules.versioning.core.api.VersioningSupport; -import org.netbeans.spi.queries.CollocationQueryImplementation; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.util.ContextAwareAction; import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; @@ -137,7 +137,7 @@ } @Override - public CollocationQueryImplementation getCollocationQueryImplementation() { + public CollocationQueryImplementation2 getCollocationQueryImplementation() { return getDelegate().getCollocationQueryImplementation(); } Index: versioning.core/src/org/netbeans/modules/versioning/core/Utils.java --- versioning.core/src/org/netbeans/modules/versioning/core/Utils.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/Utils.java Locally Modified (Based On LOCAL) @@ -43,24 +43,19 @@ */ package org.netbeans.modules.versioning.core; -import org.netbeans.modules.versioning.core.util.VCSSystemProvider; -import org.openide.filesystems.FileStateInvalidException; import org.openide.util.RequestProcessor; import org.openide.util.Lookup; import org.openide.util.actions.Presenter; import org.openide.awt.Actions; -import org.openide.filesystems.FileUtil; import org.openide.filesystems.FileObject; import org.openide.nodes.Node; import org.netbeans.modules.versioning.core.spi.VCSContext; import org.netbeans.api.fileinfo.NonRecursiveFolder; import javax.swing.*; -import javax.swing.text.Document; import java.io.File; -import java.io.Reader; -import java.io.StringReader; -import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; import java.util.*; import java.util.logging.Logger; import java.util.logging.Level; @@ -68,8 +63,7 @@ import java.util.prefs.Preferences; import org.netbeans.modules.versioning.core.api.VCSFileProxy; import org.netbeans.modules.versioning.core.api.VersioningSupport; -import org.netbeans.modules.versioning.core.spi.VersioningSystem; -import org.openide.filesystems.FileSystem; +import org.openide.filesystems.*; import org.openide.util.Utilities; /** @@ -388,4 +382,14 @@ Logger.getLogger(Utils.class.getName()).log(Level.INFO, sb.toString()); } } + + public static VCSFileProxy toFileProxy(URI uri) { + FileObject fo = null; + try { + fo = URLMapper.findFileObject(uri.toURL()); + } catch (MalformedURLException ex) { + VersioningManager.LOG.log(Level.WARNING, uri != null ? uri.toString() : null, ex); } + return fo != null ? VCSFileProxy.createFileProxy(fo) : null; + } +} Index: versioning.core/src/org/netbeans/modules/versioning/core/VcsCollocationQueryImplementation.java --- versioning.core/src/org/netbeans/modules/versioning/core/VcsCollocationQueryImplementation.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/VcsCollocationQueryImplementation.java Locally Modified (Based On LOCAL) @@ -47,28 +47,70 @@ import org.netbeans.modules.versioning.core.util.VCSSystemProvider.VersioningSystem; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Level; import org.netbeans.modules.versioning.core.api.VCSFileProxy; +import org.netbeans.spi.queries.CollocationQueryImplementation2; /** * Delegates the work to the owner of files in query. * * @author Maros Sandor + * @author Tomas Stupka */ @org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.CollocationQueryImplementation.class, position=50) -public class VcsCollocationQueryImplementation implements CollocationQueryImplementation { +public class VcsCollocationQueryImplementation implements CollocationQueryImplementation, CollocationQueryImplementation2 { + @Override public boolean areCollocated(File a, File b) { - VersioningSystem vsa = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(a)); - VersioningSystem vsb = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(b)); + URI aUri = a.toURI(); + URI bUri = b.toURI(); + return areCollocated(bUri, bUri); + } + + @Override + public File findRoot(File file) { + URI uri = findRoot(file.toURI()); + return uri != null ? new File(uri) : null; + } + + @Override + public boolean areCollocated(URI file1, URI file2) { + VCSFileProxy proxy1 = Utils.toFileProxy(file1); + VCSFileProxy proxy2 = Utils.toFileProxy(file2); + + if(proxy1 == null || proxy2 == null) return false; + VersioningSystem vsa = VersioningManager.getInstance().getOwner(proxy1); + VersioningSystem vsb = VersioningManager.getInstance().getOwner(proxy2); if (vsa == null || vsa != vsb) return false; - CollocationQueryImplementation cqi = vsa.getCollocationQueryImplementation(); - return cqi != null && cqi.areCollocated(a, b); + CollocationQueryImplementation2 cqi = vsa.getCollocationQueryImplementation(); + return cqi != null && cqi.areCollocated(file1, file2); } - public File findRoot(File file) { - VersioningSystem system = VersioningManager.getInstance().getOwner(VCSFileProxy.createFileProxy(file)); - CollocationQueryImplementation cqi = system.getCollocationQueryImplementation(); + @Override + public URI findRoot(URI file) { + VCSFileProxy proxy = Utils.toFileProxy(file); + if(proxy != null) { + VersioningSystem system = VersioningManager.getInstance().getOwner(proxy); + CollocationQueryImplementation2 cqi = system.getCollocationQueryImplementation(); return cqi == null ? null : cqi.findRoot(file); + } else { + String path = file.getPath(); + int idx = path.lastIndexOf("/"); + if(idx > 0) { + path = path.substring(0, idx); + } else { + return null; } + try { + file = new URI(file.getScheme(), file.getUserInfo(), file.getHost(), file.getPort(), path, file.getQuery(), file.getFragment()); + } catch (URISyntaxException ex) { + VersioningManager.LOG.log(Level.WARNING, path, ex); + return null; } + return findRoot(file); + } + } +} Index: versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java --- versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/VersioningManager.java Locally Modified (Based On LOCAL) @@ -69,7 +69,7 @@ import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationEvent; import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationListener; import org.netbeans.modules.versioning.core.util.VCSSystemProvider; -import org.netbeans.spi.queries.CollocationQueryImplementation; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.util.*; import org.openide.util.Lookup.Result; @@ -191,7 +191,7 @@ @Override public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) { throw new IllegalStateException(); } @Override public VCSInterceptor getInterceptor() { throw new IllegalStateException(); } @Override public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { throw new IllegalStateException(); } - @Override public CollocationQueryImplementation getCollocationQueryImplementation() { throw new IllegalStateException(); } + @Override public CollocationQueryImplementation2 getCollocationQueryImplementation() { throw new IllegalStateException(); } @Override public void addPropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); } @Override public void removePropertyCL(PropertyChangeListener listener) { throw new IllegalStateException(); } @Override public boolean isExcluded(VCSFileProxy file) { throw new IllegalStateException(); } Index: versioning.core/src/org/netbeans/modules/versioning/core/spi/VersioningSystem.java --- versioning.core/src/org/netbeans/modules/versioning/core/spi/VersioningSystem.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/spi/VersioningSystem.java Locally Modified (Based On LOCAL) @@ -44,7 +44,6 @@ package org.netbeans.modules.versioning.core.spi; import org.netbeans.modules.versioning.core.VersioningManager; -import org.netbeans.spi.queries.CollocationQueryImplementation; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -54,6 +53,7 @@ import java.lang.annotation.Target; import java.util.*; import org.netbeans.modules.versioning.core.api.VCSFileProxy; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; @@ -130,7 +130,7 @@ * * @return CollocationQueryImplementation a CollocationQueryImplementation instance or null if the system does not provide the service */ - public CollocationQueryImplementation getCollocationQueryImplementation() { + public CollocationQueryImplementation2 getCollocationQueryImplementation() { return null; } Index: versioning.core/src/org/netbeans/modules/versioning/core/util/VCSSystemProvider.java --- versioning.core/src/org/netbeans/modules/versioning/core/util/VCSSystemProvider.java Base (BASE) +++ versioning.core/src/org/netbeans/modules/versioning/core/util/VCSSystemProvider.java Locally Modified (Based On LOCAL) @@ -49,7 +49,7 @@ import org.netbeans.modules.versioning.core.spi.VCSContext; import org.netbeans.modules.versioning.core.spi.VCSInterceptor; import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery; -import org.netbeans.spi.queries.CollocationQueryImplementation; +import org.netbeans.spi.queries.CollocationQueryImplementation2; /** * Warning: VCS internal use only. Not to be implemented by clients. @@ -103,7 +103,7 @@ public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile); - public CollocationQueryImplementation getCollocationQueryImplementation(); + public CollocationQueryImplementation2 getCollocationQueryImplementation(); public VCSVisibilityQuery getVisibility(); Index: versioning.core/test/unit/src/org/netbeans/modules/versioning/core/ConnectDisconnectTest.java --- versioning.core/test/unit/src/org/netbeans/modules/versioning/core/ConnectDisconnectTest.java Base (BASE) +++ versioning.core/test/unit/src/org/netbeans/modules/versioning/core/ConnectDisconnectTest.java Locally Modified (Based On LOCAL) @@ -54,7 +54,7 @@ import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery; import org.netbeans.modules.versioning.core.api.VersioningSupport; import org.netbeans.modules.versioning.core.spi.VCSContext; -import org.netbeans.spi.queries.CollocationQueryImplementation; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.util.NbPreferences; import org.openide.util.test.MockLookup; @@ -269,7 +269,7 @@ public void getOriginalFile(VCSFileProxy workingCopy, VCSFileProxy originalFile) { } @Override - public CollocationQueryImplementation getCollocationQueryImplementation() { + public CollocationQueryImplementation2 getCollocationQueryImplementation() { return null; } Index: versioning.core/test/unit/src/org/netbeans/modules/versioning/core/spi/VCSCollocationQueryTest.java --- versioning.core/test/unit/src/org/netbeans/modules/versioning/core/spi/VCSCollocationQueryTest.java Base (BASE) +++ versioning.core/test/unit/src/org/netbeans/modules/versioning/core/spi/VCSCollocationQueryTest.java Locally New @@ -0,0 +1,154 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.versioning.core.spi; + +import java.io.IOException; +import org.openide.filesystems.FileStateInvalidException; + +import java.io.File; +import org.netbeans.api.queries.CollocationQuery; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.versioning.spi.testvcs.TestVCS; +import org.netbeans.modules.versioning.spi.testvcs.TestVCSCollocationQuery; +import org.openide.util.test.MockLookup; + +/** + * Versioning SPI unit tests of VCSVisibilityQuery. + * + * @author Tomas Stupka + */ +public class VCSCollocationQueryTest extends NbTestCase { + + + public VCSCollocationQueryTest(String testName) { + super(testName); + MockLookup.setLayersAndInstances(); + } + + protected void setUp() throws Exception { + MockLookup.setLayersAndInstances(); + File userdir = new File(getWorkDir() + "userdir"); + userdir.mkdirs(); + System.setProperty("netbeans.user", userdir.getAbsolutePath()); + super.setUp(); + } + + public void testFindRootExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + File file = new File(folder, "somefile"); + file.createNewFile(); + + assertRoot(folder, file); + } + + public void testFindRootNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + File file = new File(folder, "somefile"); + assertRoot(folder, file); + } + + private void assertRoot(File root, File file) { + assertEquals(root.toURI(), CollocationQuery.findRoot(file.toURI())); + } + + public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file1.createNewFile(); + File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file2.createNewFile(); + + assertCollocated(true, file1, file2); + } + + public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file1.createNewFile(); + File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file2.createNewFile(); + + assertCollocated(true, file1, file2); + } + + + public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file1"); + file1.createNewFile(); + File file2 = new File(folder, "file2"); + file2.createNewFile(); + + assertCollocated(false, file1, file2); + } + + public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file1"); + file1.createNewFile(); + File file2 = new File(folder, "file2"); + file2.createNewFile(); + + assertCollocated(false, file1, file2); + } + + void assertCollocated(boolean expected, File file1, File file2) { + if(expected) { + assertTrue(CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + } else { + assertFalse(CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + } + } + +} Index: versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java --- versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java Base (BASE) +++ versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java Locally Modified (Based On LOCAL) @@ -49,6 +49,7 @@ import org.netbeans.modules.versioning.core.spi.VCSInterceptor; import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery; import org.netbeans.modules.versioning.core.spi.VersioningSystem; +import org.netbeans.spi.queries.CollocationQueryImplementation2; /** * Test versioning system. @@ -62,6 +63,7 @@ private VCSInterceptor interceptor; private VCSAnnotator annotator; private VCSVisibilityQuery vq; + private CollocationQueryImplementation2 vcq; public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned"; @@ -74,6 +76,7 @@ interceptor = new TestVCSInterceptor(); annotator = new TestVCSAnnotator(); vq = new TestVCSVisibilityQuery(); + vcq = new TestVCSCollocationQuery(); } public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy file) { @@ -99,4 +102,9 @@ return vq; } + @Override + public CollocationQueryImplementation2 getCollocationQueryImplementation() { + return vcq; } + +} Index: versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java --- versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java Base (BASE) +++ versioning.core/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java Locally New @@ -0,0 +1,76 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.versioning.spi.testvcs; + +import java.net.URI; +import org.netbeans.modules.versioning.core.Utils; +import org.netbeans.modules.versioning.core.api.VCSFileProxy; +import org.netbeans.spi.queries.CollocationQueryImplementation2; + +/** + * + * @author tomas + */ +public class TestVCSCollocationQuery implements CollocationQueryImplementation2 { + + public static String COLLOCATED_FILENAME_SUFFIX = "_iscollocated"; + @Override + public boolean areCollocated(URI file1, URI file2) { + String name1 = file1.getPath(); + String name2 = file2.getPath(); + + return name1.endsWith(COLLOCATED_FILENAME_SUFFIX) && name2.endsWith(COLLOCATED_FILENAME_SUFFIX); + } + + @Override + public URI findRoot(URI file) { + VCSFileProxy proxy = TestVCS.getInstance().getTopmostManagedAncestor(Utils.toFileProxy(file)); + try { + return proxy.toFileObject().getURL().toURI(); + } catch (Exception ex) { + ex.printStackTrace(); + assert false; + return null; + } + } + +} Index: versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java --- versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java Base (BASE) +++ versioning/src/org/netbeans/modules/versioning/DelegatingVCS.java Locally Modified (Based On LOCAL) @@ -47,6 +47,7 @@ import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,6 +60,7 @@ import org.netbeans.modules.versioning.core.spi.VCSVisibilityQuery; import org.netbeans.modules.versioning.spi.VersioningSupport; import org.netbeans.spi.queries.CollocationQueryImplementation; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.util.ContextAwareAction; import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; @@ -87,6 +89,7 @@ private VCSAnnotator annotator; private VCSVisibilityQuery visibilityQuery; private VCSInterceptor interceptor; + private CollocationQueryImplementation2 collocationQuery; private DelegatingVCS(Map map) { this.map = map; @@ -146,9 +149,23 @@ } @Override - public CollocationQueryImplementation getCollocationQueryImplementation() { - return getDelegate().getCollocationQueryImplementation(); + public CollocationQueryImplementation2 getCollocationQueryImplementation() { + if(collocationQuery == null) { + collocationQuery = new CollocationQueryImplementation2() { + private CollocationQueryImplementation cqi = getDelegate().getCollocationQueryImplementation(); + @Override + public boolean areCollocated(URI uri1, URI uri2) { + return cqi != null && cqi.areCollocated(new File(uri1), new File(uri2)); } + @Override + public URI findRoot(URI uri) { + File file = cqi != null ? cqi.findRoot(new File(uri)) : null; + return file != null ? file.toURI() : null; + } + }; + } + return collocationQuery; + } @Override public VCSFileProxy getTopmostManagedAncestor(VCSFileProxy proxy) { Index: versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSCollocationQueryTest.java --- versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSCollocationQueryTest.java Base (BASE) +++ versioning/test/unit/src/org/netbeans/modules/versioning/spi/VCSCollocationQueryTest.java Locally New @@ -0,0 +1,154 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.versioning.spi; + +import java.io.IOException; +import org.openide.filesystems.FileStateInvalidException; + +import java.io.File; +import org.netbeans.api.queries.CollocationQuery; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.versioning.spi.testvcs.TestVCS; +import org.netbeans.modules.versioning.spi.testvcs.TestVCSCollocationQuery; +import org.openide.util.test.MockLookup; + +/** + * Versioning SPI unit tests of VCSVisibilityQuery. + * + * @author Tomas Stupka + */ +public class VCSCollocationQueryTest extends NbTestCase { + + + public VCSCollocationQueryTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + MockLookup.setLayersAndInstances(); + File userdir = new File(getWorkDir() + "userdir"); + userdir.mkdirs(); + System.setProperty("netbeans.user", userdir.getAbsolutePath()); + super.setUp(); + } + + public void testFindRootExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + File file = new File(folder, "somefile"); + file.createNewFile(); + + assertRoot(folder, file); + } + + public void testFindRootNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + File file = new File(folder, "somefile"); + assertRoot(folder, file); + } + + private void assertRoot(File root, File file) { + assertEquals(root, CollocationQuery.findRoot(file)); + } + + public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file1.createNewFile(); + File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file2.createNewFile(); + + assertCollocated(true, file1, file2); + } + + public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file1.createNewFile(); + File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); + file2.createNewFile(); + + assertCollocated(true, file1, file2); + } + + + public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file1"); + file1.createNewFile(); + File file2 = new File(folder, "file2"); + file2.createNewFile(); + + assertCollocated(false, file1, file2); + } + + public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { + File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); + folder.mkdirs(); + + File file1 = new File(folder, "file1"); + file1.createNewFile(); + File file2 = new File(folder, "file2"); + file2.createNewFile(); + + assertCollocated(false, file1, file2); + } + + void assertCollocated(boolean expected, File file1, File file2) { + if(expected) { + assertTrue(CollocationQuery.areCollocated(file1, file2)); + } else { + assertFalse(CollocationQuery.areCollocated(file1, file2)); + } + } + + +} Index: versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java --- versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java Base (BASE) +++ versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCS.java Locally Modified (Based On LOCAL) @@ -49,6 +49,7 @@ import java.io.File; import org.netbeans.modules.versioning.spi.VCSVisibilityQuery; +import org.netbeans.spi.queries.CollocationQueryImplementation; /** * Test versioning system. @@ -62,6 +63,7 @@ private VCSInterceptor interceptor; private VCSAnnotator annotator; private VCSVisibilityQuery vq; + private TestVCSCollocationQuery vcq; public static final String VERSIONED_FOLDER_SUFFIX = "-test-versioned"; @@ -74,6 +76,7 @@ interceptor = new TestVCSInterceptor(); annotator = new TestVCSAnnotator(); vq = new TestVCSVisibilityQuery(); + vcq = new TestVCSCollocationQuery(); } public File getTopmostManagedAncestor(File file) { @@ -99,4 +102,10 @@ return vq; } + @Override + public CollocationQueryImplementation getCollocationQueryImplementation() { + return vcq; } + + +} Index: versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java --- versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java Base (BASE) +++ versioning/test/unit/src/org/netbeans/modules/versioning/spi/testvcs/TestVCSCollocationQuery.java Locally New @@ -0,0 +1,67 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.versioning.spi.testvcs; + +import java.io.File; +import org.netbeans.spi.queries.CollocationQueryImplementation; + +/** + * + * @author tomas + */ +public class TestVCSCollocationQuery implements CollocationQueryImplementation { + + public static String COLLOCATED_FILENAME_SUFFIX = "_iscollocated"; + @Override + public boolean areCollocated(File file1, File file2) { + String name1 = file1.getName(); + String name2 = file2.getName(); + + return name1.endsWith(COLLOCATED_FILENAME_SUFFIX) && name2.endsWith(COLLOCATED_FILENAME_SUFFIX); + } + + @Override + public File findRoot(File file) { + return TestVCS.getInstance().getTopmostManagedAncestor(file); + } + +}