|
From: <jbo...@li...> - 2005-09-27 13:23:48
|
Author: adamw
Date: 2005-09-27 09:23:35 -0400 (Tue, 27 Sep 2005)
New Revision: 1220
Added:
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/AddDelayedOperation.java
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/CommitDelayedOperation.java
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/DelayedOperation.java
Modified:
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java
trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java
trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java
trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java
trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java
trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java
Log:
Property get/set, improved delayed operations support
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -52,7 +52,7 @@
* @return True if there are any changes in properties.
*/
protected boolean checkForChanges() {
- return modifiedProperties.size() > 1;
+ return modifiedProperties.size() > 0;
}
/**
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -81,7 +81,7 @@
public Directory getDirectory(String path) {
File file = getFileForPath(path);
- if (!file.isFile())
+ if (!file.isDirectory())
throw new ResourceDoesNotExist();
return new SvnDirectory(id, getPrefixedPath(path), file);
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -9,6 +9,7 @@
import org.jboss.shotoku.Node;
import org.jboss.shotoku.NodeList;
import org.jboss.shotoku.exceptions.RepositoryException;
+import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
public class SvnDirectory extends AbstractSvnResource implements Directory {
public SvnDirectory(String id, String fullPath, File file) {
@@ -69,9 +70,15 @@
public Node newNode(String name) {
String childFullPath = fullPath + '/' + name;
+
try {
- return new SvnNewNode(id, childFullPath, new File(service
- .getFileSystemPath(id, childFullPath)));
+ File newFile = new File(service.getFileSystemPath(id,
+ childFullPath));
+
+ if (newFile.exists())
+ throw new ResourceAlreadyExists();
+
+ return new SvnNewNode(id, childFullPath, newFile);
} catch (SvnOperationFailed e) {
throw new RepositoryException(e);
}
@@ -80,8 +87,13 @@
public Directory newDirectory(String name) {
String childFullPath = fullPath + '/' + name;
try {
- return new SvnNewDirectory(id, childFullPath, new File(service
- .getFileSystemPath(id, childFullPath)));
+ File newDir = new File(service.getFileSystemPath(id,
+ childFullPath));
+
+ if (newDir.exists())
+ throw new ResourceAlreadyExists();
+
+ return new SvnNewDirectory(id, childFullPath, newDir);
} catch (SvnOperationFailed e) {
throw new RepositoryException(e);
}
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -84,8 +84,15 @@
return -1;
}
+ protected boolean checkForChanges() {
+ if (saved)
+ return super.checkForChanges();
+ else
+ return true;
+ }
+
@Override
- public void save(String logMessage) {
+ public void save(String logMessage) throws RepositoryException {
if (!saved) {
try {
file.createNewFile();
@@ -95,11 +102,11 @@
} catch (SvnOperationFailed e) {
throw new RepositoryException(e);
}
-
- saved = true;
}
super.save(logMessage);
+
+ saved = true;
}
@Override
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -1,19 +1,22 @@
package org.jboss.shotoku.svn.service;
import java.io.File;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.Semaphore;
import org.apache.log4j.Logger;
+import org.jboss.shotoku.svn.SvnOperationFailed;
+import org.jboss.shotoku.svn.service.operations.DelayedOperation;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNOptions;
+import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
import org.tmatesoft.svn.core.wc.SVNClientManager;
-import org.tmatesoft.svn.core.wc.SVNCommitClient;
+import org.tmatesoft.svn.core.wc.SVNPropertyData;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
@@ -30,7 +33,7 @@
private String url;
private String localpath;
private File wc;
- private Set<String[]> toCommit;
+ private List<DelayedOperation> delayedOperations;
private Map<String, Semaphore> semaphores;
public SvnRepository(String username, String password,
@@ -43,7 +46,7 @@
this.localpath = localpath;
wc = new File(localpath);
- toCommit = Collections.synchronizedSet(new HashSet<String[]>());
+ delayedOperations = Collections.synchronizedList(new ArrayList<DelayedOperation>());
semaphores = new HashMap<String, Semaphore>();
}
@@ -81,44 +84,43 @@
SVNRevision.HEAD, SVNRevision.HEAD, true);
}
} catch (SVNException e) {
+ // TODO
e.printStackTrace();
+
tryCleanup();
}
}
/**
- * Adds a given file with a given log message to a commit queue.
- * @param path Path (file/ directory) to commit.
- * @param logMessage Log message with thich to commit.
+ * Adds a delayed operation to an execution queue.
+ * @param op Operation to add.
*/
- public void addToCommit(String path, String logMessage) {
- toCommit.add(new String[] { path, logMessage });
+ public void addDelayedOperation(DelayedOperation op) {
+ delayedOperations.add(op);
}
/**
- * Commits all paths (files/ directories) that were scheduled for a commit.
+ * Performs all scheduled delayed operations.
*/
- public void commit() {
- String[][] allToCommit;
+ public void performDelayedOperations() {
+ DelayedOperation[] allOps;
- synchronized (toCommit) {
- allToCommit = toCommit.toArray(new String[0][0]);
- toCommit.clear();
+ synchronized (delayedOperations) {
+ allOps = delayedOperations.toArray(new DelayedOperation[0]);
+ delayedOperations.clear();
}
- for (String[] oneToCommit : allToCommit) {
- SVNCommitClient commitClient = ourClientManager.getCommitClient();
+ for (DelayedOperation op : allOps) {
try {
- log.info("Commiting: " + oneToCommit[0]);
- commitClient.doCommit(
- new File[] { new File(getFileSystemPath(oneToCommit[0])) },
- false, oneToCommit[1], true, false);
+ log.info("Performing delayed op: " + op.getClass().getName());
- putWriteLock(oneToCommit[0]);
+ op.performOperation(ourClientManager);
} catch (SVNException e) {
+ // TODO Delete
+ e.printStackTrace();
+
tryCleanup();
- putWriteLock(oneToCommit[0]);
- log.warn("Commiting: " + oneToCommit[0] + " failed", e);
+ log.warn("Performing delayed op: " + op.getClass().getName() + " failed.", e);
}
}
}
@@ -159,4 +161,30 @@
return '/' == File.separatorChar ?
path : path.replace('/', File.separatorChar);
}
+
+ public String getProperty(String path, String name)
+ throws SvnOperationFailed {
+ try {
+ SVNPropertyData data =
+ ourClientManager.getWCClient().doGetProperty(
+ new File(getFileSystemPath(path)), name,
+ SVNRevision.WORKING, SVNRevision.WORKING,
+ false);
+
+ return data == null ? null : data.getValue();
+ } catch (SVNException e) {
+ throw new SvnOperationFailed(e);
+ }
+ }
+
+ public void setProperty(String path, String name, String value)
+ throws SvnOperationFailed {
+ try {
+ ourClientManager.getWCClient().doSetProperty(
+ new File(getFileSystemPath(path)), name,
+ value, true, false, ISVNPropertyHandler.NULL);
+ } catch (SVNException e) {
+ throw new SvnOperationFailed(e);
+ }
+ }
}
Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -12,7 +12,10 @@
import org.jboss.annotation.ejb.Service;
import org.jboss.shotoku.ContentManager;
import org.jboss.shotoku.Tools;
+import org.jboss.shotoku.svn.SvnOperationFailed;
import org.jboss.shotoku.svn.SvnService;
+import org.jboss.shotoku.svn.service.operations.AddDelayedOperation;
+import org.jboss.shotoku.svn.service.operations.CommitDelayedOperation;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.w3c.dom.Document;
@@ -112,7 +115,7 @@
public void update() {
for (SvnRepository repo : repositories.values()) {
repo.update();
- repo.commit();
+ repo.performDelayedOperations();
}
}
@@ -128,16 +131,21 @@
repositories.get(id).putWriteLock(path);
}
- public void commit(String id, String path, String logMessage) {
- repositories.get(id).addToCommit(path, logMessage);
+ public void commit(String id, String path, String logMessage)
+ throws SvnOperationFailed {
+ SvnRepository repo = repositories.get(id);
+ repo.addDelayedOperation( new CommitDelayedOperation(repo, path,
+ logMessage));
}
- public void setProperty(String id, String path, String name, String value) {
-
+ public void setProperty(String id, String path, String name, String value)
+ throws SvnOperationFailed{
+ repositories.get(id).setProperty(path, name, value);
}
- public String getProperty(String id, String path, String name) {
- return null;
+ public String getProperty(String id, String path, String name)
+ throws SvnOperationFailed{
+ return repositories.get(id).getProperty(path, name);
}
public String getNodeAtRevision(String id, String path, int revision) {
@@ -156,8 +164,9 @@
}
- public void add(String id, String path) {
-
+ public void add(String id, String path) throws SvnOperationFailed {
+ SvnRepository repo = repositories.get(id);
+ repo.addDelayedOperation(new AddDelayedOperation(repo, path));
}
public String getFileSystemPath(String id, String path) {
Added: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/AddDelayedOperation.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/AddDelayedOperation.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/AddDelayedOperation.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -0,0 +1,22 @@
+package org.jboss.shotoku.svn.service.operations;
+
+import java.io.File;
+
+import org.jboss.shotoku.svn.service.SvnRepository;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.SVNClientManager;
+
+public class AddDelayedOperation implements DelayedOperation {
+ private String fileSystemPath;
+
+ public AddDelayedOperation(SvnRepository repo, String path) {
+ fileSystemPath = repo.getFileSystemPath(path);
+ }
+
+ public void performOperation(SVNClientManager clientManager)
+ throws SVNException {
+ clientManager.getWCClient().doAdd(new File(fileSystemPath), true,
+ false, false, false);
+ }
+
+}
Added: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/CommitDelayedOperation.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/CommitDelayedOperation.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/CommitDelayedOperation.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -0,0 +1,34 @@
+package org.jboss.shotoku.svn.service.operations;
+
+import java.io.File;
+
+import org.jboss.shotoku.svn.service.SvnRepository;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.SVNClientManager;
+
+public class CommitDelayedOperation implements DelayedOperation {
+ private String path;
+
+ private String logMessage;
+
+ private SvnRepository repo;
+
+ public CommitDelayedOperation(SvnRepository repo, String path,
+ String logMessage) {
+ this.path = path;
+ this.logMessage = logMessage;
+ this.repo = repo;
+ }
+
+ public void performOperation(SVNClientManager clientManager)
+ throws SVNException {
+ try {
+ clientManager.getCommitClient().doCommit(
+ new File[] { new File(repo.getFileSystemPath(path)) },
+ false, logMessage, true, false);
+ } finally {
+ repo.putWriteLock(path);
+ }
+ }
+
+}
Added: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/DelayedOperation.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/DelayedOperation.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/operations/DelayedOperation.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -0,0 +1,9 @@
+package org.jboss.shotoku.svn.service.operations;
+
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.SVNClientManager;
+
+public interface DelayedOperation {
+ public void performOperation(SVNClientManager clientManager)
+ throws SVNException;
+}
Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java
===================================================================
--- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java 2005-09-27 10:16:00 UTC (rev 1219)
+++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java 2005-09-27 13:23:35 UTC (rev 1220)
@@ -21,7 +21,7 @@
ContentManager cm = ContentManager.getContentManager("");
- String filePath = "shotoku-test/test1.txt";
+ /*String filePath = "shotoku-test/test1.txt";
Node n = cm.getNode(filePath);
@@ -40,7 +40,13 @@
pw.println("Saving ... <br />");
n.save("Shotoku test 2");
- pw.println("done<br />");
+ pw.println("done<br />");*/
+
+ Node n = cm.getNode("shotoku-test/test2.txt");
+ pw.println(n.getProperty("z") + "<br />");
+ n.setProperty("z", "y");
+ pw.println(n.getProperty("z") + "<br />");
+ n.save("test");
}
}
|