]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/SshFilesDeployment.java
Private keys support
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / jsch / SshFilesDeployment.java
1 package org.argeo.slc.jsch;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.argeo.slc.core.deploy.ResourceSet;
8 import org.springframework.core.io.Resource;
9
10 public class SshFilesDeployment implements Runnable {
11 private String targetBase = "";
12 private ResourceSet resourceSet;
13 private SshTarget sshTarget;
14
15 public void run() {
16 JschMultiTasks multiTasks = new JschMultiTasks();
17 multiTasks.setSshTarget(sshTarget);
18
19 List<String> subDirs = new ArrayList<String>();
20 Map<String, Resource> resources = resourceSet.listResources();
21 for (String relPath : resources.keySet()) {
22 // Create dir if necessary
23 String dir;
24 int lastIndexSubDir = relPath.lastIndexOf('/');
25 if (lastIndexSubDir > 0)
26 dir = targetBase + '/' + relPath.substring(0, lastIndexSubDir);
27 else
28 dir = targetBase;
29 if (!subDirs.contains(dir)) {
30 RemoteExec remoteExec = new RemoteExec();
31 remoteExec.setCommand("mkdir -p " + dir);
32 subDirs.add(dir);
33 multiTasks.getTasks().add(remoteExec);
34 }
35
36 // Copy resource
37 Resource resource = resources.get(relPath);
38 ScpTo scpTo = new ScpTo();
39 scpTo.setLocalResource(resource);
40 scpTo.setRemotePath(targetBase + "/" + relPath);
41 multiTasks.getTasks().add(scpTo);
42 }
43
44 multiTasks.run();
45 }
46
47 public void setTargetBase(String targetBase) {
48 this.targetBase = targetBase;
49 }
50
51 public void setResourceSet(ResourceSet resourceSet) {
52 this.resourceSet = resourceSet;
53 }
54
55 public void setSshTarget(SshTarget sshTarget) {
56 this.sshTarget = sshTarget;
57 }
58
59 }