1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.tool.envcheck.plugins;
19
20 import org.apache.river.tool.envcheck.AbstractPlugin;
21 import org.apache.river.tool.envcheck.Plugin;
22 import org.apache.river.tool.envcheck.EnvCheck;
23 import org.apache.river.tool.envcheck.Reporter;
24 import org.apache.river.tool.envcheck.Reporter.Message;
25 import org.apache.river.tool.envcheck.SubVMTask;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.net.URLClassLoader;
30 import java.net.URL;
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.jar.JarFile;
34 import java.util.jar.Manifest;
35 import java.util.StringTokenizer;
36
37 import org.apache.river.start.SharedActivationGroupDescriptor;
38
39
40
41
42
43
44 public class CheckJSKPlatform extends AbstractPlugin {
45
46
47 private EnvCheck envCheck;
48
49
50 private HashSet seen = new HashSet();
51
52
53
54
55
56
57
58 public void run(EnvCheck envCheck) {
59 this.envCheck = envCheck;
60 String classpath = envCheck.getJarToRun();
61 if (classpath != null) {
62 checkPlatform(classpath, getString("jarfile"));
63 } else {
64 classpath = envCheck.getClasspath();
65 checkPlatform(classpath, getString("cmdline"));
66 }
67 SharedActivationGroupDescriptor gd = envCheck.getGroupDescriptor();
68 if (gd != null) {
69 classpath = gd.getClasspath();
70 checkPlatform(classpath, getString("grouppath"));
71 }
72 }
73
74
75
76
77
78
79
80
81 private void checkPlatform(String classpath, String source) {
82 Message message;
83 String[] paths = parseClasspath(classpath, source);
84 for (int i = 0; i < paths.length; i++) {
85 if (paths[i].endsWith("jsk-platform.jar")) {
86 message = new Message(Reporter.INFO,
87 getString("hasplatform"),
88 getString("platformExp"));
89 Reporter.print(message, source);
90 return;
91 }
92 }
93 message = new Message(Reporter.WARNING,
94 getString("noplatform"),
95 getString("platformExp"));
96 Reporter.print(message, source);
97 }
98
99
100
101
102
103
104
105 private String[] parseClasspath(String path, String source) {
106 if (path == null || path.trim().length() == 0) {
107 return new String[0];
108 }
109 ArrayList list = new ArrayList();
110 StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
111 while (tok.hasMoreTokens()) {
112 String item = tok.nextToken();
113 list.addAll(checkItem(item, source));
114 }
115 return (String[]) list.toArray(new String[list.size()]);
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 private ArrayList checkItem(String item, String source) {
133 Message message;
134 ArrayList list = new ArrayList();
135 if (seen.contains(item)) {
136 return list;
137 }
138 seen.add(item);
139 File itemFile = new File(item);
140 if (!itemFile.exists()) {
141 message = new Message(Reporter.WARNING,
142 getString("nosuchitem", item),
143 null);
144 Reporter.print(message, source);
145 return list;
146 }
147 if (!itemFile.canRead()) {
148 message = new Message(Reporter.WARNING,
149 getString("unreadableitem", item),
150 null);
151 Reporter.print(message, source);
152 return list;
153 }
154 list.add(item);
155 JarFile jar;
156 try {
157 jar = new JarFile(item);
158 } catch (IOException e) {
159 return list;
160 }
161 Manifest manifest;
162 try {
163 manifest = jar.getManifest();
164 if (manifest == null) {
165 return list;
166 }
167 } catch (IOException e) {
168 e.printStackTrace();
169 return list;
170 }
171 String classPath = manifest.getMainAttributes().getValue("Class-Path");
172 if (classPath != null) {
173 StringTokenizer tok = new StringTokenizer(classPath);
174 while (tok.hasMoreTokens()) {
175 String fileName = tok.nextToken();
176 File nextJar = new File(itemFile.getParentFile(), fileName);
177 source = source + ": " + item + " Manifest Class-Path";
178 list.addAll(checkItem(nextJar.toString(), source));
179 }
180 }
181 return list;
182 }
183 }