Author: adamw Date: 2005-10-29 04:53:49 -0400 (Sat, 29 Oct 2005) New Revision: 1468 Added: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Directory.java trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.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/SvnNewDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-24 Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -171,8 +171,8 @@ return (ContentManager) constructor.newInstance(new Object[] { id, prefix }); } catch (Throwable e) { - // TODO - e.printStackTrace(); + log.warn("Unable to get a content manager: (" + id + ", " + + prefix + ").", e); return null; } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Directory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Directory.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Directory.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -85,7 +85,8 @@ public boolean hasIndex(String propertyName) throws RepositoryException; /** - * Creates or deletes an index on a property. + * Creates or deletes an index on a property. The directory must be saved + * before this operation. * * @param propertyName * Name of the property for which to create/ delete an index. 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-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnDirectory.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -111,7 +111,8 @@ if (newFile.exists()) throw new ResourceAlreadyExists(); - return new SvnNewNode(id, childFullPath, newFile, name, svnCm); + return new SvnNewNodeHelper(id, childFullPath, newFile, name, + svnCm, this); } catch (SvnOperationFailed e) { throw new RepositoryException(e); } @@ -128,7 +129,7 @@ if (newDir.exists()) throw new ResourceAlreadyExists(); - return new SvnNewDirectory(id, childFullPath, newDir, name, svnCm); + return new SvnNewDirectoryHelper(id, childFullPath, newDir, name, svnCm, this); } catch (SvnOperationFailed e) { throw new RepositoryException(e); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectory.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -10,122 +10,84 @@ import org.jboss.shotoku.exceptions.ResourceDoesNotExist; public class SvnNewDirectory extends SvnDirectory { - private boolean saved; - public SvnNewDirectory(String id, String fullPath, File file, String name, SvnContentManager svnCm) { super(id, fullPath, file, name, svnCm); - - saved = false; } @Override public void delete() { - // We only have to delete a corresponding directory if this directory - // has been saved already. - if (saved) - super.delete(); + // We don't have to do anything if this is a new node, not yet saved. } @Override public List<Directory> getDirectories() { - if (saved) - return super.getDirectories(); - else - return null; + return null; } public Node getNode(String name) throws RepositoryException, ResourceDoesNotExist { - if (saved) - return super.getNode(name); - else - return null; + return null; } public Directory getDirectory(String name) throws RepositoryException, ResourceDoesNotExist { - if (saved) - return super.getDirectory(name); - else - return null; + return null; } @Override public String getLogMessage() { - if (saved) - return super.getLogMessage(); - else - return null; + return null; } @Override public NodeList getNodes() { - if (saved) - return super.getNodes(); - else - return null; + return null; } @Override public boolean hasIndex(String propertyName) { - if (saved) - return super.hasIndex(propertyName); - else - return false; + return false; } @Override public Directory newDirectory(String name) { - if (saved) - return super.newDirectory(name); - else - return null; + return null; } @Override public Node newNode(String name) { - if (saved) - return super.newNode(name); - else - return null; + return null; } @Override public void save(String logMessage) { - if (saved) { - super.save(logMessage); - } else { - service.getWriteLock(id, fullPath); + service.getWriteLock(id, fullPath); + + if (!file.mkdir()) { + service.putWriteLock(id, fullPath); + throw new RepositoryException( + "Could not create directory: " + + file.getAbsolutePath()); + } + + try { + service.add(id, fullPath); - if (!file.mkdir()) { - service.putWriteLock(id, fullPath); - throw new RepositoryException( - "Could not create directory: " - + file.getAbsolutePath()); - } - - try { - service.add(id, fullPath); - - // Saving properties. - save(); - } catch (SvnOperationFailed e) { - service.putWriteLock(id, fullPath); - throw new RepositoryException(e); - } - - try { - service.commit(id, fullPath, logMessage); - } catch (SvnOperationFailed e) { - throw new RepositoryException(e); - } - - saved = true; + // Saving properties. + save(); + } catch (SvnOperationFailed e) { + service.putWriteLock(id, fullPath); + throw new RepositoryException(e); } + + try { + service.commit(id, fullPath, logMessage); + } catch (SvnOperationFailed e) { + throw new RepositoryException(e); + } } @Override public void setIndex(String propertyName, boolean index) { - if (saved) - super.setIndex(propertyName, index); + throw new RepositoryException("Directory not yet saved."); } } Added: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewDirectoryHelper.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -0,0 +1,87 @@ +package org.jboss.shotoku.svn; + +import java.io.File; +import java.util.List; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.NodeList; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceAlreadyExists; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +public class SvnNewDirectoryHelper extends SvnNewResourceHelper implements + Directory { + private Directory currentDirectory; + + public SvnNewDirectoryHelper(String id, String fullPath, File file, + String name, SvnContentManager svnCm, Directory parentDirectory) { + super(parentDirectory, name); + currentDirectory = new SvnNewDirectory(id, fullPath, file, name, svnCm); + } + + public void save(String logMessage) throws RepositoryException { + currentDirectory.save(logMessage); + currentDirectory = parentDirectory.getDirectory(name); + } + + public void delete() throws RepositoryException { + currentDirectory.delete(); + } + + public List<Directory> getDirectories() throws RepositoryException { + return currentDirectory.getDirectories(); + } + + public Directory getDirectory(String name) throws RepositoryException, + ResourceDoesNotExist { + return currentDirectory.getDirectory(name); + } + + public String getLogMessage() throws RepositoryException { + return currentDirectory.getLogMessage(); + } + + public String getName() { + return currentDirectory.getName(); + } + + public Node getNode(String name) throws RepositoryException, + ResourceDoesNotExist { + return currentDirectory.getNode(name); + } + + public NodeList getNodes() throws RepositoryException { + return currentDirectory.getNodes(); + } + + public Directory getParent() throws RepositoryException { + return currentDirectory.getParent(); + } + + public String getProperty(String name) throws RepositoryException { + return currentDirectory.getProperty(name); + } + + public boolean hasIndex(String name) throws RepositoryException { + return currentDirectory.hasIndex(name); + } + + public Directory newDirectory(String name) throws ResourceAlreadyExists, + RepositoryException { + return currentDirectory.newDirectory(name); + } + + public Node newNode(String name) throws ResourceAlreadyExists, + RepositoryException { + return currentDirectory.newNode(name); + } + + public void setIndex(String name, boolean index) throws RepositoryException { + currentDirectory.setIndex(name, index); + } + + public void setProperty(String name, String value) { + currentDirectory.setProperty(name, value); + } +} 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-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNode.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -12,179 +12,121 @@ public class SvnNewNode extends SvnHeadNode { private NodeContent content; - private boolean saved; - public SvnNewNode(String id, String fullPath, File file, String name, SvnContentManager svnCm) { super(id, fullPath, file, name, svnCm); content = new NodeContent(); - saved = false; } @Override public void delete() { - // We only have to delete a corresponding file if this node has - // been saved already. - if (saved) - super.delete(); + // If the file hasn't been saved, no deleting necessary. } @Override public String getContent() { - if (saved) - return super.getContent(); - else { - return content.asString(); - } + return content.asString(); } @Override public InputStream getContentInputStream() { - if (saved) - return super.getContentInputStream(); - else { - return content.asInputStream(); - } + return content.asInputStream(); } @Override public byte[] getContentByteArray() { - if (saved) - return super.getContentByteArray(); - else { - return content.asByteArray(); - } + return content.asByteArray(); } @Override public History getHistory() { - if (saved) - return super.getHistory(); - else - return null; + return null; } @Override public long getLastModfication() { - if (saved) - return super.getLastModfication(); - else - return Calendar.getInstance().getTimeInMillis(); + return Calendar.getInstance().getTimeInMillis(); } @Override public long getLength() { - if (saved) - return super.getLength(); - else - return content.getLength(); + return content.getLength(); } @Override public String getLogMessage() { - if (saved) - return super.getLogMessage(); - else - return null; + return null; } @Override public int getRevisionNumber() { - if (saved) - return super.getRevisionNumber(); - else - return -1; + return -1; } + @Override protected boolean checkForChanges() { - if (saved) - return super.checkForChanges(); - else - return true; + return true; } @Override public void save(String logMessage) throws RepositoryException { - if (saved) - super.save(logMessage); - else { - service.getWriteLock(id, fullPath); - - try { - if (!file.createNewFile()) { - service.putWriteLock(id, fullPath); - throw new RepositoryException( - "Could not create file: " - + file.getAbsolutePath()); - } - } catch (IOException e) { + service.getWriteLock(id, fullPath); + + try { + if (!file.createNewFile()) { service.putWriteLock(id, fullPath); - throw new RepositoryException(e); - } - - try { - service.add(id, fullPath); - } catch (SvnOperationFailed e) { - service.putWriteLock(id, fullPath); - throw new RepositoryException(e); - } - - super.setContent(content.asString()); + throw new RepositoryException( + "Could not create file: " + + file.getAbsolutePath()); + } + } catch (IOException e) { + service.putWriteLock(id, fullPath); + throw new RepositoryException(e); + } - saveWithLock(logMessage); - - saved = true; + try { + service.add(id, fullPath); + } catch (SvnOperationFailed e) { + service.putWriteLock(id, fullPath); + throw new RepositoryException(e); } + + super.setContent(content.asString()); + + saveWithLock(logMessage); } @Override public void setContent(String stringContent) { - if (saved) - super.setContent(stringContent); - else { - content.setContent(stringContent); - } + content.setContent(stringContent); } + @Override public void setContent(InputStream is) { - if (saved) - super.setContent(is); - else { - try { - content.setContent(is); - } catch (IOException e) { - throw new RepositoryException(e); - } + try { + content.setContent(is); + } catch (IOException e) { + throw new RepositoryException(e); } } + @Override public void setContent(byte[] bytes) { - if (saved) - super.setContent(bytes); - else { - content.setContent(bytes); - } + content.setContent(bytes); } + @Override public OutputStream getOutputStream() { - if (saved) - return super.getOutputStream(); - else { - return content.getOutputStream(); - } + return content.getOutputStream(); } @Override public void copyToFile(String filename) throws RepositoryException { - if (saved) - super.copyToFile(filename); - else { - try { - content.copyToFile(file); - } catch (Exception e) { - throw new RepositoryException(e); - } + try { + content.copyToFile(file); + } catch (Exception e) { + throw new RepositoryException(e); } } } Added: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewNodeHelper.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -0,0 +1,101 @@ +package org.jboss.shotoku.svn; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.History; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.exceptions.RepositoryException; + +public class SvnNewNodeHelper extends SvnNewResourceHelper implements Node { + private Node currentNode; + + public SvnNewNodeHelper(String id, String fullPath, File file, String name, + SvnContentManager svnCm, Directory parentDirectory) { + super(parentDirectory, name); + currentNode = new SvnNewNode(id, fullPath, file, name, svnCm); + } + + public void save(String logMessage) throws RepositoryException { + currentNode.save(logMessage); + currentNode = parentDirectory.getNode(name); + } + + public void copyToFile(String fileName) throws RepositoryException { + currentNode.copyToFile(fileName); + } + + public void delete() throws RepositoryException { + currentNode.delete(); + } + + public String getContent() throws RepositoryException { + return currentNode.getContent(); + } + + public byte[] getContentByteArray() throws RepositoryException { + return currentNode.getContentByteArray(); + } + + public InputStream getContentInputStream() throws RepositoryException { + return currentNode.getContentInputStream(); + } + + public History getHistory() throws RepositoryException { + return currentNode.getHistory(); + } + + public long getLastModfication() throws RepositoryException { + return currentNode.getLastModfication(); + } + + public long getLength() throws RepositoryException { + return currentNode.getLength(); + } + + public String getLogMessage() throws RepositoryException { + return currentNode.getLogMessage(); + } + + public String getMimeType() { + return currentNode.getMimeType(); + } + + public String getName() { + return currentNode.getName(); + } + + public OutputStream getOutputStream() { + return currentNode.getOutputStream(); + } + + public Directory getParent() throws RepositoryException { + return currentNode.getParent(); + } + + public String getProperty(String name) throws RepositoryException { + return currentNode.getProperty(name); + } + + public int getRevisionNumber() throws RepositoryException { + return currentNode.getRevisionNumber(); + } + + public void setContent(byte[] bytes) { + currentNode.setContent(bytes); + } + + public void setContent(InputStream is) { + currentNode.setContent(is); + } + + public void setContent(String content) { + currentNode.setContent(content); + } + + public void setProperty(String name, String value) { + currentNode.setProperty(name, value); + } +} Added: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java 2005-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNewResourceHelper.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -0,0 +1,13 @@ +package org.jboss.shotoku.svn; + +import org.jboss.shotoku.Directory; + +public abstract class SvnNewResourceHelper { + protected Directory parentDirectory; + protected String name; + + public SvnNewResourceHelper(Directory parentDirectory, String name) { + this.parentDirectory = parentDirectory; + this.name = name; + } +} 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-10-28 22:06:28 UTC (rev 1467) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2005-10-29 08:53:49 UTC (rev 1468) @@ -103,8 +103,7 @@ SVNRevision.HEAD, SVNRevision.HEAD, true); } } catch (SVNException e) { - // TODO - e.printStackTrace(); + log.error("Error while updating the repository.", e); tryCleanup(); } @@ -233,10 +232,10 @@ try { final List<RevisionInfo> ret = new ArrayList<RevisionInfo>(); - // TODO: check the maximum number. + // Hopefully nobody will have more the 10mil revisions :). ourClientManager.getLogClient().doLog(new File[] { file }, SVNRevision.create(0), SVNRevision.HEAD, false, - false, 999999, + false, 10000000, new ISVNLogEntryHandler() { public void handleLogEntry(SVNLogEntry entry) { ret.add(new RevisionInfo(entry.getDate(), |