You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2016/06/24 18:43:47 UTC

zeppelin git commit: [MINOR] Remove unused util methods and its tests

Repository: zeppelin
Updated Branches:
  refs/heads/master 57e0dc883 -> f55290f49


[MINOR] Remove unused util methods and its tests

### What is this PR for?
removing unused codes and its test

### What type of PR is it?
[Refactoring]

### Todos
* [x] - Remove codes

### What is the Jira issue?
N/A

### How should this be tested?

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jongyoul Lee <jo...@gmail.com>

Closes #1072 from jongyoul/minor-remove-unused-codes and squashes the following commits:

d89b0b1 [Jongyoul Lee] Removed duplicated setting of dependency
d624cb5 [Jongyoul Lee] Removed unused codes
06d44d0 [Jongyoul Lee] Remove unused util methods and its tests


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/f55290f4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/f55290f4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/f55290f4

Branch: refs/heads/master
Commit: f55290f49449ca6db0f06985ee3ecbce5864a05e
Parents: 57e0dc8
Author: Jongyoul Lee <jo...@gmail.com>
Authored: Fri Jun 24 03:18:11 2016 +0900
Committer: Jongyoul Lee <jo...@apache.org>
Committed: Sat Jun 25 03:41:50 2016 +0900

----------------------------------------------------------------------
 zeppelin-server/pom.xml                         |   7 -
 .../java/org/apache/zeppelin/util/Util.java     | 161 -------------------
 .../java/org/apache/zeppelin/util/UtilTest.java | 106 ------------
 .../org/apache/zeppelin/util/UtilsForTests.java | 124 --------------
 4 files changed, 398 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f55290f4/zeppelin-server/pom.xml
----------------------------------------------------------------------
diff --git a/zeppelin-server/pom.xml b/zeppelin-server/pom.xml
index 270eb58..b88e175 100644
--- a/zeppelin-server/pom.xml
+++ b/zeppelin-server/pom.xml
@@ -257,13 +257,6 @@
     </dependency>
 
     <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
-      <version>4.3.6</version>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
       <groupId>org.scalatest</groupId>
       <artifactId>scalatest_2.10</artifactId>
       <version>2.1.1</version>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f55290f4/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java
index f9dec0f..e8c9076 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java
@@ -18,13 +18,8 @@
 package org.apache.zeppelin.util;
 
 import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Properties;
 
 /**
@@ -44,162 +39,6 @@ public class Util {
     }
   }
 
-  public static String[] split(String str, char split) {
-    return split(str, new String[] {String.valueOf(split)}, false);
-  }
-
-  public static String[] split(String str, String[] splitters, boolean includeSplitter) {
-    String escapeSeq = "\"',;<%>";
-    char escapeChar = '\\';
-    String[] blockStart = new String[] {"\"", "'", "<%", "N_<"};
-    String[] blockEnd = new String[] {"\"", "'", "%>", "N_>"};
-
-    return split(str, escapeSeq, escapeChar, blockStart, blockEnd, splitters, includeSplitter);
-
-  }
-
-  public static String[] split(String str, String escapeSeq, char escapeChar, String[] blockStart,
-      String[] blockEnd, String[] splitters, boolean includeSplitter) {
-
-    List<String> splits = new ArrayList<String>();
-
-    String curString = "";
-
-    boolean escape = false; // true when escape char is found
-    int lastEscapeOffset = -1;
-    int blockStartPos = -1;
-    List<Integer> blockStack = new LinkedList<Integer>();
-
-    for (int i = 0; i < str.length(); i++) {
-      char c = str.charAt(i);
-
-      // escape char detected
-      if (c == escapeChar && escape == false) {
-        escape = true;
-        continue;
-      }
-
-      // escaped char comes
-      if (escape == true) {
-        if (escapeSeq.indexOf(c) < 0) {
-          curString += escapeChar;
-        }
-        curString += c;
-        escape = false;
-        lastEscapeOffset = curString.length();
-        continue;
-      }
-
-      if (blockStack.size() > 0) { // inside of block
-        curString += c;
-        // check multichar block
-        boolean multicharBlockDetected = false;
-        for (int b = 0; b < blockStart.length; b++) {
-          if (blockStartPos >= 0
-              && getBlockStr(blockStart[b]).compareTo(str.substring(blockStartPos, i)) == 0) {
-            blockStack.remove(0);
-            blockStack.add(0, b);
-            multicharBlockDetected = true;
-            break;
-          }
-        }
-        if (multicharBlockDetected == true) {
-          continue;
-        }
-
-        // check if current block is nestable
-        if (isNestedBlock(blockStart[blockStack.get(0)]) == true) {
-          // try to find nested block start
-
-          if (curString.substring(lastEscapeOffset + 1).endsWith(
-              getBlockStr(blockStart[blockStack.get(0)])) == true) {
-            blockStack.add(0, blockStack.get(0)); // block is started
-            blockStartPos = i;
-            continue;
-          }
-        }
-
-        // check if block is finishing
-        if (curString.substring(lastEscapeOffset + 1).endsWith(
-            getBlockStr(blockEnd[blockStack.get(0)]))) {
-          // the block closer is one of the splitters (and not nested block)
-          if (isNestedBlock(blockEnd[blockStack.get(0)]) == false) {
-            for (String splitter : splitters) {
-              if (splitter.compareTo(getBlockStr(blockEnd[blockStack.get(0)])) == 0) {
-                splits.add(curString);
-                if (includeSplitter == true) {
-                  splits.add(splitter);
-                }
-                curString = "";
-                lastEscapeOffset = -1;
-
-                break;
-              }
-            }
-          }
-          blockStartPos = -1;
-          blockStack.remove(0);
-          continue;
-        }
-
-      } else { // not in the block
-        boolean splitted = false;
-        for (String splitter : splitters) {
-          // forward check for splitter
-          if (splitter.compareTo(
-              str.substring(i, Math.min(i + splitter.length(), str.length()))) == 0) {
-            splits.add(curString);
-            if (includeSplitter == true) {
-              splits.add(splitter);
-            }
-            curString = "";
-            lastEscapeOffset = -1;
-            i += splitter.length() - 1;
-            splitted = true;
-            break;
-          }
-        }
-        if (splitted == true) {
-          continue;
-        }
-
-        // add char to current string
-        curString += c;
-
-        // check if block is started
-        for (int b = 0; b < blockStart.length; b++) {
-          if (curString.substring(lastEscapeOffset + 1)
-                       .endsWith(getBlockStr(blockStart[b])) == true) {
-            blockStack.add(0, b); // block is started
-            blockStartPos = i;
-            break;
-          }
-        }
-      }
-    }
-    if (curString.length() > 0) {
-      splits.add(curString.trim());
-    }
-    return splits.toArray(new String[] {});
-
-  }
-
-  private static String getBlockStr(String blockDef) {
-    if (blockDef.startsWith("N_")) {
-      return blockDef.substring("N_".length());
-    } else {
-      return blockDef;
-    }
-  }
-
-  private static boolean isNestedBlock(String blockDef) {
-    if (blockDef.startsWith("N_")) {
-      return true;
-    } else {
-      return false;
-    }
-  }
-
   /**
    * Get Zeppelin version
    *

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f55290f4/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java
deleted file mode 100644
index 713166d..0000000
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zeppelin.util;
-
-import org.apache.zeppelin.util.Util;
-
-import junit.framework.TestCase;
-
-public class UtilTest extends TestCase {
-
-	@Override
-  protected void setUp() throws Exception {
-		super.setUp();
-	}
-
-	@Override
-  protected void tearDown() throws Exception {
-		super.tearDown();
-	}
-
-	public void testSplitIncludingToken() {
-		String[] token = Util.split("hello | \"world '>|hehe\" > next >> sink", new String[]{"|", ">>",  ">"}, true);
-		assertEquals(7, token.length);
-		assertEquals(" \"world '>|hehe\" ", token[2]);
-	}
-
-	public void testSplitExcludingToken() {
-		String[] token = Util.split("hello | \"world '>|hehe\" > next >> sink", new String[]{"|", ">>",  ">"}, false);
-		assertEquals(4, token.length);
-		assertEquals(" \"world '>|hehe\" ", token[1]);
-	}
-
-	public void testSplitWithSemicolonEnd(){
-		String[] token = Util.split("show tables;", ';');
-		assertEquals(1, token.length);
-		assertEquals("show tables", token[0]);
-	}
-
-	public void testEscapeTemplate(){
-		String[] token = Util.split("select * from <%=table%> limit 1 > output", '>');
-		assertEquals(2, token.length);
-		assertEquals("output", token[1]);
-	}
-
-	public void testSplit(){
-		String [] op = new String[]{";", "|", ">>", ">"};
-
-		String str = "CREATE external table news20b_train (\n"+
-			"	rowid int,\n"+
-			"   label int,\n"+
-			"   features ARRAY<STRING>\n"+
-			")\n"+
-			"ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' \n"+
-			"COLLECTION ITEMS TERMINATED BY \",\" \n"+
-			"STORED AS TEXTFILE;\n";
-		Util.split(str, op, true);
-
-	}
-
-	public void testSplitDifferentBlockStartEnd(){
-		String [] op = new String[]{";", "|", ">>", ">"};
-		String escapeSeq = "\"',;<%>!";
-		char escapeChar = '\\';
-		String [] blockStart = new String[]{ "\"", "'", "<%", "<", "!"};
-		String [] blockEnd = new String[]{ "\"", "'", "%>", ">", ";" };
-		String [] t = Util.split("!echo a;!echo b;", escapeSeq, escapeChar, blockStart, blockEnd, op, true);
-		assertEquals(4, t.length);
-		assertEquals("!echo a;", t[0]);
-		assertEquals(";", t[1]);
-		assertEquals("!echo b;", t[2]);
-		assertEquals(";", t[3]);
-	}
-
-	public void testNestedBlock(){
-		String [] op = new String[]{";", "|", ">>", ">"};
-		String escapeSeq = "\"',;<%>!";
-		char escapeChar = '\\';
-		String [] blockStart = new String[]{ "\"", "'", "<%", "N_<", "<", "!"};
-		String [] blockEnd = new String[]{ "\"", "'", "%>", "N_>", ";", ";" };
-		String [] t = Util.split("array <STRUCT<STRING>> tags|aa", escapeSeq, escapeChar, blockStart, blockEnd, op, true);
-		assertEquals(3, t.length);
-		assertEquals("array <STRUCT<STRING>> tags", t[0]);
-		assertEquals("aa", t[2]);
-	}
-
-	public void testGetVersion(){
-		String version = Util.getVersion();
-		assertNotNull(version);
-		System.out.println(version);
-	}
-}

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f55290f4/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilsForTests.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilsForTests.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilsForTests.java
deleted file mode 100644
index 22002ee..0000000
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilsForTests.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zeppelin.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class UtilsForTests {
-
-  static Logger LOGGER = LoggerFactory.getLogger(UtilsForTests.class);
-
-  public static File createTmpDir() throws Exception {
-    File tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
-    tmpDir.mkdir();
-    return tmpDir;
-
-  }
-  /*
-	private static final String HADOOP_DIST="http://apache.mirror.cdnetworks.com/hadoop/common/hadoop-1.2.1/hadoop-1.2.1-bin.tar.gz";
-	//private static final String HADOOP_DIST="http://www.us.apache.org/dist/hadoop/common/hadoop-1.2.1/hadoop-1.2.1-bin.tar.gz";
-
-	public static void getHadoop() throws MalformedURLException, IOException{
-		setEnv("HADOOP_HOME", new File("./target/hadoop-1.2.1").getAbsolutePath());
-		if(new File("./target/hadoop-1.2.1").isDirectory()) return;
-		//System.out.println("Downloading a hadoop distribution ... it will take a while");
-		//FileUtils.copyURLToFile(new URL(HADOOP_DIST), new File("/tmp/zp_test_hadoop-bin.tar.gz"));
-		System.out.println("Unarchive hadoop distribution ... ");
-		new File("./target").mkdir();
-		Runtime.getRuntime().exec("tar -xzf /tmp/zp_test_hadoop-bin.tar.gz -C ./target");
-	}
-	*/
-
-  public static void delete(File file) {
-    if (file.isFile()) file.delete();
-    else if (file.isDirectory()) {
-      File[] files = file.listFiles();
-      if (files != null && files.length > 0) {
-        for (File f : files) {
-          delete(f);
-        }
-      }
-      file.delete();
-    }
-  }
-
-  /**
-   * Utility method to create a file (if does not exist) and populate it the the given content
-   *
-   * @param path    to file
-   * @param content of the file
-   * @throws IOException
-   */
-  public static void createFileWithContent(String path, String content) throws IOException {
-    File f = new File(path);
-    if (!f.exists()) {
-      stringToFile(content, f);
-    }
-  }
-
-  public static void stringToFile(String string, File file) throws IOException {
-    FileOutputStream out = new FileOutputStream(file);
-    out.write(string.getBytes());
-    out.close();
-  }
-
-  @SuppressWarnings({"unchecked", "rawtypes"})
-  public static void setEnv(String k, String v) {
-    Map<String, String> newenv = new HashMap<String, String>();
-    newenv.put(k, v);
-    try {
-      Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
-      Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
-      theEnvironmentField.setAccessible(true);
-      Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
-      env.putAll(newenv);
-      Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
-      theCaseInsensitiveEnvironmentField.setAccessible(true);
-      Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
-      cienv.putAll(newenv);
-    } catch (NoSuchFieldException e) {
-      try {
-        Class[] classes = Collections.class.getDeclaredClasses();
-        Map<String, String> env = System.getenv();
-        for (Class cl : classes) {
-          if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
-            Field field = cl.getDeclaredField("m");
-            field.setAccessible(true);
-            Object obj = field.get(env);
-            Map<String, String> map = (Map<String, String>) obj;
-            map.clear();
-            map.putAll(newenv);
-          }
-        }
-      } catch (Exception e2) {
-        LOGGER.error(e2.toString(), e2);
-      }
-    } catch (Exception e1) {
-      LOGGER.error(e1.toString(), e1);
-    }
-  }
-}