Lines 36-41
Link Here
|
36 |
import org.netbeans.api.project.ProjectInformation; |
36 |
import org.netbeans.api.project.ProjectInformation; |
37 |
import org.netbeans.api.project.ProjectManager; |
37 |
import org.netbeans.api.project.ProjectManager; |
38 |
import org.netbeans.api.project.SourceGroup; |
38 |
import org.netbeans.api.project.SourceGroup; |
|
|
39 |
import org.netbeans.api.project.PotentialSourceGroup; |
39 |
import org.netbeans.api.project.Sources; |
40 |
import org.netbeans.api.project.Sources; |
40 |
import org.netbeans.api.queries.SharabilityQuery; |
41 |
import org.netbeans.api.queries.SharabilityQuery; |
41 |
import org.netbeans.api.queries.VisibilityQuery; |
42 |
import org.netbeans.api.queries.VisibilityQuery; |
Lines 83-88
Link Here
|
83 |
if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) { |
84 |
if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) { |
84 |
checkChanges(true); |
85 |
checkChanges(true); |
85 |
} |
86 |
} |
|
|
87 |
if (NbMavenProject.PROP_RESOURCE.equals(event.getPropertyName())) { |
88 |
checkChanges(true); |
89 |
} |
86 |
} |
90 |
} |
87 |
}); |
91 |
}); |
88 |
} |
92 |
} |
Lines 92-102
Link Here
|
92 |
synchronized (lock) { |
96 |
synchronized (lock) { |
93 |
MavenProject mp = project.getOriginalMavenProject(); |
97 |
MavenProject mp = project.getOriginalMavenProject(); |
94 |
if (mp != null) { |
98 |
if (mp != null) { |
95 |
FileObject folder = FileUtilities.convertStringToFileObject(mp.getBuild().getSourceDirectory()); |
99 |
// FileObject folder = FileUtilities.convertStringToFileObject(mp.getBuild().getSourceDirectory()); |
96 |
changed = changed | checkJavaGroupCache(folder, NAME_SOURCE, NbBundle.getMessage(MavenSourcesImpl.class, "SG_Sources")); |
100 |
URI folderUri = FileUtilities.convertStringToUri(mp.getBuild().getSourceDirectory()); |
97 |
folder = FileUtilities.convertStringToFileObject(mp.getBuild().getTestSourceDirectory()); |
101 |
changed = changed | checkJavaGroupCache(folderUri, NAME_SOURCE, NbBundle.getMessage(MavenSourcesImpl.class, "SG_Sources")); |
98 |
changed = changed | checkJavaGroupCache(folder, NAME_TESTSOURCE, NbBundle.getMessage(MavenSourcesImpl.class, "SG_Test_Sources")); |
102 |
folderUri = FileUtilities.convertStringToUri(mp.getBuild().getTestSourceDirectory()); |
|
|
103 |
changed = changed | checkJavaGroupCache(folderUri, NAME_TESTSOURCE, NbBundle.getMessage(MavenSourcesImpl.class, "SG_Test_Sources")); |
99 |
URI[] uris = project.getGeneratedSourceRoots(); |
104 |
URI[] uris = project.getGeneratedSourceRoots(); |
|
|
105 |
FileObject folder; |
100 |
if (uris.length > 0) { |
106 |
if (uris.length > 0) { |
101 |
try { |
107 |
try { |
102 |
folder = URLMapper.findFileObject(uris[0].toURL()); |
108 |
folder = URLMapper.findFileObject(uris[0].toURL()); |
Lines 221-230
Link Here
|
221 |
/** |
227 |
/** |
222 |
* consult the SourceGroup cache, return true if anything changed.. |
228 |
* consult the SourceGroup cache, return true if anything changed.. |
223 |
*/ |
229 |
*/ |
224 |
private boolean checkJavaGroupCache(FileObject root, String name, String displayName) { |
230 |
private boolean checkJavaGroupCache(URI root, String name, String displayName) { |
|
|
231 |
FileObject fo = FileUtilities.convertURItoFileObject(root); |
225 |
SourceGroup group = javaGroup.get(name); |
232 |
SourceGroup group = javaGroup.get(name); |
226 |
if (root == null && group != null) { |
233 |
if (root == null && group != null) { |
227 |
javaGroup.remove(name); |
234 |
javaGroup.remove(name); |
|
|
235 |
ProjectURLWatcher watch = project.getLookup().lookup(ProjectURLWatcher.class); |
236 |
URI uri; |
237 |
if (group instanceof PotentialSourceGroup) { |
238 |
uri = ((PotentialSourceGroup)group).getPotencialRootFolder(); |
239 |
} else { |
240 |
uri = FileUtil.toFile(group.getRootFolder()).toURI(); |
241 |
} |
242 |
watch.removeWatchedPath(uri); |
228 |
return true; |
243 |
return true; |
229 |
} |
244 |
} |
230 |
if (root == null) { |
245 |
if (root == null) { |
Lines 232-246
Link Here
|
232 |
} |
247 |
} |
233 |
boolean changed = false; |
248 |
boolean changed = false; |
234 |
if (group == null) { |
249 |
if (group == null) { |
235 |
group = GenericSources.group(project, root, name, displayName, null, null); |
250 |
if (fo != null) { |
|
|
251 |
group = GenericSources.group(project, fo, name, displayName, null, null); |
252 |
} else { |
253 |
group = new PotGroup(project, root, name, displayName); |
254 |
} |
236 |
javaGroup.put(name, group); |
255 |
javaGroup.put(name, group); |
237 |
changed = true; |
256 |
changed = true; |
|
|
257 |
ProjectURLWatcher watch = project.getLookup().lookup(ProjectURLWatcher.class); |
258 |
watch.addWatchedPath(root); |
238 |
} else { |
259 |
} else { |
239 |
if (!group.getRootFolder().equals(root)) { |
260 |
boolean pot = group instanceof PotGroup; |
240 |
group = GenericSources.group(project, root, name, displayName, null, null); |
261 |
ProjectURLWatcher watch = project.getLookup().lookup(ProjectURLWatcher.class); |
|
|
262 |
URI uri; |
263 |
if (group instanceof PotentialSourceGroup) { |
264 |
uri = ((PotentialSourceGroup)group).getPotencialRootFolder(); |
265 |
} else { |
266 |
uri = FileUtil.toFile(group.getRootFolder()).toURI(); |
267 |
} |
268 |
watch.removeWatchedPath(uri); |
269 |
if ((fo != null && fo.isValid()) && (pot || !group.getRootFolder().equals(fo))) { |
270 |
group = GenericSources.group(project, fo, name, displayName, null, null); |
241 |
javaGroup.put(name, group); |
271 |
javaGroup.put(name, group); |
242 |
changed = true; |
272 |
changed = true; |
243 |
} |
273 |
} |
|
|
274 |
if ((fo == null || !fo.isValid())&& (!pot || !((PotGroup)group).getPotencialRootFolder().equals(root))) { |
275 |
group = new PotGroup(project, root, name, displayName); |
276 |
javaGroup.put(name, group); |
277 |
changed = true; |
278 |
} |
279 |
if (group instanceof PotentialSourceGroup) { |
280 |
uri = ((PotentialSourceGroup)group).getPotencialRootFolder(); |
281 |
} else { |
282 |
uri = FileUtil.toFile(group.getRootFolder()).toURI(); |
283 |
} |
284 |
watch.addWatchedPath(uri); |
285 |
|
244 |
} |
286 |
} |
245 |
return changed; |
287 |
return changed; |
246 |
} |
288 |
} |
Lines 328-334
Link Here
|
328 |
// Not on disk, include it. |
370 |
// Not on disk, include it. |
329 |
return true; |
371 |
return true; |
330 |
} |
372 |
} |
331 |
|
|
|
332 |
} |
373 |
} |
333 |
|
374 |
|
334 |
public void addPropertyChangeListener(PropertyChangeListener l) { |
375 |
public void addPropertyChangeListener(PropertyChangeListener l) { |
Lines 340-343
Link Here
|
340 |
} |
381 |
} |
341 |
|
382 |
|
342 |
} |
383 |
} |
|
|
384 |
|
385 |
public final class PotGroup implements PotentialSourceGroup { |
386 |
|
387 |
private final URI rootFolder; |
388 |
private final String name; |
389 |
private final String displayName; |
390 |
private final Icon icon = null; |
391 |
private final Icon openedIcon = null; |
392 |
private NbMavenProject project; |
393 |
private boolean fired = false; |
394 |
|
395 |
PotGroup(NbMavenProject p, URI rootFold, String nm, String displayNm/*, |
396 |
Icon icn, Icon opened*/) { |
397 |
project = p; |
398 |
rootFolder = rootFold; |
399 |
name = nm; |
400 |
displayName = displayNm != null ? displayNm : NbBundle.getMessage(MavenSourcesImpl.class, "SG_Root_not_defined"); |
401 |
// icon = icn; |
402 |
// openedIcon = opened; |
343 |
} |
403 |
} |
|
|
404 |
|
405 |
public FileObject getRootFolder() { |
406 |
File fil = new File(rootFolder); |
407 |
if (!fil.exists()) { |
408 |
fil.mkdirs(); |
409 |
if (!fired) { |
410 |
fired = true; |
411 |
Thread.dumpStack(); |
412 |
RequestProcessor.getDefault().post(new Runnable() { |
413 |
public void run() { |
414 |
MavenSourcesImpl.this.checkChanges(true); |
415 |
} |
416 |
}); |
417 |
} |
418 |
} |
419 |
return FileUtil.toFileObject(fil); |
420 |
} |
421 |
|
422 |
public URI getPotencialRootFolder() { |
423 |
return rootFolder; |
424 |
} |
425 |
|
426 |
public String getName() { |
427 |
return name; |
428 |
} |
429 |
|
430 |
public String getDisplayName() { |
431 |
return displayName; |
432 |
} |
433 |
|
434 |
public Icon getIcon(boolean opened) { |
435 |
return opened ? icon : openedIcon; |
436 |
} |
437 |
|
438 |
public boolean contains(FileObject file) { |
439 |
File fil = new File(rootFolder); |
440 |
if (!fil.exists()) { |
441 |
return false; |
442 |
} |
443 |
FileObject root = FileUtil.toFileObject(fil); |
444 |
if (file != root && !FileUtil.isParentOf(root, file)) { |
445 |
throw new IllegalArgumentException(); |
446 |
} |
447 |
if (project != null) { |
448 |
if (file.isFolder() && file != project.getProjectDirectory() && ProjectManager.getDefault().isProject(file)) { |
449 |
// #67450: avoid actually loading the nested project. |
450 |
return false; |
451 |
} |
452 |
if (FileOwnerQuery.getOwner(file) != project) { |
453 |
return false; |
454 |
} |
455 |
} |
456 |
File f = FileUtil.toFile(file); |
457 |
if (f != null) { |
458 |
// MIXED, UNKNOWN, and SHARABLE -> include it |
459 |
return SharabilityQuery.getSharability(f) != SharabilityQuery.NOT_SHARABLE; |
460 |
} else { |
461 |
// Not on disk, include it. |
462 |
return true; |
463 |
} |
464 |
} |
465 |
|
466 |
public void addPropertyChangeListener(PropertyChangeListener l) { |
467 |
// XXX should react to ProjectInformation changes |
468 |
} |
469 |
|
470 |
public void removePropertyChangeListener(PropertyChangeListener l) { |
471 |
// XXX |
472 |
} |
473 |
} |
474 |
|
475 |
|
476 |
} |