Bug 163574 - Handle updating the generated results better
Summary: Handle updating the generated results better
Status: VERIFIED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Jet (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Paul Elder CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on: 149770
Blocks:
  Show dependency tree
 
Reported: 2006-11-06 13:24 EST by Ed Merks CLA
Modified: 2020-05-01 16:11 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Merks CLA 2006-11-06 13:24:51 EST
Paul,

In JETCompileTemplateOperation we do the following.

              String encoding = outputFile.getCharset();
              String result = stringWriter.getBuffer().toString();
              byte [] bytes;
              try
              {
                bytes = encoding == null ? result.getBytes() : result.getBytes(encoding);
              }
              catch (UnsupportedEncodingException exception)
              {
                bytes = result.getBytes();
              }
              
              if (!outputFile.exists()) 
              {
                outputFile.create(new ByteArrayInputStream(bytes), true, progressMonitor);
              } 
              else 
              {
                boolean changed = true;
                try
                {
                  InputStream inputStream = outputFile.getContents();
                  byte [] oldBytes =  new byte[inputStream.available()];
                  inputStream.read(oldBytes);
                  inputStream.close();
                  changed = !Arrays.equals(oldBytes, bytes);
                }
                catch (IOException exception) 
                {
                }
  
                if (changed)
                {
                  if (outputFile.isReadOnly()) 
                  {
                    // This call should get the files checked out from version control if the project is a 'team' project.
                    //
                    IStatus status = ResourcesPlugin.getWorkspace().validateEdit(new IFile [] { outputFile }, null);
                    if (!status.isOK()) 
                    {
                      throw new CoreException(status);
                    }
                  }
                  outputFile.setContents(new ByteArrayInputStream(bytes), true, true, progressMonitor);
                }
              }

The validateEdit code was contributed by https://bugs.eclipse.org/bugs/show_bug.cgi?id=149770, so I'm making that change but don't want to lose it when we move to JET2.  That made me notice the other nice things we're already doing that JET2Compiler.writeFile is not already doing.  It's nice to minimize the number of deltas on a file, so creating an empty version and then writing to it isn't so nice.  Most importantly, producing a no-op delta on the file is quite unpleasant and makes for a bad CVS experience where files change for no good reason.  So I would suggest that this method be changed to be more like what's being done in old JET right now.
Comment 1 Ed Merks CLA 2006-11-06 13:34:55 EST
This should be marked as a contribution once the changes with the validateEdit support have been commited.
Comment 2 Paul Elder CLA 2007-05-03 14:53:18 EDT
Changes committed to CVS. IP log updated.
Comment 3 Paul Elder CLA 2007-05-07 09:08:31 EDT
Fixed in build I200705031530.
Comment 4 Paul Elder CLA 2007-05-07 09:12:38 EDT
Fixed in build I200705031530
Comment 5 Nick Boldt CLA 2008-01-28 16:55:53 EST
Move to verified as per bug 206558.
Comment 6 Nick Boldt CLA 2008-05-15 12:03:04 EDT
[contrib email="merks@ca.ibm.com"/]