[Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin/nature PythonNatureStore.java, 1.19, 1.20
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-07-19 20:18:06
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5510/src/org/python/pydev/plugin/nature Modified Files: PythonNatureStore.java Log Message: Applied patch that fixes race condition in PythonNatureStore: https://sourceforge.net/tracker/index.php?func=detail&aid=2019499&group_id=85796&atid=577329 Index: PythonNatureStore.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/nature/PythonNatureStore.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** PythonNatureStore.java 14 Jun 2008 22:14:55 -0000 1.19 --- PythonNatureStore.java 19 Jul 2008 20:18:14 -0000 1.20 *************** *** 11,14 **** --- 11,16 ---- import java.io.IOException; import java.util.ArrayList; + import java.util.Collections; + import java.util.LinkedList; import java.util.List; *************** *** 50,60 **** /** ! * This class stores PythonNature and PythonPathNature properties inside the project in a file instead of persistent properties. This allows PYTHONPATH and Python project version to be checked in into ! * version control systems. * * @author Gergely Kis <ger...@gm...> * */ - class PythonNatureStore implements IResourceChangeListener, IPythonNatureStore { --- 52,61 ---- /** ! * This class stores PythonNature and PythonPathNature properties inside the project in a file instead of persistent ! * properties. This allows PYTHONPATH and Python project version to be checked in into version control systems. * * @author Gergely Kis <ger...@gm...> * */ class PythonNatureStore implements IResourceChangeListener, IPythonNatureStore { *************** *** 65,87 **** */ private final class PythonNatureStoreJob extends Job { - private final ByteArrayInputStream is; ! private PythonNatureStoreJob(String name, ByteArrayInputStream is) { super(name); - this.is = is; } @Override protected IStatus run(IProgressMonitor monitor) { ! synchronized(xmlFile){ try{ onIgnoreRefresh++; if (!xmlFile.exists()) { xmlFile.create(is, true, monitor); - modStamp = xmlFile.getModificationStamp(); } else { xmlFile.setContents(is, true, false, monitor); - modStamp = xmlFile.getModificationStamp(); } xmlFile.refreshLocal(IResource.DEPTH_ZERO, monitor); }catch(Exception e){ --- 66,86 ---- */ private final class PythonNatureStoreJob extends Job { ! private PythonNatureStoreJob(String name) { super(name); } @Override protected IStatus run(IProgressMonitor monitor) { ! synchronized(saveLock){ ! ByteArrayInputStream is = (ByteArrayInputStream)pydevprojectStreams.remove(0); // remove() when it becomes queue try{ onIgnoreRefresh++; if (!xmlFile.exists()) { xmlFile.create(is, true, monitor); } else { xmlFile.setContents(is, true, false, monitor); } + modStamp = xmlFile.getModificationStamp(); xmlFile.refreshLocal(IResource.DEPTH_ZERO, monitor); }catch(Exception e){ *************** *** 115,118 **** --- 114,123 ---- private volatile int onIgnoreRefresh = 0; + private final Object saveLock = new Object(); + + // use Queue and ConcurrentLinkedQueue with 1.5 + private final List<ByteArrayInputStream> pydevprojectStreams = + Collections.synchronizedList(new LinkedList<ByteArrayInputStream>()); + /** * 0 means we're not in a store job *************** *** 157,161 **** * @see org.python.pydev.plugin.nature.IPythonNatureStore#setProject(org.eclipse.core.resources.IProject) */ ! public synchronized void setProject(IProject project) { synchronized (this) { if(project == null){ --- 162,166 ---- * @see org.python.pydev.plugin.nature.IPythonNatureStore#setProject(org.eclipse.core.resources.IProject) */ ! public void setProject(IProject project) { synchronized (this) { if(project == null){ *************** *** 196,204 **** private synchronized void checkLoad(String function) { traceFunc("checkLoad"); - synchronized (this) { if(!loaded){ PydevPlugin.log(new RuntimeException(StringUtils.format("%s still not loaded and '%s' already called.", xmlFile, function))); } - } traceFunc("END checkLoad"); } --- 201,207 ---- *************** *** 212,221 **** } traceFunc("getPathProperty - ", key); - synchronized (this) { checkLoad("getPathProperty"); String ret = getPathStringFromArray(getPathPropertyFromXml(key)); traceFunc("END getPathProperty - ", ret); return ret; - } } --- 215,222 ---- *************** *** 225,232 **** public synchronized void setPathProperty(QualifiedName key, String value) throws CoreException { traceFunc("setPathProperty"); - synchronized (this) { checkLoad("setPathProperty"); setPathPropertyToXml(key, getArrayFromPathString(value), true); - } traceFunc("END setPathProperty"); } --- 226,231 ---- *************** *** 246,250 **** traceFunc("loadFromFile"); boolean ret; - synchronized (this) { try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); --- 245,248 ---- *************** *** 292,296 **** throw new CoreException(status); } - } traceFunc("END loadFromFile"); --- 290,293 ---- *************** *** 313,317 **** private synchronized void migratePath(QualifiedName key) throws CoreException { traceFunc("migratePath"); - synchronized (this) { // Try to migrate from persistent property String[] propertyVal = getArrayFromPathString(project.getPersistentProperty(key)); --- 310,313 ---- *************** *** 322,326 **** project.setPersistentProperty(key, (String) null); } - } traceFunc("END migratePath"); } --- 318,321 ---- *************** *** 334,338 **** private synchronized Node getRootNodeInXml() { traceFunc("getRootNodeInXml"); - synchronized (this) { Assert.isNotNull(document); NodeList nodeList = document.getElementsByTagName(PYDEV_PROJECT_DESCRIPTION); --- 329,332 ---- *************** *** 348,352 **** throw new RuntimeException(StringUtils.format("Error. Unable to get the %s tag by its name. Project: %s", PYDEV_PROJECT_DESCRIPTION, project)); } - } /** --- 342,345 ---- *************** *** 358,362 **** private synchronized String getKeyString(QualifiedName key) { traceFunc("getKeyString"); - synchronized (this) { String keyString = key.getQualifier() != null ? key.getQualifier() : ""; String ret = keyString + "." + key.getLocalName(); --- 351,354 ---- *************** *** 364,368 **** return ret; } - } /** --- 356,359 ---- *************** *** 376,380 **** private synchronized Node findPropertyNodeInXml(String type, QualifiedName key) { traceFunc("findPropertyNodeInXml"); - synchronized (this) { Node root = getRootNodeInXml(); NodeList childNodes = root.getChildNodes(); --- 367,370 ---- *************** *** 398,402 **** return null; } - } /** --- 388,391 ---- *************** *** 407,413 **** * @return the array of strings with the text contents or null if the node has no children. */ ! private synchronized String[] getChildValuesWithType(Node node, String type) { traceFunc("getChildValuesWithType"); - synchronized (this) { NodeList childNodes = node.getChildNodes(); if (childNodes != null && childNodes.getLength() > 0) { --- 396,401 ---- * @return the array of strings with the text contents or null if the node has no children. */ ! private String[] getChildValuesWithType(Node node, String type) { traceFunc("getChildValuesWithType"); NodeList childNodes = node.getChildNodes(); if (childNodes != null && childNodes.getLength() > 0) { *************** *** 426,430 **** return null; } - } /** --- 414,417 ---- *************** *** 435,441 **** * @param values */ ! private synchronized void addChildValuesWithType(Node node, String type, String[] values) { traceFunc("addChildValuesWithType"); - synchronized (this) { assert (node != null); assert (values != null); --- 422,427 ---- * @param values */ ! private void addChildValuesWithType(Node node, String type, String[] values) { traceFunc("addChildValuesWithType"); assert (node != null); assert (values != null); *************** *** 446,450 **** node.appendChild(child); } - } traceFunc("END addChildValuesWithType"); } --- 432,435 ---- *************** *** 456,462 **** * @return the assembled string of paths or null if the input was null */ ! private synchronized String getPathStringFromArray(String[] pathArray) { traceFunc("getPathStringFromArray"); - synchronized (this) { if (pathArray != null) { FastStringBuffer s = new FastStringBuffer(); --- 441,446 ---- * @return the assembled string of paths or null if the input was null */ ! private String getPathStringFromArray(String[] pathArray) { traceFunc("getPathStringFromArray"); if (pathArray != null) { FastStringBuffer s = new FastStringBuffer(); *************** *** 472,476 **** traceFunc("END getPathStringFromArray (null)"); return null; - } } --- 456,459 ---- *************** *** 481,494 **** * @return the splitted array of strings or null if the input was null */ ! private synchronized String[] getArrayFromPathString(String pathString) { traceFunc("getArrayFromPathString"); ! synchronized (this) { ! if (pathString != null) { ! traceFunc("END getArrayFromPathString"); ! return pathString.split("\\|"); ! } ! traceFunc("END getArrayFromPathString (null)"); ! return null; } } --- 464,477 ---- * @return the splitted array of strings or null if the input was null */ ! private String[] getArrayFromPathString(String pathString) { ! traceFunc("getArrayFromPathString"); ! ! if (pathString != null) { ! traceFunc("END getArrayFromPathString"); ! return pathString.split("\\|"); } + traceFunc("END getArrayFromPathString (null)"); + return null; } *************** *** 568,574 **** * is not available in java 1.4 */ ! private synchronized void setTextContent(String textContent, Node self) throws DOMException { traceFunc("setTextContent"); - synchronized (this) { // get rid of any existing children Node child; --- 551,556 ---- * is not available in java 1.4 */ ! private void setTextContent(String textContent, Node self) throws DOMException { traceFunc("setTextContent"); // get rid of any existing children Node child; *************** *** 580,591 **** self.appendChild(document.createTextNode(textContent)); } - } traceFunc("END setTextContent"); } ! private synchronized String getTextContent(Node self) throws DOMException { traceFunc("getTextContent"); - synchronized (this) { FastStringBuffer fBufferStr = new FastStringBuffer(); Node child = self.getFirstChild(); --- 562,571 ---- self.appendChild(document.createTextNode(textContent)); } traceFunc("END setTextContent"); } ! private String getTextContent(Node self) throws DOMException { traceFunc("getTextContent"); FastStringBuffer fBufferStr = new FastStringBuffer(); Node child = self.getFirstChild(); *************** *** 610,614 **** traceFunc("END getTextContent - EMPTY"); return ""; - } } --- 590,593 ---- *************** *** 630,641 **** // internal method returning whether to take the given node's text content ! private synchronized boolean hasTextContent(Node child) { traceFunc("hasTextContent"); - synchronized (this) { boolean ret = child.getNodeType() != Node.COMMENT_NODE && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; traceFunc("END hasTextContent ", ret); return ret; - } } --- 609,618 ---- // internal method returning whether to take the given node's text content ! private boolean hasTextContent(Node child) { traceFunc("hasTextContent"); boolean ret = child.getNodeType() != Node.COMMENT_NODE && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; traceFunc("END hasTextContent ", ret); return ret; } *************** *** 649,653 **** * @throws CoreException */ ! private synchronized String[] getPathPropertyFromXml(QualifiedName key) throws CoreException { traceFunc("getPathPropertyFromXml"); synchronized (this) { --- 626,630 ---- * @throws CoreException */ ! private String[] getPathPropertyFromXml(QualifiedName key) throws CoreException { traceFunc("getPathPropertyFromXml"); synchronized (this) { *************** *** 677,681 **** * @throws CoreException */ ! private synchronized void setPathPropertyToXml(QualifiedName key, String[] paths, boolean store) throws CoreException { traceFunc("setPathPropertyToXml"); synchronized (this) { --- 654,658 ---- * @throws CoreException */ ! private void setPathPropertyToXml(QualifiedName key, String[] paths, boolean store) throws CoreException { traceFunc("setPathPropertyToXml"); synchronized (this) { *************** *** 719,723 **** * @throws TransformerException */ ! private synchronized byte[] serializeDocument(Document doc) throws IOException, TransformerException { traceFunc("serializeDocument"); synchronized (this) { --- 696,700 ---- * @throws TransformerException */ ! private byte[] serializeDocument(Document doc) throws IOException, TransformerException { traceFunc("serializeDocument"); synchronized (this) { *************** *** 840,846 **** } ! final ByteArrayInputStream is = new ByteArrayInputStream(serializeDocument(document)); ! PythonNatureStoreJob job = new PythonNatureStoreJob("Save .pydevproject", is); if (ProjectModulesManager.IN_TESTS){ --- 817,823 ---- } ! pydevprojectStreams.add(new ByteArrayInputStream(serializeDocument(document))); ! PythonNatureStoreJob job = new PythonNatureStoreJob("Save .pydevproject"); if (ProjectModulesManager.IN_TESTS){ |