Author: spagop
Date: 2009-12-29 17:46:08 -0500 (Tue, 29 Dec 2009)
New Revision: 1489
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddFile.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/ISVNEditorUtil.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
Log:
some write svn access (add file/dir, update file)
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java 2009-12-29
22:46:08 UTC (rev 1489)
@@ -0,0 +1,59 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import org.jboss.dna.connector.scm.ScmAction;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+
+/**
+ * root should be the last, previously created, parent folder. Each directory in the path
will be created.
+ */
+public class AddDirectory implements ScmAction {
+ private String rootDirPath;
+ private String childDirPath;
+
+ public AddDirectory( String rootPath,
+ String childDirPath ) {
+ this.rootDirPath = rootPath;
+ this.childDirPath = childDirPath;
+ }
+
+ public void applyAction( Object context ) throws SVNException {
+
+ ISVNEditor editor = (ISVNEditor)context;
+
+ ISVNEditorUtil.openDirectories(editor, this.rootDirPath);
+ String[] paths = this.childDirPath.split("/");
+ String newPath = this.rootDirPath;
+ for (int i = 0, length = paths.length; i < length; i++) {
+ newPath = (newPath.length() != 0) ? newPath + "/" + paths[i] :
paths[i];
+
+ editor.addDir(newPath, null, -1);
+ }
+
+ ISVNEditorUtil.closeDirectories(editor, childDirPath);
+ ISVNEditorUtil.closeDirectories(editor, this.rootDirPath);
+ }
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddDirectory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddFile.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddFile.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddFile.java 2009-12-29
22:46:08 UTC (rev 1489)
@@ -0,0 +1,57 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import java.io.ByteArrayInputStream;
+import org.jboss.dna.connector.scm.ScmAction;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
+
+public class AddFile implements ScmAction {
+ private String path;
+ private String file;
+ private byte[] content;
+
+ public AddFile( String path,
+ String file,
+ byte[] content ) {
+ this.path = path;
+ this.file = file;
+ this.content = content;
+ }
+
+ public void applyAction( Object context ) throws Exception {
+ ISVNEditor editor = (ISVNEditor)context;
+ ISVNEditorUtil.openDirectories(editor, this.path);
+ if(this.file.startsWith("/")) this.file = file.substring(1);
+ editor.addFile(this.path + "/" + this.file, null, -1);
+ editor.applyTextDelta(this.path + "/" + this.file, null);
+ SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+ String checksum = deltaGenerator.sendDelta(this.path + "/" + this.file,
new ByteArrayInputStream(this.content), editor, true);
+ editor.closeFile(this.path + "/" + this.file, checksum);
+
+ ISVNEditorUtil.closeDirectories(editor, this.path);
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/AddFile.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/ISVNEditorUtil.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/ISVNEditorUtil.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/ISVNEditorUtil.java 2009-12-29
22:46:08 UTC (rev 1489)
@@ -0,0 +1,73 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+
+/**
+ * @author sp
+ *
+ */
+public class ISVNEditorUtil {
+
+ /**
+ * Open the directories where change has to be made.
+ *
+ * @param editor - abstract editor.
+ * @param rootPath - the pa to open.
+ * @throws SVNException when a error occur.
+ */
+ protected static void openDirectories( ISVNEditor editor,
+ String rootPath ) throws SVNException {
+ assert rootPath != null;
+ int pos = rootPath.indexOf('/', 0);
+ while (pos != -1) {
+ String dir = rootPath.substring(0, pos);
+ editor.openDir(dir, -1);
+ pos = rootPath.indexOf('/', pos + 1);
+ }
+ String dir = rootPath.substring(0, rootPath.length());
+ editor.openDir(dir, -1);
+ }
+
+ /**
+ * Close the directories where change was made.
+ *
+ * @param editor - the abstract editor.
+ * @param path - the directories to open.
+ * @throws SVNException when a error occur.
+ */
+ protected static void closeDirectories( ISVNEditor editor,
+ String path ) throws SVNException {
+ int length = path.length() - 1;
+ int pos = path.lastIndexOf('/', length);
+ editor.closeDir();
+ while (pos != -1) {
+ editor.closeDir();
+ pos = path.lastIndexOf('/', pos - 1);
+ }
+ }
+
+}
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/ISVNEditorUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
(rev 0)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java 2009-12-29
22:46:08 UTC (rev 1489)
@@ -0,0 +1,64 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.connector.svn.mgnt;
+
+import java.io.ByteArrayInputStream;
+import org.jboss.dna.connector.scm.ScmAction;
+import org.tmatesoft.svn.core.io.ISVNEditor;
+import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
+
+public class MergeFile implements ScmAction {
+ private String path;
+ private String file;
+ private byte[] oldData;
+ private byte[] newData;
+
+ public MergeFile( String path,
+ String file,
+ byte[] oldData,
+ byte[] newData ) {
+ this.path = path;
+ this.file = file;
+ this.oldData = oldData;
+ this.newData = newData;
+ }
+
+ public void applyAction( Object context ) throws Exception {
+ ISVNEditor editor = (ISVNEditor)context;
+ ISVNEditorUtil.openDirectories(editor, this.path);
+
+ editor.openFile(this.path + "/" + this.file, -1);
+ editor.applyTextDelta(this.path + "/" + this.file, null);
+ SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
+ String checksum = deltaGenerator.sendDelta(this.path + "/" +
this.file,
+ new
ByteArrayInputStream(this.oldData),
+ 0,
+ new
ByteArrayInputStream(this.newData),
+ editor,
+ true);
+ editor.closeFile(this.path + "/" + this.file, checksum);
+ ISVNEditorUtil.closeDirectories(editor, path);
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/mgnt/MergeFile.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF