1 package org
.argeo
.cms
.cmd
;
4 import java
.nio
.file
.FileSystems
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.spi
.FileSystemProvider
;
8 import java
.time
.ZonedDateTime
;
9 import java
.util
.HashMap
;
12 import org
.apache
.commons
.logging
.Log
;
13 import org
.apache
.commons
.logging
.LogFactory
;
14 import org
.argeo
.cms
.CmsException
;
15 import org
.argeo
.jackrabbit
.fs
.DavexFsProvider
;
16 import org
.argeo
.util
.LangUtils
;
19 private final static Log log
= LogFactory
.getLog(Sync
.class);
21 public static void main(String args
[]) {
22 Map
<String
, String
> arguments
= new HashMap
<>();
23 boolean skipNext
= false;
24 String currValue
= null;
25 for (int i
= 0; i
< args
.length
; i
++) {
32 if (arg
.startsWith("-")) {
33 if (i
+ 1 < args
.length
) {
34 if (!args
[i
+ 1].startsWith("-")) {
35 currValue
= args
[i
+ 1];
39 arguments
.put(arg
, currValue
);
46 URI sourceUri
= new URI(arguments
.get("-i"));
47 URI targetUri
= new URI(arguments
.get("-o"));
48 FileSystemProvider sourceFsProvider
= createFsProvider(sourceUri
);
49 FileSystemProvider targetFsProvider
= createFsProvider(targetUri
);
50 Path sourceBasePath
= sourceFsProvider
.getPath(sourceUri
);
51 Path targetBasePath
= targetFsProvider
.getPath(targetUri
);
52 SyncFileVisitor syncFileVisitor
= new SyncFileVisitor(sourceBasePath
, targetBasePath
);
53 ZonedDateTime begin
= ZonedDateTime
.now();
54 Files
.walkFileTree(sourceBasePath
, syncFileVisitor
);
55 if (log
.isDebugEnabled())
56 log
.debug("Sync from " + sourceBasePath
+ " to " + targetBasePath
+ " took " + LangUtils
.since(begin
));
57 } catch (Exception e
) {
62 private static FileSystemProvider
createFsProvider(URI uri
) {
63 FileSystemProvider fsProvider
;
64 if (uri
.getScheme().equals("file"))
65 fsProvider
= FileSystems
.getDefault().provider();
66 else if (uri
.getScheme().equals("davex"))
67 fsProvider
= new DavexFsProvider();
69 throw new CmsException("URI scheme not supported for " + uri
);