|
From: Christopher W. <caw...@us...> - 2006-02-22 20:04:10
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4101/src/org/rubypeople/rdt/internal/core Modified Files: CommitWorkingCopyOperation.java BecomeWorkingCopyOperation.java DiscardWorkingCopyOperation.java Log Message: extend RubyModelOperation Index: CommitWorkingCopyOperation.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/CommitWorkingCopyOperation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CommitWorkingCopyOperation.java 11 Mar 2005 03:09:25 -0000 1.2 --- CommitWorkingCopyOperation.java 22 Feb 2006 20:04:05 -0000 1.3 *************** *** 18,28 **** import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; - import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.rubypeople.rdt.core.IBuffer; import org.rubypeople.rdt.core.IRubyModelStatus; import org.rubypeople.rdt.core.IRubyModelStatusConstants; import org.rubypeople.rdt.core.IRubyScript; import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.internal.core.util.Util; --- 18,29 ---- import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.rubypeople.rdt.core.IBuffer; + import org.rubypeople.rdt.core.IRubyElement; import org.rubypeople.rdt.core.IRubyModelStatus; import org.rubypeople.rdt.core.IRubyModelStatusConstants; import org.rubypeople.rdt.core.IRubyScript; import org.rubypeople.rdt.core.RubyModelException; + import org.rubypeople.rdt.internal.core.util.Messages; import org.rubypeople.rdt.internal.core.util.Util; *************** *** 54,190 **** * of the folder containing the compilation unit). */ ! public class CommitWorkingCopyOperation { - private IRubyScript element; - private boolean force; - private IProgressMonitor progress; ! /** ! * Constructs an operation to commit the contents of a working copy to its ! * original compilation unit. ! */ ! public CommitWorkingCopyOperation(IRubyScript element, boolean force) { ! this.element = element; ! this.force = force; ! } ! /** ! * @exception RubyModelException ! * if setting the source of the original compilation unit ! * fails ! */ ! protected void executeOperation() throws RubyModelException { ! RubyScript workingCopy = getRubyScript(); ! IFile resource = (IFile) workingCopy.getResource(); ! IRubyScript primary = workingCopy.getPrimary(); ! boolean isPrimary = workingCopy.isPrimary(); ! if (isPrimary || (resource.isAccessible() && Util.isValidRubyScriptName(workingCopy.getElementName()))) { ! // force opening so that the delta builder can get the old info ! if (!isPrimary && !primary.isOpen()) { ! primary.open(null); ! } ! // save the cu ! IBuffer primaryBuffer = primary.getBuffer(); ! if (!isPrimary) { ! if (primaryBuffer == null) return; ! char[] primaryContents = primaryBuffer.getCharacters(); ! boolean hasSaved = false; ! try { ! IBuffer workingCopyBuffer = workingCopy.getBuffer(); ! if (workingCopyBuffer == null) return; ! primaryBuffer.setContents(workingCopyBuffer.getCharacters()); ! primaryBuffer.save(this.progress, this.force); ! primary.makeConsistent(this.progress); ! hasSaved = true; ! } finally { ! if (!hasSaved) { ! // restore original buffer contents since something went ! // wrong ! primaryBuffer.setContents(primaryContents); ! } ! } ! } else { ! // for a primary working copy no need to set the content of the ! // buffer again ! // FIXME Primary Buffer is null! ! primaryBuffer.save(this.progress, this.force); ! primary.makeConsistent(this.progress); ! } ! } else { ! // working copy on cu outside classpath OR resource doesn't exist ! // yet ! String encoding = null; ! try { ! encoding = resource.getCharset(); ! } catch (CoreException ce) { ! // use no encoding ! } ! String contents = workingCopy.getSource(); ! if (contents == null) return; ! try { ! byte[] bytes = encoding == null ? contents.getBytes() : contents.getBytes(encoding); ! ByteArrayInputStream stream = new ByteArrayInputStream(bytes); ! if (resource.exists()) { ! resource.setContents(stream, this.force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, null); ! } else { ! resource.create(stream, this.force, this.progress); ! } ! } catch (CoreException e) { ! throw new RubyModelException(e); ! } catch (UnsupportedEncodingException e) { ! throw new RubyModelException(e, IRubyModelStatusConstants.IO_EXCEPTION); ! } ! } ! // setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); ! // make sure working copy is in sync ! workingCopy.updateTimeStamp((RubyScript) primary); ! workingCopy.makeConsistent(this.progress); ! } ! /** ! * Returns the compilation unit this operation is working on. ! */ ! protected RubyScript getRubyScript() { ! return (RubyScript) element; ! } ! protected ISchedulingRule getSchedulingRule() { ! IResource resource = element.getResource(); ! IWorkspace workspace = resource.getWorkspace(); ! if (resource.exists()) { return workspace.getRuleFactory().modifyRule(resource); } ! return workspace.getRuleFactory().createRule(resource); ! } ! /** ! * Possible failures: ! * <ul> ! * <li>INVALID_ELEMENT_TYPES - the compilation unit supplied to this ! * operation is not a working copy ! * <li>ELEMENT_NOT_PRESENT - the compilation unit the working copy is based ! * on no longer exists. ! * <li>UPDATE_CONFLICT - the original compilation unit has changed since ! * the working copy was created and the operation specifies no force ! * <li>READ_ONLY - the original compilation unit is in read-only mode ! * </ul> ! */ ! public IRubyModelStatus verify() { ! RubyScript cu = getRubyScript(); ! if (!cu.isWorkingCopy()) { return new RubyModelStatus(IRubyModelStatusConstants.INVALID_ELEMENT_TYPES, cu); } ! if (cu.hasResourceChanged() && !this.force) { return new RubyModelStatus(IRubyModelStatusConstants.UPDATE_CONFLICT); } ! // no read-only check, since some repository adapters can change the ! // flag on save ! // operation. ! return RubyModelStatus.VERIFIED_OK; ! } ! public void runOperation(IProgressMonitor monitor) throws RubyModelException { ! this.progress = monitor; ! executeOperation(); ! } } --- 55,227 ---- * of the folder containing the compilation unit). */ ! public class CommitWorkingCopyOperation extends RubyModelOperation { ! /** ! * Constructs an operation to commit the contents of a working copy to its ! * original compilation unit. ! */ ! public CommitWorkingCopyOperation(IRubyScript element, boolean force) { ! super(new IRubyElement[] { element}, force); ! } ! /** ! * @exception RubyModelException ! * if setting the source of the original compilation unit ! * fails ! */ ! protected void executeOperation() throws RubyModelException { ! try { ! beginTask(Messages.workingCopy_commit, 2); ! RubyScript workingCopy = getRubyScript(); ! IFile resource = (IFile) workingCopy.getResource(); ! if (resource == null) { ! // case of a working copy without a resource ! workingCopy.getBuffer().save(this.progressMonitor, this.force); ! return; ! } ! IRubyScript primary = workingCopy.getPrimary(); ! boolean isPrimary = workingCopy.isPrimary(); ! RubyElementDeltaBuilder deltaBuilder = null; ! ! boolean isIncluded = !Util.isExcluded(workingCopy); ! if (isPrimary ! || (isIncluded && resource.isAccessible() && Util ! .isValidRubyScriptName(workingCopy.getElementName()))) { ! // force opening so that the delta builder can get the old info ! if (!isPrimary && !primary.isOpen()) { ! primary.open(null); ! } ! // creates the delta builder (this remembers the content of the ! // cu) if: ! // - it is not excluded ! // - and it is not a primary or it is a non-consistent primary ! if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) { ! deltaBuilder = new RubyElementDeltaBuilder(primary); ! } ! // save the cu ! IBuffer primaryBuffer = primary.getBuffer(); ! if (!isPrimary) { ! if (primaryBuffer == null) return; ! char[] primaryContents = primaryBuffer.getCharacters(); ! boolean hasSaved = false; ! try { ! IBuffer workingCopyBuffer = workingCopy.getBuffer(); ! if (workingCopyBuffer == null) return; ! primaryBuffer.setContents(workingCopyBuffer.getCharacters()); ! primaryBuffer.save(this.progressMonitor, this.force); ! primary.makeConsistent(this); ! hasSaved = true; ! } finally { ! if (!hasSaved) { ! // restore original buffer contents since something ! // went wrong ! primaryBuffer.setContents(primaryContents); ! } ! } ! } else { ! // for a primary working copy no need to set the content of ! // the buffer again ! primaryBuffer.save(this.progressMonitor, this.force); ! primary.makeConsistent(this); ! } ! } else { ! // working copy on cu outside classpath OR resource doesn't ! // exist yet ! String encoding = null; ! try { ! encoding = resource.getCharset(); ! } catch (CoreException ce) { ! // use no encoding ! } ! String contents = workingCopy.getSource(); ! if (contents == null) return; ! try { ! byte[] bytes = encoding == null ? contents.getBytes() : contents ! .getBytes(encoding); ! ByteArrayInputStream stream = new ByteArrayInputStream(bytes); ! if (resource.exists()) { ! resource.setContents(stream, this.force ? IResource.FORCE ! | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, null); ! } else { ! resource.create(stream, this.force, this.progressMonitor); ! } ! } catch (CoreException e) { ! throw new RubyModelException(e); ! } catch (UnsupportedEncodingException e) { ! throw new RubyModelException(e, IRubyModelStatusConstants.IO_EXCEPTION); ! } ! } ! setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); ! // make sure working copy is in sync ! workingCopy.updateTimeStamp((RubyScript) primary); ! workingCopy.makeConsistent(this); ! worked(1); ! // build the deltas ! if (deltaBuilder != null) { ! deltaBuilder.buildDeltas(); ! ! // add the deltas to the list of deltas created during this ! // operation ! if (deltaBuilder.delta != null) { ! addDelta(deltaBuilder.delta); ! } ! } ! worked(1); ! } finally { ! done(); ! } ! } ! ! /** ! * Returns the compilation unit this operation is working on. ! */ ! protected RubyScript getRubyScript() { ! return (RubyScript) getElementToProcess(); ! } ! ! protected ISchedulingRule getSchedulingRule() { ! IResource resource = getElementToProcess().getResource(); ! if (resource == null) return null; ! IWorkspace workspace = resource.getWorkspace(); ! if (resource.exists()) { ! return workspace.getRuleFactory().modifyRule(resource); ! } else { ! return workspace.getRuleFactory().createRule(resource); ! } ! } ! ! /** ! * Possible failures: ! * <ul> ! * <li>INVALID_ELEMENT_TYPES - the compilation unit supplied to this ! * operation is not a working copy ! * <li>ELEMENT_NOT_PRESENT - the compilation unit the working copy is based ! * on no longer exists. ! * <li>UPDATE_CONFLICT - the original compilation unit has changed since ! * the working copy was created and the operation specifies no force ! * <li>READ_ONLY - the original compilation unit is in read-only mode ! * </ul> ! */ ! public IRubyModelStatus verify() { ! RubyScript cu = getRubyScript(); ! if (!cu.isWorkingCopy()) { return new RubyModelStatus( ! IRubyModelStatusConstants.INVALID_ELEMENT_TYPES, cu); } ! if (cu.hasResourceChanged() && !this.force) { return new RubyModelStatus( ! IRubyModelStatusConstants.UPDATE_CONFLICT); } ! // no read-only check, since some repository adapters can change the ! // flag on save ! // operation. ! return RubyModelStatus.VERIFIED_OK; ! } } Index: BecomeWorkingCopyOperation.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/BecomeWorkingCopyOperation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BecomeWorkingCopyOperation.java 4 Mar 2005 13:54:47 -0000 1.3 --- BecomeWorkingCopyOperation.java 22 Feb 2006 20:04:05 -0000 1.4 *************** *** 11,16 **** package org.rubypeople.rdt.internal.core; - import org.eclipse.core.runtime.IProgressMonitor; import org.rubypeople.rdt.core.IProblemRequestor; import org.rubypeople.rdt.core.RubyModelException; --- 11,17 ---- package org.rubypeople.rdt.internal.core; import org.rubypeople.rdt.core.IProblemRequestor; + import org.rubypeople.rdt.core.IRubyElement; + import org.rubypeople.rdt.core.IRubyElementDelta; import org.rubypeople.rdt.core.RubyModelException; *************** *** 19,67 **** * addition through a delta. */ ! public class BecomeWorkingCopyOperation { ! private RubyScript workingCopy; ! private IProgressMonitor monitor; ! private IProblemRequestor problemRequestor; ! /* ! * Creates a BecomeWorkingCopyOperation for the given working copy. ! * perOwnerWorkingCopies map is not null if the working copy is a shared ! * working copy. ! */ ! public BecomeWorkingCopyOperation(RubyScript workingCopy, IProblemRequestor problemRequestor) { ! this.workingCopy = workingCopy; ! this.problemRequestor = problemRequestor; ! } ! protected void executeOperation() throws RubyModelException { ! // open the working copy now to ensure contents are that of the current ! // state of this element ! RubyModelManager.getRubyModelManager().getPerWorkingCopyInfo(workingCopy, true/* ! * create ! * if ! * needed ! */, true/* ! * record ! * usage ! */, problemRequestor); ! workingCopy.openWhenClosed(workingCopy.createElementInfo(), monitor); ! } ! /* ! * @see RubyModelOperation#isReadOnly ! */ ! public boolean isReadOnly() { ! return true; ! } ! /** ! * @param monitor ! * @throws RubyModelException ! */ ! public void runOperation(IProgressMonitor monitor) throws RubyModelException { ! this.monitor = monitor; ! executeOperation(); ! } } --- 20,81 ---- * addition through a delta. */ ! public class BecomeWorkingCopyOperation extends RubyModelOperation { ! private IProblemRequestor problemRequestor; ! /* ! * Creates a BecomeWorkingCopyOperation for the given working copy. ! * perOwnerWorkingCopies map is not null if the working copy is a shared ! * working copy. ! */ ! public BecomeWorkingCopyOperation(RubyScript workingCopy, IProblemRequestor problemRequestor) { ! super(new IRubyElement[] { workingCopy}); ! this.problemRequestor = problemRequestor; ! } ! protected void executeOperation() throws RubyModelException { ! // open the working copy now to ensure contents are that of the current ! // state of this element ! RubyScript workingCopy = getWorkingCopy(); ! RubyModelManager.getRubyModelManager().getPerWorkingCopyInfo(workingCopy, ! true/* create if needed */, true/* record usage */, this.problemRequestor); ! workingCopy.openWhenClosed(workingCopy.createElementInfo(), this.progressMonitor); ! if (!workingCopy.isPrimary()) { ! // report added java delta for a non-primary working copy ! RubyElementDelta delta = new RubyElementDelta(getRubyModel()); ! delta.added(workingCopy); ! addDelta(delta); ! } else { ! if (workingCopy.getResource().isAccessible()) { ! // report a F_PRIMARY_WORKING_COPY change delta for a primary ! // working copy ! RubyElementDelta delta = new RubyElementDelta(getRubyModel()); ! delta.changed(workingCopy, IRubyElementDelta.F_PRIMARY_WORKING_COPY); ! addDelta(delta); ! } else { ! // report an ADDED delta ! RubyElementDelta delta = new RubyElementDelta(this.getRubyModel()); ! delta.added(workingCopy, IRubyElementDelta.F_PRIMARY_WORKING_COPY); ! addDelta(delta); ! } ! } ! this.resultElements = new IRubyElement[] { workingCopy}; ! } ! ! /* ! * Returns the working copy this operation is working on. ! */ ! protected RubyScript getWorkingCopy() { ! return (RubyScript) getElementToProcess(); ! } ! ! /* ! * @see RubyModelOperation#isReadOnly ! */ ! public boolean isReadOnly() { ! return true; ! } } Index: DiscardWorkingCopyOperation.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/DiscardWorkingCopyOperation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DiscardWorkingCopyOperation.java 2 Mar 2005 00:54:02 -0000 1.2 --- DiscardWorkingCopyOperation.java 22 Feb 2006 20:04:05 -0000 1.3 *************** *** 11,15 **** package org.rubypeople.rdt.internal.core; ! import org.eclipse.core.runtime.IProgressMonitor; import org.rubypeople.rdt.core.RubyModelException; --- 11,16 ---- package org.rubypeople.rdt.internal.core; ! import org.rubypeople.rdt.core.IRubyElement; ! import org.rubypeople.rdt.core.IRubyElementDelta; import org.rubypeople.rdt.core.RubyModelException; *************** *** 18,41 **** * info if the use count is 0) and signal its removal through a delta. */ ! public class DiscardWorkingCopyOperation { ! private RubyScript workingCopy; ! public DiscardWorkingCopyOperation(RubyScript workingCopy) { ! this.workingCopy = workingCopy; ! } ! protected void runOperation(IProgressMonitor monitor) throws RubyModelException { ! int useCount = RubyModelManager.getRubyModelManager().discardPerWorkingCopyInfo(workingCopy); ! if (useCount == 0) { ! // TODO Create RubyElementDeltas ! } ! } ! /** ! * @see RubyModelOperation#isReadOnly ! */ ! public boolean isReadOnly() { ! return true; ! } } --- 19,69 ---- * info if the use count is 0) and signal its removal through a delta. */ ! public class DiscardWorkingCopyOperation extends RubyModelOperation { ! public DiscardWorkingCopyOperation(RubyScript workingCopy) { ! super(new IRubyElement[] { workingCopy}); ! } ! protected void executeOperation() throws RubyModelException { ! RubyScript workingCopy = getWorkingCopy(); ! int useCount = RubyModelManager.getRubyModelManager() ! .discardPerWorkingCopyInfo(workingCopy); ! if (useCount == 0) { ! if (!workingCopy.isPrimary()) { ! // report removed java delta for a non-primary working copy ! RubyElementDelta delta = new RubyElementDelta(this.getRubyModel()); ! delta.removed(workingCopy); ! addDelta(delta); ! removeReconcileDelta(workingCopy); ! } else { ! if (workingCopy.getResource().isAccessible()) { ! // report a F_PRIMARY_WORKING_COPY change delta for a ! // primary working copy ! RubyElementDelta delta = new RubyElementDelta(this.getRubyModel()); ! delta.changed(workingCopy, IRubyElementDelta.F_PRIMARY_WORKING_COPY); ! addDelta(delta); ! } else { ! // report a REMOVED delta ! RubyElementDelta delta = new RubyElementDelta(this.getRubyModel()); ! delta.removed(workingCopy, IRubyElementDelta.F_PRIMARY_WORKING_COPY); ! addDelta(delta); ! } ! } ! } ! } ! /** ! * Returns the working copy this operation is working on. ! */ ! protected RubyScript getWorkingCopy() { ! return (RubyScript) getElementToProcess(); ! } ! ! /** ! * @see RubyModelOperation#isReadOnly ! */ ! public boolean isReadOnly() { ! return true; ! } } |