/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ * Copyright (C) 2007-2012 Mathieu Baudier
*
* 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);
}
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;
+ }
+
}