Bug 196187 - validateEdit problem
Summary: validateEdit problem
Status: RESOLVED DUPLICATE of bug 212178
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal
Target Milestone: ---   Edit
Assignee: GMF Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-11 12:29 EDT by Eleonora Ludin CLA
Modified: 2010-07-19 12:24 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eleonora Ludin CLA 2007-07-11 12:29:49 EDT
Build ID: M20070212-1330

Steps To Reproduce:
Scenario:

RSA UML project source-controlled by ClearCase.
User tries to modify a checked in model (without explicitly checking it out from ClearCase first). ClearCase gets the validateEdit call from the gmf editor and tries to checkout the file. ClearCase discovers that a later version of the file exists in the repository. ClearCase offers the user two choices - checkout the loaded version or checkout the latest version. If the user picks the 1st option, everything is fine. If they pick the "latest" option, the checkout succeeds but then they get an error message saying that "no modifications are allowed; resource is out of sync with the file system" (or something to that effect).

More information:
Debugging through the code, we've discovered that once our validateEdit returns an OK status, the GMF code tries to verify that the file is "in sync". The test includes comparing the length of the file before and after the call to validateEdit. Since ClearCase checks out a different version of the file, that test, of course, fails.
The code I am referring to is in:

package org.eclipse.gmf.runtime.emf.core.internal.util;

public class FileValidator implements MSLFileModificationValidator {
.....

        public boolean hasFileChanged() {
            IPath path = file.getLocation();
            if (path == null) {
                return false;
            }
            File ioFile = path.toFile();
            if (ioFile == null) {
                return false;
            }

            // new timestamp
            Timestamp newTimestamp = new Timestamp(ioFile.lastModified());
            newTimestamp.setNanos(0);

            return !(lastModified.getTime() == newTimestamp.getTime() && fileLength == ioFile
                    .length());            
        }
}
Comment 1 Michael Valenta CLA 2007-07-11 12:50:59 EDT
CVS has a similar setting in case that helps when trying to reproduce this (i.e. Watch/Edit can be configured to perform an update before editing). I've tried this with the GMF ecore editor and it does leave the editor in a bad state (i.e. the editor no longer saves and doesn't issue any error).

The steps to follow with CVS are:

1) From the CVS properties of a CVS project containing an ecore model linked to the GMF ecore editor, check the "Enable watch/edit for this project" property.
2) In the Team>CVS>Watch/Edit preference page, check the 'Send CVS Notifications to the server", "Always Prompt" and "Prompt to update if out of date".
3) From a different workspace, commit a change to the ecore model file.
4) From your workspace, try to edit the ecore model using the GMF editor. You should be prompted to edit the file and then prompted to update.
5) After the file is updated, there are no errors but saving from the editor doesn't update the file on disk.

Although this is not the same as the reported scenario, it may be related.
Comment 2 Alex Shatalin CLA 2007-07-11 13:07:37 EDT
Are you usign lates version of GMF? I can not see org.eclipse.gmf.runtime.emf.core.internal.util.FileValidator in my org.eclipse.gmf.runtime.emf.core plugin in workspace..

Are you using generated code?

Concerning the ClearCase problem - looks like ClearCase integration just update java.io.File on the local file system in this situation and leave eclipse Resource out of synch. CVS problem could be a little bit different - i suppose once ClearCase integration will be corrected, the results will be aligned with CVS scenario..
Comment 3 Eleonora Ludin CLA 2007-07-11 13:45:04 EDT
We are using whatever version of GMF comes with our RSA install. From the According to the About box, this is org.eclipse.gmf (1.0.3.v20070202-1200-gW3quizrSB1Fxqp) "Graphical Modeling Framework".
Version: 1.0.0.I20060505-1400
Build id: 1.0.3

We actually do update the Eclipse resource by calling IResource.refreshLocal.
Here is more code for you from the same FileValidator class in org.eclipse.gmf.runtime.emf.core.internal.util:

 public IStatus validateEdit(IFile[] files, Object shell) {
        IStatus status = Status.OK_STATUS;
        if (files == null || files.length == 0) {
            return status;
        }
        Set unsynchedFiles = new HashSet();
        Map filesToModificationStamps = new HashMap();
        if (!MSLUtil.DISABLE_SHARED_DYNAMIC_VIEW_SUPPORT) {
            for (int i = 0; i < files.length; i++) {
                IFile file = files[i];
                filesToModificationStamps.put(file, new ModificationStamp(file));
                boolean inSync = file.isSynchronized(IResource.DEPTH_ZERO);
                if (!inSync) {
                    unsynchedFiles.add(file);
                }
            }
            if (!unsynchedFiles.isEmpty()) {
                status = buildOutOfSyncStatus(unsynchedFiles);
            }
        }
        if (status.isOK()) {
            status = ResourcesPlugin.getWorkspace().validateEdit(files, shell);
            if (!MSLUtil.DISABLE_SHARED_DYNAMIC_VIEW_SUPPORT) {
                for (Iterator entries = filesToModificationStamps.entrySet().iterator(); entries.hasNext();) {
                    Map.Entry entry = (Map.Entry)entries.next();
                    IFile file = (IFile)entry.getKey();
                    ModificationStamp stamp = (ModificationStamp)entry.getValue();
                    if (stamp.hasFileChanged()) {
                        unsynchedFiles.add(file);
                    }
                }
                if (!unsynchedFiles.isEmpty()) {
                    status = buildOutOfSyncStatus(unsynchedFiles);
                }
            }
        }
        return status;
       
    }

Note how after the call to ResourcesPlugin.getWorkspace().validateEdit(), it goes over the set of ModificationStamp(s) it had collected before the call and calls stamp.hasFileChanged(). If it returns true, an error is buit. Like I said, the file is changed in our implementation of validateEdit(), it is intentional.
Comment 4 Artem Tikhomirov CLA 2007-10-16 06:23:26 EDT
Reassigning to Runtime team as it seems to have nothing to do with the generated code or models.
Comment 5 Anthony Hunter CLA 2007-12-19 16:33:35 EST

*** This bug has been marked as a duplicate of bug 212178 ***
Comment 6 Eclipse Webmaster CLA 2010-07-19 12:24:08 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime EMF was the original product and component for this bug