]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/ScpTo.java
Improve deployment
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / jsch / ScpTo.java
index 8d7e49b01e4d24c1930e76dac7bc7ca499466c64..5da5f79e7ba2511ee774f8e4b62498d17fb65b4e 100644 (file)
@@ -57,7 +57,7 @@ public class ScpTo extends AbstractJschTask {
                }
 
                if (localResource != null) {
-                       uploadResource(session, localResource, remoteDir);
+                       uploadResource(session, localResource);
                }
        }
 
@@ -109,18 +109,19 @@ public class ScpTo extends AbstractJschTask {
 
        protected void uploadFile(Session session, File file, String remoteFile) {
                try {
-                       uploadFile(session, new FileInputStream(file), file.length(), file
+                       upload(session, new FileInputStream(file), file.length(), file
                                        .getPath(), file.toString(), remoteFile);
                } catch (FileNotFoundException e) {
                        throw new SlcException("Cannot upload " + file, e);
                }
        }
 
-       protected void uploadResource(Session session, Resource resource,
-                       String remoteFile) {
+       protected void uploadResource(Session session, Resource resource) {
+               String targetPath = remotePath != null ? remotePath : remoteDir + '/'
+                               + resource.getFilename();
                try {
                        File lFile = resource.getFile();
-                       uploadFile(session, lFile, remotePath);
+                       uploadFile(session, lFile, targetPath);
                } catch (IOException e) {
                        // no underlying file found
                        // load the resource in memory before transferring it
@@ -137,10 +138,12 @@ public class ScpTo extends AbstractJschTask {
                                        IOUtils.copy(in, out);
                                        arr = out.toByteArray();
                                        path = resource.getURL().getPath();
+                                       if (path.startsWith("/"))
+                                               path = path.substring(1);
                                }
                                ByteArrayInputStream content = new ByteArrayInputStream(arr);
-                               uploadFile(session, content, arr.length, path, resource
-                                               .toString(), remotePath);
+                               upload(session, content, arr.length, path, resource.toString(),
+                                               targetPath);
                                arr = null;
                        } catch (IOException e1) {
                                throw new SlcException("Can not interpret resource "
@@ -152,7 +155,7 @@ public class ScpTo extends AbstractJschTask {
                }
        }
 
-       protected void uploadFile(Session session, InputStream in, long size,
+       protected void upload(Session session, InputStream in, long size,
                        String path, String sourceDesc, String remoteFile) {
                OutputStream channelOut;
                InputStream channelIn;