# 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: queries/apichanges.xml --- queries/apichanges.xml +++ queries/apichanges.xml @@ -107,6 +107,23 @@ + + + added VersioningQuery + + + + + + +

+ Added a new query VersioningQuery which provides Versioning relevant info like + e.g. if a particular file is managed by a Versioning System. +

+
+ + +
VisibilityQueryChangeEvent added Index: queries/manifest.mf --- queries/manifest.mf +++ queries/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.queries/1 -OpenIDE-Module-Specification-Version: 1.34 +OpenIDE-Module-Specification-Version: 1.35 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/queries/Bundle.properties Index: queries/src/org/netbeans/api/queries/VersioningQuery.java --- queries/src/org/netbeans/api/queries/VersioningQuery.java +++ queries/src/org/netbeans/api/queries/VersioningQuery.java @@ -0,0 +1,128 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.api.queries; + +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.spi.queries.VersioningQueryImplementation; +import org.openide.util.Lookup; + +/** + * Find out Versioning System relevant information about a file. + * + * @author Tomas Stupka + * @since 1.35 + */ +public final class VersioningQuery { + + private static final Logger LOG = Logger.getLogger(FileEncodingQuery.class.getName()); + + private static final Lookup.Result implementations = + Lookup.getDefault().lookupResult(org.netbeans.spi.queries.VersioningQueryImplementation.class); + + private VersioningQuery() { } + + /** + * Determines whether the given local file or directory is managed by a Versioning System + * - e.g. located in a SVN checkout or Mercurial clone. + * + * @param uri a {@link org.openide.filesystems.FileUtil#normalizeFile normalized} file to check if managed + * @return true if the file is managed, otherwise false. + * @since 1.35 + */ + public static boolean isManaged(URI uri) { + java.util.Objects.requireNonNull(uri); + boolean asserts = false; + assert asserts = true; + if (asserts) { + URI normUri = uri.normalize(); + if (!uri.equals(normUri)) { + throw new IllegalArgumentException("Must pass a normalized URI: " + uri + " vs. " + normUri); + } + } + + for (VersioningQueryImplementation vqi : implementations.allInstances()) { + if(vqi.isManaged(uri)) { + LOG.log(Level.FINE, "{0} is VCS managed", new Object[] {uri}); // NOI18N + return true; + } + } + + LOG.log(Level.FINE, "{0} isn't managed by any VCS", new Object[] {uri}); // NOI18N + return false; + } + + /** + * Provides the Versioning System specific information about a files remote repository or origin. + * This might be for example in case of Subversion the repository url, or in case of Mercurial the default pull url. + * Also note that only Versioning Systems available by a supported Team Server are expected to return a + * valid value. + * + * @param uri a {@link org.openide.filesystems.FileUtil#normalizeFile normalized} file to check if managed + * @return value describing the remote location or null if not available or provided + * @since 1.35 + */ + public static String getRemoteLocation(URI uri) { + java.util.Objects.requireNonNull(uri); + boolean asserts = false; + assert asserts = true; + if (asserts) { + URI normUri = uri.normalize(); + if (!uri.equals(normUri)) { + throw new IllegalArgumentException("Must pass a normalized URI: " + uri + " vs. " + normUri); + } + } + + for (VersioningQueryImplementation vqi : implementations.allInstances()) { + final String remoteLocation = vqi.getRemoteLocation(uri); + if(remoteLocation != null) { + LOG.log(Level.FINE, "{0}: received remote location {1}", new Object[] {uri, remoteLocation}); // NOI18N + return remoteLocation; + } + } + + LOG.log(Level.FINE, "{0}: received no remote location", new Object[] {uri}); // NOI18N + return null; + } +} Index: queries/src/org/netbeans/spi/queries/VersioningQueryImplementation.java --- queries/src/org/netbeans/spi/queries/VersioningQueryImplementation.java +++ queries/src/org/netbeans/spi/queries/VersioningQueryImplementation.java @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.queries; + +import java.net.URI; + +/** + * Provide Versioning System relevant information about a file. + * + * @author Tomas Stupka + * @since 1.35 + */ +public interface VersioningQueryImplementation { + + /** + * Determines whether the given local file or directory is managed by a Versioning System + * - e.g. located in a SVN checkout or Mercurial clone. + * + * @param uri a {@link org.openide.filesystems.FileUtil#normalizeFile normalized} file to check if managed + * @return true if the file is managed, otherwise false. + * @since 1.35 + */ + boolean isManaged(URI uri); + + /** + * Provides the Versioning System specific information about a files remote repository or origin. + * * This might be for example in case of Subversion the repository url, or in case of Mercurial the default pull url. + * Also note that only Versioning Systems available by a supported Team Server are expected to return a + * meaningful value. + * + * @param uri a {@link org.openide.filesystems.FileUtil#normalizeFile normalized} file to check if managed + * @return value describing the remote location or null if not available or provided + * @since 1.35 + */ + String getRemoteLocation(URI uri); + +} Index: queries/test/unit/src/org/netbeans/api/queries/VersioningQueryTest.java --- queries/test/unit/src/org/netbeans/api/queries/VersioningQueryTest.java +++ queries/test/unit/src/org/netbeans/api/queries/VersioningQueryTest.java @@ -0,0 +1,132 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 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 2011 Sun Microsystems, Inc. + */ +package org.netbeans.api.queries; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import org.netbeans.api.queries.SharabilityQuery.Sharability; +import org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.netbeans.spi.queries.SharabilityQueryImplementation; +import org.netbeans.spi.queries.SharabilityQueryImplementation2; +import org.netbeans.spi.queries.VersioningQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Utilities; + +/** + * + * @author Tomas Stupka + */ +public class VersioningQueryTest extends NbTestCase { + + public VersioningQueryTest(String testMethod) { + super (testMethod); + } + + private final File home = new File(System.getProperty("user.dir")); + + @Override + public void setUp() throws IOException { + clearWorkDir(); + MockServices.setServices(VersioningQueryImplementationImpl.class); + } + + public void testIsManaged() throws IOException { + File file = new File(home, "aFile.vcs"); + assertTrue(VersioningQuery.isManaged(Utilities.toURI(file))); + } + + public void testIsNotManaged() throws IOException { + File file = new File(home, "aFile.txt"); + assertFalse(VersioningQuery.isManaged(Utilities.toURI(file))); + } + + public void testGetRemoteLocation() throws IOException { + File file = new File(home, "aFile.vcs"); + assertEquals(Utilities.toURI(file).toString(), VersioningQuery.getRemoteLocation(Utilities.toURI(file))); + } + + public void testNoRemoteLocation() throws IOException { + File file = new File(home, "aFile.txt"); + assertNull(VersioningQuery.getRemoteLocation(Utilities.toURI(file))); + } + + public void testNormalized() throws IOException { + File file = new File(home, "../aFile.txt"); + Exception exception = null; + try { + VersioningQuery.isManaged(Utilities.toURI(file)); + } catch (IllegalArgumentException e) { + exception = e; + } + assertNotNull(exception); + URI uri = Utilities.toURI(file); + exception = null; + try { + VersioningQuery.getRemoteLocation(Utilities.toURI(file)); + } catch (IllegalArgumentException e) { + exception = e; + } + assertNotNull(exception); + } + + public static class VersioningQueryImplementationImpl implements VersioningQueryImplementation { + + @Override + public boolean isManaged(URI uri) { + File file = Utilities.toFile(uri); + String path = file.getAbsolutePath(); + return path.endsWith(".vcs"); + } + + @Override + public String getRemoteLocation(URI uri) { + File file = Utilities.toFile(uri); + String path = file.getAbsolutePath(); + return path.endsWith(".vcs") ? uri.toString() : null; + } + } + +}