189 // filter source class/archive
190 String cn = classFileName.replace('/', '.');
191 if (!finder.accept(archive, cn, cf.access_flags))
192 continue;
193
194 // tests if this class matches the -include
195 if (!filter.matches(cn))
196 continue;
197
198 for (Dependency d : finder.findDependencies(cf)) {
199 if (filter.accepts(d)) {
200 archive.addClass(d.getOrigin(), d.getTarget());
201 targets.add(d.getTarget());
202 } else {
203 // ensure that the parsed class is added the archive
204 archive.addClass(d.getOrigin());
205 }
206 parsedClasses.putIfAbsent(d.getOrigin(), archive);
207 }
208 }
209
210 return targets;
211 });
212 tasks.add(task);
213 pool.submit(task);
214 return Optional.of(task);
215 }
216
217 private Set<Location> parse(Archive archive, Finder finder, String name)
218 throws IOException
219 {
220 ClassFile cf = archive.reader().getClassFile(name);
221 if (cf == null) {
222 throw new IllegalArgumentException(archive.getName() +
223 " does not contain " + name);
224 }
225
226 if (cf.access_flags.is(AccessFlags.ACC_MODULE))
227 return Collections.emptySet();
228
229 Set<Location> targets = new HashSet<>();
247 targets.add(d.getTarget());
248 archive.addClass(d.getOrigin(), d.getTarget());
249 } else {
250 // ensure that the parsed class is added the archive
251 archive.addClass(d.getOrigin());
252 }
253 parsedClasses.putIfAbsent(d.getOrigin(), archive);
254 }
255 return targets;
256 }
257
258 /*
259 * Waits until all submitted tasks are completed.
260 */
261 private Set<Location> waitForTasksCompleted() {
262 try {
263 Set<Location> targets = new HashSet<>();
264 FutureTask<Set<Location>> task;
265 while ((task = tasks.poll()) != null) {
266 // wait for completion
267 if (!task.isDone())
268 targets.addAll(task.get());
269 }
270 return targets;
271 } catch (InterruptedException|ExecutionException e) {
272 throw new Error(e);
273 }
274 }
275
276 /*
277 * Shutdown the executor service.
278 */
279 void shutdown() {
280 pool.shutdown();
281 }
282
283 private interface SourceFilter {
284 boolean accept(Archive archive, String cn, AccessFlags accessFlags);
285 }
286
287 private static class Finder implements Dependency.Finder, SourceFilter {
|
189 // filter source class/archive
190 String cn = classFileName.replace('/', '.');
191 if (!finder.accept(archive, cn, cf.access_flags))
192 continue;
193
194 // tests if this class matches the -include
195 if (!filter.matches(cn))
196 continue;
197
198 for (Dependency d : finder.findDependencies(cf)) {
199 if (filter.accepts(d)) {
200 archive.addClass(d.getOrigin(), d.getTarget());
201 targets.add(d.getTarget());
202 } else {
203 // ensure that the parsed class is added the archive
204 archive.addClass(d.getOrigin());
205 }
206 parsedClasses.putIfAbsent(d.getOrigin(), archive);
207 }
208 }
209 return targets;
210 });
211 tasks.add(task);
212 pool.submit(task);
213 return Optional.of(task);
214 }
215
216 private Set<Location> parse(Archive archive, Finder finder, String name)
217 throws IOException
218 {
219 ClassFile cf = archive.reader().getClassFile(name);
220 if (cf == null) {
221 throw new IllegalArgumentException(archive.getName() +
222 " does not contain " + name);
223 }
224
225 if (cf.access_flags.is(AccessFlags.ACC_MODULE))
226 return Collections.emptySet();
227
228 Set<Location> targets = new HashSet<>();
246 targets.add(d.getTarget());
247 archive.addClass(d.getOrigin(), d.getTarget());
248 } else {
249 // ensure that the parsed class is added the archive
250 archive.addClass(d.getOrigin());
251 }
252 parsedClasses.putIfAbsent(d.getOrigin(), archive);
253 }
254 return targets;
255 }
256
257 /*
258 * Waits until all submitted tasks are completed.
259 */
260 private Set<Location> waitForTasksCompleted() {
261 try {
262 Set<Location> targets = new HashSet<>();
263 FutureTask<Set<Location>> task;
264 while ((task = tasks.poll()) != null) {
265 // wait for completion
266 targets.addAll(task.get());
267 }
268 return targets;
269 } catch (InterruptedException|ExecutionException e) {
270 throw new Error(e);
271 }
272 }
273
274 /*
275 * Shutdown the executor service.
276 */
277 void shutdown() {
278 pool.shutdown();
279 }
280
281 private interface SourceFilter {
282 boolean accept(Archive archive, String cn, AccessFlags accessFlags);
283 }
284
285 private static class Finder implements Dependency.Finder, SourceFilter {
|