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

(-)a/java.source/src/org/netbeans/modules/java/source/classpath/GlobalSourcePath.java (-4 / +8 lines)
Lines 162-170 Link Here
162
        }
162
        }
163
    }
163
    }
164
    
164
    
165
    public boolean isLibrary (final ClassPath cp) {
165
    public final boolean isLibrary (final ClassPath cp) {
166
        assert cp != null;
166
        assert cp != null;
167
        final ClassIndexManager mgr = ClassIndexManager.getDefault();
168
        for (FileObject fo : cp.getRoots()) {
167
        for (FileObject fo : cp.getRoots()) {
169
            if (isLibrary (fo)) {
168
            if (isLibrary (fo)) {
170
                return true;
169
                return true;
Lines 173-186 Link Here
173
        return false;
172
        return false;
174
    }
173
    }
175
    
174
    
176
    public boolean isLibrary (final FileObject root) {
175
    public final boolean isLibrary (final FileObject root) {
177
        assert root != null;
176
        assert root != null;
178
        try {
177
        try {
179
            return ClassIndexManager.getDefault().getUsagesQuery(root.getURL()) == null;
178
            return isLibrary(root.getURL());
180
        } catch (FileStateInvalidException e) {
179
        } catch (FileStateInvalidException e) {
181
            Exceptions.printStackTrace(e);
180
            Exceptions.printStackTrace(e);
182
            return true;    //Safer
181
            return true;    //Safer
183
        }
182
        }
183
    }
184
    
185
    public final boolean isLibrary (final URL root) {
186
        assert root != null;
187
        return ClassIndexManager.getDefault().getUsagesQuery(root) == null;
184
    }
188
    }
185
    
189
    
186
    public ClassPathImplementation getSourcePath () {
190
    public ClassPathImplementation getSourcePath () {
(-)a/java.source/src/org/netbeans/modules/java/source/classpath/SourcePath.java (-19 / +10 lines)
Lines 65-71 Link Here
65
    private final PropertyChangeSupport listeners = new PropertyChangeSupport(this);
65
    private final PropertyChangeSupport listeners = new PropertyChangeSupport(this);
66
    private final ClassPath delegate;
66
    private final ClassPath delegate;
67
    private final ClassIndexManager manager;
67
    private final ClassIndexManager manager;
68
    private volatile boolean prefSources;
68
    private final boolean forcePrefSources;
69
    private List<PathResourceImplementation> resources;
69
    private List<PathResourceImplementation> resources;
70
    private long eventId;
70
    private long eventId;
71
    
71
    
Lines 73-95 Link Here
73
        this.delegate = delegate;
73
        this.delegate = delegate;
74
        this.manager = ClassIndexManager.getDefault();
74
        this.manager = ClassIndexManager.getDefault();
75
        manager.addClassIndexManagerListener(WeakListeners.create(ClassIndexManagerListener.class, this, manager));
75
        manager.addClassIndexManagerListener(WeakListeners.create(ClassIndexManagerListener.class, this, manager));
76
        this.prefSources = bkgComp || !GlobalSourcePath.getDefault().isLibrary(delegate);
76
        this.forcePrefSources = bkgComp;
77
    }
77
    }
78
    
78
    
79
    public List<? extends PathResourceImplementation> getResources() {
79
    public List<? extends PathResourceImplementation> getResources() {
80
        boolean prefSources;
81
        long currentEventId;
80
        long currentEventId;
82
        synchronized (this) {
81
        synchronized (this) {
83
            if (resources != null) {
82
            if (resources != null) {
84
                return this.resources;
83
                return this.resources;
85
            }
84
            }
86
            prefSources = this.prefSources;
87
            currentEventId = this.eventId;
85
            currentEventId = this.eventId;
88
        }
86
        }
89
        
87
        
90
        List<PathResourceImplementation> res = new ArrayList<PathResourceImplementation>();
88
        List<PathResourceImplementation> res = new ArrayList<PathResourceImplementation>();
91
        if (prefSources) {
89
        final GlobalSourcePath gsp = GlobalSourcePath.getDefault();        
92
            for (ClassPath.Entry entry : delegate.entries()) {
90
        for (ClassPath.Entry entry : delegate.entries()) {
91
            if (forcePrefSources || !gsp.isLibrary(entry.getURL())) {
93
                res.add(ClassPathSupport.createResource(entry.getURL()));
92
                res.add(ClassPathSupport.createResource(entry.getURL()));
94
            }
93
            }
95
        }
94
        }
Lines 118-124 Link Here
118
    }
117
    }
119
    
118
    
120
    public void classIndexAdded(ClassIndexManagerEvent event) {
119
    public void classIndexAdded(ClassIndexManagerEvent event) {
121
        if (prefSources) {
120
        if (forcePrefSources) {
122
            return;
121
            return;
123
        }
122
        }
124
        final Set<? extends URL> newRoots = event.getRoots();
123
        final Set<? extends URL> newRoots = event.getRoots();
Lines 129-148 Link Here
129
                break;
128
                break;
130
            }
129
            }
131
        }
130
        }
132
        if (changed) {
131
        if (changed) {            
133
            
134
            boolean ps;
135
            synchronized (this) {
132
            synchronized (this) {
136
                ps = !GlobalSourcePath.getDefault().isLibrary(delegate);
133
                this.resources = null;
137
                if (ps) {
134
                this.eventId++;
138
                    this.prefSources = ps;
139
                    this.resources = null;
140
                    this.eventId++;
141
                }
142
            }
135
            }
143
            if (ps) {
136
            listeners.firePropertyChange(PROP_RESOURCES, null, null);
144
                listeners.firePropertyChange(PROP_RESOURCES, null, null);
145
            }
146
        }
137
        }
147
        
138
        
148
    }
139
    }
(-)a/java.source/test/unit/src/org/netbeans/modules/java/source/classpath/SourcePathTest.java (-1 / +2 lines)
Lines 88-94 Link Here
88
                return null;
88
                return null;
89
            }
89
            }
90
        });
90
        });
91
        assertTrue (sp2.entries().isEmpty());
91
        assertEquals(1,sp2.entries().size());
92
        assertEquals(base.entries().get(0).getURL(), sp2.entries().get(0).getURL());
92
        ClassIndexManager.getDefault().writeLock(new ClassIndexManager.ExceptionAction<Void>() {
93
        ClassIndexManager.getDefault().writeLock(new ClassIndexManager.ExceptionAction<Void>() {
93
            public Void run() throws IOException, InterruptedException {
94
            public Void run() throws IOException, InterruptedException {
94
                ClassIndexManager.getDefault().createUsagesQuery(base.entries().get(1).getURL(), true);
95
                ClassIndexManager.getDefault().createUsagesQuery(base.entries().get(1).getURL(), true);

Return to bug 129972