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

lesun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-gobblin.git


The following commit(s) were added to refs/heads/master by this push:
     new 8fdc7de  [GOBBLIN-1361] Avoid conflicting ivysettings.xml in classpath
8fdc7de is described below

commit 8fdc7de20303ad801f21fcbf12b648318aa0a7c6
Author: Lei Sun <[email protected]>
AuthorDate: Fri Jan 15 10:51:31 2021 -0800

    [GOBBLIN-1361] Avoid conflicting ivysettings.xml in classpath
    
    Fix a typo
    
    Address classpath-conflicts for ivysettings.xml
    
    Closes #3202 from autumnust/conflict-ivysetting
---
 .../java/org/apache/gobblin/runtime/fork/Fork.java |  2 +-
 .../org/apache/gobblin/util/DownloadUtils.java     | 32 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git 
a/gobblin-runtime/src/main/java/org/apache/gobblin/runtime/fork/Fork.java 
b/gobblin-runtime/src/main/java/org/apache/gobblin/runtime/fork/Fork.java
index 05b40e9..b35a51e 100644
--- a/gobblin-runtime/src/main/java/org/apache/gobblin/runtime/fork/Fork.java
+++ b/gobblin-runtime/src/main/java/org/apache/gobblin/runtime/fork/Fork.java
@@ -216,7 +216,7 @@ public class Fork<S, D> implements Closeable, FinalState, 
RecordStreamConsumer<S
         if (r instanceof RecordEnvelope) {
           this.writer.get().writeEnvelope((RecordEnvelope) r);
         } else if (r instanceof ControlMessage) {
-          // Nack with error and reraise the error if the control messsage 
handling raises an error.
+          // Nack with error and reraise the error if the control message 
handling raises an error.
           // This is to avoid missing an ack/nack in the error path.
           try {
             
this.writer.get().getMessageHandler().handleMessage((ControlMessage) r);
diff --git 
a/gobblin-utility/src/main/java/org/apache/gobblin/util/DownloadUtils.java 
b/gobblin-utility/src/main/java/org/apache/gobblin/util/DownloadUtils.java
index ab5468f..1a8c543 100644
--- a/gobblin-utility/src/main/java/org/apache/gobblin/util/DownloadUtils.java
+++ b/gobblin-utility/src/main/java/org/apache/gobblin/util/DownloadUtils.java
@@ -27,19 +27,28 @@ import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Map;
+import java.util.logging.Logger;
 
 import com.google.common.collect.Maps;
 import com.google.common.io.Resources;
 
 import groovy.grape.Grape;
 import groovy.lang.GroovyClassLoader;
+import lombok.NonNull;
 
 
 /**
  * Utility class for downloads using grape
  */
 public class DownloadUtils {
+  private DownloadUtils() {
+    // Utility class's constructor do nothing
+  }
+
   public static final String IVY_SETTINGS_FILE_NAME = "ivysettings.xml";
+  // This will be useful when there's already `ivysettings.xml` existed in the 
classpath.
+  private static final String CLIENT_IVY_SETTINGS_FILE_NAME = 
"client_ivysettings.xml";
+  private static final Logger logger = 
Logger.getLogger(DownloadUtils.class.getName());
 
   /**
    * Download jar through {@link Grape} given an org, module and version
@@ -67,14 +76,29 @@ public class DownloadUtils {
     return Grape.resolve(args, artifactMap);
   }
 
+  @NonNull
+  private static URL getSettingsUrl() throws IOException {
+    URL clientSettingsUrl = 
Thread.currentThread().getContextClassLoader().getResource(CLIENT_IVY_SETTINGS_FILE_NAME);
+    if (clientSettingsUrl == null) {
+      URL settingsUrl = 
Thread.currentThread().getContextClassLoader().getResource(IVY_SETTINGS_FILE_NAME);
+      if (settingsUrl == null) {
+        throw new IOException("Failed to find " + IVY_SETTINGS_FILE_NAME + 
"and "
+            + CLIENT_IVY_SETTINGS_FILE_NAME +" from class path");
+      } else {
+        logger.info("Fallback to ivysettings.xml in the classpath");
+        return settingsUrl;
+      }
+    } else {
+      logger.info("Using customized client_ivysettings.xml file");
+      return clientSettingsUrl;
+    }
+  }
+
   /**
    * Get ivy settings file from classpath
    */
   public static File getIvySettingsFile() throws IOException {
-    URL settingsUrl = 
Thread.currentThread().getContextClassLoader().getResource(IVY_SETTINGS_FILE_NAME);
-    if (settingsUrl == null) {
-      throw new IOException("Failed to find " + IVY_SETTINGS_FILE_NAME + " 
from class path");
-    }
+    URL settingsUrl = getSettingsUrl();
 
     // Check if settingsUrl is file on classpath
     File ivySettingsFile = new File(settingsUrl.getFile());

Reply via email to