/*
# Licensed Materials - Property of IBM
# Copyright IBM Corp. 2015,2016 
*/
package quarks.tests.connectors.wsclient.javax.websocket;

import java.io.File;

public class KeystorePath {
    
    public static String getStorePath(String storeLeaf) {
        String path = System.getProperty("user.dir");
        // Under eclipse/junit: path to project in repo: <repo>/connectors
        // Under ant/junit: <repo>/connectors/<project>/unittests/testrunxxxxxxx
        if (!path.endsWith("/connectors")) {
            int indx = path.indexOf("/connectors/");
            indx += "/connectors/".length() - 1;
            path = path.substring(0, indx);
        }
        path += "/wsclient-javax.websocket/src/test/keystores/" + storeLeaf;
        if (!new File(path).exists())
            throw new IllegalArgumentException("File does not exist: "+path);
        return path;
    }

}

@@ -150,16 +150,43 @@
 io.File;
+%0Aimport java.nio.file.Path;
 %0A%0Apublic
@@ -289,16 +289,19 @@
 ing path
+Str
  = Syste
@@ -495,42 +495,107 @@
     
-if (!path.endsWith(%22/connectors%22))
+// Get the path to the %3Crepo%3E/connectors%0A        Path path = new File(pathStr).toPath();%0A        do
  %7B%0A 
@@ -610,33 +610,26 @@
    i
-nt indx = 
+f (
 path.
-indexOf
+endsWith
 (%22
-/
 conn
@@ -638,12 +638,11 @@
 tors
-/
 %22)
-;
+)
 %0A   
@@ -654,98 +654,98 @@
     
-indx += %22/connectors/%22.length() - 1;%0A            path = path.substring(0, indx);%0A        %7D
+    break;%0A            path = path.getParent();%0A        %7D while (path.getNameCount() %3E 0);
 %0A   
@@ -758,13 +758,24 @@
 ath 
-+
 = 
+path.resolve(
 %22
-/
 wscl
@@ -827,16 +827,17 @@
 toreLeaf
+)
 ;%0A      
@@ -843,29 +843,28 @@
    if (!
-new 
+path.to
 File(
-path
 ).exists
@@ -945,16 +945,16 @@
 +path);%0A
-
         
@@ -964,16 +964,27 @@
 urn path
+.toString()
 ;%0A    %7D%0A

fix test keystore path formation on windows