Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Create files only once
Create files only once [message #1791127] Sun, 24 June 2018 13:14 Go to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 57
Registered: August 2013
Member
Create files only once.
Hi guys.
I would like to create some files in a project only the first time. But if a skip the generation the second time on, xtext has been deleting the files created previously. I think it makes sence, but how I can solve this issue and keep these files?

Regards,
Márcio Koch.
Re: Create files only once [message #1791128 is a reply to message #1791127] Sun, 24 June 2018 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
How did you configure the outlet? Inside the outputconfiguration there should be an option for that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Create files only once [message #1791135 is a reply to message #1791128] Sun, 24 June 2018 21:38 Go to previous messageGo to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 57
Registered: August 2013
Member
It is not working for me, when I save my DSL file, the generated files which should be kept (OUTPUT_KEEPED configuration), are removed if exists and created otherwise.
class MklOutputConfigurationProvider extends OutputConfigurationProvider {
	
	public static val DEFAULT_OUTPUT_DIRECTORY = "."
	public static val APP_OUTPUT_DIRECTORY = DEFAULT_OUTPUT_DIRECTORY + "/modules/app/"
	public static val OUTPUT_KEEPED = "OUTPUT_KEEPED"
	
	
	override getOutputConfigurations() {
		val defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT)
		defaultOutput.description = "Default and base output."
		defaultOutput.outputDirectory = DEFAULT_OUTPUT_DIRECTORY
		defaultOutput.createOutputDirectory = true
		
		
		val outputConfigKeepResources = new OutputConfiguration(OUTPUT_KEEPED)
		outputConfigKeepResources.description = "Keep generated files"
		outputConfigKeepResources.outputDirectory = APP_OUTPUT_DIRECTORY
		outputConfigKeepResources.createOutputDirectory = true
		outputConfigKeepResources.overrideExistingResources = false
		outputConfigKeepResources.setDerivedProperty = false
		outputConfigKeepResources.canClearOutputDirectory = false
		outputConfigKeepResources.cleanUpDerivedResources = false
		
		newHashSet(defaultOutput, outputConfigKeepResources)
	}
	
}


Debugging, Eclipse falls in this code that always associates the files with the DSL and deletes them, they seem to be always derived files:
public boolean installMarker(IFile file, String generator, String source) throws CoreException {
		if (!file.exists())
			return false;
		IMarker[] markers = file.findMarkers(MARKER_ID, true, IResource.DEPTH_INFINITE);
		for (IMarker marker : markers) {
			if (generator.equals(marker.getAttribute(ATTR_GENERATOR))
				&& source.equals(marker.getAttribute(ATTR_SOURCE)))
				return true;
		}
		IMarker marker = file.createMarker(MARKER_ID);
		marker.setAttribute(ATTR_GENERATOR, generator);
		marker.setAttribute(ATTR_SOURCE, source);
		return true;
	}


I'm doing something wrong?
Re: Create files only once [message #1791138 is a reply to message #1791135] Sun, 24 June 2018 23:53 Go to previous messageGo to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 57
Registered: August 2013
Member
I solved the problem by my self extending installMarker method from DerivedResourceMarkers class and checking when really is a derived file.
class MklDerivedResourceMarkers extends DerivedResourceMarkers {
	
	override installMarker(IFile file, String generator, String source) throws CoreException {
		val isDerived = file.isDerived()
		if (!isDerived) {
			return false
		}
		
		super.installMarker(file, generator, source)
	}	
}


After I bind the extended class in my DSL AbstractUiModule:
@FinalFieldsConstructor
class MklUiModule extends AbstractMklUiModule {
	
	def Class<? extends IDerivedResourceMarkers> bindDerivedResourceMarkers() {		
		return MklDerivedResourceMarkers		
	}	
}


I don't know if this is the right way, but it works for me.
Re: Create files only once [message #1791141 is a reply to message #1791138] Mon, 25 June 2018 04:55 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
So your files are not related to a model? Why are they generated at all then

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Parsing in reconciler failed. / [Model.feature] does not exist
Next Topic:Guillemets and UTF-8 encoding on Windows vs Mac
Goto Forum:
  


Current Time: Thu Apr 25 11:50:10 GMT 2024

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

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

Back to the top