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/queries/src/org/netbeans/api/queries/CollocationQuery.java (-2 / +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;
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
Lines 59-64 Link Here
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 71-77 Link Here
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
73
     */
77
     */
74
    public static boolean areCollocated(File file1, File file2) {
78
    @Deprecated public static boolean areCollocated(File file1, File file2) {
75
        if (!file1.equals(FileUtil.normalizeFile(file1))) {
79
        if (!file1.equals(FileUtil.normalizeFile(file1))) {
76
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
80
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
77
                "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1));  // NOI18N
81
                "normalized. Was "+file1+" instead of "+FileUtil.normalizeFile(file1));  // NOI18N
Lines 80-85 Link Here
80
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
84
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
81
                "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2));  // NOI18N
85
                "normalized. Was "+file2+" instead of "+FileUtil.normalizeFile(file2));  // NOI18N
82
        }
86
        }
87
        URI uri1 = null;
88
        URI uri2 = null;
89
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
90
            if (uri1 == null) {
91
                uri1 = file1.toURI();
92
                if (!uri1.equals(uri1.normalize())) {
93
                    throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
94
                        "normalized. Was "+uri1+" instead of "+uri1.normalize());  // NOI18N
95
                }
96
                uri2 = file2.toURI();
97
                if (!uri2.equals(uri2.normalize())) {
98
                    throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
99
                        "normalized. Was "+uri2+" instead of "+uri2.normalize());  // NOI18N
100
                }
101
            }
102
            if (cqi.areCollocated(uri1, uri2)) {
103
                return true;
104
            }
105
        }
83
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
106
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
84
            if (cqi.areCollocated(file1, file2)) {
107
            if (cqi.areCollocated(file1, file2)) {
85
                return true;
108
                return true;
Lines 87-92 Link Here
87
        }
110
        }
88
        return false;
111
        return false;
89
    }
112
    }
113
114
    /**
115
     * Check whether two files are logically part of one directory tree.
116
     * For example, if both files are stored in CVS, with the same server
117
     * (<code>CVSROOT</code>) they might be considered collocated.
118
     * If nothing is known about them, return false.
119
     * @param file1 one file
120
     * @param file2 another file
121
     * @return true if they are probably part of one logical tree
122
     */
123
    public static boolean areCollocated(URI file1, URI file2) {
124
        if (!file1.equals(file1.normalize())) {
125
            throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
126
                "normalized. Was "+file1+" instead of "+file1.normalize());  // NOI18N
127
        }
128
        if (!file2.equals(file2.normalize())) {
129
            throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
130
                "normalized. Was "+file2+" instead of "+file2.normalize());  // NOI18N
131
        }
132
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
133
            if (cqi.areCollocated(file1, file2)) {
134
                return true;
135
            }
136
        }
137
        if ("file".equals(file1.getScheme()) && "file".equals(file2.getScheme())) { // NOI18N
138
            File f1 = null;
139
            File f2 = null;
140
            for (CollocationQueryImplementation cqi : implementations.allInstances()) {
141
                if (f1 == null) {
142
                    f1 = new File(file1);
143
                    if (!f1.equals(FileUtil.normalizeFile(f1))) {
144
                        throw new IllegalArgumentException("Parameter file1 was not "+  // NOI18N
145
                            "normalized. Was "+f1+" instead of "+FileUtil.normalizeFile(f1));  // NOI18N
146
                    }
147
                    f2 = new File(file2);
148
                    if (!f2.equals(FileUtil.normalizeFile(f2))) {
149
                        throw new IllegalArgumentException("Parameter file2 was not "+  // NOI18N
150
                            "normalized. Was "+f2+" instead of "+FileUtil.normalizeFile(f2));  // NOI18N
151
                    }
152
                }
153
                if (cqi.areCollocated(f1, f2)) {
154
                    return true;
155
                }
156
            }
157
        }
158
        return false;
159
    }
90
    
160
    
91
    /**
161
    /**
92
     * Find a root of a logical tree containing this file, if any.
162
     * Find a root of a logical tree containing this file, if any.
Lines 94-104 Link Here
94
     * @return an ancestor directory which is the root of a logical tree,
164
     * @return an ancestor directory which is the root of a logical tree,
95
     *         if any (else null)
165
     *         if any (else null)
96
     */
166
     */
97
    public static File findRoot(File file) {
167
    @Deprecated public static File findRoot(File file) {
98
        if (!file.equals(FileUtil.normalizeFile(file))) {
168
        if (!file.equals(FileUtil.normalizeFile(file))) {
99
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
169
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
100
                "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file));  // NOI18N
170
                "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file));  // NOI18N
101
        }
171
        }
172
        URI uri = null;
173
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
174
            if (uri == null) {
175
                uri = file.toURI();
176
                if (!uri.equals(uri.normalize())) {
177
                    throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
178
                        "normalized. Was "+uri+" instead of "+uri.normalize());  // NOI18N
179
                }
180
            }
181
            URI root = cqi.findRoot(uri);
182
            if (root != null) {
183
                return new File(root);
184
            }
185
        }
102
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
186
        for (CollocationQueryImplementation cqi : implementations.allInstances()) {
103
            File root = cqi.findRoot(file);
187
            File root = cqi.findRoot(file);
104
            if (root != null) {
188
            if (root != null) {
Lines 108-111 Link Here
108
        return null;
192
        return null;
109
    }
193
    }
110
    
194
    
195
    /**
196
     * Find a root of a logical tree containing this file, if any.
197
     * @param file a file on disk
198
     * @return an ancestor directory which is the root of a logical tree,
199
     *         if any (else null)
200
     */
201
    public static URI findRoot(URI file) {
202
        if (!file.equals(file.normalize())) {
203
            throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
204
                "normalized. Was "+file+" instead of "+file.normalize());  // NOI18N
205
        }
206
        for (CollocationQueryImplementation2 cqi : implementations2.allInstances()) {
207
            URI root = cqi.findRoot(file);
208
            if (root != null) {
209
                return root;
210
            }
211
        }
212
        if ("file".equals(file.getScheme())) { // NOI18N
213
            File f = null;
214
            for (CollocationQueryImplementation cqi : implementations.allInstances()) {
215
                if (f == null) {
216
                    f = new File(file);
217
                    if (!f.equals(FileUtil.normalizeFile(f))) {
218
                        throw new IllegalArgumentException("Parameter file was not "+  // NOI18N
219
                            "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(f));  // NOI18N
220
                    }
221
                }
222
                File root = cqi.findRoot(f);
223
                if (root != null) {
224
                    return root.toURI();
225
                }
226
            }
227
        }
228
        return null;
229
    }
111
}
230
}
(-)a/queries/src/org/netbeans/api/queries/SharabilityQuery.java (-5 / +122 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.net.URL;
51
import java.util.logging.Level;
52
import java.util.logging.Logger;
48
import org.netbeans.spi.queries.SharabilityQueryImplementation;
53
import org.netbeans.spi.queries.SharabilityQueryImplementation;
54
import org.netbeans.spi.queries.SharabilityQueryImplementation2;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileStateInvalidException;
49
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Lookup;
58
import org.openide.util.Lookup;
51
import org.openide.util.Parameters;
59
import org.openide.util.Parameters;
Lines 70-81 Link Here
70
    private static final Lookup.Result<SharabilityQueryImplementation> implementations =
78
    private static final Lookup.Result<SharabilityQueryImplementation> implementations =
71
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class);
79
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation.class);
72
80
81
    private static final Lookup.Result<SharabilityQueryImplementation2> implementations2 =
82
        Lookup.getDefault().lookupResult(SharabilityQueryImplementation2.class);
83
    
84
    private static final Logger LOG = Logger.getLogger(SharabilityQuery.class.getName());
85
73
    /**
86
    /**
74
     * Constant indicating that nothing is known about whether a given
87
     * Constant indicating that nothing is known about whether a given
75
     * file should be considered sharable or not.
88
     * file should be considered sharable or not.
76
     * A client should therefore behave in the safest way it can.
89
     * A client should therefore behave in the safest way it can.
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.
Lines 83-89 Link Here
83
     * directories recursively contained in this directory are also
96
     * directories recursively contained in this directory are also
84
     * sharable.
97
     * sharable.
85
     */
98
     */
86
    public static final int SHARABLE = 1;
99
    @Deprecated public static final int SHARABLE = 1;
87
    
100
    
88
    /**
101
    /**
89
     * Constant indicating that the file or directory is not sharable.
102
     * Constant indicating that the file or directory is not sharable.
Lines 91-97 Link Here
91
     * directories recursively contained in this directory are also
104
     * directories recursively contained in this directory are also
92
     * not sharable.
105
     * not sharable.
93
     */
106
     */
94
    public static final int NOT_SHARABLE = 2;
107
    @Deprecated public static final int NOT_SHARABLE = 2;
95
    
108
    
96
    /**
109
    /**
97
     * Constant indicating that a directory is sharable but files and
110
     * Constant indicating that a directory is sharable but files and
Lines 99-105 Link Here
99
     * A client interested in children of this directory should explicitly
112
     * A client interested in children of this directory should explicitly
100
     * ask about each in turn.
113
     * ask about each in turn.
101
     */
114
     */
102
    public static final int MIXED = 3;
115
    @Deprecated public static final int MIXED = 3;
116
117
    public static enum Sharability {
118
        /**
119
        * Constant indicating that nothing is known about whether a given
120
        * file should be considered sharable or not.
121
        * A client should therefore behave in the safest way it can.
122
        */
123
        UNKNOWN,
124
125
        /**
126
        * Constant indicating that the file or directory is sharable.
127
        * In the case of a directory, this means that all files and
128
        * directories recursively contained in this directory are also
129
        * sharable.
130
        */
131
        SHARABLE,
132
133
        /**
134
        * Constant indicating that the file or directory is not sharable.
135
        * In the case of a directory, this means that all files and
136
        * directories recursively contained in this directory are also
137
        * not sharable.
138
        */
139
        NOT_SHARABLE,
140
141
        /**
142
        * Constant indicating that a directory is sharable but files and
143
        * directories recursively contained in it may or may not be sharable.
144
        * A client interested in children of this directory should explicitly
145
        * ask about each in turn.
146
        */
147
        MIXED;
148
    }
103
    
149
    
104
    private SharabilityQuery() {}
150
    private SharabilityQuery() {}
105
    
151
    
Lines 108-114 Link Here
108
     * @param file a file or directory (may or may not already exist); should be {@linkplain FileUtil#normalizeFile normalized}
154
     * @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
155
     * @return one of the constants in this class
110
     */
156
     */
111
    public static int getSharability(File file) {
157
    @Deprecated public static int getSharability(File file) {
112
        Parameters.notNull("file", file);
158
        Parameters.notNull("file", file);
113
        boolean asserts = false;
159
        boolean asserts = false;
114
        assert asserts = true;
160
        assert asserts = true;
Lines 118-123 Link Here
118
                throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile);
164
                throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile);
119
            }
165
            }
120
        }
166
        }
167
        URI uri = null;
168
        for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) {
169
            if (uri == null) {
170
                uri = file.toURI();
171
            }
172
            Sharability x = sqi.getSharability(uri);
173
            if (x != Sharability.UNKNOWN) {
174
                return x.ordinal();
175
            }
176
        }
121
        for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
177
        for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
122
            int x = sqi.getSharability(file);
178
            int x = sqi.getSharability(file);
123
            if (x != UNKNOWN) {
179
            if (x != UNKNOWN) {
Lines 127-130 Link Here
127
        return UNKNOWN;
183
        return UNKNOWN;
128
    }
184
    }
129
    
185
    
186
    /**
187
     * Check whether an existing file is sharable.
188
     * @param uri a file or directory (may or may not already exist); should be normalized.
189
     * @return one of the constants in this class
190
     * @since 1.27
191
     */
192
    public static Sharability getSharability(URI uri) {
193
        Parameters.notNull("file", uri);
194
        boolean asserts = false;
195
        assert asserts = true;
196
        if (asserts && !Utilities.isMac()) {
197
            URI normUri = uri.normalize();
198
            if (!uri.equals(normUri)) {
199
                throw new IllegalArgumentException("Must pass a normalized URI: " + uri + " vs. " + normUri);
200
            }
201
        }
202
        for (SharabilityQueryImplementation2 sqi : implementations2.allInstances()) {
203
            Sharability x = sqi.getSharability(uri);
204
            if (x != Sharability.UNKNOWN) {
205
                return x;
206
            }
207
        }
208
        if ("file".equals(uri.getScheme())) { // NOI18N
209
            File file = null;
210
            for (SharabilityQueryImplementation sqi : implementations.allInstances()) {
211
                if (file == null) {
212
                    file = new File(uri);
213
                    if (asserts && !Utilities.isMac()) {
214
                        File normFile = FileUtil.normalizeFile(file);
215
                        if (!file.equals(normFile)) {
216
                            throw new IllegalArgumentException("Must pass a normalized file: " + file + " vs. " + normFile);
217
                        }
218
                    }
219
                }
220
                int x = sqi.getSharability(file);
221
                if (x != UNKNOWN) {
222
                    return Sharability.values()[x];
223
                }
224
            }
225
        }
226
        return Sharability.UNKNOWN;
227
    }
228
    /**
229
     * Check whether an existing file is sharable.
230
     * @param fo a file or directory; should be normalized.
231
     * @return one of the constants in this class
232
     * @since 1.27
233
     */
234
    public static Sharability getSharability(FileObject fo) {
235
        try {
236
            URL url = fo.getURL();
237
            if (url != null) {
238
                return getSharability(url.toURI());
239
            }
240
        } catch (URISyntaxException ex) {
241
            LOG.log(Level.FINE, null, ex);
242
        } catch (FileStateInvalidException ex) {
243
            LOG.log(Level.FINE, null, ex);
244
        }
245
        return Sharability.UNKNOWN;
246
    }
130
}
247
}
(-)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 (+95 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
 * @author Jesse Glick
68
 * @author Alexander Simon
69
 */
70
public interface CollocationQueryImplementation2 {
71
    
72
    /**
73
     * Check whether two files are logically part of one directory tree.
74
     * For example, if both files are stored in CVS, with the same server
75
     * (<code>CVSROOT</code>) they might be considered collocated.
76
     * If they are to be collocated their absolute paths must share a
77
     * prefix directory, i.e. they must be located in the same filesystem root.
78
     * If nothing is known about them, return false.
79
     * @param file1 one file
80
     * @param file2 another file
81
     * @return true if they are probably part of one logical tree
82
     */
83
    boolean areCollocated(URI file1, URI file2);
84
    
85
    /**
86
     * Find a root of a logical tree containing this file, if any.
87
     * The path of the root (if there is one) must be a prefix of the path of the file.
88
     * @param file a file on disk (must be an absolute URI)
89
     * @return an ancestor directory which is the root of a logical tree,
90
     *         if any (else null) (must be an absolute URI)
91
     */
92
    URI findRoot(URI file);
93
    
94
}
95
(-)a/queries/src/org/netbeans/spi/queries/SharabilityQueryImplementation.java (-1 / +3 lines)
Lines 70-77 Link Here
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
 * @author Jesse Glick
72
 * @author Jesse Glick
73
 * @deprecated Use (@link org.netbeans.spi.queries.SharabilityQueryImplementation2) instead.
74
 * 
73
 */
75
 */
74
public interface SharabilityQueryImplementation {
76
@Deprecated public interface SharabilityQueryImplementation {
75
    
77
    
76
    /**
78
    /**
77
     * Check whether a file or directory should be shared.
79
     * 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 {@link org.netbeans.api.queries.SharabilityQuery.Sharability}
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
}

Return to bug 198060