2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.api.java.queries;
45
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
46
import org.openide.filesystems.FileObject;
47
import org.openide.util.Lookup;
51
* Query to find Java package root of unit tests for Java package root of
52
* sources and vice versa.
54
* @see org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation
55
* @author David Konecny, Tomas Zezula
56
* @since org.netbeans.api.java/1 1.4
58
public class UnitTestForSourceQuery {
60
@SuppressWarnings ("deprecation") // NOI18N
61
private static final Lookup.Result<? extends org.netbeans.spi.java.queries.UnitTestForSourceQueryImplementation> implementations =
62
Lookup.getDefault().lookupResult(org.netbeans.spi.java.queries.UnitTestForSourceQueryImplementation.class);
63
private static final Lookup.Result<? extends MultipleRootsUnitTestForSourceQueryImplementation> mrImplementations =
64
Lookup.getDefault().lookupResult(MultipleRootsUnitTestForSourceQueryImplementation.class);
66
private UnitTestForSourceQuery() {
70
* Returns the test root for a given source root.
72
* @param source Java package root with sources
73
* @return corresponding Java package root with unit tests. The
74
* returned URL does not have to point to existing file. It can be null
75
* when the mapping from source to unit test is not known.
76
* @deprecated Use {@link #findUnitTests} instead.
78
public static URL findUnitTest(FileObject source) {
79
URL[] result = findUnitTests (source);
80
return result.length == 0 ? null : result[0];
85
* Returns the test roots for a given source root.
87
* @param source Java package root with sources
88
* @return corresponding Java package roots with unit tests. The
89
* returned URLs do not have to point to existing files. It can be an empty
90
* array (but not null) when the mapping from source to unit tests is not known.
91
* @since org.netbeans.api.java/1 1.7
93
@SuppressWarnings ("deprecation") // NOI18N
94
public static URL[] findUnitTests(FileObject source) {
96
throw new IllegalArgumentException("Parameter source cannot be null"); // NOI18N
98
for (MultipleRootsUnitTestForSourceQueryImplementation query : mrImplementations.allInstances()) {
99
URL[] urls = query.findUnitTests(source);
104
for (org.netbeans.spi.java.queries.UnitTestForSourceQueryImplementation query : implementations.allInstances()) {
105
URL u = query.findUnitTest(source);
107
return new URL[] {u};
114
* Returns the source root for a given test root.
116
* @param unitTest Java package root with unit tests
117
* @return corresponding Java package root with sources. It can be null
118
* when the mapping from unit test to source is not known.
119
* @deprecated Use {@link #findSources} instead.
121
public static URL findSource(FileObject unitTest) {
122
URL[] result = findSources (unitTest);
123
return result.length == 0 ? null : result[0];
127
* Returns the source roots for a given test root.
129
* @param unitTest Java package root with unit tests
130
* @return corresponding Java package roots with sources. It can be an empty array (not null)
131
* when the mapping from unit test to sources is not known.
132
* @since org.netbeans.api.java/1 1.7
134
@SuppressWarnings ("deprecation") // NOI18N
135
public static URL[] findSources (FileObject unitTest) {
136
if (unitTest == null) {
137
throw new IllegalArgumentException("Parameter unitTest cannot be null"); // NOI18N
139
for (MultipleRootsUnitTestForSourceQueryImplementation query : mrImplementations.allInstances()) {
140
URL[] urls = query.findSources(unitTest);
145
for (org.netbeans.spi.java.queries.UnitTestForSourceQueryImplementation query : implementations.allInstances()) {
146
URL u = query.findSource(unitTest);
148
return new URL[] {u};