Lines 41-48
Link Here
|
41 |
*/ |
41 |
*/ |
42 |
package org.netbeans.modules.java.editor.whitelist; |
42 |
package org.netbeans.modules.java.editor.whitelist; |
43 |
|
43 |
|
44 |
import java.io.File; |
|
|
45 |
import java.io.IOException; |
46 |
import java.net.URL; |
44 |
import java.net.URL; |
47 |
import java.util.ArrayList; |
45 |
import java.util.ArrayList; |
48 |
import java.util.Collections; |
46 |
import java.util.Collections; |
Lines 62-79
Link Here
|
62 |
import org.netbeans.api.project.Project; |
60 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.ProjectUtils; |
61 |
import org.netbeans.api.project.ProjectUtils; |
64 |
import org.netbeans.api.project.SourceGroup; |
62 |
import org.netbeans.api.project.SourceGroup; |
65 |
import org.netbeans.modules.parsing.lucene.support.DocumentIndex; |
|
|
66 |
import org.netbeans.modules.parsing.lucene.support.Index; |
67 |
import org.netbeans.modules.parsing.lucene.support.IndexDocument; |
68 |
import org.netbeans.modules.parsing.lucene.support.IndexManager; |
69 |
import org.netbeans.modules.parsing.lucene.support.Queries.QueryKind; |
70 |
import org.netbeans.spi.tasklist.PushTaskScanner; |
63 |
import org.netbeans.spi.tasklist.PushTaskScanner; |
71 |
import org.netbeans.spi.tasklist.Task; |
64 |
import org.netbeans.spi.tasklist.Task; |
72 |
import org.netbeans.spi.tasklist.TaskScanningScope; |
65 |
import org.netbeans.spi.tasklist.TaskScanningScope; |
|
|
66 |
import org.netbeans.api.whitelist.index.WhiteListIndex; |
67 |
import org.netbeans.api.whitelist.index.WhiteListIndexEvent; |
68 |
import org.netbeans.api.whitelist.index.WhiteListIndexListener; |
73 |
import org.openide.filesystems.FileObject; |
69 |
import org.openide.filesystems.FileObject; |
74 |
import org.openide.filesystems.FileUtil; |
70 |
import org.openide.filesystems.FileUtil; |
75 |
import org.openide.filesystems.URLMapper; |
71 |
import org.openide.filesystems.URLMapper; |
76 |
import org.openide.util.Exceptions; |
|
|
77 |
import org.openide.util.NbBundle; |
72 |
import org.openide.util.NbBundle; |
78 |
import org.openide.util.RequestProcessor; |
73 |
import org.openide.util.RequestProcessor; |
79 |
import org.openide.util.TaskListener; |
74 |
import org.openide.util.TaskListener; |
Lines 109-136
Link Here
|
109 |
super(Bundle.LBL_ProviderName(), |
104 |
super(Bundle.LBL_ProviderName(), |
110 |
Bundle.LBL_ProviderDescription(), |
105 |
Bundle.LBL_ProviderDescription(), |
111 |
null); |
106 |
null); |
112 |
INSTANCE = this; |
107 |
WhiteListIndex.getDefault().addWhiteListIndexListener(new WhiteListIndexListener() { |
113 |
} |
108 |
@Override |
114 |
|
109 |
public void indexChanged(WhiteListIndexEvent event) { |
115 |
@CheckForNull |
110 |
refresh(event.getRoot()); |
116 |
static WhiteListTaskProvider getInstance() { |
111 |
} |
117 |
return INSTANCE; |
112 |
}); |
118 |
} |
|
|
119 |
|
120 |
void refresh(final @NonNull URL root) { |
121 |
final FileObject rootFo = URLMapper.findFileObject(root); |
122 |
final Set<FileObject> files; |
123 |
final Callback callback; |
124 |
synchronized (this) { |
125 |
files = currentFiles; |
126 |
callback = currentCallback; |
127 |
} |
128 |
if (rootFo != null && |
129 |
files != null && |
130 |
files.contains(rootFo)) { |
131 |
assert callback != null; |
132 |
enqueue(new Work(rootFo, currentCallback)); |
133 |
} |
134 |
} |
113 |
} |
135 |
|
114 |
|
136 |
@Override |
115 |
@Override |
Lines 158-163
Link Here
|
158 |
} |
137 |
} |
159 |
} |
138 |
} |
160 |
|
139 |
|
|
|
140 |
private void refresh(final @NonNull URL root) { |
141 |
assert root != null; |
142 |
final FileObject rootFo = URLMapper.findFileObject(root); |
143 |
final Set<FileObject> files; |
144 |
final Callback callback; |
145 |
synchronized (this) { |
146 |
files = currentFiles; |
147 |
callback = currentCallback; |
148 |
} |
149 |
if (rootFo != null && |
150 |
files != null && |
151 |
files.contains(rootFo)) { |
152 |
assert callback != null; |
153 |
enqueue(new Work(rootFo, currentCallback)); |
154 |
} |
155 |
} |
156 |
|
161 |
private static void enqueue(Work w) { |
157 |
private static void enqueue(Work w) { |
162 |
synchronized (TASKS) { |
158 |
synchronized (TASKS) { |
163 |
final RequestProcessor.Task task = WORKER.post(w); |
159 |
final RequestProcessor.Task task = WORKER.post(w); |
Lines 205-222
Link Here
|
205 |
} |
201 |
} |
206 |
|
202 |
|
207 |
@CheckForNull |
203 |
@CheckForNull |
208 |
private static Map.Entry<FileObject,Task> createTask( |
204 |
private static Map.Entry<FileObject,Task> createTask(@NonNull final WhiteListIndex.Problem problem) { |
209 |
@NonNull final FileObject root, |
205 |
final FileObject file = problem.getFile(); |
210 |
@NonNull final IndexDocument doc) { |
|
|
211 |
final FileObject file = root.getFileObject(doc.getPrimaryKey()); |
212 |
if (file == null) { |
206 |
if (file == null) { |
213 |
return null; |
207 |
return null; |
214 |
} |
208 |
} |
215 |
final Task task = Task.create( |
209 |
final Task task = Task.create( |
216 |
file, |
210 |
file, |
217 |
"nb-whitelist-warning", //NOI18N |
211 |
"nb-whitelist-warning", //NOI18N |
218 |
doc.getValue(WhiteListIndexerPlugin.MSG), |
212 |
problem.getResult().getViolatedRuleDescription(), |
219 |
Integer.parseInt(doc.getValue(WhiteListIndexerPlugin.LINE))); |
213 |
problem.getLine()); |
220 |
return new Map.Entry<FileObject, Task>() { |
214 |
return new Map.Entry<FileObject, Task>() { |
221 |
@Override |
215 |
@Override |
222 |
public FileObject getKey() { |
216 |
public FileObject getKey() { |
Lines 233-252
Link Here
|
233 |
}; |
227 |
}; |
234 |
} |
228 |
} |
235 |
|
229 |
|
236 |
@CheckForNull |
|
|
237 |
private static DocumentIndex getIndex(@NonNull final FileObject root) { |
238 |
try { |
239 |
final File whiteListFolder = WhiteListIndexerPlugin.getWhiteListDir(root.getURL()); |
240 |
if (whiteListFolder != null) { |
241 |
final DocumentIndex index = IndexManager.createDocumentIndex(whiteListFolder); |
242 |
return index.getStatus() == Index.Status.VALID ? index : null; |
243 |
} |
244 |
} catch (IOException ioe) { |
245 |
Exceptions.printStackTrace(ioe); |
246 |
} |
247 |
return null; |
248 |
} |
249 |
|
250 |
private static void updateErrorsInRoot( |
230 |
private static void updateErrorsInRoot( |
251 |
@NonNull final Callback callback, |
231 |
@NonNull final Callback callback, |
252 |
@NonNull final FileObject root) { |
232 |
@NonNull final FileObject root) { |
Lines 255-289
Link Here
|
255 |
filesWithErrors.clear(); |
235 |
filesWithErrors.clear(); |
256 |
Set<FileObject> nueFilesWithErrors = new HashSet<FileObject>(); |
236 |
Set<FileObject> nueFilesWithErrors = new HashSet<FileObject>(); |
257 |
final Map<FileObject,List<Task>> filesToTasks = new HashMap<FileObject,List<Task>>(); |
237 |
final Map<FileObject,List<Task>> filesToTasks = new HashMap<FileObject,List<Task>>(); |
258 |
try { |
238 |
for (WhiteListIndex.Problem problem : WhiteListIndex.getDefault().getWhiteListViolations(root, null)) { |
259 |
IndexManager.readAccess(new IndexManager.Action<Void>() { |
239 |
final Map.Entry<FileObject,Task> task = createTask(problem); |
260 |
@Override |
240 |
if (task != null) { |
261 |
public Void run() throws IOException, InterruptedException { |
241 |
List<Task> tasks = filesToTasks.get(task.getKey()); |
262 |
final DocumentIndex index = getIndex(root); |
242 |
if (tasks == null) { |
263 |
if (index != null) { |
243 |
tasks = new ArrayList<Task>(); |
264 |
try { |
244 |
filesToTasks.put(task.getKey(), tasks); |
265 |
for (IndexDocument doc : index.findByPrimaryKey("", QueryKind.PREFIX)) { //NOI18N |
|
|
266 |
final Map.Entry<FileObject,Task> task = createTask(root, doc); |
267 |
if (task != null) { |
268 |
List<Task> tasks = filesToTasks.get(task.getKey()); |
269 |
if (tasks == null) { |
270 |
tasks = new ArrayList<Task>(); |
271 |
filesToTasks.put(task.getKey(), tasks); |
272 |
} |
273 |
tasks.add(task.getValue()); |
274 |
} |
275 |
} |
276 |
} finally { |
277 |
index.close(); |
278 |
} |
279 |
} |
280 |
return null; |
281 |
} |
245 |
} |
282 |
}); |
246 |
tasks.add(task.getValue()); |
283 |
} catch (IOException e) { |
247 |
} |
284 |
Exceptions.printStackTrace(e); |
|
|
285 |
} catch (InterruptedException e) { |
286 |
Exceptions.printStackTrace(e); |
287 |
} |
248 |
} |
288 |
for (Map.Entry<FileObject,List<Task>> e : filesToTasks.entrySet()) { |
249 |
for (Map.Entry<FileObject,List<Task>> e : filesToTasks.entrySet()) { |
289 |
LOG.log(Level.FINE, "Setting {1} for {0}\n", |
250 |
LOG.log(Level.FINE, "Setting {1} for {0}\n", |
Lines 304-343
Link Here
|
304 |
@NonNull final Callback callback, |
265 |
@NonNull final Callback callback, |
305 |
@NonNull final FileObject root, |
266 |
@NonNull final FileObject root, |
306 |
@NonNull final FileObject file) { |
267 |
@NonNull final FileObject file) { |
307 |
try { |
268 |
final List<Task> tasks = new ArrayList<Task>(); |
308 |
IndexManager.readAccess(new IndexManager.Action<Void>(){ |
269 |
for (WhiteListIndex.Problem problem : WhiteListIndex.getDefault().getWhiteListViolations(root, file)) { |
309 |
@Override |
270 |
final Map.Entry<FileObject,Task> task = createTask(problem); |
310 |
public Void run() throws IOException, InterruptedException { |
271 |
if (task != null) { |
311 |
final List<Task> tasks = new ArrayList<Task>(); |
272 |
tasks.add(task.getValue()); |
312 |
final DocumentIndex index = getIndex(root); |
273 |
} |
313 |
if (index != null) { |
|
|
314 |
try { |
315 |
for (IndexDocument doc : index.findByPrimaryKey(FileUtil.getRelativePath(root, file), QueryKind.PREFIX)) { |
316 |
final Map.Entry<FileObject,Task> task = createTask(root, doc); |
317 |
if (task != null) { |
318 |
tasks.add(task.getValue()); |
319 |
} |
320 |
} |
321 |
} finally { |
322 |
index.close(); |
323 |
} |
324 |
} |
325 |
Set<FileObject> filesWithErrors = getFilesWithAttachedErrors(root); |
326 |
if (tasks.isEmpty()) { |
327 |
filesWithErrors.remove(file); |
328 |
} else { |
329 |
filesWithErrors.add(file); |
330 |
} |
331 |
LOG.log(Level.FINE, "setting {1} for {0}", new Object[]{file, tasks}); |
332 |
callback.setTasks(file, tasks); |
333 |
return null; |
334 |
} |
335 |
}); |
336 |
} catch (IOException e) { |
337 |
Exceptions.printStackTrace(e); |
338 |
} catch (InterruptedException e) { |
339 |
Exceptions.printStackTrace(e); |
340 |
} |
274 |
} |
|
|
275 |
final Set<FileObject> filesWithErrors = getFilesWithAttachedErrors(root); |
276 |
if (tasks.isEmpty()) { |
277 |
filesWithErrors.remove(file); |
278 |
} else { |
279 |
filesWithErrors.add(file); |
280 |
} |
281 |
LOG.log(Level.FINE, "setting {1} for {0}", new Object[]{file, tasks}); |
282 |
callback.setTasks(file, tasks); |
341 |
} |
283 |
} |
342 |
|
284 |
|
343 |
private static final class Work implements Runnable { |
285 |
private static final class Work implements Runnable { |