You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by ra...@apache.org on 2015/08/10 03:52:41 UTC
incubator-lens git commit: LENS-720 : Accept regex paths for DB
resources
Repository: incubator-lens
Updated Branches:
refs/heads/master e35b10652 -> 96cbccd95
LENS-720 : Accept regex paths for DB resources
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/96cbccd9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/96cbccd9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/96cbccd9
Branch: refs/heads/master
Commit: 96cbccd9510cb5c01b21551ced276d4de6e2847f
Parents: e35b106
Author: Rajat Khandelwal <pr...@apache.org>
Authored: Mon Aug 10 07:22:11 2015 +0530
Committer: Raju Bairishetti <ra...@apache.org>
Committed: Mon Aug 10 07:22:11 2015 +0530
----------------------------------------------------------------------
.../server/session/DatabaseResourceService.java | 47 +--
.../apache/lens/server/util/ScannedPaths.java | 124 ++++----
.../lens/server/util/TestScannedPaths.java | 314 +++++++++----------
3 files changed, 219 insertions(+), 266 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/96cbccd9/lens-server/src/main/java/org/apache/lens/server/session/DatabaseResourceService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/session/DatabaseResourceService.java b/lens-server/src/main/java/org/apache/lens/server/session/DatabaseResourceService.java
index df7396c..72f5c53 100644
--- a/lens-server/src/main/java/org/apache/lens/server/session/DatabaseResourceService.java
+++ b/lens-server/src/main/java/org/apache/lens/server/session/DatabaseResourceService.java
@@ -19,19 +19,17 @@
package org.apache.lens.server.session;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.nio.charset.Charset;
import java.util.*;
import org.apache.lens.server.LensServices;
import org.apache.lens.server.api.LensConfConstants;
import org.apache.lens.server.api.error.LensException;
import org.apache.lens.server.api.metrics.MetricsService;
+import org.apache.lens.server.util.ScannedPaths;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -69,16 +67,6 @@ public class DatabaseResourceService extends AbstractService {
getMetrics().incrCounter(DatabaseResourceService.class, counter);
}
- /**
- * Gets counter value.
- *
- * @param counter the counter
- */
- private long getCounter(String counter) {
- return getMetrics().getCounter(DatabaseResourceService.class, counter);
- }
-
-
public DatabaseResourceService(String name) {
super(name);
@@ -87,8 +75,8 @@ public class DatabaseResourceService extends AbstractService {
@Override
public synchronized void init(HiveConf hiveConf) {
super.init(hiveConf);
- classLoaderCache = new HashMap<String, ClassLoader>();
- dbResEntryMap = new HashMap<String, List<LensSessionImpl.ResourceEntry>>();
+ classLoaderCache = new HashMap<>();
+ dbResEntryMap = new HashMap<>();
}
@Override
@@ -159,20 +147,7 @@ public class DatabaseResourceService extends AbstractService {
private void findResourcesInDir(FileSystem serverFs, String database, Path dbDirPath) throws IOException {
// Check if order file is present in the directory
- List<String> jars = null;
- Path jarOrderFile = new Path(dbDirPath, "jar_order");
- if (serverFs.exists(jarOrderFile)) {
- InputStream jarOrderInputStream = null;
- try {
- jarOrderInputStream = serverFs.open(jarOrderFile);
- jars = IOUtils.readLines(jarOrderInputStream, Charset.forName("UTF-8"));
- } catch (IOException ioexc) {
- log.error("Unable to load jar order file for {}", dbDirPath, ioexc);
- } finally {
- IOUtils.closeQuietly(jarOrderInputStream);
- }
- }
-
+ List<String> jars = new ScannedPaths(dbDirPath, "jar").getFinalPaths();
if (jars != null && !jars.isEmpty()) {
log.info("{} picking jar in jar_order: {}", database, jars);
for (String jar : jars) {
@@ -212,7 +187,7 @@ public class DatabaseResourceService extends AbstractService {
synchronized (dbResEntryMap) {
List<LensSessionImpl.ResourceEntry> dbEntryList = dbResEntryMap.get(dbName);
if (dbEntryList == null) {
- dbEntryList = new ArrayList<LensSessionImpl.ResourceEntry>();
+ dbEntryList = new ArrayList<>();
dbResEntryMap.put(dbName, dbEntryList);
}
dbEntryList.add(entry);
@@ -266,11 +241,9 @@ public class DatabaseResourceService extends AbstractService {
URL[] preUrls = urlLoader.getURLs();
// Add to set to remove duplicate additions
- Set<URL> newUrls = new LinkedHashSet<URL>();
+ Set<URL> newUrls = new LinkedHashSet<>();
// New class loader = URLs of DB jars + argument jars
- for (URL url : preUrls) {
- newUrls.add(url);
- }
+ Collections.addAll(newUrls, preUrls);
for (LensSessionImpl.ResourceEntry res : resources) {
try {
@@ -308,8 +281,8 @@ public class DatabaseResourceService extends AbstractService {
/**
* Get class loader of a database added with database specific jars
- * @param database
- * @return
+ * @param database database
+ * @return class loader from cache of classloaders for each db
* @throws LensException
*/
protected ClassLoader getClassLoader(String database) throws LensException {
@@ -318,7 +291,7 @@ public class DatabaseResourceService extends AbstractService {
/**
* Get resources added statically to the database
- * @param database
+ * @param database db
* @return resources added to the database, or null if no resources are noted for this database
*/
public Collection<LensSessionImpl.ResourceEntry> getResourcesForDatabase(String database) {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/96cbccd9/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
index 50b3da8..e48eab4 100644
--- a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
+++ b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
@@ -22,35 +22,39 @@ package org.apache.lens.server.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import lombok.AllArgsConstructor;
+import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
+@Data
+@AllArgsConstructor
public class ScannedPaths implements Iterable<String> {
- private String path = null;
- private String type = null;
+ private final Path path;
+ private final String type;
/* The Chosen Ones */
- @Getter(lazy=true) private final List<String> finalPaths = getMatchedPaths(path, type);
+ @Getter(lazy = true) private final List<String> finalPaths = getMatchedPaths(path, type);
public ScannedPaths(String path, String type) {
- this.path = path;
- this.type = type;
+ this(new Path(path), type);
}
+
@Override
public Iterator<String> iterator() {
/** Does all the pattern matching and returns the iterator to finalPaths collection.
@@ -66,68 +70,60 @@ public class ScannedPaths implements Iterable<String> {
*
* Updates finalPaths List with matched paths and returns an iterator for matched paths.
*/
- private List<String> getMatchedPaths(String path, String type) {
+ private List<String> getMatchedPaths(Path pt, String type) {
List<String> finalPaths = new ArrayList<>();
InputStream resourceOrderIStream = null;
- FileSystem fs = null;
+ FileSystem fs;
try {
- fs = FileSystem.get(new URI(path), new Configuration());
- Path pt = new Path(new URI(path));
-
-
- if (fs.exists(pt) && fs.isFile(pt)) {
- /**
- * CASE 1 : Direct FILE provided in path
- **/
- finalPaths.add(pt.toUri().toString());
- } else if (fs.exists(pt) && fs.isDirectory(pt)) {
- /**
- * CASE 2 : DIR provided in path
- **/
- Path resourceOrderFile = null;
- FileStatus[] statuses;
- List<String> newMatches;
- List<String> resources;
- boolean resourceFileFound = false;
-
- fs = pt.getFileSystem(new Configuration());
- resourceOrderFile = new Path(pt, "jar_order");
- /** Add everything in dir if no jar_order or glob_order is present **/
- if (!fs.exists(resourceOrderFile)) {
- resourceOrderFile = new Path(pt, "glob_order");
+ fs = pt.getFileSystem(new Configuration());
+ if (fs.exists(pt)) {
+ if (fs.isFile(pt)) {
+ /**
+ * CASE 1 : Direct FILE provided in path
+ **/
+ finalPaths.add(pt.toUri().toString());
+ } else if (fs.isDirectory(pt)) {
+ /**
+ * CASE 2 : DIR provided in path
+ **/
+ Path resourceOrderFile;
+ FileStatus[] statuses;
+ List<String> newMatches;
+ List<String> resources;
+
+ resourceOrderFile = new Path(pt, "jar_order");
+ /** Add everything in dir if no jar_order or glob_order is present **/
if (!fs.exists(resourceOrderFile)) {
- /** Get matched resources recursively for all files **/
- statuses = fs.globStatus(new Path(pt, "*"));
- if (statuses != null) {
- for (FileStatus st : statuses) {
- finalPaths.add(st.getPath().toUri().toString());
+ resourceOrderFile = new Path(pt, "glob_order");
+ if (!fs.exists(resourceOrderFile)) {
+ resourceOrderFile = null;
+ /** Get matched resources recursively for all files **/
+ statuses = fs.globStatus(new Path(pt, "*"));
+ if (statuses != null) {
+ for (FileStatus st : statuses) {
+ newMatches = getMatchedPaths(st.getPath(), type);
+ finalPaths.addAll(newMatches);
+ }
}
}
- } else {
- resourceFileFound = true;
}
- } else {
- resourceFileFound = true;
- }
-
- if (resourceFileFound) {
- /** Else get jars as per order specified in jar_order/glob_order **/
- resourceOrderIStream = fs.open(resourceOrderFile);
- resources = IOUtils.readLines(resourceOrderIStream, Charset.forName("UTF-8"));
- for (String resource : resources) {
- if (resource == null || resource.isEmpty()) {
- continue;
- }
-
- /** Get matched resources recursively for provided path/pattern **/
- if (resource.startsWith("/") || resource.contains(":/")) {
- newMatches = getMatchedPaths(new Path(resource).toString(), type);
- } else {
- newMatches = getMatchedPaths(new Path(pt, resource).toString(), type);
- }
+ if (resourceOrderFile != null) {
+ /** Else get jars as per order specified in jar_order/glob_order **/
+ resourceOrderIStream = fs.open(resourceOrderFile);
+ resources = IOUtils.readLines(resourceOrderIStream, Charset.forName("UTF-8"));
+ for (String resource : resources) {
+ if (StringUtils.isBlank(resource)) {
+ continue;
+ }
+ resource = resource.trim();
- if (newMatches != null) {
+ /** Get matched resources recursively for provided path/pattern **/
+ if (resource.startsWith("/") || resource.contains(":/")) {
+ newMatches = getMatchedPaths(new Path(resource), type);
+ } else {
+ newMatches = getMatchedPaths(new Path(pt, resource), type);
+ }
finalPaths.addAll(newMatches);
}
}
@@ -136,19 +132,15 @@ public class ScannedPaths implements Iterable<String> {
/**
* CASE 3 : REGEX provided in path
* */
- FileStatus[] statuses = fs.globStatus(pt);
+ FileStatus[] statuses = fs.globStatus(Path.getPathWithoutSchemeAndAuthority(pt));
if (statuses != null) {
for (FileStatus st : statuses) {
- List<String> newMatches = getMatchedPaths(st.getPath().toString(), type);
- if (newMatches != null) {
- finalPaths.addAll(newMatches);
- }
+ List<String> newMatches = getMatchedPaths(st.getPath(), type);
+ finalPaths.addAll(newMatches);
}
}
}
-
filterDirsAndJarType(fs, finalPaths);
-
} catch (FileNotFoundException fex) {
log.error("File not found while scanning path. Path: {}, Type: {}", path, type, fex);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/96cbccd9/lens-server/src/test/java/org/apache/lens/server/util/TestScannedPaths.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/util/TestScannedPaths.java b/lens-server/src/test/java/org/apache/lens/server/util/TestScannedPaths.java
index 9092420..6ad8153 100644
--- a/lens-server/src/test/java/org/apache/lens/server/util/TestScannedPaths.java
+++ b/lens-server/src/test/java/org/apache/lens/server/util/TestScannedPaths.java
@@ -19,22 +19,19 @@
package org.apache.lens.server.util;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import org.apache.commons.io.FileUtils;
-import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Joiner;
-
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -63,9 +60,7 @@ public class TestScannedPaths {
fileRegex = tempPath + "tempdata_unknown_*";
sc = new ScannedPaths(fileRegex, "file");
- Assert.assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
- } catch (Exception e) {
- Assert.fail("Exception while testing ScannedPaths : " + e.getMessage());
+ assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
} finally {
FileUtils.deleteQuietly(new File(tempPath));
}
@@ -76,7 +71,6 @@ public class TestScannedPaths {
String filenameA, filenameB, filenameC, fileRegex;
String tempPath = "target/tempfiles/";
ScannedPaths sc;
- Iterator<String> iter = null;
PrintWriter writer;
try {
@@ -113,8 +107,6 @@ public class TestScannedPaths {
assertOrdered(sc, filenameB, filenameA, filenameC);
- } catch (Exception e) {
- Assert.fail("Exception while testing ScannedPaths : " + e.getMessage());
} finally {
FileUtils.deleteQuietly(new File(tempPath));
}
@@ -144,7 +136,8 @@ public class TestScannedPaths {
* sourceDirPath/tempfiles/dir3/innerDirB/inceptionLevel2/tempdata_c-duplicate-2.jar
* @param sourceDirPath
*/
- private void createTempDirStructure1(String sourceDirPath) {
+ private void createTempDirStructure1(String sourceDirPath)
+ throws IOException {
File jarFile, globFile;
String filenameA, filenameB, filenameC;
String tempPath = sourceDirPath + "/tempfiles/";
@@ -160,62 +153,58 @@ public class TestScannedPaths {
PrintWriter writer;
- try {
- createNewPath(tempPath, filenameC, jarExtension);
- createNewPath(tempPath, filenameA, jarExtension);
- createNewPath(tempPath, dir1, filenameA, jarExtension);
- createNewPath(tempPath, dir1, filenameB, jarExtension);
- createNewPath(tempPath, dir1, filenameC, dataExtension);
- createNewPath(tempPath, dir2, filenameA, dataExtension);
- createNewPath(tempPath, dir2, filenameB, dataExtension);
- createNewPath(tempPath, dir2, filenameC, jarExtension);
- createNewPath(tempPath, dir3, filenameA, jarExtension);
- createNewPath(tempPath, dir3, filenameB, dataExtension);
- createNewPath(tempPath, dir3, filenameC, jarExtension);
- createNewPath(tempPath, dir3, filenameC, "-duplicate", jarExtension);
-
- /** Additional paths for inner dirs **/
- createNewPath(tempPath, dir3, "innerDirA/inceptionLevel2/", filenameC, jarExtension);
- createNewPath(tempPath, dir3, "innerDirA/inceptionLevel2/", filenameC, "-duplicate", jarExtension);
- createNewPath(tempPath, dir3, "innerDirB/inceptionLevel2/", filenameC, "-duplicate-2", jarExtension);
-
- /** Create jar_order **/
- jarFile = createNewPath(tempPath, dir1, "jar_order");
- writer = new PrintWriter(jarFile, "UTF-8");
- writer.println(filenameB + jarExtension);
- writer.println(filenameA + jarExtension);
- writer.close();
- jarFile = createNewPath(tempPath, dir2, "jar_order");
- writer = new PrintWriter(jarFile, "UTF-8");
- writer.println(filenameC + jarExtension);
- writer.close();
- jarFile = createNewPath(tempPath, dir3, "jar_order");
- writer = new PrintWriter(jarFile, "UTF-8");
- writer.println(filenameC + "-duplicate" + jarExtension);
- writer.println(filenameA + jarExtension);
- writer.close();
- /** Create glob_order **/
- globFile = createNewPath(tempPath, dir1, "glob_order");
- writer = new PrintWriter(globFile, "UTF-8");
- writer.println(filenameC + dataExtension);
- writer.println(filenameB + jarExtension);
- writer.println(filenameA + jarExtension);
- writer.close();
-
- globFile = createNewPath(tempPath, dir3, "glob_order");
- writer = new PrintWriter(globFile, "UTF-8");
- writer.println(filenameC + jarExtension);
- writer.println(filenameC + "-duplicate" + jarExtension);
- /** Check regex compatibility in order files **/
- writer.println("inner*/*Level*/" + filenameC + "-duplicate*" + jarExtension);
- writer.close();
+ createNewPath(tempPath, filenameC, jarExtension);
+ createNewPath(tempPath, filenameA, jarExtension);
+ createNewPath(tempPath, dir1, filenameA, jarExtension);
+ createNewPath(tempPath, dir1, filenameB, jarExtension);
+ createNewPath(tempPath, dir1, filenameC, dataExtension);
+ createNewPath(tempPath, dir2, filenameA, dataExtension);
+ createNewPath(tempPath, dir2, filenameB, dataExtension);
+ createNewPath(tempPath, dir2, filenameC, jarExtension);
+ createNewPath(tempPath, dir3, filenameA, jarExtension);
+ createNewPath(tempPath, dir3, filenameB, dataExtension);
+ createNewPath(tempPath, dir3, filenameC, jarExtension);
+ createNewPath(tempPath, dir3, filenameC, "-duplicate", jarExtension);
+
+ /** Additional paths for inner dirs **/
+ createNewPath(tempPath, dir3, "innerDirA/inceptionLevel2/", filenameC, jarExtension);
+ createNewPath(tempPath, dir3, "innerDirA/inceptionLevel2/", filenameC, "-duplicate", jarExtension);
+ createNewPath(tempPath, dir3, "innerDirB/inceptionLevel2/", filenameC, "-duplicate-2", jarExtension);
+
+ /** Create jar_order **/
+ jarFile = createNewPath(tempPath, dir1, "jar_order");
+ writer = new PrintWriter(jarFile, "UTF-8");
+ writer.println(filenameB + jarExtension);
+ writer.println(filenameA + jarExtension);
+ writer.close();
+ jarFile = createNewPath(tempPath, dir2, "jar_order");
+ writer = new PrintWriter(jarFile, "UTF-8");
+ writer.println(filenameC + jarExtension);
+ writer.close();
+ jarFile = createNewPath(tempPath, dir3, "jar_order");
+ writer = new PrintWriter(jarFile, "UTF-8");
+ writer.println(filenameC + "-duplicate" + jarExtension);
+ writer.println(filenameA + jarExtension);
+ writer.close();
+
+ /** Create glob_order **/
+ globFile = createNewPath(tempPath, dir1, "glob_order");
+ writer = new PrintWriter(globFile, "UTF-8");
+ writer.println(filenameC + dataExtension);
+ writer.println(filenameB + jarExtension);
+ writer.println(filenameA + jarExtension);
+ writer.close();
+
+ globFile = createNewPath(tempPath, dir3, "glob_order");
+ writer = new PrintWriter(globFile, "UTF-8");
+ writer.println(filenameC + jarExtension);
+ writer.println(filenameC + "-duplicate" + jarExtension);
+ /** Check regex compatibility in order files **/
+ writer.println("inner*/*Level*/" + filenameC + "-duplicate*" + jarExtension);
+ writer.close();
-
- } catch (Exception ex) {
- Assert.fail("Exception while creating temp paths : " + ex.getMessage());
- }
}
@@ -239,45 +228,41 @@ public class TestScannedPaths {
*
* @param sourceDirPath
*/
- private void createTempDirStructure2(String sourceDirPath) {
+ private void createTempDirStructure2(String sourceDirPath)
+ throws IOException {
File orderFile;
String tempPath = sourceDirPath + "/parent_dir/";
FileUtils.deleteQuietly(new File(tempPath));
PrintWriter writer;
- try {
- createNewPath(tempPath, "a_dir/jar_1");
- createNewPath(tempPath, "a_dir/jar_2");
- createNewPath(tempPath, "b_dir/jar_3");
- createNewPath(tempPath, "b_dir/jar_4");
- createNewPath(tempPath, "c_dir/jar_5");
- createNewPath(tempPath, "c_dir/jar_6");
-
-
- /** Create jar_order **/
- orderFile = createNewPath(tempPath, "a_dir/jar_order");
- writer = new PrintWriter(orderFile, "UTF-8");
- writer.println("*1");
- writer.println("*2");
- writer.close();
-
- orderFile = createNewPath(tempPath, "b_dir/glob_order");
- writer = new PrintWriter(orderFile, "UTF-8");
- writer.println("*4");
- writer.println("*3");
- writer.close();
-
- orderFile = createNewPath(tempPath, "jar_order");
- writer = new PrintWriter(orderFile, "UTF-8");
- writer.println("a*");
- writer.println("b*");
- writer.println("c*");
- writer.close();
-
- } catch (Exception ex) {
- Assert.fail("Exception while creating temp paths : " + ex.getMessage());
- }
+ createNewPath(tempPath, "a_dir/jar_1");
+ createNewPath(tempPath, "a_dir/jar_2");
+ createNewPath(tempPath, "b_dir/jar_3");
+ createNewPath(tempPath, "b_dir/jar_4");
+ createNewPath(tempPath, "c_dir/jar_5");
+ createNewPath(tempPath, "c_dir/jar_6");
+
+
+ /** Create jar_order **/
+ orderFile = createNewPath(tempPath, "a_dir/jar_order");
+ writer = new PrintWriter(orderFile, "UTF-8");
+ writer.println("*1");
+ writer.println("*2");
+ writer.close();
+
+ orderFile = createNewPath(tempPath, "b_dir/glob_order");
+ writer = new PrintWriter(orderFile, "UTF-8");
+ writer.println("*4");
+ writer.println("*3");
+ writer.close();
+
+ orderFile = createNewPath(tempPath, "jar_order");
+ writer = new PrintWriter(orderFile, "UTF-8");
+ writer.println("a*");
+ writer.println("b*");
+ writer.println("c*");
+ writer.close();
}
public void testScannedPathsMultipleJarGlobOrder() throws Exception {
@@ -300,18 +285,18 @@ public class TestScannedPaths {
createTempDirStructure1(tempPath);
sc = new ScannedPaths(fileRegex1, "jar");
- assertUnOrdered(sc, filenameCJar, filenameAJar);
+ assertUnOrdered(sc, filenameCJar, filenameAJar, filenameBJar, filenameCDupJar);
sc = new ScannedPaths(fileRegex2, "jar");
assertUnOrdered(sc,
- filenameBJar,
- filenameAJar,
- filenameCJar, // Direct matched tempdata_c.jar
- filenameCJar,
- filenameCDupJar,
- filenameAJar,
- filenameAJar // Direct matched tempdata_a.jar
+ filenameBJar,
+ filenameAJar,
+ filenameCJar, // Direct matched tempdata_c.jar
+ filenameCJar,
+ filenameCDupJar,
+ filenameAJar,
+ filenameAJar // Direct matched tempdata_a.jar
);
/** Remove jar_order files from temp dir **/
@@ -320,27 +305,26 @@ public class TestScannedPaths {
FileUtils.deleteQuietly(new File(tempPath + "tempfiles/dir3/jar_order"));
sc = new ScannedPaths(fileRegex1, "file");
- assertUnOrdered(sc, filenameCJar, filenameAJar);
+ assertUnOrdered(sc, filenameCJar, filenameAJar, filenameAData, filenameBJar, filenameBData, filenameCData,
+ filenameCDupJar, filenameCDupJar2);
sc = new ScannedPaths(fileRegex2, "file");
assertUnOrdered(sc,
- filenameCData, // dir1
- filenameBJar, // dir1
- filenameAJar, // dir1
- filenameCJar, // Direct matched tempdata_c.jar
- filenameCJar, // dir2
- filenameBData, // dir2
- filenameAData, // dir2
- filenameCJar, // dir3
- filenameCDupJar, //dir3
- filenameCDupJar2, // dir3/inner
- filenameCDupJar, // dir3/inner
- filenameAJar // Direct matched tempdata_a.jar
+ filenameCData, // dir1
+ filenameBJar, // dir1
+ filenameAJar, // dir1
+ filenameCJar, // Direct matched tempdata_c.jar
+ filenameCJar, // dir2
+ filenameBData, // dir2
+ filenameAData, // dir2
+ filenameCJar, // dir3
+ filenameCDupJar, //dir3
+ filenameCDupJar2, // dir3/inner
+ filenameCDupJar, // dir3/inner
+ filenameAJar // Direct matched tempdata_a.jar
);
- } catch (Exception e) {
- Assert.fail("Exception while testing ScannedPaths : " + e.getMessage());
} finally {
FileUtils.deleteQuietly(new File(tempPath));
}
@@ -359,12 +343,12 @@ public class TestScannedPaths {
sc = new ScannedPaths(fileRegex, "file");
assertUnOrdered(sc,
- "jar_1",
- "jar_2",
- "jar_4",
- "jar_3",
- "jar_6",
- "jar_5");
+ "jar_1",
+ "jar_2",
+ "jar_4",
+ "jar_3",
+ "jar_6",
+ "jar_5");
/** Now also enforce order for c_dir **/
File orderFile = createNewPath(tempPath, "parent_dir/c_dir/glob_order");
@@ -376,15 +360,13 @@ public class TestScannedPaths {
sc = new ScannedPaths(fileRegex, "file");
assertUnOrdered(sc,
- "jar_1",
- "jar_2",
- "jar_4",
- "jar_3",
- "jar_5",
- "jar_6");
-
- } catch (Exception e) {
- Assert.fail("Exception while testing ScannedPaths : " + e.getMessage());
+ "jar_1",
+ "jar_2",
+ "jar_4",
+ "jar_3",
+ "jar_5",
+ "jar_6");
+
} finally {
FileUtils.deleteQuietly(new File(tempPath));
}
@@ -400,60 +382,66 @@ public class TestScannedPaths {
try {
sc = new ScannedPaths(fileRegex, "file");
- Assert.assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
+ assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
sc = new ScannedPaths(fileRegex, "jar");
- Assert.assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
+ assertFalse(sc.iterator().hasNext(), "Iterator should be empty for unmatched path patterns.");
- } catch (Exception e) {
- Assert.fail("Exception while testing ScannedPaths : " + e.getMessage());
} finally {
FileUtils.deleteQuietly(new File(tempPath));
}
}
- private File createNewPath(String ... params) {
+ private File createNewPath(String... params) throws IOException {
String fileName = Joiner.on("").join(params);
File f = new File(fileName);
- try {
- if (!f.getParentFile().exists()) {
- f.getParentFile().mkdirs();
- }
- if (!f.exists()) {
- f.createNewFile();
- }
- } catch (IOException e) {
- Assert.fail("Unable to create test file, so bailing out.");
+
+ if (!f.getParentFile().exists()) {
+ f.getParentFile().mkdirs();
+ }
+ if (!f.exists()) {
+ f.createNewFile();
}
return f;
}
- private void assertOrdered(ScannedPaths sc, String ... expectedPaths) {
+ private void assertOrdered(ScannedPaths sc, String... expectedPaths) {
+ ScannedPaths sc2 = new ScannedPaths(new File(sc.getPath().toString()).getAbsolutePath(), sc.getType());
+ ScannedPaths sc3 = new ScannedPaths("file:" + new File(sc.getPath().toString()).getAbsolutePath(), sc.getType());
+ assertSameScannedPaths(sc2, sc3);
List<String> actual = new ArrayList<>();
for (String path : sc) {
actual.add(path.substring(path.lastIndexOf("/") + 1, path.length()));
}
List<String> expected = new ArrayList<>();
- for (String path : expectedPaths) {
- expected.add(path);
- }
-
- Assert.assertEquals(actual, expected);
+ Collections.addAll(expected, expectedPaths);
+ assertEquals(actual, expected);
}
- private void assertUnOrdered(ScannedPaths sc, String ... expectedPaths) {
+ private void assertUnOrdered(ScannedPaths sc, String... expectedPaths) {
+ ScannedPaths sc2 = new ScannedPaths(new File(sc.getPath().toString()).getAbsolutePath(), sc.getType());
+ ScannedPaths sc3 = new ScannedPaths("file:" + new File(sc.getPath().toString()).getAbsolutePath(), sc.getType());
+ assertSameScannedPaths(sc2, sc3);
+ assertEquals(sc2.getFinalPaths(), sc3.getFinalPaths());
Set<String> actual = new HashSet<>();
for (String path : sc) {
actual.add(path.substring(path.lastIndexOf("/") + 1, path.length()));
}
Set<String> expected = new HashSet<>();
- for (String path : expectedPaths) {
- expected.add(path);
- }
+ Collections.addAll(expected, expectedPaths);
+ assertEquals(actual, expected);
+ }
- Assert.assertEquals(actual, expected);
+ private void assertSameScannedPaths(ScannedPaths sc2, ScannedPaths sc3) {
+ assertEquals(sc2.getFinalPaths().size(), sc3.getFinalPaths().size());
+ for (int i = 0; i < sc2.getFinalPaths().size(); i++) {
+ assertEquals(
+ sc2.getFinalPaths().get(i).replaceAll("^file:", ""),
+ sc3.getFinalPaths().get(i).replaceAll("^file:", "")
+ );
+ }
}
}