19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 package com.sun.classanalyzer;
25
26 import java.io.BufferedReader;
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.Set;
35 import java.util.TreeSet;
36 import java.util.Map;
37
38 import com.sun.classanalyzer.Module.Reference;
39 import java.util.LinkedList;
40 import java.util.TreeMap;
41
42 /**
43 *
44 * @author Mandy Chung
45 */
46 public abstract class AnnotatedDependency implements Comparable<AnnotatedDependency> {
47
48 final Klass from;
49 final List<String> classes;
50 protected boolean optional;
51 String description;
52 Klass.Method method;
53 private List<Filter> filters = null;
54
55 public AnnotatedDependency(Klass klass) {
56 this(klass, false);
57 }
58
260 if ((s = s.trim()).length() > 0) {
261 if (s.startsWith("META-INF")) {
262 services.add(s);
263 readServiceConfiguration(s, classes);
264 } else {
265 throw new RuntimeException("invalid value" + s);
266 }
267 }
268 }
269 }
270
271 boolean isEmpty() {
272 return services.isEmpty();
273 }
274 static final String metaInfPath =
275 "META-INF" + File.separator + "services" + File.separator;
276
277 static void readServiceConfiguration(String config, List<String> names) {
278 BufferedReader br = null;
279 try {
280 InputStream is = ClassPath.open(config);
281 if (is != null) {
282 // Properties doesn't perserve the order of the input file
283 br = new BufferedReader(new InputStreamReader(is, "utf-8"));
284 int lc = 1;
285 while ((lc = parseLine(br, lc, names)) >= 0);
286 }
287 } catch (IOException ex) {
288 throw new RuntimeException(ex);
289 } finally {
290 if (br != null) {
291 try {
292 br.close();
293 } catch (IOException ex) {
294 throw new RuntimeException(ex);
295 }
296 }
297 }
298 }
299
300 // Parse a single line from the given configuration file, adding the name
554 OptionalDependency dep = new OptionalDependency(klass);
555 optionalDependencies.add(dep);
556 return dep;
557 }
558 static Map<Reference, Set<AnnotatedDependency>> annotatedDepsMap = null;
559 static Map<Reference, Set<AnnotatedDependency>> optionalDepsMap = null;
560
561 static Map<Reference, Set<AnnotatedDependency>> getReferences(Module m) {
562 // ensure it's initialized
563 initDependencies();
564
565 Map<Reference, Set<AnnotatedDependency>> result = new TreeMap<Reference, Set<AnnotatedDependency>>();
566 for (Reference ref : annotatedDepsMap.keySet()) {
567 if (m.contains(ref.referrer()) && m.isModuleDependence(ref.referree())) {
568 result.put(ref, annotatedDepsMap.get(ref));
569 }
570 }
571 return result;
572 }
573
574 static Set<Module.Dependency> getDependencies(Module m) {
575 // ensure it's initialized
576 initDependencies();
577
578 Set<Module.Dependency> deps = new TreeSet<Module.Dependency>();
579 for (Reference ref : annotatedDepsMap.keySet()) {
580 if (m.contains(ref.referrer())) {
581 Module other = m.getModuleDependence(ref.referree());
582 if (other != null) {
583 for (AnnotatedDependency ad : annotatedDepsMap.get(ref)) {
584 Module.Dependency d = new Module.Dependency(other, ad.isOptional(), ad.isDynamic());
585 deps.add(d);
586 }
587 }
588 }
589 }
590 return deps;
591 }
592
593 synchronized static void initDependencies() {
594 if (annotatedDepsMap != null) {
595 return;
596 }
597
598 // Build a map of references to its dependencies
599 annotatedDepsMap = new TreeMap<Reference, Set<AnnotatedDependency>>();
600 optionalDepsMap = new TreeMap<Reference, Set<AnnotatedDependency>>();
601
602 for (Klass k : Klass.getAllClasses()) {
603 for (AnnotatedDependency ad : annotatedDependencies) {
604 if (ad.matches(k.getClassName())) {
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 package com.sun.classanalyzer;
25
26 import java.io.BufferedReader;
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.Set;
35 import java.util.TreeSet;
36 import java.util.Map;
37
38 import com.sun.classanalyzer.Module.Reference;
39 import com.sun.classanalyzer.ModuleInfo.Dependence;
40 import java.util.LinkedList;
41 import java.util.TreeMap;
42
43 /**
44 *
45 * @author Mandy Chung
46 */
47 public abstract class AnnotatedDependency implements Comparable<AnnotatedDependency> {
48
49 final Klass from;
50 final List<String> classes;
51 protected boolean optional;
52 String description;
53 Klass.Method method;
54 private List<Filter> filters = null;
55
56 public AnnotatedDependency(Klass klass) {
57 this(klass, false);
58 }
59
261 if ((s = s.trim()).length() > 0) {
262 if (s.startsWith("META-INF")) {
263 services.add(s);
264 readServiceConfiguration(s, classes);
265 } else {
266 throw new RuntimeException("invalid value" + s);
267 }
268 }
269 }
270 }
271
272 boolean isEmpty() {
273 return services.isEmpty();
274 }
275 static final String metaInfPath =
276 "META-INF" + File.separator + "services" + File.separator;
277
278 static void readServiceConfiguration(String config, List<String> names) {
279 BufferedReader br = null;
280 try {
281 InputStream is = ClassPaths.open(config);
282 if (is != null) {
283 // Properties doesn't perserve the order of the input file
284 br = new BufferedReader(new InputStreamReader(is, "utf-8"));
285 int lc = 1;
286 while ((lc = parseLine(br, lc, names)) >= 0);
287 }
288 } catch (IOException ex) {
289 throw new RuntimeException(ex);
290 } finally {
291 if (br != null) {
292 try {
293 br.close();
294 } catch (IOException ex) {
295 throw new RuntimeException(ex);
296 }
297 }
298 }
299 }
300
301 // Parse a single line from the given configuration file, adding the name
555 OptionalDependency dep = new OptionalDependency(klass);
556 optionalDependencies.add(dep);
557 return dep;
558 }
559 static Map<Reference, Set<AnnotatedDependency>> annotatedDepsMap = null;
560 static Map<Reference, Set<AnnotatedDependency>> optionalDepsMap = null;
561
562 static Map<Reference, Set<AnnotatedDependency>> getReferences(Module m) {
563 // ensure it's initialized
564 initDependencies();
565
566 Map<Reference, Set<AnnotatedDependency>> result = new TreeMap<Reference, Set<AnnotatedDependency>>();
567 for (Reference ref : annotatedDepsMap.keySet()) {
568 if (m.contains(ref.referrer()) && m.isModuleDependence(ref.referree())) {
569 result.put(ref, annotatedDepsMap.get(ref));
570 }
571 }
572 return result;
573 }
574
575 static Set<Dependence> getDependencies(Module m) {
576 // ensure it's initialized
577 initDependencies();
578
579 Set<Dependence> deps = new TreeSet<Dependence>();
580 for (Reference ref : annotatedDepsMap.keySet()) {
581 if (m.contains(ref.referrer())) {
582 Module other = m.getModuleDependence(ref.referree());
583 if (other != null) {
584 for (AnnotatedDependency ad : annotatedDepsMap.get(ref)) {
585 Dependence d = new Dependence(other, ad.isOptional());
586 deps.add(d);
587 }
588 }
589 }
590 }
591 return deps;
592 }
593
594 synchronized static void initDependencies() {
595 if (annotatedDepsMap != null) {
596 return;
597 }
598
599 // Build a map of references to its dependencies
600 annotatedDepsMap = new TreeMap<Reference, Set<AnnotatedDependency>>();
601 optionalDepsMap = new TreeMap<Reference, Set<AnnotatedDependency>>();
602
603 for (Klass k : Klass.getAllClasses()) {
604 for (AnnotatedDependency ad : annotatedDependencies) {
605 if (ad.matches(k.getClassName())) {
|