Repository: atlas
Updated Branches:
  refs/heads/master 72030ad1b -> 7c80aba28


ATLAS-2370: Fix LocalSolrRunner path issue in Windows

Signed-off-by: Sarath Subramanian <[email protected]>


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

Branch: refs/heads/master
Commit: 7c80aba28bedd2a53aeb7a2f8a4e5ad47b31d06d
Parents: 72030ad
Author: Graham Wallis <[email protected]>
Authored: Wed Jan 17 21:27:51 2018 -0800
Committer: Sarath Subramanian <[email protected]>
Committed: Wed Jan 17 21:28:28 2018 -0800

----------------------------------------------------------------------
 .../apache/atlas/runner/LocalSolrRunner.java    | 25 +++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/7c80aba2/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
----------------------------------------------------------------------
diff --git 
a/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java 
b/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
index ed8e9e1..2c79e2f 100644
--- a/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
+++ b/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
@@ -36,11 +36,12 @@ import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 public class LocalSolrRunner {
-    protected static final String[] COLLECTIONS        = readCollections();
+
     private   static final String   TARGET_DIRECTORY   = 
System.getProperty("embedded.solr.directory");
     private   static final String   COLLECTIONS_FILE   = "collections.txt";
     private   static final String   SOLR_XML           = "solr.xml";
     private   static final String   TEMPLATE_DIRECTORY = "core-template";
+    protected static final String[] COLLECTIONS        = readCollections();
 
     private static final Logger LOG = 
LoggerFactory.getLogger(LocalSolrRunner.class);
 
@@ -105,16 +106,26 @@ public class LocalSolrRunner {
     }
 
     private static String[] readCollections() {
-        try (InputStream inputStream = 
LocalSolrRunner.class.getResourceAsStream("/solr" + File.separator + 
COLLECTIONS_FILE);
-             BufferedReader buffer = new BufferedReader(new 
InputStreamReader(inputStream))) {
+        // For the classloader you need the following path: 
"/solr/collections.txt";
+        // Use explicit '/' separators (not File.separator) because even on 
Windows you want '/'
+        String resName = "/solr/" + COLLECTIONS_FILE;
+        try {
+            InputStream inputStream = 
LocalSolrRunner.class.getResourceAsStream(resName);
+            InputStreamReader isr = new InputStreamReader(inputStream);
+            BufferedReader buffer = new BufferedReader(isr);
             return 
Pattern.compile("\\s+").split(buffer.lines().collect(Collectors.joining("\n")));
-        } catch (IOException e) {
+        } catch (Exception e) {
             throw new RuntimeException("Unable to read collections file", e);
         }
     }
 
     private static String readSolrXml() throws IOException {
-        InputStream inputStream = getClassLoader().getResourceAsStream("solr" 
+ File.separator + SOLR_XML);
+        // For the classloader you need the following path: "/solr/solr.xml";
+        // Use explicit '/' separators (not File.separator) because even on 
Windows you want '/'
+        String resName = "/solr/" + SOLR_XML;
+        // Use the local classloader rather than the system classloader - i.e. 
avoid using
+        // 
Thread.currentThread().getContextClassLoader().getResourceAsStream(resName);
+        InputStream inputStream = 
LocalSolrRunner.class.getResourceAsStream(resName);
 
         if (inputStream == null) {
             throw new RuntimeException("Unable to read solr xml");
@@ -123,10 +134,6 @@ public class LocalSolrRunner {
         return IOUtils.toString(inputStream, Charset.forName("UTF-8"));
     }
 
-    private static ClassLoader getClassLoader() {
-        return Thread.currentThread().getContextClassLoader();
-    }
-
     private static String getRandomString() {
         return UUID.randomUUID().toString();
     }

Reply via email to