Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to delete generated files(I would like to delete the previously generated files if they aren't generated again)
How to delete generated files [message #1777505] Wed, 29 November 2017 18:59 Go to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 40
Registered: August 2013
Member
On save I would like to delete the previously generated files if they aren't generated again.
I have a flag that determines if a file should be generated or not. If some file was generated, but after the user turn the flag off and save again, that old file must be deleted. There is a way to do this using the Xtext plug-in?
Re: How to delete generated files [message #1777507 is a reply to message #1777505] Wed, 29 November 2017 19:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
Hi, i am not sure if i can follow you. you can have a look at org.eclipse.xtext.builder.BuilderParticipant.cleanDerivedResources(Delta, Set<IFile>, IBuildContext, EclipseResourceFileSystemAccess2, IProgressMonitor) or org.eclipse.xtext.builder.BuilderParticipant.getDerivedResources(Delta, Map<String, OutputConfiguration>, Map<OutputConfiguration, Iterable<IMarker>>)

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: How to delete generated files [message #1777508 is a reply to message #1777507] Wed, 29 November 2017 19:30 Go to previous messageGo to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 40
Registered: August 2013
Member
Hi thank you for the quick reply.
The method getDerivedResources returns an empty list, but I have files generated and others that should be deleted.
Re: How to delete generated files [message #1777509 is a reply to message #1777508] Wed, 29 November 2017 19:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
Can you give some more insights on what you are doing inside your generator

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: How to delete generated files [message #1777517 is a reply to message #1777509] Wed, 29 November 2017 21:09 Go to previous messageGo to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 40
Registered: August 2013
Member
Nothing special, I'm using default output configuration and calling:
def protected void generateFile(String fileName, CharSequence contents) {
    fsa.generateFile(fileName, contents);
}
Re: How to delete generated files [message #1777519 is a reply to message #1777517] Wed, 29 November 2017 21:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11900
Registered: July 2009
Senior Member
but this works out of the box

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID doNotGenerate?='skip'? '!';



class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		for (g : resource.allContents.filter(Greeting).toIterable.filter[!isDoNotGenerate]) {
			fsa.generateFile(g.name+".txt",'''«g.name»''')
		}
	}
}


add a skip to a greeting and generated file will go away


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: How to delete generated files [message #1777618 is a reply to message #1777519] Thu, 30 November 2017 20:44 Go to previous message
Márcio Koch is currently offline Márcio KochFriend
Messages: 40
Registered: August 2013
Member
Hi thanks for your reply.
The problem was happening because I'm changing the outputDirectory to '.' at doGenerate method. But the outputDirectory in BuilderParticipant.build method was being created with "./src-gen", so it wasn't deleting the expected old files because directories are different. The solution was to do like described in https://stackoverflow.com/questions/10350022/how-to-add-multiple-outlets-for-generated-xtext-dsl.
Now it is deleting not generated files as expected.
Previous Topic:Parsing from a tree
Next Topic:java.lang.RuntimeException: path to .genmodel is unmapped
Goto Forum:
  


Current Time: Tue Apr 24 10:24:01 GMT 2018

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

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