Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to overwrite previously generated file?(How to overwrite previously generated file?)
How to overwrite previously generated file? [message #1854507] Tue, 23 August 2022 04:45 Go to next message
Eclipse UserFriend
Greetings,

I generate files running Acceleo in the standalone mode. I am facing a challenge when running generation subsequent the initial generation. The file doesn't get overwritten/regenerated. If I delete the existing file, a new one based on a newer template is created. In my files, which is a Java class, I have protected zones, so I would like to be able to regenerate when either the model or the template structure changes.

Would appreciate any guidance on how to either to turn it on or triage on where the problem might be.

Thank you!
Re: How to overwrite previously generated file? [message #1854514 is a reply to message #1854507] Tue, 23 August 2022 13:58 Go to previous messageGo to next message
Eclipse UserFriend
I have done more digging and debugging and it all boils down to the logic in the AcceleoFileWriter's close method below.

The content flush isn't performed if not running within Eclipse. Wonder if anyone has a POV on this.

@Override
public void close() throws IOException {
if (!shouldMerge || !EMFPlugin.IS_ECLIPSE_RUNNING) {
delegate.close();
} else {
// The decorated writer is a StringWriter. Closing has no effect on it
flush();
try {
Class.forName("org.eclipse.emf.codegen.merge.java.JMerger"); //$NON-NLS-1$
final String mergedContent = JMergeUtil.mergeFileContent(new File(targetPath), toString(),
selectedCharset);
// Write the new file on disk
Writer writer = null;
try {
if (selectedCharset == null) {
writer = new BufferedWriter(new FileWriter(new File(targetPath)));
} else {
final OutputStream fileOutputStream = new FileOutputStream(new File(targetPath));
final OutputStreamWriter fileWriter = new OutputStreamWriter(fileOutputStream,
selectedCharset);
writer = new BufferedWriter(fileWriter);
}
writer.append(mergedContent);
} finally {
if (writer != null) {
writer.close();
}
}
} catch (ClassNotFoundException e) {
/*
* shouldn't happen. This would mean we are in eclipse yet org.eclipse.emf.codegen cannot be
* found as a dependency of the generator plugin. This shouldn't happen since it is a
* reexported dependency of the engine.
*/
AcceleoEnginePlugin.log(e, true);
}
}
}
Re: How to overwrite previously generated file? [message #1854521 is a reply to message #1854514] Tue, 23 August 2022 16:05 Go to previous message
Eclipse UserFriend
Hi

Well diagnosed. If you report the bug, and better still provide the patch, it could well get fixed.

A difference in IDE / standalone behaviour certainly seems wrong, but I never used protected regions so it's beyond my knowledge.

Regards

Ed Willink
Previous Topic:[Acceleo] Null when accessing reference from a linked metamodel
Next Topic:Call service wrapper function in the post() black
Goto Forum:
  


Current Time: Wed Feb 19 00:20:22 GMT 2025

Powered by FUDForum. Page generated in 0.03042 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top