File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\os\windows\WindowsRemoteFileSystem.java.html

1 package hudson.os.windows;
2
3 import hudson.tools.JDKInstaller.FileSystem;
4 import jcifs.smb.NtlmPasswordAuthentication;
5 import jcifs.smb.SmbFile;
6
7 import java.io.IOException;
8 import java.io.InputStream;
9 import java.net.MalformedURLException;
10 import java.util.List;
11
12 import static java.util.Arrays.asList;
13
14 /**
15 * {@link FileSystem} implementation for remote Windows system.
16 *
17 * @author Kohsuke Kawaguchi
18 */
19 public class WindowsRemoteFileSystem implements FileSystem {
20 private final String hostName;
21 private final NtlmPasswordAuthentication auth;
22
23 public WindowsRemoteFileSystem(String hostName, NtlmPasswordAuthentication auth) {
24 this.hostName = hostName;
25 this.auth = auth;
26 }
27
28 private SmbFile $(String path) throws MalformedURLException {
29 return new SmbFile("smb://" + hostName + "/" + path.replace('\\', '/').replace(':', '$')+"/",auth);
30 }
31
32 public void delete(String file) throws IOException, InterruptedException {
33 $(file).delete();
34 }
35
36 public void chmod(String file, int mode) throws IOException, InterruptedException {
37 // no-op on Windows
38 }
39
40 public InputStream read(String file) throws IOException {
41 return $(file).getInputStream();
42 }
43
44 public List<String> listSubDirectories(String dir) throws IOException, InterruptedException {
45 return asList($(dir).list());
46 }
47
48 public void pullUp(String from, String to) throws IOException, InterruptedException {
49 SmbFile src = $(from);
50 SmbFile dst = $(to);
51 for (SmbFile e : src.listFiles()) {
52 e.renameTo(new SmbFile(dst,e.getName()));
53 }
54 src.delete();
55 }
56
57 public void mkdirs(String path) throws IOException {
58 $(path).mkdirs();
59 }
60 }
61