1 /* |
|
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
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 package com.sun.classanalyzer; |
|
24 |
|
25 import java.io.BufferedReader; |
|
26 import java.io.FileInputStream; |
|
27 import java.io.IOException; |
|
28 import java.io.InputStreamReader; |
|
29 import java.util.List; |
|
30 |
|
31 /** |
|
32 * Config file specifying additional dependency |
|
33 * Each line consists of: |
|
34 * <tag> <classname> -> <value> |
|
35 * where <tag> can be: |
|
36 * @ClassForName and <value> is its dependency |
|
37 * @Provider and <value> is the service name |
|
38 * @Providers and <value> is the list of the service names |
|
39 * |
|
40 * @author Mandy Chung |
|
41 */ |
|
42 public class DependencyConfig { |
|
43 private DependencyConfig() { |
|
44 } |
|
45 |
|
46 static void parse(List<String> configs) throws IOException { |
|
47 for (String s : configs) { |
|
48 parse(s); |
|
49 } |
|
50 } |
|
51 |
|
52 private static void parse(String config) throws IOException { |
|
53 // parse configuration file |
|
54 FileInputStream in = new FileInputStream(config); |
|
55 try { |
|
56 BufferedReader reader = new BufferedReader(new InputStreamReader(in)); |
|
57 String line; |
|
58 int lineNumber = 0; |
|
59 String type = null; |
|
60 while ((line = reader.readLine()) != null) { |
|
61 lineNumber++; |
|
62 line = line.trim(); |
|
63 if (line.length() == 0 || line.charAt(0) == '#') { |
|
64 continue; |
|
65 } |
|
66 if (line.charAt(0) == '@') { |
|
67 if (AnnotatedDependency.isValidType(line)) { |
|
68 type = line; |
|
69 continue; |
|
70 } else { |
|
71 throw new RuntimeException(config + ", line " + |
|
72 lineNumber + ", invalid annotation type."); |
|
73 } |
|
74 } |
|
75 String[] s = line.split("\\s+"); |
|
76 if (s.length < 3 || !s[1].equals("->")) { |
|
77 throw new RuntimeException(config + ", line " + |
|
78 lineNumber + ", is malformed"); |
|
79 } |
|
80 String classname = s[0].trim(); |
|
81 String value = s[2].trim(); |
|
82 |
|
83 Klass k = Klass.findKlass(classname); |
|
84 if (k == null) { |
|
85 // System.out.println("Warning: " + classname + " cannot be found"); |
|
86 continue; |
|
87 } |
|
88 AnnotatedDependency dep = AnnotatedDependency.newAnnotatedDependency(type, value, k); |
|
89 if (dep == null) { |
|
90 throw new RuntimeException(config + ", line " + |
|
91 lineNumber + ", is malformed. Fail to construct the dependency."); |
|
92 } |
|
93 } |
|
94 |
|
95 } finally { |
|
96 in.close(); |
|
97 } |
|
98 } |
|
99 } |
|