You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2018/08/30 19:35:16 UTC

[geode] branch feature/GEODE-5660 updated: GEODE-5660: Adding back the trivial path options removed earlier

This is an automated email from the ASF dual-hosted git repository.

udo pushed a commit to branch feature/GEODE-5660
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-5660 by this push:
     new 6c3f226  GEODE-5660: Adding back the trivial path options removed earlier
6c3f226 is described below

commit 6c3f2269f52364ce471fa200ee2cd7b40d75e675
Author: Udo Kohlmeyer <uk...@pivotal.io>
AuthorDate: Thu Aug 30 12:35:02 2018 -0700

    GEODE-5660: Adding back the trivial path options removed earlier
---
 .../geode/management/internal/AgentUtil.java       | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java b/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java
index f97f97b..ec6c912 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/AgentUtil.java
@@ -16,7 +16,9 @@
 package org.apache.geode.management.internal;
 
 import java.io.File;
+import java.net.URL;
 import java.util.Arrays;
+import java.util.Objects;
 import java.util.stream.Stream;
 
 import org.apache.commons.lang.StringUtils;
@@ -66,11 +68,36 @@ public class AgentUtil {
     if (possiblePath != null) {
       return possiblePath;
     }
+    // if $GEODE_HOME is not set or we are not able to find it in all the possible locations under
+    // $GEODE_HOME, try to find in the classpath
+    possiblePath =
+        findPossibleWarLocationFromExtraLocations(versionedWarFileName, unversionedWarFileName);
+    if (possiblePath != null) {
+      return possiblePath;
+    }
 
     logger.warn(warFilePrefix + " war file was not found");
     return null;
   }
 
+  private String findPossibleWarLocationFromExtraLocations(String versionedWarFileName,
+      String unversionedWarFileName) {
+    final URL url = Arrays.stream(new String[] {versionedWarFileName,
+        "tools/Pulse/" + versionedWarFileName,
+        "tools/Extensions/" + versionedWarFileName,
+        "lib/" + versionedWarFileName,
+        unversionedWarFileName})
+        .map(possibleFile -> this.getClass().getClassLoader().getResource(possibleFile))
+        .filter(Objects::nonNull).findFirst().orElse(null);
+
+    if (url != null) {
+      final String path = url.getPath();
+      logger.info("War file found: {}", path);
+      return path;
+    }
+    return null;
+  }
+
   private String findPossibleWarLocationForGeodeHome(String versionedWarFileName,
       String unversionedWarFileName) {
     String[] possibleFiles = {};