This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 198060
Collapse All | Expand All

(-)a/apisupport.wizards/nbproject/project.xml (-1 / +1 lines)
Lines 126-132 Link Here
126
                    <compile-dependency/>
126
                    <compile-dependency/>
127
                    <run-dependency>
127
                    <run-dependency>
128
                        <release-version>1</release-version>
128
                        <release-version>1</release-version>
129
                        <specification-version>1.26</specification-version>
129
                        <specification-version>1.27</specification-version>
130
                    </run-dependency>
130
                    </run-dependency>
131
                </dependency>
131
                </dependency>
132
                <dependency>
132
                <dependency>
(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java (-6 / +6 lines)
Lines 307-313 Link Here
307
        SourceGroup group = grps[0];
307
        SourceGroup group = grps[0];
308
        Collection<FileObject> files = new ArrayList<FileObject>();
308
        Collection<FileObject> files = new ArrayList<FileObject>();
309
        collectFiles(group.getRootFolder(), files,
309
        collectFiles(group.getRootFolder(), files,
310
                SharabilityQuery.getSharability(FileUtil.toFile(group.getRootFolder())));
310
                SharabilityQuery.getSharability(group.getRootFolder()));
311
        createZipFile(target, group.getRootFolder(), files);
311
        createZipFile(target, group.getRootFolder(), files);
312
    }
312
    }
313
313
Lines 320-338 Link Here
320
        ImageIO.write(image, "png", target);
320
        ImageIO.write(image, "png", target);
321
    }
321
    }
322
    
322
    
323
    private static void collectFiles(FileObject parent, Collection<FileObject> accepted, int parentSharab) {
323
    private static void collectFiles(FileObject parent, Collection<FileObject> accepted, SharabilityQuery.Sharability parentSharab) {
324
        for (FileObject fo : parent.getChildren()) {
324
        for (FileObject fo : parent.getChildren()) {
325
            if (!VisibilityQuery.getDefault().isVisible(fo)) {
325
            if (!VisibilityQuery.getDefault().isVisible(fo)) {
326
                // #66765: ignore invisible files/folders, like CVS subdirectory
326
                // #66765: ignore invisible files/folders, like CVS subdirectory
327
                continue;
327
                continue;
328
            }
328
            }
329
            int sharab;
329
            SharabilityQuery.Sharability sharab;
330
            if (parentSharab == SharabilityQuery.UNKNOWN || parentSharab == SharabilityQuery.MIXED) {
330
            if (parentSharab == SharabilityQuery.Sharability.UNKNOWN || parentSharab == SharabilityQuery.Sharability.MIXED) {
331
                sharab = SharabilityQuery.getSharability(FileUtil.toFile(fo));
331
                sharab = SharabilityQuery.getSharability(fo);
332
            } else {
332
            } else {
333
                sharab = parentSharab;
333
                sharab = parentSharab;
334
            }
334
            }
335
            if (sharab == SharabilityQuery.NOT_SHARABLE) {
335
            if (sharab == SharabilityQuery.Sharability.NOT_SHARABLE) {
336
                continue;
336
                continue;
337
            }
337
            }
338
            if (fo.isData() && !fo.isVirtual()) {
338
            if (fo.isData() && !fo.isVirtual()) {
(-)a/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
4
OpenIDE-Module-Specification-Version: 1.41
4
OpenIDE-Module-Specification-Version: 1.42
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
7
7
(-)a/projectapi/nbproject/project.xml (-1 / +1 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.9</specification-version>
58
                        <specification-version>1.27</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery.java (+1 lines)
Lines 54-59 Link Here
54
 * Delegates {@link SharabilityQuery} to implementations in project lookup.
54
 * Delegates {@link SharabilityQuery} to implementations in project lookup.
55
 * @author Jesse Glick
55
 * @author Jesse Glick
56
 */
56
 */
57
@SuppressWarnings("deprecation")
57
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.SharabilityQueryImplementation.class)
58
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.SharabilityQueryImplementation.class)
58
public class ProjectSharabilityQuery implements SharabilityQueryImplementation {
59
public class ProjectSharabilityQuery implements SharabilityQueryImplementation {
59
60
(-)a/projectapi/src/org/netbeans/modules/projectapi/ProjectSharabilityQuery2.java (+73 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.projectapi;
43
44
import org.netbeans.spi.queries.SharabilityQueryImplementation2;
45
import java.net.URI;
46
import org.netbeans.api.project.FileOwnerQuery;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.queries.SharabilityQuery;
49
import org.netbeans.api.queries.SharabilityQuery.Sharability;
50
51
/**
52
 * Delegates {@link SharabilityQuery} to implementations in project lookup.
53
 * @author Jesse Glick
54
 * @author Alexander Simon
55
 */
56
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.queries.SharabilityQueryImplementation2.class)
57
public class ProjectSharabilityQuery2 implements SharabilityQueryImplementation2 {
58
59
    public ProjectSharabilityQuery2() {}
60
    
61
    @Override
62
    public Sharability getSharability(URI uri) {
63
        Project p = FileOwnerQuery.getOwner(uri);
64
        if (p != null) {
65
            SharabilityQueryImplementation2 sqi = p.getLookup().lookup(SharabilityQueryImplementation2.class);
66
            if (sqi != null) {
67
                return sqi.getSharability(uri);
68
            }
69
        }
70
        return Sharability.UNKNOWN;
71
    }
72
    
73
}
(-)a/projectui/nbproject/project.xml (+1 lines)
Lines 118-123 Link Here
118
                    <compile-dependency/>
118
                    <compile-dependency/>
119
                    <run-dependency>
119
                    <run-dependency>
120
                        <release-version>1</release-version>
120
                        <release-version>1</release-version>
121
                        <specification-version>1.27</specification-version>
121
                    </run-dependency>
122
                    </run-dependency>
122
                </dependency>
123
                </dependency>
123
                <dependency>
124
                <dependency>
(-)a/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java (-5 / +4 lines)
Lines 139-149 Link Here
139
        while (e.hasMoreElements()) {
139
        while (e.hasMoreElements()) {
140
            try {
140
            try {
141
                FileObject em = e.nextElement();
141
                FileObject em = e.nextElement();
142
                File f = FileUtil.toFile(fo);
142
                SharabilityQuery.Sharability share = SharabilityQuery.Sharability.UNKNOWN;
143
                int share = SharabilityQuery.UNKNOWN;
144
                if (checkShare) {
143
                if (checkShare) {
145
                    share = SharabilityQuery.getSharability(f);
144
                    share = SharabilityQuery.getSharability(fo);
146
                    if (share == SharabilityQuery.NOT_SHARABLE) {
145
                    if (share == SharabilityQuery.Sharability.NOT_SHARABLE) {
147
                        continue;
146
                        continue;
148
                    }
147
                    }
149
                }
148
                }
Lines 154-160 Link Here
154
                        h.progress(progressMessage(p), Math.min(++counter.start, counter.end));
153
                        h.progress(progressMessage(p), Math.min(++counter.start, counter.end));
155
                    }
154
                    }
156
                }
155
                }
157
                checkShare = share != SharabilityQuery.SHARABLE;
156
                checkShare = share != SharabilityQuery.Sharability.SHARABLE;
158
                // don't need to check the sharability if the current folder is marked as recursively sharable
157
                // don't need to check the sharability if the current folder is marked as recursively sharable
159
                
158
                
160
                processFolderChildren(em, projects, h, counter, checkShare);
159
                processFolderChildren(em, projects, h, counter, checkShare);
(-)a/projectuiapi/nbproject/project.xml (-1 / +1 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.5</specification-version>
85
                        <specification-version>1.27</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/projectuiapi/src/org/netbeans/modules/project/uiapi/DefaultProjectOperationsImplementation.java (-1 / +1 lines)
Lines 558-564 Link Here
558
        }
558
        }
559
        
559
        
560
        //#109580
560
        //#109580
561
        if (SharabilityQuery.getSharability(FileUtil.toFile(from)) == SharabilityQuery.NOT_SHARABLE) {
561
        if (SharabilityQuery.getSharability(from) == SharabilityQuery.Sharability.NOT_SHARABLE) {
562
            return;
562
            return;
563
        }
563
        }
564
        
564
        
(-)a/queries/apichanges.xml (+30 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
       <change id="SharabilityQueryBasedOnURI">
111
        <api name="general"/>
112
        <summary>SharabilityQuery and CollocationQuery extended to use URI</summary>
113
        <version major="1" minor="27"/>
114
        <date day="13" month="01" year="2012"/>
115
        <author login="alexvsimon"/>
116
        <compatibility addition="yes" binary="compatible" semantic="compatible" source="compatible">
117
        </compatibility>
118
        <description>
119
          <p>
120
             Added new methods CollocationQuery.areCollocated(URI, URI) and CollocationQuery.findRoot(URI).
121
             Methods query all CollocationQueryImplementation (if possible) and CollocationQueryImplementation2 instances found in global lookup.
122
             Deprecated existing methods CollocationQuery.areCollocated(File, File) and CollocationQuery.findRoot(File).
123
             Methods query all CollocationQueryImplementation and CollocationQueryImplementation2 instances found in global lookup.
124
          </p>
125
          <p>
126
             Added new methods SharabilityQuery.getSharability(URI) and SharabilityQuery.getSharability(FileObject).
127
             Methods query all SharabilityQueryImplementation (if possible) and SharabilityQueryImplementation2 instances found in global lookup.
128
             Deprecated existing method SharabilityQuery.getSharability(File).
129
             Method query all SharabilityQueryImplementation and SharabilityQueryImplementation2 instances found in global lookup.
130
          </p>
131
        </description>
132
        <class package="org.netbeans.api.queries" name="CollocationQuery"/>
133
        <class package="org.netbeans.api.queries" name="SharabilityQuery"/>
134
        <class package="org.netbeans.spi.queries" name="CollocationQueryImplementation"/>
135
        <class package="org.netbeans.spi.queries" name="CollocationQueryImplementation2"/>
136
        <class package="org.netbeans.spi.queries" name="SharabilityQueryImplementation"/>
137
        <class package="org.netbeans.spi.queries" name="SharabilityQueryImplementation2"/>
138
        <issue number="198060"/>
139
      </change>
110
      <change id="FileBasedIsVisible">
140
      <change id="FileBasedIsVisible">
111
        <api name="general"/>
141
        <api name="general"/>
112
        <summary>VisibilityQuery.isVisible(File) added</summary>
142
        <summary>VisibilityQuery.isVisible(File) added</summary>
(-)a/queries/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.queries/1
2
OpenIDE-Module: org.netbeans.modules.queries/1
3
OpenIDE-Module-Specification-Version: 1.26
3
OpenIDE-Module-Specification-Version: 1.27
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/queries/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/queries/Bundle.properties
5
5
(-)a/queries/src/org/netbeans/api/queries/CollocationQuery.java (-3 / +88 lines)
Lines 45-64 Link Here
45
package org.netbeans.api.queries;
45
package org.netbeans.api.queries;
46
46
47
import java.io.File;
47
import java.io.File;
48
import java.net.URI;
48
import org.netbeans.spi.queries.CollocationQueryImplementation;
49
import org.netbeans.spi.queries.CollocationQueryImplementation;
50
import org.netbeans.spi.queries.CollocationQueryImplementation2;
49
import org.openide.filesystems.FileUtil;
51
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Lookup;
52
import org.openide.util.Lookup;
51
53
52
/**
54
/**
53
 * Find out whether some files logically belong in one directory tree,
55
 * Find out whether some files logically belong in one directory tree,
54
 * for example as part of a VCS checkout.
56
 * for example as part of a VCS checkout.
55
 * @see CollocationQueryImplementation
57
 * @see CollocationQueryImplementation2
56
 * @author Jesse Glick
58
 * @author Jesse Glick
57
 */
59
 */
58
public final class CollocationQuery {
60
public final class CollocationQuery {
59
61
60
    private static final Lookup.Result<CollocationQueryImplementation> implementations =
62
    private static final Lookup.Result<CollocationQueryImplementation> implementations =
61
        Lookup.getDefault().lookupResult(CollocationQueryImplementation.class);
63
        Lookup.getDefault().lookupResult(CollocationQueryImplementation.class);
64
    private static final Lookup.Result<CollocationQueryImplementation2> implementations2 =
65
        Lookup.getDefault().lookupResult(CollocationQueryImplementation2.class);
62
    
66
    
63
    private CollocationQuery() {}
67
    private CollocationQuery() {}
64
    
68
    
Lines 70-77 Link Here
70
     * @param file1 one file
74
     * @param file1 one file
71
     * @param file2 another file
75
     * @param file2 another file
72
     * @return true if they are probably part of one logical tree
76
     * @return true if they are probably part of one logical tree
77
     * @deprecated Use {@link #areCollocated(java.net.URI, java.net.URI)} instead.
73
     */
78
     */
74
    public static boolean areCollocated(File file1, File file2) {
79
    @Deprecated public static boolean areCollocated(File file1, File file2) {
75
        if (!file1.equals(FileUtil.normalizeFile(file1))) {
80
        if (!file1.equals(FileUtil.normalizeFile(file1))) {
76
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
81
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
77
                "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1));  // NOI18N
82
                "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1));  // NOI18N
Lines 80-85 Link Here
80
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
85
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
81
                "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2));  // NOI18N
86
                "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2));  // NOI18N
82
        }
87
        }
88
        URI uri1 = file1.toURI();
89
        URI uri2 = file2.toURI();
90
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
91
            if (cqi.areCollocated(uri1, uri2)) {
92
                return true;
93
            }
94
        }
83
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
95
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
84
            if (cqi.areCollocated(file1, file2)) {
96
            if (cqi.areCollocated(file1, file2)) {
85
                return true;
97
                return true;
Lines 87-104 Link Here
87
        }
99
        }
88
        return false;
100
        return false;
89
    }
101
    }
102
103
    /**
104
     * Check whether two files are logically part of one directory tree.
105
     * For example, if both files are stored in CVS, with the same server
106
     * (<code>CVSROOT</code>) they might be considered collocated.
107
     * If nothing is known about them, return false.
108
     * @param file1 one file
109
     * @param file2 another file
110
     * @return true if they are probably part of one logical tree
111
     * @since 1.27
112
     */
113
    public static boolean areCollocated(URI file1, URI file2) {
114
        if (!file1.equals(file1.normalize())) {
115
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
116
                "normalized. Was "+file1+" instead of "+file1.normalize());  // NOI18N
117
        }
118
        if (!file2.equals(file2.normalize())) {
119
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
120
                "normalized. Was "+file2+" instead of "+file2.normalize());  // NOI18N
121
        }
122
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
123
            if (cqi.areCollocated(file1, file2)) {
124
                return true;
125
            }
126
        }
127
        if ("file".equals(file1.getScheme()) && "file".equals(file2.getScheme())) { // NOI18N
128
            File f1 = FileUtil.normalizeFile(new File(file1));
129
            File f2 = FileUtil.normalizeFile(new File(file2));
130
            for (CollocationQueryImplementation cqi : implementations.allInstances()) {
131
                if (cqi.areCollocated(f1, f2)) {
132
                    return true;
133
                }
134
            }
135
        }
136
        return false;
137
    }
90
    
138
    
91
    /**
139
    /**
92
     * Find a root of a logical tree containing this file, if any.
140
     * Find a root of a logical tree containing this file, if any.
93
     * @param file a file on disk
141
     * @param file a file on disk
94
     * @return an ancestor directory which is the root of a logical tree,
142
     * @return an ancestor directory which is the root of a logical tree,
95
     *         if any (else null)
143
     *         if any (else null)
144
     * @deprecated Use {@link #findRoot(java.net.URI)} instead.
96
     */
145
     */
97
    public static File findRoot(File file) {
146
    @Deprecated public static File findRoot(File file) {
98
        if (!file.equals(FileUtil.normalizeFile(file))) {
147
        if (!file.equals(FileUtil.normalizeFile(file))) {
99
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
148
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
100
                "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file));  // NOI18N
149
                "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file));  // NOI18N
101
        }
150
        }
151
        URI uri = file.toURI();
152
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
153
            URI root = cqi.findRoot(uri);
154
            if (root != null) {
155
                return new File(root);
156
            }
157
        }
102
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
158
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
103
            File root = cqi.findRoot(file);
159
            File root = cqi.findRoot(file);
104
            if (root != null) {
160
            if (root != null) {
Lines 108-111 Link Here
108
        return null;
164
        return null;
109
    }
165
    }
110
    
166
    
167
    /**
168
     * Find a root of a logical tree containing this file, if any.
169
     * @param file a file on disk
170
     * @return an ancestor directory which is the root of a logical tree,
171
     *         if any (else null)
172
     * @since 1.27
173
     */
174
    public static URI findRoot(URI file) {
175
        if (!file.equals(file.normalize())) {
176
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
177
                "normalized. Was "+file+" instead of "+file.normalize());  // NOI18N
178
        }
179
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
180
            URI root = cqi.findRoot(file);
181
            if (root != null) {
182
                return root;
183
            }
184
        }
185
        if ("file".equals(file.getScheme())) { // NOI18N
186
            File f = FileUtil.normalizeFile(new File(file));
187
            for (CollocationQueryImplementation cqi : implementations.allInstances()) {
188
                File root = cqi.findRoot(f);
189
                if (root != null) {
190
                    return root.toURI();
191
                }
192
            }
193
        }
194
        return null;
195
    }
111
}
196
}
(-)a/queries/src/org/netbeans/api/queries/SharabilityQuery.java (-7 / +121 lines)
Lines 45-51 Link Here
45
package org.netbeans.api.queries;
45
package org.netbeans.api.queries;
46
46
47
import java.io.File;
47
import java.io.File;
48
import java.net.URI;
49
import java.net.URISyntaxException;
50
import java.util.logging.Level;
51
import java.util.logging.Logger;
48
import org.netbeans.spi.queries.SharabilityQueryImplementation;
52
import org.netbeans.spi.queries.SharabilityQueryImplementation;
53
import org.netbeans.spi.queries.SharabilityQueryImplementation2;
54
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileStateInvalidException;
49
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Lookup;
57
import org.openide.util.Lookup;
51
import org.openide.util.Parameters;
58
import org.openide.util.Parameters;
Lines 62-68 Link Here
62
 * Unlike that method, the information is pulled by the VCS filesystem on
69
 * Unlike that method, the information is pulled by the VCS filesystem on
63
 * demand, which may be more reliable than ensuring that the information
70
 * demand, which may be more reliable than ensuring that the information
64
 * is pushed by a project type (or other implementor) eagerly.
71
 * is pushed by a project type (or other implementor) eagerly.
65
 * @see SharabilityQueryImplementation
72
 * @see SharabilityQueryImplementation2
66
 * @author Jesse Glick
73
 * @author Jesse Glick
67
 */
74
 */
68
public final class SharabilityQuery {
75
public final class SharabilityQuery {
Lines 70-114 Link Here
70
    private static final Lookup.Result<SharabilityQueryImplementation> implementations =
77
    private static final Lookup.Result<SharabilityQueryImplementation> implementations =
71
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class);
78
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class);
72
79
80
    private static final Lookup.Result<SharabilityQueryImplementation2> implementations2 =
81
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation2.class);
82
    
83
    private static final Logger LOG = Logger.getLogger(SharabilityQuery.class.getName());
84
73
    /**
85
    /**
74
     * Constant indicating that nothing is known about whether a given
86
     * Constant indicating that nothing is known about whether a given
75
     * file should be considered sharable or not.
87
     * file should be considered sharable or not.
76
     * A client should therefore behave in the safest way it can.
88
     * A client should therefore behave in the safest way it can.
89
     * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#UNKNOWN} instead.
77
     */
90
     */
78
    public static final int UNKNOWN = 0;
91
    @Deprecated public static final int UNKNOWN = 0;
79
    
92
    
80
    /**
93
    /**
81
     * Constant indicating that the file or directory is sharable.
94
     * Constant indicating that the file or directory is sharable.
82
     * In the case of a directory, this means that all files and
95
     * In the case of a directory, this means that all files and
83
     * directories recursively contained in this directory are also
96
     * directories recursively contained in this directory are also
84
     * sharable.
97
     * sharable.
98
     * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#SHARABLE} instead.
85
     */
99
     */
86
    public static final int SHARABLE = 1;
100
    @Deprecated public static final int SHARABLE = 1;
87
    
101
    
88
    /**
102
    /**
89
     * Constant indicating that the file or directory is not sharable.
103
     * Constant indicating that the file or directory is not sharable.
90
     * In the case of a directory, this means that all files and
104
     * In the case of a directory, this means that all files and
91
     * directories recursively contained in this directory are also
105
     * directories recursively contained in this directory are also
92
     * not sharable.
106
     * not sharable.
107
     * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#NOT_SHARABLE} instead.
93
     */
108
     */
94
    public static final int NOT_SHARABLE = 2;
109
    @Deprecated public static final int NOT_SHARABLE = 2;
95
    
110
    
96
    /**
111
    /**
97
     * Constant indicating that a directory is sharable but files and
112
     * Constant indicating that a directory is sharable but files and
98
     * directories recursively contained in it may or may not be sharable.
113
     * directories recursively contained in it may or may not be sharable.
99
     * A client interested in children of this directory should explicitly
114
     * A client interested in children of this directory should explicitly
100
     * ask about each in turn.
115
     * ask about each in turn.
116
     * @deprecated Use {@link org.netbeans.api.queries.SharabilityQuery.Sharability#MIXED} instead.
101
     */
117
     */
102
    public static final int MIXED = 3;
118
    @Deprecated public static final int MIXED = 3;
119
120
    /**
121
     * Sharability constants.
122
     * @since 1.27
123
     */
124
    public enum Sharability {
125
        /**
126
        * Constant indicating that nothing is known about whether a given
127
        * file should be considered sharable or not.
128
        * A client should therefore behave in the safest way it can.
129
        */
130
        UNKNOWN,
131
132
        /**
133
        * Constant indicating that the file or directory is sharable.
134
        * In the case of a directory, this means that all files and
135
        * directories recursively contained in this directory are also
136
        * sharable.
137
        */
138
        SHARABLE,
139
140
        /**
141
        * Constant indicating that the file or directory is not sharable.
142
        * In the case of a directory, this means that all files and
143
        * directories recursively contained in this directory are also
144
        * not sharable.
145
        */
146
        NOT_SHARABLE,
147
148
        /**
149
        * Constant indicating that a directory is sharable but files and
150
        * directories recursively contained in it may or may not be sharable.
151
        * A client interested in children of this directory should explicitly
152
        * ask about each in turn.
153
        */
154
        MIXED;
155
    }
103
    
156
    
104
    private SharabilityQuery() {}
157
    private SharabilityQuery() {}
105
    
158
    
106
    /**
159
    /**
107
     * Check whether an existing file is sharable.
160
     * Check whether an existing file is sharable.
108
     * @param file a file or directory (may or may not already exist); should be {@linkplain FileUtil#normalizeFile normalized}
161
     * @param file a file or directory (may or may not already exist); should be {@linkplain FileUtil#normalizeFile normalized}
109
     * @return one of the constants in this class
162
     * @return an answer or {@code UNKNOWN}
163
     * @deprecated Use {@link #getSharability(java.net.URI)} instead.
110
     */
164
     */
111
    public static int getSharability(File file) {
165
    @Deprecated public static int getSharability(File file) {
112
        Parameters.notNull("file", file);
166
        Parameters.notNull("file", file);
113
        boolean asserts = false;
167
        boolean asserts = false;
114
        assert asserts = true;
168
        assert asserts = true;
Lines 118-123 Link Here
118
                throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile);
172
                throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile);
119
            }
173
            }
120
        }
174
        }
175
        URI uri = null;
176
        for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) {
177
            if (uri == null) {
178
                uri = file.toURI();
179
            }
180
            Sharability x = sqi.getSharability(uri);
181
            if (x != Sharability.UNKNOWN) {
182
                return x.ordinal();
183
            }
184
        }
121
        for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
185
        for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
122
            int x = sqi.getSharability(file);
186
            int x = sqi.getSharability(file);
123
            if (x != UNKNOWN) {
187
            if (x != UNKNOWN) {
Lines 127-130 Link Here
127
        return UNKNOWN;
191
        return UNKNOWN;
128
    }
192
    }
129
    
193
    
194
    /**
195
     * Check whether an existing file is sharable.
196
     * @param uri a file or directory (may or may not already exist); should be normalized.
197
     * @return an answer or {@code UNKNOWN}
198
     * @since 1.27
199
     */
200
    public static Sharability getSharability(URI uri) {
201
        Parameters.notNull("uri", uri);
202
        boolean asserts = false;
203
        assert asserts = true;
204
        if (asserts) {
205
            URI normUri = uri.normalize();
206
            if (!uri.equals(normUri)) {
207
                throw new IllegalArgumentException("Must pass a normalized URI: " + uri + " vs. " + normUri);
208
            }
209
        }
210
        for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) {
211
            Sharability x = sqi.getSharability(uri);
212
            if (x != Sharability.UNKNOWN) {
213
                return x;
214
            }
215
        }
216
        if ("file".equals(uri.getScheme())) { // NOI18N
217
            File file = FileUtil.normalizeFile(new File(uri));
218
            for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
219
                int x = sqi.getSharability(file);
220
                if (x != UNKNOWN) {
221
                    return Sharability.values()[x];
222
                }
223
            }
224
        }
225
        return Sharability.UNKNOWN;
226
    }
227
    
228
    /**
229
     * Check whether an existing file is sharable.
230
     * @param fo a file or directory; should be normalized.
231
     * @return an answer or {@code UNKNOWN}
232
     * @since 1.27
233
     */
234
    public static Sharability getSharability(FileObject fo) {
235
        try {
236
            return getSharability(fo.getURL().toURI());
237
        } catch (URISyntaxException ex) {
238
            LOG.log(Level.FINE, null, ex);
239
        } catch (FileStateInvalidException ex) {
240
            LOG.log(Level.FINE, null, ex);
241
        }
242
        return Sharability.UNKNOWN;
243
    }
130
}
244
}
(-)a/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation.java (-1 / +2 lines)
Lines 68-75 Link Here
68
 * </p>
68
 * </p>
69
 * @see org.netbeans.api.queries.CollocationQuery
69
 * @see org.netbeans.api.queries.CollocationQuery
70
 * @author Jesse Glick
70
 * @author Jesse Glick
71
 * @deprecated Use {@link org.netbeans.spi.queries.CollocationQueryImplementation2} instead.
71
 */
72
 */
72
public interface CollocationQueryImplementation {
73
@Deprecated public interface CollocationQueryImplementation {
73
    
74
    
74
    /**
75
    /**
75
     * Check whether two files are logically part of one directory tree.
76
     * Check whether two files are logically part of one directory tree.
(-)a/queries/src/org/netbeans/spi/queries/CollocationQueryImplementation2.java (+96 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.queries;
43
44
import java.net.URI;
45
46
/**
47
 * A query which should typically be provided by a VCS to give information
48
 * about whether some files can be considered part of one logical directory tree.
49
 * <p>
50
 * This should be treated as a heuristic, useful when deciding whether to use
51
 * absolute or relative links between path locations.
52
 * </p>
53
 * <p>
54
 * The file names might refer to nonexistent files. A provider may or may not
55
 * be able to say anything useful about them in this case.
56
 * </p>
57
 * <p>
58
 * File names passed to this query will already have been normalized according to
59
 * the semantics of {@link org.openide.filesystems.FileUtil#normalizeFile}.
60
 * </p>
61
 * <p>
62
 * Threading note: implementors should avoid acquiring locks that might be held
63
 * by other threads. Generally treat this interface similarly to SPIs in
64
 * {@link org.openide.filesystems} with respect to threading semantics.
65
 * </p>
66
 * @see org.netbeans.api.queries.CollocationQuery
67
 * @since 1.27
68
 * @author Jesse Glick
69
 * @author Alexander Simon
70
 */
71
public interface CollocationQueryImplementation2 {
72
    
73
    /**
74
     * Check whether two files are logically part of one directory tree.
75
     * For example, if both files are stored in CVS, with the same server
76
     * (<code>CVSROOT</code>) they might be considered collocated.
77
     * If they are to be collocated their absolute paths must share a
78
     * prefix directory, i.e. they must be located in the same filesystem root.
79
     * If nothing is known about them, return false.
80
     * @param file1 one file
81
     * @param file2 another file
82
     * @return true if they are probably part of one logical tree
83
     */
84
    boolean areCollocated(URI file1, URI file2);
85
    
86
    /**
87
     * Find a root of a logical tree containing this file, if any.
88
     * The path of the root (if there is one) must be a prefix of the path of the file.
89
     * @param file a file on disk (must be an absolute URI)
90
     * @return an ancestor directory which is the root of a logical tree,
91
     *         if any (else null) (must be an absolute URI)
92
     */
93
    URI findRoot(URI file);
94
    
95
}
96
(-)a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java (-1 / +4 lines)
Lines 69-77 Link Here
69
 * </p>
69
 * </p>
70
 * @see org.netbeans.api.queries.SharabilityQuery
70
 * @see org.netbeans.api.queries.SharabilityQuery
71
 * @see <a href="@org-netbeans-modules-project-ant@/org/netbeans/spi/project/support/ant/AntProjectHelper.html#createSharabilityQuery(java.lang.String[],%20java.lang.String[])"><code>AntProjectHelper.createSharabilityQuery(...)</code></a>
71
 * @see <a href="@org-netbeans-modules-project-ant@/org/netbeans/spi/project/support/ant/AntProjectHelper.html#createSharabilityQuery(java.lang.String[],%20java.lang.String[])"><code>AntProjectHelper.createSharabilityQuery(...)</code></a>
72
 * @since 1.27
72
 * @author Jesse Glick
73
 * @author Jesse Glick
74
 * @deprecated Use {@link org.netbeans.spi.queries.SharabilityQueryImplementation2} instead.
75
 * 
73
 */
76
 */
74
public interface SharabilityQueryImplementation {
77
@Deprecated public interface SharabilityQueryImplementation {
75
    
78
    
76
    /**
79
    /**
77
     * Check whether a file or directory should be shared.
80
     * Check whether a file or directory should be shared.
(-)a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation2.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.queries;
43
44
import java.net.URI;
45
import org.netbeans.api.queries.SharabilityQuery.Sharability;
46
47
/**
48
 * Determine whether files should be shared (for example in a VCS) or are intended
49
 * to be unshared.
50
 * <div class="nonnormative">
51
 * <p>
52
 * Could be implemented e.g. by project types which know that certain files or folders in
53
 * a project (e.g. <samp>src/</samp>) are intended for VCS sharing while others
54
 * (e.g. <samp>build/</samp>) are not.
55
 * </p>
56
 * <p>
57
 * Note that the Project API module registers a default implementation of this query
58
 * which delegates to the project which owns the queried file, if there is one.
59
 * This is more efficient than searching instances in global lookup, so use that
60
 * facility wherever possible.
61
 * </p>
62
 * </div>
63
 * <p>
64
 * Threading note: implementors should avoid acquiring locks that might be held
65
 * by other threads. Generally treat this interface similarly to SPIs in
66
 * {@link org.openide.filesystems} with respect to threading semantics.
67
 * </p>
68
 * @see org.netbeans.api.queries.SharabilityQuery
69
 * @see <a href="@org-netbeans-modules-project-ant@/org/netbeans/spi/project/support/ant/AntProjectHelper.html#createSharabilityQuery(java.lang.String[],%20java.lang.String[])"><code>AntProjectHelper.createSharabilityQuery(...)</code></a>
70
 * @author Jesse Glick
71
 * @author Alexander Simon
72
 * @since 1.27
73
 */
74
public interface SharabilityQueryImplementation2 {
75
    
76
    /**
77
     * Check whether a file or directory should be shared.
78
     * If it is, it ought to be committed to a VCS if the user is using one.
79
     * If it is not, it is either a disposable build product, or a per-user
80
     * private file which is important but should not be shared.
81
     * @param uri a normalized URI to check for sharability (may or may not yet exist).
82
     * @return one of the {@link org.netbeans.api.queries.SharabilityQuery.Sharability}'s constant
83
     */
84
    Sharability getSharability(URI uri);
85
}
(-)a/queries/test/unit/src/org/netbeans/api/queries/CollocationQuery2Test.java (+135 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.queries;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.net.URI;
47
import org.netbeans.junit.MockServices;
48
import org.netbeans.junit.NbTestCase;
49
import org.netbeans.spi.queries.CollocationQueryImplementation2;
50
51
/**
52
 *
53
 * @author Alexander Simon
54
 */
55
public class CollocationQuery2Test extends NbTestCase {
56
    
57
    public CollocationQuery2Test(String testMethod) {
58
        super (testMethod);
59
    }
60
    
61
    @Override
62
    public void setUp() throws IOException {
63
        MockServices.setServices(CollocationQuery2Test.CollocationQueryImplementation2Impl.class);
64
    }
65
    
66
    public void testAreCollocated() throws Exception {
67
        clearWorkDir();
68
        File base = getWorkDir();
69
        File proj1 = new File(base, "proj1");
70
        proj1.mkdirs();
71
        File proj3 = new File(proj1, "proj3");
72
        proj3.mkdirs();
73
        File proj2 = new File(base, "proj2");
74
        proj2.mkdirs();
75
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3));
76
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI()));
77
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1));
78
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI()));
79
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2));
80
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI()));
81
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1));
82
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI()));
83
        
84
        // folder does not exist:
85
        File proj4 = new File(base, "proj");
86
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4));
87
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI()));
88
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1));
89
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI()));
90
        proj4.mkdirs();
91
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4));
92
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI()));
93
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1));
94
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI()));
95
        
96
        // files do not exist:
97
        File file1 = new File(base, "file1.txt");
98
        File file2 = new File(base, "file1");
99
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2));
100
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
101
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1));
102
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI()));
103
        
104
        // passing the same parameter
105
        assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1));
106
        assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI()));
107
    }
108
109
    public static class CollocationQueryImplementation2Impl implements CollocationQueryImplementation2 {
110
111
        @Override
112
        public boolean areCollocated(URI uri1, URI uri2) {
113
            if (uri1.equals(uri2)) {
114
                return true;
115
            }
116
            File file1 = new File(uri1);
117
            File file2 = new File(uri2);
118
            String f1 = file1.getPath();
119
            if ((file1.isDirectory() || !file1.exists()) && !f1.endsWith(File.separator)) {
120
                f1 += File.separatorChar;
121
            }
122
            String f2 = file2.getAbsolutePath();
123
            if ((file2.isDirectory() || !file2.exists()) && !f2.endsWith(File.separator)) {
124
                f2 += File.separatorChar;
125
            }
126
            return f1.startsWith(f2) || f2.startsWith(f1);
127
        }
128
129
        @Override
130
        public URI findRoot(URI file) {
131
            return null;
132
        }
133
134
    }
135
}
(-)a/queries/test/unit/src/org/netbeans/api/queries/CollocationQueryTest.java (+105 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.queries;
43
44
import java.io.File;
45
import java.io.IOException;
46
import org.netbeans.junit.NbTestCase;
47
48
/**
49
 *
50
 * @author Alexander Simon
51
 */
52
public class CollocationQueryTest extends NbTestCase {
53
    
54
    public CollocationQueryTest(String testMethod) {
55
        super (testMethod);
56
    }
57
    
58
    @Override
59
    public void setUp() throws IOException {
60
    }
61
    
62
    public void testAreCollocated() throws Exception {
63
        clearWorkDir();
64
        File base = getWorkDir();
65
        File proj1 = new File(base, "proj1");
66
        proj1.mkdirs();
67
        File proj3 = new File(proj1, "proj3");
68
        proj3.mkdirs();
69
        File proj2 = new File(base, "proj2");
70
        proj2.mkdirs();
71
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1, proj3));
72
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj3.toURI()));
73
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3, proj1));
74
        assertTrue("Must be collocated", CollocationQuery.areCollocated(proj3.toURI(), proj1.toURI()));
75
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj2));
76
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj2.toURI()));
77
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2, proj1));
78
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj2.toURI(), proj1.toURI()));
79
        
80
        // folder does not exist:
81
        File proj4 = new File(base, "proj");
82
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4));
83
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI()));
84
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1));
85
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI()));
86
        proj4.mkdirs();
87
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1, proj4));
88
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj1.toURI(), proj4.toURI()));
89
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4, proj1));
90
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(proj4.toURI(), proj1.toURI()));
91
        
92
        // files do not exist:
93
        File file1 = new File(base, "file1.txt");
94
        File file2 = new File(base, "file1");
95
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1, file2));
96
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file1.toURI(), file2.toURI()));
97
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2, file1));
98
        assertFalse("Cannot be collocated", CollocationQuery.areCollocated(file2.toURI(), file1.toURI()));
99
        
100
        // passing the same parameter
101
        assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1, proj1));
102
        assertTrue("A file must be collocated with itself", CollocationQuery.areCollocated(proj1.toURI(), proj1.toURI()));
103
    }
104
105
}
(-)a/queries/test/unit/src/org/netbeans/api/queries/SharabilityQueryTest.java (+208 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.queries;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.net.URI;
47
import java.net.URISyntaxException;
48
import org.netbeans.api.queries.SharabilityQuery.Sharability;
49
import org.netbeans.junit.MockServices;
50
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.spi.queries.SharabilityQueryImplementation;
52
import org.netbeans.spi.queries.SharabilityQueryImplementation2;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
55
56
/**
57
 *
58
 * @author Alexander Simon
59
 */
60
public class SharabilityQueryTest extends NbTestCase {
61
    
62
    public SharabilityQueryTest(String testMethod) {
63
        super (testMethod);
64
    }
65
    
66
    @Override
67
    public void setUp() throws IOException {
68
        clearWorkDir();
69
        MockServices.setServices(SharabilityQueryImplementationImpl.class, SharabilityQueryImplementation2Impl.class);
70
    }
71
    
72
    public void testSharableBridge2Old() throws IOException {
73
        File file = new File("/home/user/aFile.sharable");
74
        int sharability = SharabilityQuery.getSharability(file);
75
        assertEquals(SharabilityQuery.SHARABLE, sharability);
76
        URI uri = file.toURI();
77
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
78
        assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2);
79
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable");
80
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
81
    }
82
83
    public void testSharableBridge2New() throws IOException {
84
        File file = new File("/home/user/aFile.sharable2");
85
        int sharability = SharabilityQuery.getSharability(file);
86
        assertEquals(SharabilityQuery.SHARABLE, sharability);
87
        URI uri = file.toURI();
88
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
89
        assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2);
90
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "sharable2");
91
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
92
    }
93
94
    public void testNotSharableBridge2Old() throws IOException {
95
        File file = new File("/home/user/aFile.not_sharable");
96
        int sharability = SharabilityQuery.getSharability(file);
97
        assertEquals(SharabilityQuery.NOT_SHARABLE, sharability);
98
        URI uri = file.toURI();
99
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
100
        assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2);
101
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable");
102
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
103
    }
104
105
    public void testNotSharableBridge2New() throws IOException {
106
        File file = new File("/home/user/aFile.not_sharable2");
107
        int sharability = SharabilityQuery.getSharability(file);
108
        assertEquals(SharabilityQuery.NOT_SHARABLE, sharability);
109
        URI uri = file.toURI();
110
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
111
        assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, sharability2);
112
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "not_sharable2");
113
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
114
    }
115
    
116
    public void testMixedBridge2Old() throws IOException {
117
        File file = new File("/home/user/aFile.mixed");
118
        int sharability = SharabilityQuery.getSharability(file);
119
        assertEquals(SharabilityQuery.MIXED, sharability);
120
        URI uri = file.toURI();
121
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
122
        assertEquals(SharabilityQuery.Sharability.MIXED, sharability2);
123
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed");
124
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
125
    }
126
127
    public void testMixedBridge2New() throws IOException {
128
        File file = new File("/home/user/aFile.mixed2");
129
        int sharability = SharabilityQuery.getSharability(file);
130
        assertEquals(SharabilityQuery.MIXED, sharability);
131
        URI uri = file.toURI();
132
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
133
        assertEquals(SharabilityQuery.Sharability.MIXED, sharability2);
134
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "mixed2");
135
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
136
    }
137
138
    public void testUnknown() throws IOException {
139
        File file = new File("/home/user/aFile.txt");
140
        int sharability = SharabilityQuery.getSharability(file);
141
        assertEquals(SharabilityQuery.UNKNOWN, sharability);
142
        URI uri = file.toURI();
143
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
144
        assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability2);
145
        FileObject fo = FileUtil.toFileObject(getWorkDir()).createData("aFile", "txt");
146
        assertEquals(sharability2, SharabilityQuery.getSharability(fo));
147
    }
148
149
    public void testNormalized() throws IOException {
150
        File file = new File("/home/user/../aFile.txt");
151
        Exception exception = null;
152
        try {
153
            SharabilityQuery.getSharability(file);
154
        } catch (IllegalArgumentException e) {
155
            exception = e;
156
        }
157
        assertNotNull(exception);
158
        URI uri = file.toURI();
159
        exception = null;
160
        try {
161
            SharabilityQuery.getSharability(uri);
162
        } catch (IllegalArgumentException e) {
163
            exception = e;
164
        }
165
        assertNotNull(exception);
166
    }
167
168
    public void testRfs() throws IOException, URISyntaxException {
169
        URI uri = new URI("rfs", "tester", "localhost", 22, "/home/tester/aFile.sharable", null, null);
170
        Sharability sharability = SharabilityQuery.getSharability(uri);
171
        assertEquals(SharabilityQuery.Sharability.UNKNOWN, sharability);
172
        uri = new URI("rfs", "tester", "localhost", 22, "/home/tester/aFile.sharable2", null, null);
173
        Sharability sharability2 = SharabilityQuery.getSharability(uri);
174
        assertEquals(SharabilityQuery.Sharability.SHARABLE, sharability2);
175
    }
176
177
    public static class SharabilityQueryImplementationImpl implements SharabilityQueryImplementation {
178
179
        @Override
180
        public int getSharability(File file) {
181
            String path = file.getAbsolutePath();
182
            if (path.endsWith(".sharable")) {
183
                return SharabilityQuery.SHARABLE;
184
            } else if (path.endsWith(".not_sharable")) {
185
                return SharabilityQuery.NOT_SHARABLE;
186
            } else if (path.endsWith(".mixed")) {
187
                return SharabilityQuery.MIXED;
188
            }
189
            return SharabilityQuery.UNKNOWN;
190
        }
191
    }
192
193
    public static class SharabilityQueryImplementation2Impl implements SharabilityQueryImplementation2 {
194
195
        @Override
196
        public Sharability getSharability(URI uri) {
197
            String path = uri.getPath();
198
            if (path.endsWith(".sharable2")) {
199
                return SharabilityQuery.Sharability.SHARABLE;
200
            } else if (path.endsWith(".not_sharable2")) {
201
                return SharabilityQuery.Sharability.NOT_SHARABLE;
202
            } else if (path.endsWith(".mixed2")) {
203
                return SharabilityQuery.Sharability.MIXED;
204
            }
205
            return SharabilityQuery.Sharability.UNKNOWN;
206
        }
207
    }
208
}
(-)a/refactoring.api/nbproject/project.xml (-1 / +1 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.8</specification-version>
85
                        <specification-version>1.27</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java (-1 / +1 lines)
Lines 443-449 Link Here
443
                        dob = DataObject.find(f);
443
                        dob = DataObject.find(f);
444
                        for (Iterator j = dob.files().iterator(); j.hasNext();) {
444
                        for (Iterator j = dob.files().iterator(); j.hasNext();) {
445
                            FileObject file = (FileObject) j.next();
445
                            FileObject file = (FileObject) j.next();
446
                            if (SharabilityQuery.getSharability(FileUtil.toFile(file)) == SharabilityQuery.SHARABLE) {
446
                            if (SharabilityQuery.getSharability(file) == SharabilityQuery.Sharability.SHARABLE) {
447
                                allFiles.add(file);
447
                                allFiles.add(file);
448
                            }
448
                            }
449
                        }
449
                        }

Return to bug 198060