Author: spagop
Date: 2009-01-22 06:06:04 -0500 (Thu, 22 Jan 2009)
New Revision: 716
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
some exception handling enhancements
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java 2009-01-20
19:47:01 UTC (rev 715)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNActionExecutor.java 2009-01-22
11:06:04 UTC (rev 716)
@@ -25,6 +25,8 @@
import org.jboss.dna.connector.scm.ScmAction;
import org.jboss.dna.connector.scm.ScmActionExecutor;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.io.ISVNEditor;
import org.tmatesoft.svn.core.io.SVNRepository;
@@ -53,21 +55,20 @@
/**
* @param action
* @param message
- * @throws Exception
+ * @throws SVNException
*/
public void execute( ScmAction action,
- String message ) throws Exception {
+ String message ) throws SVNException {
+ ISVNEditor editor = this.repository.getCommitEditor(message, null);
+ editor.openRoot(-1);
try {
- ISVNEditor editor = this.repository.getCommitEditor( message,
- null );
- editor.openRoot( -1 );
- action.applyAction( editor );
- editor.closeDir();
- editor.closeEdit();
- } catch ( SVNException e ) {
- e.printStackTrace();
- //logger.error( "svn error: " );
- throw e;
+ action.applyAction(editor);
+ } catch (Exception e) {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "This
error is appeared: '{0}'", e.getMessage());
+ throw new SVNException(err);
}
+ editor.closeDir();
+ editor.closeEdit();
+
}
}
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2009-01-20
19:47:01 UTC (rev 715)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2009-01-22
11:06:04 UTC (rev 716)
@@ -42,6 +42,7 @@
public static I18n objectFoundInJndiWasNotCacheFactory;
public static I18n locationInRequestMustHavePath;
public static I18n sourceIsReadOnly;
+ public static I18n connectingFailureOrUserAuthenticationProblem;
static {
try {
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-01-20
19:47:01 UTC (rev 715)
+++
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2009-01-22
11:06:04 UTC (rev 716)
@@ -58,6 +58,8 @@
import org.jboss.dna.graph.request.UpdatePropertiesRequest;
import org.jboss.dna.graph.request.processor.RequestProcessor;
import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
@@ -125,49 +127,46 @@
String root =
parent.getString(getExecutionContext().getNamespaceRegistry());
SVNNodeKind rootKind = repository.checkPath(root, -1);
if (rootKind == SVNNodeKind.UNKNOWN) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "path with name
'{0}' is unknown in the repository",
+ root);
+ SVNException ex = new SVNException(err);
+ request.setError(ex);
} else if (rootKind == SVNNodeKind.NONE) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "path with name
'{0}' is missing in the repository",
+ root);
+ SVNException ex = new SVNException(err);
+ request.setError(ex);
} else if (rootKind == SVNNodeKind.FILE) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "pretended root item
with name '{0}' is a file",
+ root);
+ SVNException ex = new SVNException(err);
+ request.setError(ex);
} else if (rootKind == SVNNodeKind.DIR) {
+
+ // TODO if node is a file
+
+ // if the node is a directory
String childName =
request.named().getString(getExecutionContext().getNamespaceRegistry());
if (root.length() == 1 && root.charAt(0) == '/') {
// test if so a directory does not exist.
- mkdir("",childName, request.toString());
+ mkdir("", childName, request.toString());
} else {
- if(root.length() > 1 && root.charAt(0) == '/') {
+ if (root.length() > 1 && root.charAt(0) == '/') {
// test if so a directory does not exist.
- mkdir(root.substring(1),childName, request.toString());
+ mkdir(root.substring(1), childName, request.toString());
}
}
}
- } catch (Exception e) {
+ } catch (SVNException e) {
+ request.setError(e);
}
- //
}
/**
- * Create a directory .
- * @param root - the root directory where the created directory will reside
- * @param childName - the name of the created directory.
- * @param message - comment for the creation.
- * @throws Exception - if during the creation, there is an error.
- */
- private void mkdir( String root,
- String childName, String message) throws Exception {
- SVNNodeKind childKind = repository.checkPath(childName, -1);
- if (childKind == SVNNodeKind.NONE) {
- ScmAction addNodeAction = addDirectory(root, childName);
- SVNActionExecutor executor = new SVNActionExecutor(repository);
- executor.execute(addNodeAction, message);
- } else {
- // TODO throwns an exception
- }
- }
-
- /**
* {@inheritDoc}
*
* @see
org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.DeleteBranchRequest)
@@ -240,11 +239,6 @@
}
request.setActualLocationOfNode(myLocation);
} catch (SVNException e) {
- // if a failure occured while connecting to a repository
- // or the user's authentication failed (see
- // path not found in the specified revision
- // or is not a directory
- e.printStackTrace();
request.setError(e);
}
@@ -323,7 +317,6 @@
request.setActualLocationOfNode(myLocation);
} catch (SVNException e) {
- e.printStackTrace();
request.setError(e);
}
}
@@ -483,10 +476,9 @@
SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(myPath));
}
} catch (SVNException e) {
- // if a failure occured while connecting to a repository
- // * or the user's authentication failed (see
- // * {@link org.tmatesoft.svn.core.SVNAuthenticationException})
- // TODO RepositorySourceAuthenticationException
+ throw new RepositorySourceException(
+ getSourceName(),
+
SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
}
return kind;
@@ -504,10 +496,9 @@
try {
entry = getRepository().info(path, -1);
} catch (SVNException e) {
- // if a failure occured while connecting to a repository
- // * or the user's authentication failed (see
- // * {@link org.tmatesoft.svn.core.SVNAuthenticationException})
- // TODO RepositorySourceAuthenticationException
+ throw new RepositorySourceException(
+ getSourceName(),
+
SVNRepositoryConnectorI18n.connectingFailureOrUserAuthenticationProblem.text(getSourceName()));
}
return entry;
}
@@ -517,7 +508,7 @@
*
* @param editor - abstract editor.
* @param rootPath - the pa to open.
- * @throws SVNException
+ * @throws SVNException when a error occur.
*/
protected static void openDirectories( ISVNEditor editor,
String rootPath ) throws SVNException {
@@ -537,7 +528,7 @@
*
* @param editor - the abstract editor.
* @param path - the directories to open.
- * @throws SVNException
+ * @throws SVNException when a error occur.
*/
protected static void closeDirectories( ISVNEditor editor,
String path ) throws SVNException {
@@ -567,11 +558,13 @@
}
/**
- * @param repository
+ * Add directory in a repository
+ *
+ * @param repository - the repository.
* @param root - the root path has to exist.
* @param child - new path to be added.
* @param message - information about the change action.
- * @throws SVNException
+ * @throws SVNException when a error occur.
*/
protected void addDirEntry( SVNRepository repository,
String root,
@@ -580,11 +573,20 @@
assert root.trim().length() != 0;
SVNNodeKind rootKind = repository.checkPath(root, -1);
if (rootKind == SVNNodeKind.UNKNOWN) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "path with name
'{0}' is unknown in the repository",
+ root);
+ throw new SVNException(err);
} else if (rootKind == SVNNodeKind.NONE) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "path with name
'{0}' is missing in the repository",
+ root);
+ throw new SVNException(err);
} else if (rootKind == SVNNodeKind.FILE) {
- // TODO throw an checked exception
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "path with name
'{0}' is a file, you need a directory",
+ root);
+ throw new SVNException(err);
} else if (rootKind == SVNNodeKind.DIR) {
ISVNEditor editor = repository.getCommitEditor(message, null, true, null);
if (root.length() == 1 && root.charAt(0) == '/') {
@@ -613,7 +615,6 @@
}
} else {
- // TODO throws an exception
closeDirectories(editor, childSegmentName);
if (editedRoot != null) {
closeDirectories(editor, editedRoot);
@@ -624,6 +625,28 @@
}
/**
+ * Create a directory .
+ *
+ * @param root - the root directory where the created directory will reside
+ * @param childName - the name of the created directory.
+ * @param message - comment for the creation.
+ * @throws SVNException - if during the creation, there is an error.
+ */
+ private void mkdir( String root,
+ String childName,
+ String message ) throws SVNException {
+ SVNNodeKind childKind = repository.checkPath(childName, -1);
+ if (childKind == SVNNodeKind.NONE) {
+ ScmAction addNodeAction = addDirectory(root, childName);
+ SVNActionExecutor executor = new SVNActionExecutor(repository);
+ executor.execute(addNodeAction, message);
+ } else {
+ SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Item
with name '{0}' can't be created", childName);
+ throw new SVNException(err);
+ }
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.connector.scm.ScmActionFactory#addDirectory(java.lang.String,
java.lang.String)
@@ -690,7 +713,7 @@
public void applyAction( Object context ) throws SVNException {
ISVNEditor editor = (ISVNEditor)context;
-
+
openDirectories(editor, this.root);
String[] paths = this.path.split("/");
String newPath = this.root;