Info page (modules)
This commit is contained in:
parent
2cd18af72c
commit
05416186b1
|
@ -3,7 +3,6 @@ package eu.dnetlib.is.info;
|
|||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -36,11 +35,44 @@ public class InfoRestController {
|
|||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private final RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
|
||||
|
||||
private static final Log log = LogFactory.getLog(InfoRestController.class);
|
||||
|
||||
@GetMapping("/")
|
||||
public List<InfoSection<KeyValue>> info() throws Exception {
|
||||
final RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
|
||||
public List<InfoSection<?>> info() throws Exception {
|
||||
return Arrays.asList(jvm(), env(), libs(), sysProps(), appProps(), modules());
|
||||
}
|
||||
|
||||
private InfoSection<KeyValue> appProps() {
|
||||
final InfoSection<KeyValue> appProps = new InfoSection<>("Application properties");
|
||||
configurableEnvironment.getPropertySources()
|
||||
.forEach(ps -> appProps.getData().add(new KeyValue(ps.getName(), ps.getSource().toString())));
|
||||
return appProps;
|
||||
}
|
||||
|
||||
private InfoSection<KeyValue> sysProps() {
|
||||
final InfoSection<KeyValue> sysProps = new InfoSection<>("System properties");
|
||||
configurableEnvironment.getSystemProperties().forEach((k, v) -> sysProps.getData().add(new KeyValue(k, v)));
|
||||
return sysProps;
|
||||
}
|
||||
|
||||
private InfoSection<KeyValue> libs() {
|
||||
final InfoSection<KeyValue> libs = new InfoSection<>("Libraries and arguments");
|
||||
libs.getData().add(new KeyValue("Classpath", mxbean.getClassPath().replaceAll(":", " : ")));
|
||||
libs.getData().add(new KeyValue("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : ")));
|
||||
libs.getData().add(new KeyValue("Input arguments", mxbean.getInputArguments().toString()));
|
||||
libs.getData().add(new KeyValue("Library Path", mxbean.getLibraryPath().replaceAll(":", " : ")));
|
||||
return libs;
|
||||
}
|
||||
|
||||
private InfoSection<KeyValue> env() {
|
||||
final InfoSection<KeyValue> env = new InfoSection<>("Environment");
|
||||
configurableEnvironment.getSystemEnvironment().forEach((k, v) -> env.getData().add(new KeyValue(k, v)));
|
||||
return env;
|
||||
}
|
||||
|
||||
private InfoSection<KeyValue> jvm() {
|
||||
|
||||
final InfoSection<KeyValue> jvm = new InfoSection<>("JVM");
|
||||
jvm.getData().add(new KeyValue("JVM Name", mxbean.getVmName()));
|
||||
|
@ -51,25 +83,11 @@ public class InfoRestController {
|
|||
jvm.getData().add(new KeyValue("JVM Spec Version", mxbean.getSpecVersion()));
|
||||
jvm.getData().add(new KeyValue("Running JVM Name", mxbean.getName()));
|
||||
jvm.getData().add(new KeyValue("Management Spec Version", mxbean.getManagementSpecVersion()));
|
||||
|
||||
final InfoSection<KeyValue> env = new InfoSection<>("Environment");
|
||||
configurableEnvironment.getSystemEnvironment().forEach((k, v) -> env.getData().add(new KeyValue(k, v)));
|
||||
|
||||
final InfoSection<KeyValue> libs = new InfoSection<>("Libraries and arguments");
|
||||
libs.getData().add(new KeyValue("Classpath", mxbean.getClassPath().replaceAll(":", " : ")));
|
||||
libs.getData().add(new KeyValue("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : ")));
|
||||
libs.getData().add(new KeyValue("Input arguments", mxbean.getInputArguments().toString()));
|
||||
libs.getData().add(new KeyValue("Library Path", mxbean.getLibraryPath().replaceAll(":", " : ")));
|
||||
|
||||
final InfoSection<KeyValue> sysProps = new InfoSection<>("Environment");
|
||||
configurableEnvironment.getSystemProperties().forEach((k, v) -> sysProps.getData().add(new KeyValue(k, v)));
|
||||
|
||||
return Arrays.asList(jvm, env, libs, sysProps);
|
||||
return jvm;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map<String, Object>> modules() throws IOException {
|
||||
final Map<String, Map<String, Map<String, Object>>> modules = new LinkedHashMap<>();
|
||||
public InfoSection<JavaModule> modules() throws IOException {
|
||||
final Map<String, Map<String, JavaModule>> modules = new LinkedHashMap<>();
|
||||
|
||||
final MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
for (final Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/META-INF/**/pom.xml")) {
|
||||
|
@ -89,44 +107,29 @@ public class InfoRestController {
|
|||
}
|
||||
|
||||
if (!modules.containsKey(groupId)) {
|
||||
modules.put(groupId, new HashMap<String, Map<String, Object>>());
|
||||
modules.put(groupId, new HashMap<String, JavaModule>());
|
||||
}
|
||||
if (!modules.get(groupId).containsKey(name)) {
|
||||
final Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("group", groupId);
|
||||
map.put("name", name);
|
||||
map.put("files", new ArrayList<String>());
|
||||
map.put("versions", new ArrayList<String>());
|
||||
modules.get(groupId).put(name, map);
|
||||
} else {
|
||||
// Artifact already found
|
||||
modules.get(groupId).get(name).put("warning", "1");
|
||||
modules.get(groupId).put(name, new JavaModule(groupId, name));
|
||||
}
|
||||
((List<String>) modules.get(groupId).get(name).get("versions")).add(version);
|
||||
((List<String>) modules.get(groupId).get(name).get("files")).add(res.getURI().toString());
|
||||
modules.get(groupId).get(name).addFileAndVersion(res.getURI().toString(), version);
|
||||
} catch (final Exception e) {
|
||||
log.error("Error evaluating pom: " + res.getURI());
|
||||
log.debug("-- ERROR --", e);
|
||||
}
|
||||
}
|
||||
|
||||
final List<Map<String, Object>> list = new ArrayList<>();
|
||||
final InfoSection<JavaModule> res = new InfoSection<>("Modules");
|
||||
|
||||
for (final Entry<String, Map<String, Map<String, Object>>> e : modules.entrySet()) {
|
||||
for (final Entry<String, Map<String, Object>> e1 : e.getValue().entrySet()) {
|
||||
list.add(e1.getValue());
|
||||
for (final Entry<String, Map<String, JavaModule>> e : modules.entrySet()) {
|
||||
for (final Entry<String, JavaModule> e1 : e.getValue().entrySet()) {
|
||||
res.getData().add(e1.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(list, (o1, o2) -> {
|
||||
if (o1.get("group").equals(o2.get("group"))) {
|
||||
return o1.get("name").toString().compareTo(o2.get("name").toString());
|
||||
} else {
|
||||
return o1.get("group").toString().compareTo(o2.get("group").toString());
|
||||
}
|
||||
});
|
||||
Collections.sort(res.getData());
|
||||
|
||||
return list;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package eu.dnetlib.is.info;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JavaModule implements Comparable<JavaModule> {
|
||||
|
||||
private final String group;
|
||||
private final String name;
|
||||
private final Set<String> versions = new LinkedHashSet<>();
|
||||
private final Set<String> files = new LinkedHashSet<>();
|
||||
|
||||
public JavaModule(final String group, final String name) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Set<String> getVersions() {
|
||||
return versions;
|
||||
}
|
||||
|
||||
public Set<String> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void addFileAndVersion(final String file, final String version) {
|
||||
files.add(file);
|
||||
versions.add(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final JavaModule o) {
|
||||
if (getGroup().equals(o.getGroup())) {
|
||||
return StringUtils.compare(getName(), o.getName());
|
||||
} else {
|
||||
return StringUtils.compare(getGroup(), o.getGroup());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,17 +14,7 @@
|
|||
<div class="card mb-3" ng-repeat="section in info">
|
||||
<div class="card-header">{{section.name}}</div>
|
||||
<table class="table table-striped table-sm small">
|
||||
<tr ng-repeat="r in section.data">
|
||||
<th style="width:30%">{{r.k}}</th>
|
||||
<td>{{r.v}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Modules</div>
|
||||
<table class="table table-striped table-sm small">
|
||||
<thead>
|
||||
<thead ng-if="section.name == 'Modules'">
|
||||
<tr>
|
||||
<th>Group ID</th>
|
||||
<th>Artifact ID</th>
|
||||
|
@ -33,17 +23,23 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="m : ${modules}" class="warning">
|
||||
<td th:text="${m.group}"></td>
|
||||
<td th:text="${m.name}"></td>
|
||||
<td th:text="${m.versions}"></td>
|
||||
<td th:text="${m.files}"></td>
|
||||
<tr ng-repeat="r in section.data" ng-if="section.name != 'Modules'">
|
||||
<th style="width:30%">{{r.k}}</th>
|
||||
<td>{{r.v}}</td>
|
||||
</tr>
|
||||
<tr ng-repeat="r in section.data" ng-if="section.name == 'Modules'" ng-class="{'table-warning' : r.files.length > 1}">
|
||||
<td>{{r.group}}</td>
|
||||
<td>{{r.name}}</td>
|
||||
<td><span ng-repeat="v in r.versions">{{v}}<br /></span></td>
|
||||
<td><span ng-repeat="f in r.files">{{f}}<br /></span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<table class="table table-striped table-sm small" >
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
<p>
|
||||
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#editVocabularyModal" ng-click="prepareNewVoc()">create a new vocabulary</button>
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue