Revision 61718
Added by Michele Artini over 2 years ago
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/InfoController.java | ||
---|---|---|
5 | 5 |
import java.lang.management.RuntimeMXBean; |
6 | 6 |
import java.util.ArrayList; |
7 | 7 |
import java.util.Collections; |
8 |
import java.util.Comparator; |
|
9 | 8 |
import java.util.HashMap; |
10 | 9 |
import java.util.List; |
11 | 10 |
import java.util.Map; |
... | ... | |
59 | 58 |
|
60 | 59 |
@SuppressWarnings("unchecked") |
61 | 60 |
private List<Map<String, Object>> getModules() throws IOException { |
62 |
final Map<String, Map<String, Map<String, Object>>> modules = Maps.newLinkedHashMap(); |
|
61 |
final long start = System.currentTimeMillis(); |
|
62 |
try { |
|
63 | 63 |
|
64 |
final MavenXpp3Reader reader = new MavenXpp3Reader(); |
|
65 |
for (Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/META-INF/**/pom.xml")) { |
|
66 |
try { |
|
67 |
final Model model = reader.read(res.getInputStream()); |
|
64 |
final Map<String, Map<String, Map<String, Object>>> modules = Maps.newLinkedHashMap(); |
|
68 | 65 |
|
69 |
final String name = model.getArtifactId(); |
|
66 |
final MavenXpp3Reader reader = new MavenXpp3Reader(); |
|
67 |
for (final Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/META-INF/**/pom.xml")) { |
|
68 |
try { |
|
69 |
final Model model = reader.read(res.getInputStream()); |
|
70 | 70 |
|
71 |
String groupId = model.getGroupId(); |
|
72 |
for (Parent parent = model.getParent(); groupId == null && model.getParent() != null; parent = model.getParent()) { |
|
73 |
groupId = parent.getGroupId(); |
|
74 |
} |
|
71 |
final String name = model.getArtifactId(); |
|
75 | 72 |
|
76 |
String version = model.getVersion();
|
|
77 |
for (Parent parent = model.getParent(); version == null && model.getParent() != null; parent = model.getParent()) {
|
|
78 |
version = parent.getVersion();
|
|
79 |
} |
|
73 |
String groupId = model.getGroupId();
|
|
74 |
for (Parent parent = model.getParent(); (groupId == null) && (model.getParent() != null); parent = model.getParent()) {
|
|
75 |
groupId = parent.getGroupId();
|
|
76 |
}
|
|
80 | 77 |
|
81 |
if (!modules.containsKey(groupId)) { |
|
82 |
modules.put(groupId, new HashMap<String, Map<String, Object>>()); |
|
78 |
String version = model.getVersion(); |
|
79 |
for (Parent parent = model.getParent(); (version == null) && (model.getParent() != null); parent = model.getParent()) { |
|
80 |
version = parent.getVersion(); |
|
81 |
} |
|
82 |
|
|
83 |
if (!modules.containsKey(groupId)) { |
|
84 |
modules.put(groupId, new HashMap<String, Map<String, Object>>()); |
|
85 |
} |
|
86 |
if (!modules.get(groupId).containsKey(name)) { |
|
87 |
final Map<String, Object> map = Maps.newHashMap(); |
|
88 |
map.put("group", groupId); |
|
89 |
map.put("name", name); |
|
90 |
map.put("files", new ArrayList<String>()); |
|
91 |
map.put("versions", new ArrayList<String>()); |
|
92 |
modules.get(groupId).put(name, map); |
|
93 |
} else { |
|
94 |
// Artifact already found |
|
95 |
modules.get(groupId).get(name).put("warning", "1"); |
|
96 |
} |
|
97 |
((List<String>) modules.get(groupId).get(name).get("versions")).add(version); |
|
98 |
((List<String>) modules.get(groupId).get(name).get("files")).add(res.getURI().toString()); |
|
99 |
} catch (final Exception e) { |
|
100 |
log.error("Error evaluating pom: " + res.getURI()); |
|
101 |
log.debug("-- ERROR --", e); |
|
83 | 102 |
} |
84 |
if (!modules.get(groupId).containsKey(name)) { |
|
85 |
final Map<String, Object> map = Maps.newHashMap(); |
|
86 |
map.put("group", groupId); |
|
87 |
map.put("name", name); |
|
88 |
map.put("files", new ArrayList<String>()); |
|
89 |
map.put("versions", new ArrayList<String>()); |
|
90 |
modules.get(groupId).put(name, map); |
|
91 |
} else { |
|
92 |
// Artifact already found |
|
93 |
modules.get(groupId).get(name).put("warning", "1"); |
|
94 |
} |
|
95 |
((List<String>) modules.get(groupId).get(name).get("versions")).add(version); |
|
96 |
((List<String>) modules.get(groupId).get(name).get("files")).add(res.getURI().toString()); |
|
97 |
} catch (Exception e) { |
|
98 |
log.error("Error evaluating pom: " + res.getURI()); |
|
99 |
log.debug("-- ERROR --", e); |
|
100 | 103 |
} |
101 |
} |
|
102 | 104 |
|
103 |
final List<Map<String, Object>> list = Lists.newArrayList(); |
|
104 |
for (Entry<String, Map<String, Map<String, Object>>> e : modules.entrySet()) { |
|
105 |
for (Entry<String, Map<String, Object>> e1 : e.getValue().entrySet()) { |
|
106 |
list.add(e1.getValue()); |
|
105 |
final List<Map<String, Object>> list = Lists.newArrayList(); |
|
106 |
for (final Entry<String, Map<String, Map<String, Object>>> e : modules.entrySet()) { |
|
107 |
for (final Entry<String, Map<String, Object>> e1 : e.getValue().entrySet()) { |
|
108 |
list.add(e1.getValue()); |
|
109 |
} |
|
107 | 110 |
} |
108 |
} |
|
109 | 111 |
|
110 |
Collections.sort(list, new Comparator<Map<String, Object>>() { |
|
111 |
|
|
112 |
@Override |
|
113 |
public int compare(final Map<String, Object> o1, final Map<String, Object> o2) { |
|
112 |
Collections.sort(list, (o1, o2) -> { |
|
114 | 113 |
if (o1.get("group").equals(o2.get("group"))) { |
115 | 114 |
return o1.get("name").toString().compareTo(o2.get("name").toString()); |
116 | 115 |
} else { |
117 | 116 |
return o1.get("group").toString().compareTo(o2.get("group").toString()); |
118 | 117 |
} |
119 |
} |
|
120 |
}); |
|
118 |
}); |
|
121 | 119 |
|
122 |
return list; |
|
120 |
return list; |
|
121 |
} finally { |
|
122 |
log.debug(" - getModules(): " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); |
|
123 |
} |
|
123 | 124 |
} |
124 | 125 |
|
125 | 126 |
private Map<String, String> getSysInfo(final RuntimeMXBean mxbean) { |
126 |
return mxbean.getSystemProperties(); |
|
127 |
final long start = System.currentTimeMillis(); |
|
128 |
try { |
|
129 |
return mxbean.getSystemProperties(); |
|
130 |
} finally { |
|
131 |
log.debug(" - getSysInfo(): " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); |
|
132 |
} |
|
133 |
|
|
127 | 134 |
} |
128 | 135 |
|
129 | 136 |
private Map<String, String> getGeneralInfo(final RuntimeMXBean mxbean) { |
130 |
final Map<String, String> genInfo = Maps.newLinkedHashMap(); |
|
131 |
genInfo.put("Hostname", hostname); |
|
132 |
genInfo.put("Port", port); |
|
133 |
genInfo.put("Context", context); |
|
134 |
genInfo.put("Uptime", HumanTime.exactly(mxbean.getUptime())); |
|
135 |
genInfo.put("Start Time", DateUtils.calculate_ISO8601(mxbean.getStartTime())); |
|
136 |
return genInfo; |
|
137 |
final long start = System.currentTimeMillis(); |
|
138 |
try { |
|
139 |
final Map<String, String> genInfo = Maps.newLinkedHashMap(); |
|
140 |
genInfo.put("Hostname", hostname); |
|
141 |
genInfo.put("Port", port); |
|
142 |
genInfo.put("Context", context); |
|
143 |
genInfo.put("Uptime", HumanTime.exactly(mxbean.getUptime())); |
|
144 |
genInfo.put("Start Time", DateUtils.calculate_ISO8601(mxbean.getStartTime())); |
|
145 |
return genInfo; |
|
146 |
} finally { |
|
147 |
log.debug(" - getGeneralInfo(): " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); |
|
148 |
} |
|
149 |
|
|
137 | 150 |
} |
138 | 151 |
|
139 | 152 |
private Map<String, String> getJvmInfo(final RuntimeMXBean mxbean) { |
140 |
final Map<String, String> jvmInfo = Maps.newLinkedHashMap(); |
|
141 |
jvmInfo.put("JVM Name", mxbean.getVmName()); |
|
142 |
jvmInfo.put("JVM Vendor", mxbean.getVmVendor()); |
|
143 |
jvmInfo.put("JVM Version", mxbean.getVmVersion()); |
|
144 |
jvmInfo.put("JVM Spec Name", mxbean.getSpecName()); |
|
145 |
jvmInfo.put("JVM Spec Vendor", mxbean.getSpecVendor()); |
|
146 |
jvmInfo.put("JVM Spec Version", mxbean.getSpecVersion()); |
|
147 |
jvmInfo.put("Running JVM Name", mxbean.getName()); |
|
148 |
jvmInfo.put("Management Spec Version", mxbean.getManagementSpecVersion()); |
|
149 |
return jvmInfo; |
|
153 |
final long start = System.currentTimeMillis(); |
|
154 |
try { |
|
155 |
final Map<String, String> jvmInfo = Maps.newLinkedHashMap(); |
|
156 |
jvmInfo.put("JVM Name", mxbean.getVmName()); |
|
157 |
jvmInfo.put("JVM Vendor", mxbean.getVmVendor()); |
|
158 |
jvmInfo.put("JVM Version", mxbean.getVmVersion()); |
|
159 |
jvmInfo.put("JVM Spec Name", mxbean.getSpecName()); |
|
160 |
jvmInfo.put("JVM Spec Vendor", mxbean.getSpecVendor()); |
|
161 |
jvmInfo.put("JVM Spec Version", mxbean.getSpecVersion()); |
|
162 |
jvmInfo.put("Running JVM Name", mxbean.getName()); |
|
163 |
jvmInfo.put("Management Spec Version", mxbean.getManagementSpecVersion()); |
|
164 |
return jvmInfo; |
|
165 |
} finally { |
|
166 |
log.debug(" - getJvmInfo(): " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); |
|
167 |
} |
|
168 |
|
|
150 | 169 |
} |
151 | 170 |
|
152 | 171 |
private Map<String, String> getLibInfo(final RuntimeMXBean mxbean) { |
153 |
final Map<String, String> libInfo = Maps.newLinkedHashMap(); |
|
154 |
libInfo.put("Classpath", mxbean.getClassPath().replaceAll(":", " : ")); |
|
155 |
libInfo.put("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : ")); |
|
156 |
libInfo.put("Input arguments", mxbean.getInputArguments().toString()); |
|
157 |
libInfo.put("Library Path", mxbean.getLibraryPath().replaceAll(":", " : ")); |
|
158 |
return libInfo; |
|
172 |
final long start = System.currentTimeMillis(); |
|
173 |
try { |
|
174 |
final Map<String, String> libInfo = Maps.newLinkedHashMap(); |
|
175 |
libInfo.put("Classpath", mxbean.getClassPath().replaceAll(":", " : ")); |
|
176 |
libInfo.put("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : ")); |
|
177 |
libInfo.put("Input arguments", mxbean.getInputArguments().toString()); |
|
178 |
libInfo.put("Library Path", mxbean.getLibraryPath().replaceAll(":", " : ")); |
|
179 |
return libInfo; |
|
180 |
} finally { |
|
181 |
log.debug(" - getLibInfo(): " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); |
|
182 |
} |
|
183 |
|
|
159 | 184 |
} |
160 | 185 |
|
161 | 186 |
public String getHostname() { |
Also available in: Unified diff
logs