[Swift-commit] r6674 - in branches/release-0.94/src/org/griphyn/vdl: karajan/lib karajan/lib/swiftscript mapping

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Mon Jul 29 00:58:47 CDT 2013


Author: hategan
Date: 2013-07-29 00:58:47 -0500 (Mon, 29 Jul 2013)
New Revision: 6674

Modified:
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageins.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageouts.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/FileCopier.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InFileDirs.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/PathUtils.java
   branches/release-0.94/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
   branches/release-0.94/src/org/griphyn/vdl/mapping/AbsFile.java
Log:
merged 6673 from trunk

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageins.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageins.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageins.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -63,8 +63,8 @@
             if (protocol.equals("file")) {
                 protocol = TypeUtil.toString(STAGING_METHOD.getValue(stack));
             }
-            String path = file.getDir().equals("") ? 
-                    file.getName() : file.getDir() + "/" + file.getName();
+            String path = file.getDirectory() == null ? 
+                    file.getName() : file.getDirectory() + "/" + file.getName();
             String relpath = path.startsWith("/") ? path.substring(1) : path;
             if (logger.isDebugEnabled()) {
                 logger.debug("will stage in: " + relpath + " via: " + protocol);

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageouts.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageouts.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/AppStageouts.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -59,7 +59,7 @@
                 if (protocol.equals("file")) {
                     protocol = TypeUtil.toString(STAGING_METHOD.getValue(stack));
                 }
-                String path = file.getDir().equals("") ? file.getName() : file.getDir()
+                String path = file.getDirectory() == null ? file.getName() : file.getDirectory()
                         + "/" + file.getName();
                 String relpath = path.startsWith("/") ? path.substring(1) : path;
                 ArgUtil.getChannelReturn(stack, STAGEOUT).append(

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/FileCopier.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/FileCopier.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/FileCopier.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -57,9 +57,9 @@
         AbsFile fsrc = (AbsFile) src;
         AbsFile fdst = (AbsFile) dst;
         FileTransferSpecification fts = new FileTransferSpecificationImpl();
-        fts.setDestinationDirectory(fdst.getDir());
+        fts.setDestinationDirectory(fdst.getDirectory());
         fts.setDestinationFile(fdst.getName());
-        fts.setSourceDirectory(fsrc.getDir());
+        fts.setSourceDirectory(fsrc.getDirectory());
         fts.setSourceFile(fsrc.getName());
         fts.setThirdPartyIfPossible(true);
         task = new FileTransferTask();

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InFileDirs.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InFileDirs.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/InFileDirs.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -45,23 +45,21 @@
         for (Object f : files) { 
         	String path = (String) f;
         	AbsFile af = new AbsFile(path);
-        	if ("file".equals(af.getProtocol())) {
-                String dir = af.getDir();
-                // there could be a clash here since
-                // "/a/b/c.txt" would be remotely the same
-                // as "a/b/c.txt". Perhaps absolute paths
-                // should have a unique prefix.
-                if (dir.startsWith("/") && dir.length() != 1) {
-                	ret.append(dir.substring(1));
-                }
-                else if (dir.length() != 0) {
-                    ret.append(dir);
-                }
+        	String dir = af.getDirectory();
+        	if (dir != null) {
+            	if ("file".equals(af.getProtocol())) {
+            		if (dir.startsWith("/") && dir.length() != 1) {
+                    	ret.append(dir.substring(1));
+                    }
+                    else {
+                    	ret.append(dir);
+                    }
+            	}
+            	else {
+            	    // also prepend host name to the path
+            	    ret.append(af.getHost() + "/" + dir);
+            	}
         	}
-        	else {
-        	    // also prepend host name to the path
-        	    ret.append(af.getHost() + "/" + af.getDir());
-        	}
         }
         super.post(stack);
     }

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -51,18 +51,20 @@
                 DSHandle leaf = handle.getField(p);
                 String fname = VDLFunction.filename(leaf)[0];
                 AbsFile af = new AbsFile(fname);
-                if ("file".equals(af.getProtocol())) {
-                    String dir = af.getDir();
-                    if (dir.startsWith("/") && dir.length() != 1) {
-                        ret.append(dir.substring(1));
+                String dir = af.getDirectory();
+                if (dir != null) {
+                    if ("file".equals(af.getProtocol())) {
+                    	if (dir.startsWith("/") && dir.length() != 1) {
+                    		ret.append(dir.substring(1));
+                    	}
+                    	else {
+                    		ret.append(dir);
+                    	}
                     }
-                    else if (dir.length() != 0) {
-                        ret.append(dir);
+                    else {
+                        ret.add(af.getHost() + "/" + dir);
                     }
                 }
-                else {
-                	ret.append(af.getHost() + "/" + af.getDir());
-                }
             }
         }
         catch (Exception e) {

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/PathUtils.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/PathUtils.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/PathUtils.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -39,7 +39,7 @@
 
 	public String vdl_dirname(VariableStack stack) throws ExecutionException {
 		String path = TypeUtil.toString(PATH.getValue(stack));
-		return new AbsFile(path).getDir();
+		return new AbsFile(path).getDirectory();
 	}
     
     static {
@@ -48,13 +48,15 @@
 
     public String vdl_reldirname(VariableStack stack) throws ExecutionException {
         String path = TypeUtil.toString(PATH.getValue(stack));
-        String dir = new AbsFile(path).getDir();
-        if (dir.startsWith("/")) {
-            return dir.substring(1);
+        String dir = new AbsFile(path).getDirectory();
+        if (dir != null) {
+            if (dir.startsWith("/")) {
+                return dir.substring(1);
+            }
+            else {
+                return dir;
+            }
         }
-        else {
-            return dir;
-        }
     }
     
     static {

Modified: branches/release-0.94/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -431,7 +431,7 @@
 	    AbstractDataNode n = (AbstractDataNode) PA_FILE.getRawValue(stack);
 	    n.waitFor();
         String name = VDLFunction.filename(n)[0];
-        String result = new AbsFile(name).getDir();
+        String result = new AbsFile(name).getDirectory();
         return new RootDataNode(Types.STRING, result);
 	}
 

Modified: branches/release-0.94/src/org/griphyn/vdl/mapping/AbsFile.java
===================================================================
--- branches/release-0.94/src/org/griphyn/vdl/mapping/AbsFile.java	2013-07-29 04:35:49 UTC (rev 6673)
+++ branches/release-0.94/src/org/griphyn/vdl/mapping/AbsFile.java	2013-07-29 05:58:47 UTC (rev 6674)
@@ -31,72 +31,43 @@
 import org.globus.cog.abstraction.impl.file.FileResourceCache;
 import org.globus.cog.abstraction.interfaces.FileResource;
 import org.globus.cog.abstraction.interfaces.GridFile;
+import org.globus.cog.abstraction.interfaces.RemoteFile;
 import org.globus.cog.abstraction.interfaces.Service;
 
-public class AbsFile implements GeneralizedFileFormat {
-	private final String protocol;
-	private final String host;
-	private final String path;
-	private String dir, name;
+public class AbsFile extends RemoteFile implements GeneralizedFileFormat {
 	
 	public AbsFile(String url) {
-		int pi = url.indexOf("://");
-		if (pi == -1) {
-			protocol = "file";
-			host = "localhost";
-			path = url;
-		}
-		else {
-			protocol = url.substring(0, pi);
-			if (protocol.equals("file")) {
-				host = "localhost";
-				String rp = url.substring(pi + 3);
-				if (rp.startsWith("localhost/")) {
-					rp = rp.substring("localhost/".length());
-				}
-                path = rp;
-			}
-			else {
-				int si = url.indexOf('/', pi + 3);
-				if (si == -1) {
-					host = url.substring(pi + 3);
-					path = "";
-				}
-				else {
-					host = url.substring(pi + 3, si);
-					path = url.substring(si + 1);
-				}
-			}
-		}
-		initDirAndName();
+	    super(url);
 	}
     
-    private void initDirAndName() {
-    	int di = path.lastIndexOf('/');
-        if (di == 0) {
-            dir = "/";
+	public AbsFile(String protocol, String host, String path) {
+	    super(protocol, host, path);
+	}
+	
+	public AbsFile(String protocol, String host, int port, String dir, String name) {
+        super(protocol, host, port, dir, name);    
+    }
+
+    public AbsFile(String protocol, String host, int port, String path) {
+        super(protocol, host, port, path);    
+    }
+
+    @Override
+    protected void parse(String str) {
+        super.parse(str);
+        if (getProtocol() == null) {
+            setProtocol("file");
         }
-        else if (di > 0) {
-            dir = path.substring(0, di);
+        if (getHost() == null) {
+            setHost("localhost");
         }
-        else {
-            dir = "";
-        }
-        name = path.substring(di + 1);        
     }
 
-	public AbsFile(String protocol, String host, String path) {
-		this.protocol = protocol;
-		this.host = host;
-		this.path = path;
-		initDirAndName();
-	}
-
-	protected FileResource getFileResource() throws IOException {
+    protected FileResource getFileResource() throws IOException {
 		Service s = new ServiceImpl();
-		s.setProvider(protocol);
+		s.setProvider(getProtocol());
 		s.setType(Service.FILE_OPERATION);
-		s.setServiceContact(new ServiceContactImpl(host));
+		s.setServiceContact(new ServiceContactImpl(getHost(), getPort()));
 		try {
 			return FileResourceCache.getDefault().getResource(s);
 		}
@@ -113,7 +84,7 @@
 		try {
 			FileResource fr = getFileResource();
 			try {
-				return fr.exists(path);
+				return fr.exists(getPath());
 			}
 			finally {
 				releaseResource(fr);
@@ -126,15 +97,48 @@
 	}
 
 	private static final AbsFile[] FILE_ARRAY = new AbsFile[0];
+	
+	public List<AbsFile> listDirectories(FilenameFilter filter) {
+	    try {
+            FileResource fr = getFileResource();
+            try {
+                String protocol = getProtocol();
+                String host = getHost();
+                int port = getPort();
+                String dir = getPath();
+                List<AbsFile> l = new ArrayList<AbsFile>();
+                for (GridFile gf : fr.list(dir)) {
+                    AbsFile f = new AbsFile(protocol, host, port, dir, gf.getName());
+                    // f.getDirectory() cannot be null since dir cannot be null since getPath() returns
+                    // a non-null string
+                    if (gf.isDirectory() && (filter == null || filter.accept(new File(f.getDirectory()), f.getName()))) {
+                        l.add(f);
+                    }
+                }
+                return l;
+            }
+            finally {
+                releaseResource(fr);
+            }
+        }
+        catch (Exception e) {
+            // TODO this should be a proper exception
+            throw new RuntimeException(e);
+        }
+	}
 
 	public AbsFile[] listFiles(FilenameFilter filter) {
 		try {
 			FileResource fr = getFileResource();
 			try {
+			    String protocol = getProtocol();
+                String host = getHost();
+                int port = getPort();
+                String dir = getPath();
 				List<AbsFile> l = new ArrayList<AbsFile>();
-				for (GridFile gf : fr.list(path)) {
-					AbsFile f = new AbsFile(protocol, host, gf.getAbsolutePathName());
-					if (filter == null || filter.accept(new File(f.getDir()), f.getName())) {
+				for (GridFile gf : fr.list(dir)) {
+					AbsFile f = new AbsFile(protocol, host, port, dir, gf.getName());
+					if (filter == null || filter.accept(new File(f.getDirectory()), f.getName())) {
 						l.add(f);
 					}
 				}
@@ -150,64 +154,16 @@
 		}
 	}
 
-	public String getName() {
-		return name;
-	}
-
-	public String getDir() {
-		return dir;
-	}
-
-	public String getProtocol() {
-		return protocol;
-	}
-
-	public String getHost() {
-		return host;
-	}
-
-	public String getPath() {
-		return path;
-	}
-	
-	public boolean isAbsolute() {
-	    return !path.isEmpty() && path.startsWith("/");
-	}
-	
 	public String getType() {
 		return "file";
 	}
 	
-	public String getURIAsString() {
-		return protocol + "://" + host + '/' + path;
-	}
-	
-	public String toString() {
-		return getURIAsString();
-	}
-
     public void clean() {
         try {
-            getFileResource().deleteFile(path);
+            getFileResource().deleteFile(getPath());
         }
         catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof AbsFile) {
-            AbsFile a = (AbsFile) obj;
-            return protocol.equals(a.protocol) && host.equals(a.host) && path.equals(a.path);
-        }
-        else {
-            return false;
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        return protocol.hashCode() + host.hashCode() + path.hashCode();
-    }
 }




More information about the Swift-commit mailing list