# HG changeset patch # User Alexander Simon # Date 1326185315 -14400 # Node ID 922c35f699dca0606ec073dc3602974d96a4f6fc # Parent 1c22c1b715ece2a09ee2b776a64ba14077b8fdc7 fixing Bug #198060 SharabilityQuery / SharabilityQueryImplementation should be extended to use FileObject variant #7 (fixed JG16-JG22) diff --git a/apisupport.wizards/nbproject/project.xml b/apisupport.wizards/nbproject/project.xml --- a/apisupport.wizards/nbproject/project.xml +++ b/apisupport.wizards/nbproject/project.xml @@ -126,7 +126,7 @@ 1 - 1.26 + 1.27 diff --git a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java b/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java --- a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java +++ b/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java @@ -307,7 +307,7 @@ SourceGroup group = grps[0]; Collection files = new ArrayList(); collectFiles(group.getRootFolder(), files, - SharabilityQuery.getSharability(FileUtil.toFile(group.getRootFolder()))); + SharabilityQuery.getSharability(group.getRootFolder())); createZipFile(target, group.getRootFolder(), files); } @@ -320,19 +320,19 @@ ImageIO.write(image, "png", target); } - private static void collectFiles(FileObject parent, Collection accepted, int parentSharab) { + private static void collectFiles(FileObject parent, Collection accepted, SharabilityQuery.Sharability parentSharab) { for (FileObject fo : parent.getChildren()) { if (!VisibilityQuery.getDefault().isVisible(fo)) { // #66765: ignore invisible files/folders, like CVS subdirectory continue; } - int sharab; - if (parentSharab == SharabilityQuery.UNKNOWN || parentSharab == SharabilityQuery.MIXED) { - sharab = SharabilityQuery.getSharability(FileUtil.toFile(fo)); + SharabilityQuery.Sharability sharab; + if (parentSharab == SharabilityQuery.Sharability.UNKNOWN || parentSharab == SharabilityQuery.Sharability.MIXED) { + sharab = SharabilityQuery.getSharability(fo); } else { sharab = parentSharab; } - if (sharab == SharabilityQuery.NOT_SHARABLE) { + if (sharab == SharabilityQuery.Sharability.NOT_SHARABLE) { continue; } if (fo.isData() && !fo.isVirtual()) { diff --git a/projectapi/manifest.mf b/projectapi/manifest.mf --- a/projectapi/manifest.mf +++ b/projectapi/manifest.mf @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.projectapi/1 OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class -OpenIDE-Module-Specification-Version: 1.41 +OpenIDE-Module-Specification-Version: 1.42 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml diff --git a/projectapi/nbproject/project.xml b/projectapi/nbproject/project.xml --- a/projectapi/nbproject/project.xml +++ b/projectapi/nbproject/project.xml @@ -55,7 +55,7 @@ 1 - 1.9 + 1.27 diff --git a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java --- a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java +++ b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java @@ -48,21 +48,21 @@ import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.queries.SharabilityQuery; -import org.netbeans.spi.queries.SharabilityQueryImplementation; /** * Delegates {@link SharabilityQuery} to implementations in project lookup. * @author Jesse Glick */ +@SuppressWarnings("deprecation") @org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.SharabilityQueryImplementation.class) -public class ProjectSharabilityQuery implements SharabilityQueryImplementation { +public class ProjectSharabilityQuery implements org.netbeans.spi.queries.SharabilityQueryImplementation { public ProjectSharabilityQuery() {} public @Override int getSharability(File file) { Project p = FileOwnerQuery.getOwner(file.toURI()); if (p != null) { - SharabilityQueryImplementation sqi = p.getLookup().lookup(SharabilityQueryImplementation.class); + org.netbeans.spi.queries.SharabilityQueryImplementation sqi = p.getLookup().lookup(org.netbeans.spi.queries.SharabilityQueryImplementation.class); if (sqi != null) { return sqi.getSharability(file); } diff --git a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery2.java b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery2.java new file mode 100644 --- /dev/null +++ b/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery2.java @@ -0,0 +1,73 @@ +/* + * 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.modules.projectapi; + +import org.netbeans.spi.queries.SharabilityQueryImplementation2; +import java.net.URI; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.queries.SharabilityQuery; +import org.netbeans.api.queries.SharabilityQuery.Sharability; + +/** + * Delegates {@link SharabilityQuery} to implementations in project lookup. + * @author Jesse Glick + * @author Alexander Simon + */ +@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.SharabilityQueryImplementation2.class) +public class ProjectSharabilityQuery2 implements SharabilityQueryImplementation2 { + + public ProjectSharabilityQuery2() {} + + @Override + public Sharability getSharability(URI uri) { + Project p = FileOwnerQuery.getOwner(uri); + if (p != null) { + SharabilityQueryImplementation2 sqi = p.getLookup().lookup(SharabilityQueryImplementation2.class); + if (sqi != null) { + return sqi.getSharability(uri); + } + } + return Sharability.UNKNOWN; + } + +} diff --git a/projectui/nbproject/project.xml b/projectui/nbproject/project.xml --- a/projectui/nbproject/project.xml +++ b/projectui/nbproject/project.xml @@ -118,6 +118,7 @@ 1 + 1.27 diff --git a/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java b/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java --- a/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java +++ b/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java @@ -139,11 +139,10 @@ while (e.hasMoreElements()) { try { FileObject em = e.nextElement(); - File f = FileUtil.toFile(fo); - int share = SharabilityQuery.UNKNOWN; + SharabilityQuery.Sharability share = SharabilityQuery.Sharability.UNKNOWN; if (checkShare) { - share = SharabilityQuery.getSharability(f); - if (share == SharabilityQuery.NOT_SHARABLE) { + share = SharabilityQuery.getSharability(fo); + if (share == SharabilityQuery.Sharability.NOT_SHARABLE) { continue; } } @@ -154,7 +153,7 @@ h.progress(progressMessage(p), Math.min(++counter.start, counter.end)); } } - checkShare = share != SharabilityQuery.SHARABLE; + checkShare = share != SharabilityQuery.Sharability.SHARABLE; // don't need to check the sharability if the current folder is marked as recursively sharable processFolderChildren(em, projects, h, counter, checkShare); diff --git a/projectuiapi/nbproject/project.xml b/projectuiapi/nbproject/project.xml --- a/projectuiapi/nbproject/project.xml +++ b/projectuiapi/nbproject/project.xml @@ -82,7 +82,7 @@ 1 - 1.5 + 1.27 diff --git a/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java b/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java --- a/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java +++ b/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java @@ -558,7 +558,7 @@ } //#109580 - if (SharabilityQuery.getSharability(FileUtil.toFile(from)) == SharabilityQuery.NOT_SHARABLE) { + if (SharabilityQuery.getSharability(from) == SharabilityQuery.Sharability.NOT_SHARABLE) { return; } diff --git a/queries/apichanges.xml b/queries/apichanges.xml --- a/queries/apichanges.xml +++ b/queries/apichanges.xml @@ -107,6 +107,36 @@ + + + SharabilityQuery and CollocationQuery extended to use URI + + + + + + +

+ Added new methods CollocationQuery.areCollocated(URI, URI) and CollocationQuery.findRoot(URI). + Methods query all CollocationQueryImplementation (if possible) and CollocationQueryImplementation2 instances found in global lookup. + Deprecated existing methods CollocationQuery.areCollocated(File, File) and CollocationQuery.findRoot(File). + Methods query all CollocationQueryImplementation and CollocationQueryImplementation2 instances found in global lookup. +

+

+ Added new methods SharabilityQuery.getSharability(URI) and SharabilityQuery.getSharability(FileObject). + Methods query all SharabilityQueryImplementation (if possible) and SharabilityQueryImplementation2 instances found in global lookup. + Deprecated existing method SharabilityQuery.getSharability(File). + Method query all SharabilityQueryImplementation and SharabilityQueryImplementation2 instances found in global lookup. +

+
+ + + + + + + +
VisibilityQuery.isVisible(File) added diff --git a/queries/manifest.mf b/queries/manifest.mf --- a/queries/manifest.mf +++ b/queries/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.queries/1 -OpenIDE-Module-Specification-Version: 1.26 +OpenIDE-Module-Specification-Version: 1.27 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/queries/Bundle.properties diff --git a/queries/src/org/netbeans/api/queries/CollocationQuery.java b/queries/src/org/netbeans/api/queries/CollocationQuery.java --- a/queries/src/org/netbeans/api/queries/CollocationQuery.java +++ b/queries/src/org/netbeans/api/queries/CollocationQuery.java @@ -45,20 +45,24 @@ package org.netbeans.api.queries; import java.io.File; -import org.netbeans.spi.queries.CollocationQueryImplementation; +import java.net.URI; +import org.netbeans.spi.queries.CollocationQueryImplementation2; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; /** * Find out whether some files logically belong in one directory tree, * for example as part of a VCS checkout. - * @see CollocationQueryImplementation + * @see CollocationQueryImplementation2 * @author Jesse Glick */ +@SuppressWarnings("deprecation") public final class CollocationQuery { - private static final Lookup.Result implementations = - Lookup.getDefault().lookupResult(CollocationQueryImplementation.class); + private static final Lookup.Result implementations = + Lookup.getDefault().lookupResult(org.netbeans.spi.queries.CollocationQueryImplementation.class); + private static final Lookup.Result implementations2 = + Lookup.getDefault().lookupResult(CollocationQueryImplementation2.class); private CollocationQuery() {} @@ -70,8 +74,9 @@ * @param file1 one file * @param file2 another file * @return true if they are probably part of one logical tree + * @deprecated Use {@link #areCollocated(java.net.URI, java.net.URI)} instead. */ - public static boolean areCollocated(File file1, File file2) { + @Deprecated public static boolean areCollocated(File file1, File file2) { if (!file1.equals(FileUtil.normalizeFile(file1))) { throw new IllegalArgumentException("Parameter file1 was not "+ // NOI18N "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1)); // NOI18N @@ -80,26 +85,77 @@ throw new IllegalArgumentException("Parameter file2 was not "+ // NOI18N "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2)); // NOI18N } - for (CollocationQueryImplementation cqi : implementations.allInstances()) { + URI uri1 = file1.toURI(); + URI uri2 = file2.toURI(); + for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { + if (cqi.areCollocated(uri1, uri2)) { + return true; + } + } + for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { if (cqi.areCollocated(file1, file2)) { return true; } } return false; } + + /** + * Check whether two files are logically part of one directory tree. + * For example, if both files are stored in CVS, with the same server + * (CVSROOT) they might be considered collocated. + * If nothing is known about them, return false. + * @param file1 one file + * @param file2 another file + * @return true if they are probably part of one logical tree + * @since 1.27 + */ + public static boolean areCollocated(URI file1, URI file2) { + if (!file1.equals(file1.normalize())) { + throw new IllegalArgumentException("Parameter file1 was not "+ // NOI18N + "normalized. Was "+file1+" instead of "+file1.normalize()); // NOI18N + } + if (!file2.equals(file2.normalize())) { + throw new IllegalArgumentException("Parameter file2 was not "+ // NOI18N + "normalized. Was "+file2+" instead of "+file2.normalize()); // NOI18N + } + for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { + if (cqi.areCollocated(file1, file2)) { + return true; + } + } + if ("file".equals(file1.getScheme()) && "file".equals(file2.getScheme())) { // NOI18N + File f1 = FileUtil.normalizeFile(new File(file1)); + File f2 = FileUtil.normalizeFile(new File(file2)); + for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { + if (cqi.areCollocated(f1, f2)) { + return true; + } + } + } + return false; + } /** * Find a root of a logical tree containing this file, if any. * @param file a file on disk * @return an ancestor directory which is the root of a logical tree, * if any (else null) + * @deprecated Use {@link #findRoot(java.net.URI)} instead. */ - public static File findRoot(File file) { + @Deprecated public static File findRoot(File file) { if (!file.equals(FileUtil.normalizeFile(file))) { throw new IllegalArgumentException("Parameter file was not "+ // NOI18N "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file)); // NOI18N } - for (CollocationQueryImplementation cqi : implementations.allInstances()) { + URI uri = file.toURI(); + for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { + URI root = cqi.findRoot(uri); + if (root != null) { + return new File(root); + } + } + for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { File root = cqi.findRoot(file); if (root != null) { return root; @@ -108,4 +164,33 @@ return null; } + /** + * Find a root of a logical tree containing this file, if any. + * @param file a file on disk + * @return an ancestor directory which is the root of a logical tree, + * if any (else null) + * @since 1.27 + */ + public static URI findRoot(URI file) { + if (!file.equals(file.normalize())) { + throw new IllegalArgumentException("Parameter file was not "+ // NOI18N + "normalized. Was "+file+" instead of "+file.normalize()); // NOI18N + } + for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) { + URI root = cqi.findRoot(file); + if (root != null) { + return root; + } + } + if ("file".equals(file.getScheme())) { // NOI18N + File f = FileUtil.normalizeFile(new File(file)); + for (org.netbeans.spi.queries.CollocationQueryImplementation cqi : implementations.allInstances()) { + File root = cqi.findRoot(f); + if (root != null) { + return root.toURI(); + } + } + } + return null; + } } diff --git a/queries/src/org/netbeans/api/queries/SharabilityQuery.java b/queries/src/org/netbeans/api/queries/SharabilityQuery.java --- a/queries/src/org/netbeans/api/queries/SharabilityQuery.java +++ b/queries/src/org/netbeans/api/queries/SharabilityQuery.java @@ -45,7 +45,13 @@ package org.netbeans.api.queries; import java.io.File; -import org.netbeans.spi.queries.SharabilityQueryImplementation; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.spi.queries.SharabilityQueryImplementation2; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; import org.openide.util.Parameters; @@ -62,53 +68,101 @@ * Unlike that method, the information is pulled by the VCS filesystem on * demand, which may be more reliable than ensuring that the information * is pushed by a project type (or other implementor) eagerly. - * @see SharabilityQueryImplementation + * @see SharabilityQueryImplementation2 * @author Jesse Glick */ +@SuppressWarnings("deprecation") public final class SharabilityQuery { - private static final Lookup.Result implementations = - Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class); + private static final Lookup.Result implementations = + Lookup.getDefault().lookupResult(org.netbeans.spi.queries.SharabilityQueryImplementation.class); + + private static final Lookup.Result implementations2 = + Lookup.getDefault().lookupResult(SharabilityQueryImplementation2.class); + + private static final Logger LOG = Logger.getLogger(SharabilityQuery.class.getName()); /** * Constant indicating that nothing is known about whether a given * file should be considered sharable or not. * A client should therefore behave in the safest way it can. + * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#UNKNOWN} instead. */ - public static final int UNKNOWN = 0; + @Deprecated public static final int UNKNOWN = 0; /** * Constant indicating that the file or directory is sharable. * In the case of a directory, this means that all files and * directories recursively contained in this directory are also * sharable. + * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#SHARABLE} instead. */ - public static final int SHARABLE = 1; + @Deprecated public static final int SHARABLE = 1; /** * Constant indicating that the file or directory is not sharable. * In the case of a directory, this means that all files and * directories recursively contained in this directory are also * not sharable. + * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#NOT_SHARABLE} instead. */ - public static final int NOT_SHARABLE = 2; + @Deprecated public static final int NOT_SHARABLE = 2; /** * Constant indicating that a directory is sharable but files and * directories recursively contained in it may or may not be sharable. * A client interested in children of this directory should explicitly * ask about each in turn. + * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#MIXED} instead. */ - public static final int MIXED = 3; + @Deprecated public static final int MIXED = 3; + + /** + * Sharability constants. + * @since 1.27 + */ + public enum Sharability { + /** + * Constant indicating that nothing is known about whether a given + * file should be considered sharable or not. + * A client should therefore behave in the safest way it can. + */ + UNKNOWN, + + /** + * Constant indicating that the file or directory is sharable. + * In the case of a directory, this means that all files and + * directories recursively contained in this directory are also + * sharable. + */ + SHARABLE, + + /** + * Constant indicating that the file or directory is not sharable. + * In the case of a directory, this means that all files and + * directories recursively contained in this directory are also + * not sharable. + */ + NOT_SHARABLE, + + /** + * Constant indicating that a directory is sharable but files and + * directories recursively contained in it may or may not be sharable. + * A client interested in children of this directory should explicitly + * ask about each in turn. + */ + MIXED; + } private SharabilityQuery() {} /** * Check whether an existing file is sharable. * @param file a file or directory (may or may not already exist); should be {@linkplain FileUtil#normalizeFile normalized} - * @return one of the constants in this class + * @return an answer or {@code UNKNOWN} + * @deprecated Use {@link #getSharability(java.net.URI)} instead. */ - public static int getSharability(File file) { + @Deprecated public static int getSharability(File file) { Parameters.notNull("file", file); boolean asserts = false; assert asserts = true; @@ -118,7 +172,17 @@ throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile); } } - for (SharabilityQueryImplementation sqi : implementations.allInstances()) { + URI uri = null; + for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) { + if (uri == null) { + uri = file.toURI(); + } + Sharability x = sqi.getSharability(uri); + if (x != Sharability.UNKNOWN) { + return x.ordinal(); + } + } + for (org.netbeans.spi.queries.SharabilityQueryImplementation sqi : implementations.allInstances()) { int x = sqi.getSharability(file); if (x != UNKNOWN) { return x; @@ -127,4 +191,54 @@ return UNKNOWN; } + /** + * Check whether an existing file is sharable. + * @param uri a file or directory (may or may not already exist); should be normalized. + * @return an answer or {@code UNKNOWN} + * @since 1.27 + */ + public static Sharability getSharability(URI uri) { + Parameters.notNull("uri", 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 (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) { + Sharability x = sqi.getSharability(uri); + if (x != Sharability.UNKNOWN) { + return x; + } + } + if ("file".equals(uri.getScheme())) { // NOI18N + File file = FileUtil.normalizeFile(new File(uri)); + for (org.netbeans.spi.queries.SharabilityQueryImplementation sqi : implementations.allInstances()) { + int x = sqi.getSharability(file); + if (x != UNKNOWN) { + return Sharability.values()[x]; + } + } + } + return Sharability.UNKNOWN; + } + + /** + * Check whether an existing file is sharable. + * @param fo a file or directory; should be normalized. + * @return an answer or {@code UNKNOWN} + * @since 1.27 + */ + public static Sharability getSharability(FileObject fo) { + try { + return getSharability(fo.getURL().toURI()); + } catch (URISyntaxException ex) { + LOG.log(Level.FINE, null, ex); + } catch (FileStateInvalidException ex) { + LOG.log(Level.FINE, null, ex); + } + return Sharability.UNKNOWN; + } } diff --git a/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation.java b/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation.java --- a/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation.java +++ b/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation.java @@ -68,8 +68,9 @@ *

* @see org.netbeans.api.queries.CollocationQuery * @author Jesse Glick + * @deprecated Use {@link org.netbeans.spi.queries.CollocationQueryImplementation2} instead. */ -public interface CollocationQueryImplementation { +@Deprecated public interface CollocationQueryImplementation { /** * Check whether two files are logically part of one directory tree. diff --git a/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation2.java b/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation2.java new file mode 100644 --- /dev/null +++ b/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation2.java @@ -0,0 +1,96 @@ +/* + * 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.spi.queries; + +import java.net.URI; + +/** + * A query which should typically be provided by a VCS to give information + * about whether some files can be considered part of one logical directory tree. + *

+ * This should be treated as a heuristic, useful when deciding whether to use + * absolute or relative links between path locations. + *

+ *

+ * The file names might refer to nonexistent files. A provider may or may not + * be able to say anything useful about them in this case. + *

+ *

+ * File names passed to this query will already have been normalized according to + * the semantics of {@link org.openide.filesystems.FileUtil#normalizeFile}. + *

+ *

+ * Threading note: implementors should avoid acquiring locks that might be held + * by other threads. Generally treat this interface similarly to SPIs in + * {@link org.openide.filesystems} with respect to threading semantics. + *

+ * @see org.netbeans.api.queries.CollocationQuery + * @since 1.27 + * @author Jesse Glick + * @author Alexander Simon + */ +public interface CollocationQueryImplementation2 { + + /** + * Check whether two files are logically part of one directory tree. + * For example, if both files are stored in CVS, with the same server + * (CVSROOT) they might be considered collocated. + * If they are to be collocated their absolute paths must share a + * prefix directory, i.e. they must be located in the same filesystem root. + * If nothing is known about them, return false. + * @param file1 one file + * @param file2 another file + * @return true if they are probably part of one logical tree + */ + boolean areCollocated(URI file1, URI file2); + + /** + * Find a root of a logical tree containing this file, if any. + * The path of the root (if there is one) must be a prefix of the path of the file. + * @param file a file on disk (must be an absolute URI) + * @return an ancestor directory which is the root of a logical tree, + * if any (else null) (must be an absolute URI) + */ + URI findRoot(URI file); + +} + diff --git a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java b/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java --- a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java +++ b/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java @@ -69,9 +69,12 @@ *

* @see org.netbeans.api.queries.SharabilityQuery * @see AntProjectHelper.createSharabilityQuery(...) + * @since 1.27 * @author Jesse Glick + * @deprecated Use {@link org.netbeans.spi.queries.SharabilityQueryImplementation2} instead. + * */ -public interface SharabilityQueryImplementation { +@Deprecated public interface SharabilityQueryImplementation { /** * Check whether a file or directory should be shared. diff --git a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation2.java b/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation2.java new file mode 100644 --- /dev/null +++ b/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation2.java @@ -0,0 +1,85 @@ +/* + * 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.spi.queries; + +import java.net.URI; +import org.netbeans.api.queries.SharabilityQuery.Sharability; + +/** + * Determine whether files should be shared (for example in a VCS) or are intended + * to be unshared. + *
+ *

+ * Could be implemented e.g. by project types which know that certain files or folders in + * a project (e.g. src/) are intended for VCS sharing while others + * (e.g. build/) are not. + *

+ *

+ * Note that the Project API module registers a default implementation of this query + * which delegates to the project which owns the queried file, if there is one. + * This is more efficient than searching instances in global lookup, so use that + * facility wherever possible. + *

+ *
+ *

+ * Threading note: implementors should avoid acquiring locks that might be held + * by other threads. Generally treat this interface similarly to SPIs in + * {@link org.openide.filesystems} with respect to threading semantics. + *

+ * @see org.netbeans.api.queries.SharabilityQuery + * @see AntProjectHelper.createSharabilityQuery(...) + * @author Jesse Glick + * @author Alexander Simon + * @since 1.27 + */ +public interface SharabilityQueryImplementation2 { + + /** + * Check whether a file or directory should be shared. + * If it is, it ought to be committed to a VCS if the user is using one. + * If it is not, it is either a disposable build product, or a per-user + * private file which is important but should not be shared. + * @param uri a normalized URI to check for sharability (may or may not yet exist). + * @return one of the {@link org.netbeans.api.queries.SharabilityQuery.Sharability}'s constant + */ + Sharability getSharability(URI uri); +} diff --git a/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java b/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java new file mode 100644 --- /dev/null +++ b/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java @@ -0,0 +1,135 @@ +/* + * 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 org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.netbeans.spi.queries.CollocationQueryImplementation2; + +/** + * + * @author Alexander Simon + */ +public class CollocationQuery2Test extends NbTestCase { + + public CollocationQuery2Test(String testMethod) { + super (testMethod); + } + + @Override + public void setUp() throws IOException { + MockServices.setServices(CollocationQuery2Test.CollocationQueryImplementation2Impl.class); + } + + public void testAreCollocated() throws Exception { + clearWorkDir(); + File base = getWorkDir(); + File proj1 = new File(base, "proj1"); + proj1.mkdirs(); + File proj3 = new File(proj1, "proj3"); + proj3.mkdirs(); + File proj2 = new File(base, "proj2"); + proj2.mkdirs(); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3)); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1)); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI())); + + // folder does not exist: + File proj4 = new File(base, "proj"); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + proj4.mkdirs(); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + + // files do not exist: + File file1 = new File(base, "file1.txt"); + File file2 = new File(base, "file1"); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI())); + + // passing the same parameter + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1)); + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI())); + } + + public static class CollocationQueryImplementation2Impl implements CollocationQueryImplementation2 { + + @Override + public boolean areCollocated(URI uri1, URI uri2) { + if (uri1.equals(uri2)) { + return true; + } + File file1 = new File(uri1); + File file2 = new File(uri2); + String f1 = file1.getPath(); + if ((file1.isDirectory() || !file1.exists()) && !f1.endsWith(File.separator)) { + f1 += File.separatorChar; + } + String f2 = file2.getAbsolutePath(); + if ((file2.isDirectory() || !file2.exists()) && !f2.endsWith(File.separator)) { + f2 += File.separatorChar; + } + return f1.startsWith(f2) || f2.startsWith(f1); + } + + @Override + public URI findRoot(URI file) { + return null; + } + + } +} diff --git a/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java b/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java new file mode 100644 --- /dev/null +++ b/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java @@ -0,0 +1,105 @@ +/* + * 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 org.netbeans.junit.NbTestCase; + +/** + * + * @author Alexander Simon + */ +public class CollocationQueryTest extends NbTestCase { + + public CollocationQueryTest(String testMethod) { + super (testMethod); + } + + @Override + public void setUp() throws IOException { + } + + public void testAreCollocated() throws Exception { + clearWorkDir(); + File base = getWorkDir(); + File proj1 = new File(base, "proj1"); + proj1.mkdirs(); + File proj3 = new File(proj1, "proj3"); + proj3.mkdirs(); + File proj2 = new File(base, "proj2"); + proj2.mkdirs(); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3)); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI())); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1)); + assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI())); + + // folder does not exist: + File proj4 = new File(base, "proj"); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + proj4.mkdirs(); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI())); + + // files do not exist: + File file1 = new File(base, "file1.txt"); + File file2 = new File(base, "file1"); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1)); + assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI())); + + // passing the same parameter + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1)); + assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI())); + } + +} diff --git a/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java b/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java new file mode 100644 --- /dev/null +++ b/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java @@ -0,0 +1,208 @@ +/* + * 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.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * + * @author Alexander Simon + */ +public class SharabilityQueryTest extends NbTestCase { + + public SharabilityQueryTest(String testMethod) { + super (testMethod); + } + + @Override + public void setUp() throws IOException { + clearWorkDir(); + MockServices.setServices(SharabilityQueryImplementationImpl.class, SharabilityQueryImplementation2Impl.class); + } + + public void testSharableBridge2Old() throws IOException { + File file = new File("/home/user/aFile.sharable"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.SHARABLE, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testSharableBridge2New() throws IOException { + File file = new File("/home/user/aFile.sharable2"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.SHARABLE, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable2"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testNotSharableBridge2Old() throws IOException { + File file = new File("/home/user/aFile.not_sharable"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.NOT_SHARABLE, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testNotSharableBridge2New() throws IOException { + File file = new File("/home/user/aFile.not_sharable2"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.NOT_SHARABLE, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable2"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testMixedBridge2Old() throws IOException { + File file = new File("/home/user/aFile.mixed"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.MIXED, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.MIXED, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testMixedBridge2New() throws IOException { + File file = new File("/home/user/aFile.mixed2"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.MIXED, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.MIXED, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed2"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testUnknown() throws IOException { + File file = new File("/home/user/aFile.txt"); + int sharability = SharabilityQuery.getSharability(file); + assertEquals(SharabilityQuery.UNKNOWN, sharability); + URI uri = file.toURI(); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability2); + FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "txt"); + assertEquals(sharability2, SharabilityQuery.getSharability(fo)); + } + + public void testNormalized() throws IOException { + File file = new File("/home/user/../aFile.txt"); + Exception exception = null; + try { + SharabilityQuery.getSharability(file); + } catch (IllegalArgumentException e) { + exception = e; + } + assertNotNull(exception); + URI uri = file.toURI(); + exception = null; + try { + SharabilityQuery.getSharability(uri); + } catch (IllegalArgumentException e) { + exception = e; + } + assertNotNull(exception); + } + + public void testRfs() throws IOException, URISyntaxException { + URI uri = new URI("rfs", "tester", "localhost", 22, "/home/tester/aFile.sharable", null, null); + Sharability sharability = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability); + uri = new URI("rfs", "tester", "localhost", 22, "/home/tester/aFile.sharable2", null, null); + Sharability sharability2 = SharabilityQuery.getSharability(uri); + assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2); + } + + public static class SharabilityQueryImplementationImpl implements SharabilityQueryImplementation { + + @Override + public int getSharability(File file) { + String path = file.getAbsolutePath(); + if (path.endsWith(".sharable")) { + return SharabilityQuery.SHARABLE; + } else if (path.endsWith(".not_sharable")) { + return SharabilityQuery.NOT_SHARABLE; + } else if (path.endsWith(".mixed")) { + return SharabilityQuery.MIXED; + } + return SharabilityQuery.UNKNOWN; + } + } + + public static class SharabilityQueryImplementation2Impl implements SharabilityQueryImplementation2 { + + @Override + public Sharability getSharability(URI uri) { + String path = uri.getPath(); + if (path.endsWith(".sharable2")) { + return SharabilityQuery.Sharability.SHARABLE; + } else if (path.endsWith(".not_sharable2")) { + return SharabilityQuery.Sharability.NOT_SHARABLE; + } else if (path.endsWith(".mixed2")) { + return SharabilityQuery.Sharability.MIXED; + } + return SharabilityQuery.Sharability.UNKNOWN; + } + } +} diff --git a/refactoring.api/nbproject/project.xml b/refactoring.api/nbproject/project.xml --- a/refactoring.api/nbproject/project.xml +++ b/refactoring.api/nbproject/project.xml @@ -82,7 +82,7 @@ 1 - 1.8 + 1.27
diff --git a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java b/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java --- a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java +++ b/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java @@ -443,7 +443,7 @@ dob = DataObject.find(f); for (Iterator j = dob.files().iterator(); j.hasNext();) { FileObject file = (FileObject) j.next(); - if (SharabilityQuery.getSharability(FileUtil.toFile(file)) == SharabilityQuery.SHARABLE) { + if (SharabilityQuery.getSharability(file) == SharabilityQuery.Sharability.SHARABLE) { allFiles.add(file); } }