Lines 93-99
Link Here
|
93 |
import org.netbeans.modules.parsing.lucene.support.IndexDocument; |
93 |
import org.netbeans.modules.parsing.lucene.support.IndexDocument; |
94 |
import org.netbeans.modules.parsing.lucene.support.Queries; |
94 |
import org.netbeans.modules.parsing.lucene.support.Queries; |
95 |
import org.openide.filesystems.FileObject; |
95 |
import org.openide.filesystems.FileObject; |
96 |
import org.openide.filesystems.FileStateInvalidException; |
|
|
97 |
import org.openide.filesystems.FileUtil; |
96 |
import org.openide.filesystems.FileUtil; |
98 |
import org.openide.filesystems.URLMapper; |
97 |
import org.openide.filesystems.URLMapper; |
99 |
import org.openide.util.Pair; |
98 |
import org.openide.util.Pair; |
Lines 125-171
Link Here
|
125 |
* |
124 |
* |
126 |
* @since 1.6 |
125 |
* @since 1.6 |
127 |
*/ |
126 |
*/ |
|
|
127 |
@NonNull |
128 |
public static Collection<FileObject> findRoots( |
128 |
public static Collection<FileObject> findRoots( |
129 |
FileObject f, |
129 |
FileObject f, |
130 |
Collection<String> sourcePathIds, |
130 |
Collection<String> sourcePathIds, |
131 |
Collection<String> libraryPathIds, |
131 |
Collection<String> libraryPathIds, |
132 |
Collection<String> binaryLibraryPathIds) |
132 |
Collection<String> binaryLibraryPathIds) |
133 |
{ |
133 |
{ |
134 |
Collection<FileObject> roots = new HashSet<FileObject>(); |
134 |
final Set<FileObject> roots = collectClasspathRoots( |
135 |
|
135 |
null, |
136 |
if (sourcePathIds == null) { |
136 |
sourcePathIds, |
137 |
sourcePathIds = PathRecognizerRegistry.getDefault().getSourceIds(); |
137 |
libraryPathIds, |
138 |
} |
138 |
binaryLibraryPathIds); |
139 |
|
|
|
140 |
if (libraryPathIds == null) { |
141 |
libraryPathIds = PathRecognizerRegistry.getDefault().getLibraryIds(); |
142 |
} |
143 |
|
144 |
if (binaryLibraryPathIds == null) { |
145 |
binaryLibraryPathIds = PathRecognizerRegistry.getDefault().getBinaryLibraryIds(); |
146 |
} |
147 |
|
148 |
collectClasspathRoots(f, sourcePathIds, false, roots); |
149 |
collectClasspathRoots(f, libraryPathIds, false, roots); |
150 |
collectClasspathRoots(f, binaryLibraryPathIds, true, roots); |
151 |
|
152 |
if (LOG.isLoggable(Level.FINE)) { |
139 |
if (LOG.isLoggable(Level.FINE)) { |
153 |
LOG.fine("Roots for file " + f //NOI18N |
140 |
LOG.log( |
154 |
+ ", sourcePathIds=" + sourcePathIds //NOI18N |
141 |
Level.FINE, |
155 |
+ ", libraryPathIds=" + libraryPathIds //NOI18N |
142 |
"Roots for file {0}, sourcePathIds={1}, libraryPathIds={2}, binaryPathIds={3}: ", //NOI18N |
156 |
+ ", binaryPathIds=" + binaryLibraryPathIds //NOI18N |
143 |
new Object[]{ |
157 |
+ ": "); //NOI18N |
144 |
f, |
|
|
145 |
sourcePathIds, |
146 |
libraryPathIds, |
147 |
binaryLibraryPathIds |
148 |
}); |
158 |
for(FileObject root : roots) { |
149 |
for(FileObject root : roots) { |
159 |
try { |
150 |
LOG.log( |
160 |
LOG.fine(" " + root.getURL()); //NOI18N |
151 |
Level.FINE, |
161 |
} catch (FileStateInvalidException ex) { |
152 |
" {0}", //NOI18N |
162 |
//ignore |
153 |
root.toURL()); |
163 |
} |
|
|
164 |
} |
154 |
} |
165 |
LOG.fine("----"); //NOI18N |
155 |
LOG.fine("----"); //NOI18N |
166 |
} |
156 |
} |
167 |
|
157 |
|
168 |
return roots != null ? roots : Collections.<FileObject>emptySet(); |
158 |
return roots; |
169 |
} |
159 |
} |
170 |
|
160 |
|
171 |
/** |
161 |
/** |
Lines 249-300
Link Here
|
249 |
* |
239 |
* |
250 |
* @since 1.6 |
240 |
* @since 1.6 |
251 |
*/ |
241 |
*/ |
|
|
242 |
@NonNull |
252 |
public static Collection<FileObject> findRoots( |
243 |
public static Collection<FileObject> findRoots( |
253 |
Project project, |
244 |
@NullAllowed final Project project, |
254 |
Collection<String> sourcePathIds, |
245 |
@NullAllowed Collection<String> sourcePathIds, |
255 |
Collection<String> libraryPathIds, |
246 |
@NullAllowed Collection<String> libraryPathIds, |
256 |
Collection<String> binaryLibraryPathIds) |
247 |
@NullAllowed Collection<String> binaryLibraryPathIds) |
257 |
{ |
248 |
{ |
258 |
Set<FileObject> roots = new HashSet<FileObject>(); |
249 |
Collection<FileObject> roots = collectClasspathRoots( |
259 |
|
250 |
null, |
260 |
if (sourcePathIds == null) { |
251 |
sourcePathIds, |
261 |
sourcePathIds = PathRecognizerRegistry.getDefault().getSourceIds(); |
252 |
libraryPathIds, |
262 |
} |
253 |
binaryLibraryPathIds); |
263 |
|
|
|
264 |
if (libraryPathIds == null) { |
265 |
libraryPathIds = PathRecognizerRegistry.getDefault().getLibraryIds(); |
266 |
} |
267 |
|
268 |
if (binaryLibraryPathIds == null) { |
269 |
binaryLibraryPathIds = PathRecognizerRegistry.getDefault().getBinaryLibraryIds(); |
270 |
} |
271 |
|
272 |
collectClasspathRoots(null, sourcePathIds, false, roots); |
273 |
collectClasspathRoots(null, libraryPathIds, false, roots); |
274 |
collectClasspathRoots(null, binaryLibraryPathIds, true, roots); |
275 |
|
254 |
|
276 |
if (project != null) { |
255 |
if (project != null) { |
277 |
Set<FileObject> rootsInProject = new HashSet<FileObject>(); |
256 |
roots = reduceRootsByProjects(roots, Collections.singleton(project)).get(project); |
278 |
for(FileObject root : roots) { |
257 |
if (roots == null) { |
279 |
if (FileOwnerQuery.getOwner(root) == project) { |
258 |
roots = Collections.emptySet(); |
280 |
rootsInProject.add(root); |
|
|
281 |
} |
282 |
} |
259 |
} |
283 |
roots = rootsInProject; |
|
|
284 |
} |
260 |
} |
285 |
|
261 |
|
286 |
if (LOG.isLoggable(Level.FINE)) { |
262 |
if (LOG.isLoggable(Level.FINE)) { |
287 |
LOG.fine("Roots for project " + project //NOI18N |
263 |
LOG.log( |
288 |
+ ", sourcePathIds=" + sourcePathIds //NOI18N |
264 |
Level.FINE, |
289 |
+ ", libraryPathIds=" + libraryPathIds //NOI18N |
265 |
"Roots for project {0}, sourcePathIds={1}, libraryPathIds={2}, binaryPathIds={3}: ", //NOI18N |
290 |
+ ", binaryPathIds=" + binaryLibraryPathIds //NOI18N |
266 |
new Object[]{ |
291 |
+ ": "); //NOI18N |
267 |
project, |
|
|
268 |
sourcePathIds, |
269 |
libraryPathIds, |
270 |
binaryLibraryPathIds |
271 |
}); |
292 |
for(FileObject root : roots) { |
272 |
for(FileObject root : roots) { |
293 |
try { |
273 |
LOG.log( |
294 |
LOG.fine(" " + root.getURL()); //NOI18N |
274 |
Level.FINE, |
295 |
} catch (FileStateInvalidException ex) { |
275 |
" {0}", //NOI18N |
296 |
//ignore |
276 |
root.toURL()); |
297 |
} |
|
|
298 |
} |
277 |
} |
299 |
LOG.fine("----"); //NOI18N |
278 |
LOG.fine("----"); //NOI18N |
300 |
} |
279 |
} |
Lines 302-307
Link Here
|
302 |
return roots; |
281 |
return roots; |
303 |
} |
282 |
} |
304 |
|
283 |
|
|
|
284 |
/** |
285 |
* Gets classpath roots relevant for a projects. |
286 |
* This method tries to find classpaths with <code>sourcePathIds</code>, <code>libraryPathIds</code> and |
287 |
* <code>binaryPathIds</code> supplied by the <code>projects</code>. |
288 |
* |
289 |
* <p>The roots collected from <code>binaryLibraryPathIds</code> will be translated |
290 |
* by the <code>SourceForBinaryQuery</code> in order to find relevant sources root. |
291 |
* The roots collected from <code>libraryPathIds</code> are expected to be |
292 |
* libraries in their sources form (ie. no translation). |
293 |
* |
294 |
* @param projects The projects to find the roots for. |
295 |
* @param sourcePathIds The IDs of source classpath to look at. |
296 |
* @param libraryPathIds The IDs of library classpath to look at. |
297 |
* @param binaryLibraryPathIds The IDs of binary library classpath to look at. |
298 |
* @return The roots for a given projects. It may be empty, but never <code>null</code>. |
299 |
* |
300 |
* @since 1.76 |
301 |
*/ |
302 |
@NonNull |
303 |
public static Map<Project,Collection<FileObject>> findRoots( |
304 |
@NonNull final Collection<? extends Project> projects, |
305 |
@NullAllowed Collection<String> sourcePathIds, |
306 |
@NullAllowed Collection<String> libraryPathIds, |
307 |
@NullAllowed Collection<String> binaryLibraryPathIds) { |
308 |
Parameters.notNull("projects", projects); //NOI18N |
309 |
final Set<FileObject> roots = collectClasspathRoots( |
310 |
null, |
311 |
sourcePathIds, |
312 |
libraryPathIds, |
313 |
binaryLibraryPathIds); |
314 |
final Map<Project,Collection<FileObject>> rbp = reduceRootsByProjects(roots, projects); |
315 |
|
316 |
if (LOG.isLoggable(Level.FINE)) { |
317 |
LOG.log( |
318 |
Level.FINE, |
319 |
"Roots for projects {0}, sourcePathIds={1}, libraryPathIds={2}, binaryPathIds={3}: ", //NOI18N |
320 |
new Object[]{ |
321 |
projects, |
322 |
sourcePathIds, |
323 |
libraryPathIds, |
324 |
binaryLibraryPathIds |
325 |
}); |
326 |
for (Map.Entry<Project,Collection<FileObject>> e : rbp.entrySet()) { |
327 |
LOG.log( |
328 |
Level.FINE, |
329 |
"\tProject: {0}:", //NOI18N |
330 |
e.getKey()); |
331 |
for(FileObject root : e.getValue()) { |
332 |
LOG.log( |
333 |
Level.FINE, |
334 |
"\t\t{0}", //NOI18N |
335 |
root.toURL()); |
336 |
} |
337 |
} |
338 |
LOG.fine("----"); //NOI18N |
339 |
} |
340 |
return rbp; |
341 |
} |
342 |
|
305 |
public static QuerySupport forRoots (final String indexerName, final int indexerVersion, final URL... roots) throws IOException { |
343 |
public static QuerySupport forRoots (final String indexerName, final int indexerVersion, final URL... roots) throws IOException { |
306 |
Parameters.notNull("indexerName", indexerName); //NOI18N |
344 |
Parameters.notNull("indexerName", indexerName); //NOI18N |
307 |
Parameters.notNull("roots", roots); //NOI18N |
345 |
Parameters.notNull("roots", roots); //NOI18N |
Lines 651-656
Link Here
|
651 |
} |
689 |
} |
652 |
} |
690 |
} |
653 |
|
691 |
|
|
|
692 |
@NonNull |
693 |
private static Set<FileObject> collectClasspathRoots( |
694 |
@NullAllowed final FileObject file, |
695 |
@NullAllowed Collection<String> sourcePathIds, |
696 |
@NullAllowed Collection<String> libraryPathIds, |
697 |
@NullAllowed Collection<String> binaryLibraryPathIds) { |
698 |
final Set<FileObject> roots = new HashSet<FileObject>(); |
699 |
if (sourcePathIds == null) { |
700 |
sourcePathIds = PathRecognizerRegistry.getDefault().getSourceIds(); |
701 |
} |
702 |
|
703 |
if (libraryPathIds == null) { |
704 |
libraryPathIds = PathRecognizerRegistry.getDefault().getLibraryIds(); |
705 |
} |
706 |
|
707 |
if (binaryLibraryPathIds == null) { |
708 |
binaryLibraryPathIds = PathRecognizerRegistry.getDefault().getBinaryLibraryIds(); |
709 |
} |
710 |
collectClasspathRoots(file, sourcePathIds, false, roots); |
711 |
collectClasspathRoots(file, libraryPathIds, false, roots); |
712 |
collectClasspathRoots(file, binaryLibraryPathIds, true, roots); |
713 |
return roots; |
714 |
} |
715 |
|
654 |
private static void collectClasspathRoots(FileObject file, Collection<String> pathIds, boolean binaryPaths, Collection<FileObject> roots) { |
716 |
private static void collectClasspathRoots(FileObject file, Collection<String> pathIds, boolean binaryPaths, Collection<FileObject> roots) { |
655 |
for(String id : pathIds) { |
717 |
for(String id : pathIds) { |
656 |
Collection<FileObject> classpathRoots = getClasspathRoots(file, id); |
718 |
Collection<FileObject> classpathRoots = getClasspathRoots(file, id); |
Lines 787-792
Link Here
|
787 |
return result; |
849 |
return result; |
788 |
} |
850 |
} |
789 |
|
851 |
|
|
|
852 |
@NonNull |
853 |
private static Map<Project,Collection<FileObject>> reduceRootsByProjects( |
854 |
@NonNull Collection<? extends FileObject> roots, |
855 |
@NonNull Collection<? extends Project> projects) { |
856 |
final Map<Project,Collection<FileObject>> rbp = new HashMap<>(); |
857 |
for (FileObject root : roots) { |
858 |
final Project p = FileOwnerQuery.getOwner(root); |
859 |
if (p != null && projects.contains(p)) { |
860 |
Collection<FileObject> pr = rbp.get(p); |
861 |
if (pr == null) { |
862 |
pr = new ArrayList<>(); |
863 |
rbp.put(p, pr); |
864 |
} |
865 |
pr.add(root); |
866 |
} |
867 |
} |
868 |
return rbp; |
869 |
} |
870 |
|
790 |
/* test */ static final class IndexerQuery { |
871 |
/* test */ static final class IndexerQuery { |
791 |
|
872 |
|
792 |
public static synchronized IndexerQuery forIndexer(String indexerName, int indexerVersion) { |
873 |
public static synchronized IndexerQuery forIndexer(String indexerName, int indexerVersion) { |