diff --git a/plume-framework-dependencies/pom.xml b/plume-framework-dependencies/pom.xml
index 1f2c711..973a4a7 100644
--- a/plume-framework-dependencies/pom.xml
+++ b/plume-framework-dependencies/pom.xml
@@ -36,6 +36,7 @@
1.7
1.3.2
4.1.2
+ 4.8.161
3.3.9
4.13.2
@@ -316,6 +317,13 @@
${maven-model.version}
+
+
+ io.github.classgraph
+ classgraph
+ ${classgraph.version}
+
+
junit
diff --git a/plume-web-jersey-monitoring/pom.xml b/plume-web-jersey-monitoring/pom.xml
index 4db7d1e..10e47f5 100644
--- a/plume-web-jersey-monitoring/pom.xml
+++ b/plume-web-jersey-monitoring/pom.xml
@@ -67,6 +67,12 @@
maven-model
+
+
+ io.github.classgraph
+ classgraph
+
+
com.google.inject
diff --git a/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/ApplicationInfoProvider.java b/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/ApplicationInfoProvider.java
index 25442ba..ebec0e2 100644
--- a/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/ApplicationInfoProvider.java
+++ b/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/ApplicationInfoProvider.java
@@ -2,6 +2,10 @@
import com.coreoz.plume.jersey.monitoring.configuration.JerseyMonitoringConfigurationService;
import com.coreoz.plume.jersey.monitoring.utils.info.beans.ApplicationInfo;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ResourceList;
+import io.github.classgraph.ScanResult;
+import lombok.extern.slf4j.Slf4j;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -9,20 +13,46 @@
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
+import javax.validation.constraints.Negative;
+import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Map;
+@Slf4j
@Singleton
public class ApplicationInfoProvider implements Provider {
+ private static final String POM_FILE_NAME = "pom.xml";
+ private final JerseyMonitoringConfigurationService configurationService;
private final ApplicationInfo applicationInfo;
@Inject
- private ApplicationInfoProvider(JerseyMonitoringConfigurationService configurationService) throws IOException, XmlPullParserException {
- MavenXpp3Reader reader = new MavenXpp3Reader();
- Model model = reader.read(new FileReader("pom.xml"));
+ private ApplicationInfoProvider(JerseyMonitoringConfigurationService configurationService) {
+ this.configurationService = configurationService;
+ this.applicationInfo = this.fetchApplicationInfo();
+ }
+
+ @Override
+ public ApplicationInfo get() {
+ return this.applicationInfo;
+ }
+
+ /* PRIVATE */
+ private ApplicationInfo fetchApplicationInfo() {
+ Model model = this.readPom();
+
+ if (model == null) {
+ model = this.readMetaInfPom();
+ }
+
+ if (model == null) {
+ log.warn("Failed to read pom.xml file on root project and in META-INF folder");
+ model = new Model();
+ }
+
Map additionalInformation = configurationService.getCustomInfo();
- this.applicationInfo = new ApplicationInfo(
+ return new ApplicationInfo(
model.getName(),
model.getDescription(),
model.getVersion(),
@@ -30,8 +60,34 @@ private ApplicationInfoProvider(JerseyMonitoringConfigurationService configurati
);
}
- @Override
- public ApplicationInfo get() {
- return this.applicationInfo;
+ private Model readPom() {
+ MavenXpp3Reader reader = new MavenXpp3Reader();
+ if ((new File(POM_FILE_NAME)).exists()) {
+ try {
+ return reader.read(new FileReader(POM_FILE_NAME));
+ } catch (Exception e) {
+ log.error("Failed to read {}", POM_FILE_NAME, e);
+ return null;
+ }
+ }
+ return null;
+ }
+
+ private Model readMetaInfPom() {
+ MavenXpp3Reader reader = new MavenXpp3Reader();
+
+ try (ScanResult scanResult = new ClassGraph().acceptPaths("META-INF/maven").scan()) {
+ ResourceList resourceList = scanResult.getResourcesWithLeafName(POM_FILE_NAME);
+
+ if (resourceList == null || resourceList.isEmpty()) {
+ throw new RuntimeException("Could not find " + POM_FILE_NAME);
+ }
+
+ return reader.read(new InputStreamReader(resourceList.get(0).open()));
+ } catch (Exception e) {
+ log.error("Failed to read {} from META-INF folder", POM_FILE_NAME, e);
+ return null;
+ }
}
}
+
diff --git a/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/beans/ApplicationInfo.java b/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/beans/ApplicationInfo.java
index 599d6e2..87088e6 100644
--- a/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/beans/ApplicationInfo.java
+++ b/plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/beans/ApplicationInfo.java
@@ -1,10 +1,14 @@
package com.coreoz.plume.jersey.monitoring.utils.info.beans;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
import lombok.Value;
import java.util.Map;
@Value
+@AllArgsConstructor
+@NoArgsConstructor(force = true)
public class ApplicationInfo {
String name;
String description;