From: <jbo...@li...> - 2005-12-19 09:51:41
|
Author: adamw Date: 2005-12-19 04:51:24 -0500 (Mon, 19 Dec 2005) New Revision: 1858 Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnNode.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/SvnMemDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNodeProxy.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnRepoNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResource.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResourceProxy.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/FileNodeContent.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/NodeContent.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/WorkspaceMediator.java trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ModifyContentTest.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-48 : done 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-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -447,8 +447,7 @@ // No setup - doing nothing. } - log - .info("Added content manager: " + id + ", " + log.info("Added content manager: " + id + ", " + implementation); } } catch (Exception e) { Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnNode.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnNode.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; import javax.activation.MimetypesFileTypeMap; @@ -98,11 +99,19 @@ getCopyRevision()); } + @Override public void notifySaved() { super.notifySaved(); content.markUnchanged(); } + @Override + public void addLargePaths(Set<String> toFill) { + if (content.isLarge()) { + toFill.add(getFullPath()); + } + } + /* * Node IMPLEMENTATION */ 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-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/AbstractSvnResource.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -104,6 +104,7 @@ } public void notifySaved() { + deletedProperties.clear(); modifiedProperties.clear(); } @@ -151,6 +152,10 @@ getParent().getFullPath())); } + public void addLargePaths(Set<String> toFill) { + + } + /* * INTERNAL OPS DECLARATIONS */ 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-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnContentManager.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -318,9 +318,11 @@ * removed as we use a Set. */ Set<ResourceOperation> ops = new HashSet<ResourceOperation>(); + Set<String> largePaths = new HashSet<String>(); for (Resource resource : resources) { SvnResource svnResource = (SvnResource) resource; svnResource.addOperations(ops); + svnResource.addLargePaths(largePaths); } // Sorting all operations. @@ -329,7 +331,8 @@ Collections.sort(opsList); try { - performOperations(opsList, logMessage); + performOperations(opsList, logMessage, + new WorkspaceMediator(largePaths)); } catch (SVNException e) { throw new SaveException(e); } @@ -350,10 +353,16 @@ protected void performOperations(List<ResourceOperation> opsList, String logMessage) throws SVNException { + performOperations(opsList, logMessage, new WorkspaceMediator( + new HashSet<String>())); + } + + protected void performOperations(List<ResourceOperation> opsList, + String logMessage, WorkspaceMediator mediator) throws SVNException { ISVNEditor editor = null; try { editor = repository.getCommitEditor(logMessage, - new WorkspaceMediator()); + mediator); PathsStack stack = new PathsStack(editor); Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -140,7 +140,7 @@ public boolean forceSwitch() { /* * If a mem resource is switchable, it must have been saved. So, - * it must be switched on the neartes occasion. + * it must be switched on the nearest occasion. */ return switchable; } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNodeProxy.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNodeProxy.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnNodeProxy.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -52,9 +52,7 @@ currentNode = new SvnFileNode(getId(), getFullPath(), getSvnCm()); if (oldNode != null) { - NodeContent newNodeContent = new NodeContent(); - newNodeContent.copyFrom(oldNode.getNodeContent()); - currentNode.setNodeContent(newNodeContent); + currentNode.getNodeContent().copyFrom(oldNode.getNodeContent()); } return currentNode; @@ -65,13 +63,7 @@ currentNode = new SvnRepoNode(getId(), getFullPath(), getSvnCm()); if (oldNode != null) { - /* - * We have to set an already changed content so it won't be - * overriden by a repository version on read. - */ - NodeContent newNodeContent = new NodeContent(); - newNodeContent.copyFrom(oldNode.getNodeContent()); - currentNode.setNodeContent(newNodeContent); + currentNode.getNodeContent().copyFrom(oldNode.getNodeContent()); } return currentNode; Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnRepoNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnRepoNode.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnRepoNode.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -23,7 +23,6 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.io.OutputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -42,20 +41,10 @@ private Map<String, String> properties; private SvnRevisionInfo info; - private boolean repoContent; public SvnRepoNode(String id, String fullPath, SvnContentManager svnCm) { super(id, fullPath, svnCm); - repoContent = true; - /* - * Setting an empty node content - this is only for internal operations - * which check for content modifications. Actual content will never - * be read/ written from/ to it, because: - * - in case of read, content will be read from the repository and - * replaced - * - in case of a (first) write, a new empty content will be set. - */ setNodeContent(new NodeContent()); } @@ -77,21 +66,13 @@ return info.getMessage(); } - public void setNodeContent(NodeContent content) { - super.setNodeContent(content); - - if (content.getChanged()) { - repoContent = false; - } - } - private void loadInfo() { info = SvnTools.getCurrentRevisionInformation(getFullPath(), getSvnCm()).get(0); } private void loadContentAndProperties(boolean loadProps) { - if (loadProps || repoContent) { + if (loadProps || !getNodeContent().getChanged()) { properties = new HashMap<String, String>(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -107,19 +88,12 @@ } } - if (repoContent) { + if (!getNodeContent().getChanged()) { setNodeContent(new NodeContent(baos.toByteArray())); } } } - private void intializeNodeContent() { - if (repoContent) { - repoContent = false; - setNodeContent(new NodeContent()); - } - } - /* * Node IMPLEMENTATION */ @@ -170,32 +144,4 @@ super.copyToFile(path); } - - @Override - public OutputStream getOutputStream() { - intializeNodeContent(); - - return super.getOutputStream(); - } - - @Override - public void setContent(byte[] bytes) { - intializeNodeContent(); - - super.setContent(bytes); - } - - @Override - public void setContent(InputStream is) { - intializeNodeContent(); - - super.setContent(is); - } - - @Override - public void setContent(String stringContent) { - intializeNodeContent(); - - super.setContent(stringContent); - } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResource.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResource.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResource.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -43,6 +43,8 @@ public boolean switchable(); public boolean forceSwitch(); + public void addLargePaths(Set<String> toFill); + public String getFullPath(); public String getId(); public SvnContentManager getSvnCm(); Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResourceProxy.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResourceProxy.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnResourceProxy.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -220,6 +220,10 @@ currentResource.addDeleteOperation(ops); } + public void addLargePaths(Set<String> toFill) { + currentResource.addLargePaths(toFill); + } + /* * Resource IMPLEMENTATION */ Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -22,11 +22,17 @@ package org.jboss.shotoku.svn; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import org.jboss.mx.util.MBeanProxyExt; import org.jboss.mx.util.MBeanServerLocator; @@ -60,8 +66,16 @@ public static final String PROPERTY_PASSWORD = "password"; public static final String PROPERTY_LOCALPATH = "localpath"; + public static final String TEMP_FILE_PREFIX = "shotoku-svn"; + private static SvnService instance; + public static final Random random; + + static { + random = new Random(); + } + /** * Gets an instance of Shotoku svn service - this should be always the same * the object, so the dirty sets work properly. @@ -249,4 +263,28 @@ return res.getFullName().substring(0, lastSlash); } } + + public static ByteBuffer getFileBytes(File file) throws IOException { + FileChannel fc = new FileInputStream(file).getChannel(); + ByteBuffer buff = ByteBuffer.allocate((int) file.length()); + fc.read(buff); + buff.flip(); + + return buff; + } + + public static String getFileString(File file) throws IOException { + return Charset.forName( + System.getProperty("file.encoding")).decode( + getFileBytes(file)).toString(); + } + + public static File createTemporaryFile() { + try { + return File.createTempFile(TEMP_FILE_PREFIX, Integer.toString( + random.nextInt())); + } catch (IOException e) { + throw new RepositoryException(e); + } + } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/FileNodeContent.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/FileNodeContent.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/FileNodeContent.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -25,11 +25,9 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.charset.Charset; import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.svn.SvnTools; /** * @author Adam Warski (ad...@as...) @@ -40,15 +38,6 @@ public FileNodeContent(File file) { this.file = file; } - - private ByteBuffer getFileBytes() throws IOException { - FileChannel fc = new FileInputStream(file).getChannel(); - ByteBuffer buff = ByteBuffer.allocate((int) file.length()); - fc.read(buff); - buff.flip(); - - return buff; - } @Override public byte[] asByteArray() { @@ -56,7 +45,7 @@ return super.asByteArray(); } else { try { - return getFileBytes().array(); + return SvnTools.getFileBytes(file).array(); } catch (IOException e) { throw new RepositoryException(e); } @@ -82,9 +71,7 @@ return super.asString(); } else { try { - return Charset.forName( - System.getProperty("file.encoding")).decode( - getFileBytes()).toString(); + return SvnTools.getFileString(file); } catch (IOException e) { throw new RepositoryException(e); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/NodeContent.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/NodeContent.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/content/NodeContent.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -21,15 +21,20 @@ */ package org.jboss.shotoku.svn.content; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.svn.SvnTools; import org.jboss.shotoku.tools.Tools; /** @@ -40,7 +45,8 @@ private String stringContent; private byte[] byteContent; - private ByteArrayOutputStream currentBaos; + private File tmpFile; + private OutputStream tmpFileOs; private boolean changed; @@ -56,18 +62,28 @@ /* HELPER METHODS */ private void emptyContent() { + if (tmpFile != null) { + tmpFile.delete(); + tmpFile = null; + } + stringContent = null; byteContent = null; - currentBaos = null; } /* CONVERSION METHODS */ public String asString() { - if (currentBaos != null) { - try { currentBaos.flush(); } catch (IOException e) { } - stringContent = currentBaos.toString(); - currentBaos = null; + if (tmpFile != null) { + try { + tmpFileOs.flush(); + tmpFileOs.close(); + stringContent = SvnTools.getFileString(tmpFile); + } catch (IOException e) { + stringContent = ""; + } + tmpFile.delete(); + tmpFile = null; } else if (stringContent == null) { if (byteContent == null) stringContent = ""; @@ -79,10 +95,16 @@ } public byte[] asByteArray() { - if (currentBaos != null) { - try { currentBaos.flush(); } catch (IOException e) { } - byteContent = currentBaos.toByteArray(); - currentBaos = null; + if (tmpFile != null) { + try { + tmpFileOs.flush(); + tmpFileOs.close(); + byteContent = SvnTools.getFileBytes(tmpFile).array(); + } catch (IOException e) { + byteContent = new byte[0]; + } + tmpFile.delete(); + tmpFile = null; } else if (byteContent == null) { if (stringContent == null) byteContent = new byte[0]; @@ -94,7 +116,18 @@ } public InputStream asInputStream() { - return new ByteArrayInputStream(asByteArray()); + if (tmpFile != null) { + try { + tmpFileOs.flush(); + return new BufferedInputStream(new FileInputStream(tmpFile)); + } catch (FileNotFoundException e) { + return null; + } catch (IOException e) { + return null; + } + } else { + return new ByteArrayInputStream(asByteArray()); + } } /* SETTING METHODS */ @@ -124,10 +157,17 @@ } public OutputStream getOutputStream() { - currentBaos = new ByteArrayOutputStream(); + emptyContent(); + + tmpFile = SvnTools.createTemporaryFile(); + try { + tmpFileOs = new BufferedOutputStream(new FileOutputStream(tmpFile)); + } catch (FileNotFoundException e) { + throw new RepositoryException(e); + } changed = true; - return currentBaos; + return tmpFileOs; } /* VARIOUS METHODS */ @@ -146,26 +186,48 @@ * @return */ public void markUnchanged() { + emptyContent(); changed = false; } public long getLength() { - if (stringContent != null) + if (stringContent != null) { return stringContent.length(); + } + if (tmpFile != null) { + try { + tmpFileOs.flush(); + } catch (IOException e) { + + } + return tmpFile.length(); + } + return asByteArray().length; } public void copyFrom(NodeContent content) { if (content != null) { - setContent(content.asByteArray()); + if (content.tmpFile != null) { + this.tmpFile = content.tmpFile; + this.tmpFileOs = content.tmpFileOs; + } else { + setContent(content.asByteArray()); + } + changed = content.changed; } } - /* NOT USED */ + public boolean isLarge() { + return tmpFile != null; + } - public void free() { - + @Override + public void finalize() { + if (tmpFile != null) { + tmpFile.delete(); + } } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/WorkspaceMediator.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/WorkspaceMediator.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/WorkspaceMediator.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -21,24 +21,41 @@ */ package org.jboss.shotoku.svn.operations; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; +import java.util.Set; +import org.jboss.shotoku.svn.SvnTools; +import org.jboss.shotoku.tools.Pair; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.io.ISVNWorkspaceMediator; /** * @author Adam Warski (ad...@as...) */ -public class WorkspaceMediator implements -ISVNWorkspaceMediator { - private Map myTmpFiles = new HashMap(); +public class WorkspaceMediator implements ISVNWorkspaceMediator { + private Set<String> largePaths; + private Map<Object, Pair<File, OutputStream>> tmpFiles; + private Map<Object, ByteArrayOutputStream> tmpInMemory; + + public WorkspaceMediator(Set<String> largePaths) { + tmpFiles = new HashMap<Object, Pair<File, OutputStream>>(); + tmpInMemory = new HashMap<Object, ByteArrayOutputStream>(); + + this.largePaths = largePaths; + } + public String getWorkspaceProperty(String path, String name) throws SVNException { return null; @@ -46,45 +63,56 @@ public void setWorkspaceProperty(String path, String name, String value) throws SVNException { + } - /* - * Creates a temporary file delta storage. id will be used as the - * temporary storage identifier. Returns an OutputStream to write the - * delta data into the temporary storage. - */ - @SuppressWarnings("unchecked") public OutputStream createTemporaryLocation(String path, Object id) throws IOException { - ByteArrayOutputStream tempStorageOS = new ByteArrayOutputStream(); - myTmpFiles.put(id, tempStorageOS); - return tempStorageOS; + if (largePaths.contains(path)) { + File tmpFile = SvnTools.createTemporaryFile(); + OutputStream tmpOs = new BufferedOutputStream( + new FileOutputStream(tmpFile)); + tmpFiles.put(id, new Pair<File, OutputStream>(tmpFile, tmpOs)); + + return tmpOs; + } else { + ByteArrayOutputStream tmpBaos = new ByteArrayOutputStream(); + tmpInMemory.put(id, tmpBaos); + + return tmpBaos; + } } - /* - * Returns an InputStream of the temporary file delta storage identified - * by id to read the delta. - */ public InputStream getTemporaryLocation(Object id) throws IOException { - return new ByteArrayInputStream(((ByteArrayOutputStream)myTmpFiles.get(id)).toByteArray()); + if (tmpFiles.containsKey(id)) { + tmpFiles.get(id).getSecond().flush(); + return new BufferedInputStream(new FileInputStream( + tmpFiles.get(id).getFirst())); + } else { + return new ByteArrayInputStream(tmpInMemory.get(id).toByteArray()); + } } - /* - * Gets the length of the delta that was written to the temporary - * storage identified by id. - */ public long getLength(Object id) throws IOException { - ByteArrayOutputStream tempStorageOS = (ByteArrayOutputStream)myTmpFiles.get(id); - if (tempStorageOS != null) { - return tempStorageOS.size(); + if (tmpFiles.containsKey(id)) { + tmpFiles.get(id).getSecond().flush(); + return tmpFiles.get(id).getFirst().length(); + } else { + ByteArrayOutputStream tmpBaos = tmpInMemory.get(id); + if (tmpBaos != null) { + return tmpBaos.size(); + } + + return 0; } - return 0; } - /* - * Deletes the temporary file delta storage identified by id. - */ public void deleteTemporaryLocation(Object id) { - myTmpFiles.remove(id); + if (tmpFiles.containsKey(id)) { + tmpFiles.get(id).getFirst().delete(); + tmpFiles.remove(id); + } else { + tmpInMemory.remove(id); + } } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ModifyContentTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ModifyContentTest.java 2005-12-19 08:46:31 UTC (rev 1857) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ModifyContentTest.java 2005-12-19 09:51:24 UTC (rev 1858) @@ -85,6 +85,31 @@ TEST_FILE).getContent())); } + public void testBackgroundContentChange() throws Exception { + Node n = cm.getNode(TEST_FILE); + Node n2 = cm.getNode(TEST_FILE); + + assertTrue("initial".equals(n.getContent())); + + Node n3 = cm.getNode(TEST_FILE); + n3.setContent(TEST_CONTENT); + + assertTrue("initial".equals(n.getContent())); + + n3.save(""); + + assertTrue(TEST_CONTENT.equals(n.getContent())); + assertTrue(TEST_CONTENT.equals(n2.getContent())); + assertTrue(TEST_CONTENT.equals(n3.getContent())); + + // Waiting for a wc update. + Thread.sleep(20*1000); + + assertTrue(TEST_CONTENT.equals(n.getContent())); + assertTrue(TEST_CONTENT.equals(n2.getContent())); + assertTrue(TEST_CONTENT.equals(n3.getContent())); + } + @Override protected void tearDown() throws Exception { try { |