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 192214
Collapse All | Expand All

(-)a/java.source/src/org/netbeans/api/java/source/SourceUtils.java (-15 / +58 lines)
Lines 115-120 Link Here
115
115
116
import org.openide.filesystems.FileObject;
116
import org.openide.filesystems.FileObject;
117
import org.openide.filesystems.FileUtil;
117
import org.openide.filesystems.FileUtil;
118
import org.openide.filesystems.URLMapper;
118
import org.openide.util.Exceptions;
119
import org.openide.util.Exceptions;
119
import org.openide.util.Lookup;
120
import org.openide.util.Lookup;
120
import org.openide.util.Parameters;
121
import org.openide.util.Parameters;
Lines 600-613 Link Here
600
     */
601
     */
601
    @org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}/*,justification="URLs have never host part"*/)    //NOI18N
602
    @org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}/*,justification="URLs have never host part"*/)    //NOI18N
602
    public static Set<URL> getDependentRoots (final URL root) {
603
    public static Set<URL> getDependentRoots (final URL root) {
603
        final Map<URL, List<URL>> deps = IndexingController.getDefault().getRootDependencies();
604
        final Map<URL, List<URL>> sourceDeps = IndexingController.getDefault().getRootDependencies();
604
        return getDependentRootsImpl (root, deps);
605
        final Map<URL, List<URL>> binaryDeps = IndexingController.getDefault().getBinaryRootDependencies();
606
        return getDependentRootsImpl (root, sourceDeps, binaryDeps);
605
    }
607
    }
606
    
608
    
607
609
608
    @org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}/*,justification="URLs have never host part"*/)    //NOI18N
610
    @org.netbeans.api.annotations.common.SuppressWarnings(value={"DMI_COLLECTION_OF_URLS"}/*,justification="URLs have never host part"*/)    //NOI18N
609
    static Set<URL> getDependentRootsImpl (final URL root, final Map<URL, List<URL>> deps) {
611
    static Set<URL> getDependentRootsImpl (final URL root, final Map<URL, List<URL>> sourceDeps, Map<URL, List<URL>> binaryDeps) {
610
        //Create inverse dependencies        
612
        Set<URL> urls;
613
614
        if (sourceDeps.containsKey(root)) {
615
            urls = findReverseSourceRoots(root, sourceDeps);
616
        } else {
617
            FileObject rootFO = URLMapper.findFileObject(root);
618
619
            if (rootFO != null) {
620
                urls = new HashSet<URL>();
621
622
                for (URL binary : findBinaryRootsForSourceRoot(rootFO, binaryDeps)) {
623
                    List<URL> deps = binaryDeps.get(binary);
624
625
                    if (deps != null) {
626
                        urls.addAll(deps);
627
                    }
628
                }
629
            } else {
630
                urls = new HashSet<URL>();
631
            }
632
        }
633
634
        //Filter non opened projects
635
        Set<ClassPath> cps = GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE);
636
        Set<URL> toRetain = new HashSet<URL>();
637
        for (ClassPath cp : cps) {
638
            for (ClassPath.Entry e : cp.entries()) {
639
                toRetain.add(e.getURL());
640
            }
641
        }
642
        urls.retainAll(toRetain);
643
        return urls;
644
    }    
645
    
646
    private static Set<URL> findReverseSourceRoots(final URL thisSourceRoot, Map<URL, List<URL>> deps) {
647
        //Create inverse dependencies
611
        final Map<URL, List<URL>> inverseDeps = new HashMap<URL, List<URL>> ();
648
        final Map<URL, List<URL>> inverseDeps = new HashMap<URL, List<URL>> ();
612
        for (Map.Entry<URL,List<URL>> entry : deps.entrySet()) {
649
        for (Map.Entry<URL,List<URL>> entry : deps.entrySet()) {
613
            final URL u1 = entry.getKey();
650
            final URL u1 = entry.getKey();
Lines 624-630 Link Here
624
        //Collect dependencies
661
        //Collect dependencies
625
        final Set<URL> result = new HashSet<URL>();
662
        final Set<URL> result = new HashSet<URL>();
626
        final LinkedList<URL> todo = new LinkedList<URL> ();
663
        final LinkedList<URL> todo = new LinkedList<URL> ();
627
        todo.add (root);
664
        todo.add (thisSourceRoot);
628
        while (!todo.isEmpty()) {
665
        while (!todo.isEmpty()) {
629
            final URL u = todo.removeFirst();
666
            final URL u = todo.removeFirst();
630
            if (!result.contains(u)) {
667
            if (!result.contains(u)) {
Lines 635-653 Link Here
635
                }
672
                }
636
            }
673
            }
637
        }
674
        }
638
        //Filter non opened projects
675
639
        Set<ClassPath> cps = GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE);
676
        return result;
640
        Set<URL> toRetain = new HashSet<URL>();
677
    }
641
        for (ClassPath cp : cps) {
678
642
            for (ClassPath.Entry e : cp.entries()) {
679
    private static Set<URL> findBinaryRootsForSourceRoot(FileObject sourceRoot, Map<URL, List<URL>> binaryDeps) {
643
                toRetain.add(e.getURL());
680
        Set<URL> result = new HashSet<URL>();
681
682
        for (URL bin : binaryDeps.keySet()) {
683
            for (FileObject s : SourceForBinaryQuery.findSourceRoots(bin).getRoots()) {
684
                if (s == sourceRoot) {
685
                    result.add(bin);
686
                }
644
            }
687
            }
645
        }
688
        }
646
        result.retainAll(toRetain);
689
647
        return result;
690
        return result;
648
    }    
691
    }
649
    
692
650
    //Helper methods    
693
    //Helper methods
651
    
694
    
652
    /**
695
    /**
653
     * Returns classes declared in the given source file which have the main method.
696
     * Returns classes declared in the given source file which have the main method.
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java (-5 / +7 lines)
Lines 48-53 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.net.URL;
49
import java.net.URL;
50
import java.util.Arrays;
50
import java.util.Arrays;
51
import java.util.Collections;
51
import java.util.HashMap;
52
import java.util.HashMap;
52
import java.util.HashSet;
53
import java.util.HashSet;
53
import java.util.List;
54
import java.util.List;
Lines 293-316 Link Here
293
294
294
        final Map<URL,List<URL>> deps = new HashMap<URL,List<URL>> ();
295
        final Map<URL,List<URL>> deps = new HashMap<URL,List<URL>> ();
295
        deps.put (url1,deps0);
296
        deps.put (url1,deps0);
297
        deps.put (url2,Collections.<URL>emptyList());
296
        deps.put (url3,deps1);
298
        deps.put (url3,deps1);
297
        deps.put (url4,deps2);
299
        deps.put (url4,deps2);
298
        deps.put (url5,deps3);
300
        deps.put (url5,deps3);
299
        
301
        
300
        Set<URL> result = SourceUtils.getDependentRootsImpl(url5, deps);
302
        Set<URL> result = SourceUtils.getDependentRootsImpl(url5, deps, Collections.<URL, List<URL>>emptyMap());
301
        assertEquals (1, result.size());
303
        assertEquals (1, result.size());
302
        assertEquals (url5,result.iterator().next());
304
        assertEquals (url5,result.iterator().next());
303
        
305
        
304
        result = SourceUtils.getDependentRootsImpl(url4, deps);
306
        result = SourceUtils.getDependentRootsImpl(url4, deps, Collections.<URL, List<URL>>emptyMap());
305
        assertEquals (new URL[] {url4, url5}, result);
307
        assertEquals (new URL[] {url4, url5}, result);
306
        
308
        
307
        result = SourceUtils.getDependentRootsImpl(url3, deps);
309
        result = SourceUtils.getDependentRootsImpl(url3, deps, Collections.<URL, List<URL>>emptyMap());
308
        assertEquals (new URL[] {url3, url5}, result);
310
        assertEquals (new URL[] {url3, url5}, result);
309
        
311
        
310
        result = SourceUtils.getDependentRootsImpl(url2, deps);
312
        result = SourceUtils.getDependentRootsImpl(url2, deps, Collections.<URL, List<URL>>emptyMap());
311
        assertEquals (new URL[] {url2, url3, url4, url5}, result);
313
        assertEquals (new URL[] {url2, url3, url4, url5}, result);
312
        
314
        
313
        result = SourceUtils.getDependentRootsImpl(url1, deps);
315
        result = SourceUtils.getDependentRootsImpl(url1, deps, Collections.<URL, List<URL>>emptyMap());
314
        assertEquals (new URL[] {url1, url3, url5}, result);
316
        assertEquals (new URL[] {url1, url3, url5}, result);
315
    }
317
    }
316
    
318
    
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/RetoucheUtils.java (-12 / +7 lines)
Lines 609-640 Link Here
609
        assert files.length >0;
609
        assert files.length >0;
610
        Set<URL> dependentRoots = new HashSet();
610
        Set<URL> dependentRoots = new HashSet();
611
        for (FileObject fo: files) {
611
        for (FileObject fo: files) {
612
            Project p = null;
612
            ClassPath cp = null;
613
            FileObject ownerRoot = null;
613
            FileObject ownerRoot = null;
614
            if (fo != null) {
614
            if (fo != null) {
615
                p = FileOwnerQuery.getOwner(fo);
615
                cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
616
                ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
617
                if (cp!=null) {
616
                if (cp!=null) {
618
                    ownerRoot = cp.findOwnerRoot(fo);
617
                    ownerRoot = cp.findOwnerRoot(fo);
619
                }
618
                }
620
            }
619
            }
621
            if (p != null && ownerRoot != null) {
620
            if (cp != null && ownerRoot != null) {
622
                URL sourceRoot = URLMapper.findURL(ownerRoot, URLMapper.INTERNAL);
621
                URL sourceRoot = URLMapper.findURL(ownerRoot, URLMapper.INTERNAL);
623
                if (dependencies) {
622
                if (dependencies) {
624
                    dependentRoots.addAll(SourceUtils.getDependentRoots(sourceRoot));
623
                    dependentRoots.addAll(SourceUtils.getDependentRoots(sourceRoot));
625
                } else {
624
                } else {
626
                    dependentRoots.add(sourceRoot);
625
                    dependentRoots.add(sourceRoot);
627
                }
626
                }
628
                final Set<URL> toExclude = new HashSet<URL>(Arrays.asList(UnitTestForSourceQuery.findSources(ownerRoot)));
627
                for (FileObject f : cp.getRoots()) {
629
                for (SourceGroup root : ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
628
                    dependentRoots.add(URLMapper.findURL(f, URLMapper.INTERNAL));
630
                    final URL rootURL = URLMapper.findURL(root.getRootFolder(), URLMapper.INTERNAL);
631
                    if (!toExclude.contains(rootURL)) {
632
                        dependentRoots.add(rootURL);
633
                    }
634
                }
629
                }
635
            } else {
630
            } else {
636
                for(ClassPath cp: GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
631
                for(ClassPath scp: GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
637
                    for (FileObject root:cp.getRoots()) {
632
                    for (FileObject root:scp.getRoots()) {
638
                        dependentRoots.add(URLMapper.findURL(root, URLMapper.INTERNAL));
633
                        dependentRoots.add(URLMapper.findURL(root, URLMapper.INTERNAL));
639
                    }
634
                    }
640
                }
635
                }

Return to bug 192214