]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/VersionedDirSync.java
Move default agent to execution package
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / deploy / VersionedDirSync.java
index c6698f26bfdf941e90b8dc1ba369f9ac9784eed9..13d254366b274b53d236136562abe271cb5b8bcc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.argeo.slc.core.deploy;
 
 import java.io.File;
+import java.io.IOException;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
 import org.argeo.slc.deploy.VersioningDriver;
 
+/**
+ * Synchronizes an URL to a local directory, taking into account versioning
+ * information if possible.
+ */
 public class VersionedDirSync implements Runnable {
        private final static Log log = LogFactory.getLog(VersionedDirSync.class);
 
        private VersioningDriver versioningDriver;
        private File dir;
        private String url;
+       private Boolean clean = false;
+
+       private Boolean changed = null;
 
        public void run() {
-               versioningDriver.checkout(url, dir, true);
+               changed = null;
+               if (clean) {
+                       try {
+                               log.info("Clean " + dir);
+                               FileUtils.deleteDirectory(dir);
+                       } catch (IOException e) {
+                               throw new SlcException("Cannot delete checkout directory "
+                                               + dir, e);
+                       }
+                       dir.mkdirs();
+               }
+               log.info("Checkout " + url + " to " + dir);
+               changed = versioningDriver.checkout(url, dir, true);
                if (log.isDebugEnabled())
                        log.debug("Synchronized " + url + " to " + dir);
        }
@@ -47,4 +68,16 @@ public class VersionedDirSync implements Runnable {
                this.url = url;
        }
 
+       /** Delete before checkout */
+       public void setClean(Boolean clean) {
+               this.clean = clean;
+       }
+
+       /** Whether last call has changed the directory */
+       public Boolean getChanged() {
+               if (changed == null)
+                       throw new SlcException("Sync has not run");
+               return changed;
+       }
+
 }