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/29 00:13:51 UTC

[geode] branch feature/GEODE-5660 updated (5ccebd2 -> 4121388)

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

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


 discard 5ccebd2  GEODE-5660: Added method to lookup war file from classpath within AgentUtil.java. This is to address problem where http server is started from Java API (Spring Data Geode specifically) Now, the application can reference the `geode-web-api` war from repo and not have to specifically set `GEODE-HOME` property
     new 4121388  GEODE-5660: Added method to lookup war file from classpath within AgentUtil.java. This is to address problem where http server is started from Java API (Spring Data Geode specifically) Now, the application can reference the `geode-web-api` war from repo and not have to specifically set `GEODE-HOME` property

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5ccebd2)
            \
             N -- N -- N   refs/heads/feature/GEODE-5660 (4121388)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/geode/management/internal/AgentUtilJUnitTest.java | 3 ++-
 .../src/main/java/org/apache/geode/management/internal/AgentUtil.java | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)


[geode] 01/01: GEODE-5660: Added method to lookup war file from classpath within AgentUtil.java. This is to address problem where http server is started from Java API (Spring Data Geode specifically) Now, the application can reference the `geode-web-api` war from repo and not have to specifically set `GEODE-HOME` property

Posted by ud...@apache.org.
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

commit 4121388fb8a611f6303b621d12e1a267a303bc13
Author: Udo Kohlmeyer <uk...@pivotal.io>
AuthorDate: Tue Aug 28 17:03:47 2018 -0700

    GEODE-5660: Added method to lookup war file from classpath
    within AgentUtil.java. This is to address problem where
    http server is started from Java API (Spring Data Geode specifically)
    Now, the application can reference the `geode-web-api` war from repo
    and not have to specifically set `GEODE-HOME` property
---
 .../geode/management/internal/AgentUtilJUnitTest.java | 19 +++++++++++++++++++
 .../apache/geode/management/internal/AgentUtil.java   | 14 ++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java b/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
index 4d5b718..2bca797 100644
--- a/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
+++ b/geode-assembly/src/integrationTest/java/org/apache/geode/management/internal/AgentUtilJUnitTest.java
@@ -14,10 +14,14 @@
  */
 package org.apache.geode.management.internal;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
+import java.util.List;
 
+import org.hamcrest.text.IsEqualIgnoringCase;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -50,4 +54,19 @@ public class AgentUtilJUnitTest {
     String gemFireWarLocation = agentUtil.findWarLocation("geode-pulse");
     assertNotNull("Pulse WAR File was not found", gemFireWarLocation);
   }
+
+  @Test
+  public void testLookupOfWarFileOnClassPath() {
+    String classpath = System.getProperty("java.class.path");
+    List<String> gemFireWarLocation = agentUtil.lookupWarLocationFromClasspath("geode-web-api");
+    assertEquals(0, gemFireWarLocation.size());
+
+    classpath =
+        classpath + System.getProperty("path.separator") + "somelocation/geode-web-api.972347.war";
+    System.setProperty("java.class.path", classpath);
+    gemFireWarLocation = agentUtil.lookupWarLocationFromClasspath("geode-web-api");
+    assertEquals(1, gemFireWarLocation.size());
+    assertThat(gemFireWarLocation.get(0),
+        IsEqualIgnoringCase.equalToIgnoringCase("somelocation/geode-web-api.972347.war"));
+  }
 }
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 95e40dc..f89c1bd 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
@@ -17,6 +17,9 @@ package org.apache.geode.management.internal;
 
 import java.io.File;
 import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.Logger;
@@ -28,7 +31,6 @@ import org.apache.geode.internal.logging.LogService;
  * Hosts common utility methods needed by the management package
  *
  * @since Geode 1.0.0.0
- *
  */
 public class AgentUtil {
 
@@ -53,8 +55,9 @@ public class AgentUtil {
    *        geode-web-api
    */
   public String findWarLocation(String warFilePrefix) {
+    List<String> classpathWarLocation = lookupWarLocationFromClasspath(warFilePrefix);
     String geodeHome = getGeodeHome();
-    if (StringUtils.isNotBlank(geodeHome)) {
+    if (StringUtils.isNotBlank(geodeHome) || classpathWarLocation.size() > 0) {
       String[] possibleFiles =
           {geodeHome + "/tools/Extensions/" + warFilePrefix + "-" + gemfireVersion + ".war",
               geodeHome + "/tools/Pulse/" + warFilePrefix + "-" + gemfireVersion + ".war",
@@ -91,6 +94,13 @@ public class AgentUtil {
     return null;
   }
 
+  public List<String> lookupWarLocationFromClasspath(String warFilePrefix) {
+    return Arrays
+        .stream(System.getProperty("java.class.path").split(System.getProperty("path.separator")))
+        .filter(s -> s.contains(warFilePrefix)).collect(
+            Collectors.toList());
+  }
+
   public boolean isWebApplicationAvailable(final String warFileLocation) {
     return StringUtils.isNotBlank(warFileLocation);
   }