gobblin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject incubator-gobblin git commit: Add com.linkedin.gobblin to alias resolver
Date Sat, 29 Jul 2017 08:21:02 GMT
Repository: incubator-gobblin
Updated Branches:
  refs/heads/master 85d724c64 -> 26ab1d3f6


Add com.linkedin.gobblin to alias resolver

Closes #1516 from pcadabam/topology


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/26ab1d3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/26ab1d3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/26ab1d3f

Branch: refs/heads/master
Commit: 26ab1d3f6fdd947aa2f4720e1c14ffe48b1113d2
Parents: 85d724c
Author: Pradhan Cadabam <pcadabam@linkedin.com>
Authored: Sat Jul 29 01:20:57 2017 -0700
Committer: Abhishek Tiwari <abhishektiwari.btech@gmail.com>
Committed: Sat Jul 29 01:20:57 2017 -0700

----------------------------------------------------------------------
 .../src/main/java/gobblin/annotation/Alias.java |  4 +++
 .../java/gobblin/util/ClassAliasResolver.java   | 10 +++++---
 .../java/com/linkedin/gobblin/TestAlias.java    | 27 ++++++++++++++++++++
 .../gobblin/util/ClassAliasResolverTest.java    | 11 ++++++++
 4 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/26ab1d3f/gobblin-api/src/main/java/gobblin/annotation/Alias.java
----------------------------------------------------------------------
diff --git a/gobblin-api/src/main/java/gobblin/annotation/Alias.java b/gobblin-api/src/main/java/gobblin/annotation/Alias.java
index c73b48d..92e4d2f 100644
--- a/gobblin-api/src/main/java/gobblin/annotation/Alias.java
+++ b/gobblin-api/src/main/java/gobblin/annotation/Alias.java
@@ -22,8 +22,12 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import gobblin.util.ClassAliasResolver;
+
+
 /**
  * Denotes that a class has an alias.
+ * Using {@link ClassAliasResolver#resolve(String)}, an alias can be resolved to cannonical
name of the annotated class
  */
 @Documented @Retention(value=RetentionPolicy.RUNTIME) @Target(value=ElementType.TYPE)
 public @interface Alias {

http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/26ab1d3f/gobblin-api/src/main/java/gobblin/util/ClassAliasResolver.java
----------------------------------------------------------------------
diff --git a/gobblin-api/src/main/java/gobblin/util/ClassAliasResolver.java b/gobblin-api/src/main/java/gobblin/util/ClassAliasResolver.java
index effda57..d76d32d 100644
--- a/gobblin-api/src/main/java/gobblin/util/ClassAliasResolver.java
+++ b/gobblin-api/src/main/java/gobblin/util/ClassAliasResolver.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import lombok.extern.slf4j.Slf4j;
 
 import org.reflections.Reflections;
+import org.reflections.util.ConfigurationBuilder;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -43,16 +44,17 @@ import gobblin.annotation.Alias;
  *
  * <br>
  * <b>
- *   Note: For the moment this class will only look for classes with gobblin prefix, as scanning
the entire classpath is
- *   very expensive.
+ *   Note: For the moment this class will only look for classes with gobblin/com.linkedin.gobblin
prefix, as scanning
+ *   the entire classpath is very expensive.
  * </b>
  */
 @Slf4j
 public class ClassAliasResolver<T> {
 
-  // Scan all packages in the classpath with prefix gobblin when class is loaded.
+  // Scan all packages in the classpath with prefix gobblin, com.linkedin.gobblin when class
is loaded.
   // Since scan is expensive we do it only once when class is loaded.
-  private static final Reflections REFLECTIONS = new Reflections("gobblin");
+  private static final Reflections REFLECTIONS = new Reflections(new ConfigurationBuilder().forPackages("gobblin",
+      "com.linkedin.gobblin"));
 
   Map<String, Class<? extends T>> aliasToClassCache;
   private final List<Alias> aliasObjects;

http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/26ab1d3f/gobblin-api/src/test/java/com/linkedin/gobblin/TestAlias.java
----------------------------------------------------------------------
diff --git a/gobblin-api/src/test/java/com/linkedin/gobblin/TestAlias.java b/gobblin-api/src/test/java/com/linkedin/gobblin/TestAlias.java
new file mode 100644
index 0000000..4e54d2e
--- /dev/null
+++ b/gobblin-api/src/test/java/com/linkedin/gobblin/TestAlias.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2014-2016 LinkedIn Corp. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+ * this file except in compliance with the License. You may obtain a copy of the
+ * License at  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed
+ * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ * CONDITIONS OF ANY KIND, either express or implied.
+ */
+package com.linkedin.gobblin;
+
+import gobblin.annotation.Alias;
+
+/**
+ * Dummy test class to test alias resolution for com.linkedin.gobblin package
+ */
+public class TestAlias {
+  @Alias(value = "com.alias")
+  public static class DummyAliasCom implements IDummyAliasCom {
+  }
+
+  public static interface IDummyAliasCom {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/26ab1d3f/gobblin-api/src/test/java/gobblin/util/ClassAliasResolverTest.java
----------------------------------------------------------------------
diff --git a/gobblin-api/src/test/java/gobblin/util/ClassAliasResolverTest.java b/gobblin-api/src/test/java/gobblin/util/ClassAliasResolverTest.java
index 12328a0..d5e0c59 100644
--- a/gobblin-api/src/test/java/gobblin/util/ClassAliasResolverTest.java
+++ b/gobblin-api/src/test/java/gobblin/util/ClassAliasResolverTest.java
@@ -19,6 +19,9 @@ package gobblin.util;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import com.linkedin.gobblin.TestAlias.DummyAliasCom;
+import com.linkedin.gobblin.TestAlias.IDummyAliasCom;
+
 import gobblin.annotation.Alias;
 
 @Test(groups = { "gobblin.api.util"})
@@ -33,6 +36,14 @@ public class ClassAliasResolverTest {
   }
 
   @Test
+  public void testResolveComGobblinPackage() {
+    ClassAliasResolver<IDummyAliasCom> resolver = new ClassAliasResolver<>(IDummyAliasCom.class);
+    Assert.assertEquals(resolver.resolve("com.alias"), DummyAliasCom.class.getName());
+    // Resolve returns the passed string if alias mapping does not exist
+    Assert.assertEquals(resolver.resolve("abcd"), "abcd");
+  }
+
+  @Test
   public void testResolveClass() throws Exception {
     ClassAliasResolver<IDummyAliasTest> resolver = new ClassAliasResolver<>(IDummyAliasTest.class);
 


Mime
View raw message