Author: dkulp
Date: Tue Feb 15 02:19:31 2011
New Revision: 1070759
URL: http://svn.apache.org/viewvc?rev=1070759&view=rev
Log:
Add an "svn" mode to use an svn checkout for staging
Modified:
cxf/web/pom.xml
cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
Modified: cxf/web/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/web/pom.xml?rev=1070759&r1=1070758&r2=1070759&view=diff
==============================================================================
--- cxf/web/pom.xml (original)
+++ cxf/web/pom.xml Tue Feb 15 02:19:31 2011
@@ -83,6 +83,9 @@
<argument>${space.key}</argument>
<argument>-template</argument>
<argument>${basedir}/template/template.vm</argument>
+ <!--argument>-svn</argument>
+ <argument>-commit</argument>
+ <argument>-force</argument-->
</arguments>
</configuration>
</plugin>
Modified: cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java
URL:
http://svn.apache.org/viewvc/cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java?rev=1070759&r1=1070758&r2=1070759&view=diff
==============================================================================
--- cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java (original)
+++ cxf/web/src/main/java/org/apache/cxf/cwiki/SiteExporter.java Tue Feb 15
02:19:31 2011
@@ -31,6 +31,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -58,6 +59,7 @@ import org.xml.sax.XMLReader;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.FileUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.interceptor.LoggingInInterceptor;
@@ -101,6 +103,9 @@ public class SiteExporter {
String pageCacheFile = "pagesConfig.obj";
String templateName = "template.vm";
boolean forceAll;
+ boolean svn;
+ boolean commit;
+ StringBuilder svnCommitMessage = new StringBuilder();
File outputDir = new File(".");
@@ -139,6 +144,10 @@ public class SiteExporter {
forceAll = true;
} else if ("-template".equals(s)) {
templateName = it.next();
+ } else if ("-svn".equals(s)) {
+ svn = true;
+ } else if ("-commit".equals(s)) {
+ commit = true;
}
}
@@ -187,8 +196,17 @@ public class SiteExporter {
renderPages();
savePages();
+
+ if (commit) {
+ File file = FileUtils.createTempFile("svncommit", "txt");
+ FileWriter writer = new FileWriter(file);
+ writer.write(svnCommitMessage.toString());
+ writer.close();
+ callSvn("commit", "-F", file.getAbsolutePath(),
outputDir.getAbsolutePath());
+ }
}
+
public boolean checkRSS() throws Exception {
if (forceAll || pages == null || pages.isEmpty()) {
return false;
@@ -249,13 +267,37 @@ public class SiteExporter {
ctx.put("exporter", this);
ctx.put("page", p);
ctx.put("confluenceUri", ROOT);
- FileWriter writer = new FileWriter(new File(outputDir,
p.createFileName()));
+
+ File file = new File(outputDir, p.createFileName());
+ boolean isNew = !file.exists();
+
+ FileWriter writer = new FileWriter(file);
ctx.put("out", writer);
template.merge(ctx, writer);
writer.close();
+ if (isNew) {
+ //call "svn add"
+ callSvn("add", file.getAbsolutePath());
+ svnCommitMessage.append("Adding: " + file.getName() + "\n");
+ } else {
+ svnCommitMessage.append("Modified: " + file.getName() + "\n");
+ }
}
}
+ private void callSvn(String ... commands) throws Exception {
+ if (svn) {
+ List<String> cmds = new ArrayList<String>();
+ cmds.add("svn");
+ cmds.add("--non-interactive");
+ cmds.addAll(Arrays.asList(commands));
+ Process p = Runtime.getRuntime().exec(cmds.toArray(new
String[cmds.size()]),
+ new String[0], outputDir);
+ if (p.waitFor() != 0) {
+ IOUtils.copy(p.getErrorStream(), System.err);
+ }
+ }
+ }
private void loadAttachments(Page p) throws Exception {
Document doc = XMLUtils.newDocument();
@@ -281,14 +323,24 @@ public class SiteExporter {
String dirName = p.createFileName();
dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data";
File file = new File(outputDir, dirName);
- file.mkdirs();
+ if (!file.exists()) {
+ callSvn("mkdir", file.getAbsolutePath());
+ file.mkdirs();
+ }
file = new File(file, filename);
+ boolean exists = file.exists();
FileOutputStream out = new FileOutputStream(file);
URL url = new URL(durl);
InputStream ins = url.openStream();
IOUtils.copy(ins, out);
out.close();
ins.close();
+ if (!exists) {
+ callSvn("add", file.getAbsolutePath());
+ svnCommitMessage.append("Added: " + dirName + "/" +
file.getName() + "\n");
+ } else {
+ svnCommitMessage.append("Modified: " + dirName + "/" +
file.getName() + "\n");
+ }
el = DOMUtils.getNextElement(el);
}
}
@@ -298,14 +350,24 @@ public class SiteExporter {
String dirName = p.createFileName();
dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".thumbs";
File file = new File(outputDir, dirName);
- file.mkdirs();
+ if (!file.exists()) {
+ callSvn("mkdir", file.getAbsolutePath());
+ file.mkdirs();
+ }
file = new File(file, filename);
+ boolean exists = file.exists();
FileOutputStream out = new FileOutputStream(file);
URL url = new URL(HOST + href);
InputStream ins = url.openStream();
IOUtils.copy(ins, out);
out.close();
ins.close();
+ if (!exists) {
+ callSvn("add", file.getAbsolutePath());
+ svnCommitMessage.append("Added: " + dirName + "/" + file.getName()
+ "\n");
+ } else {
+ svnCommitMessage.append("Modified: " + dirName + "/" +
file.getName() + "\n");
+ }
}
public Page findPage(String title) throws Exception {
for (Page p : pages.values()) {
@@ -466,15 +528,31 @@ public class SiteExporter {
doc.appendChild(el);
doc = dispatch.invoke(doc);
+ Set<String> allPages = new HashSet<String>(pages.keySet());
+
Node nd = doc.getDocumentElement().getFirstChild().getFirstChild();
while (nd != null) {
if (nd instanceof Element) {
- loadPage((Element)nd);
+ loadPage((Element)nd, allPages);
}
nd = nd.getNextSibling();
}
+
+ for (String id : allPages) {
+ //these pages have been deleted
+ Page p = pages.remove(id);
+
+ File file = new File(outputDir, p.createFileName());
+ if (file.exists()) {
+ callSvn("rm", file.getAbsolutePath());
+ svnCommitMessage.append("Deleted: " + file.getName() + "\n");
+ }
+ if (file.exists()) {
+ file.delete();
+ }
+ }
}
- public void loadPage(Element pageSumEl) throws Exception {
+ public void loadPage(Element pageSumEl, Set<String> allPages) throws
Exception {
Document doc = XMLUtils.newDocument();
Element el = doc.createElementNS(SOAPNS, "ns1:getPage");
Element el2 = doc.createElement("in0");
@@ -492,6 +570,9 @@ public class SiteExporter {
modifiedPages.add(page);
pages.put(page.getId(), page);
}
+ if (allPages.contains(page.getId())) {
+ allPages.remove(page.getId());
+ }
}
private String updateContentLinks(Page page, String content, String id)
throws Exception {