Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » generator denies to run
generator denies to run [message #1832370] Thu, 17 September 2020 08:36 Go to next message
M T is currently offline M TFriend
Messages: 22
Registered: February 2016
Junior Member
Hi

i have installed the newest xtext 2.23.0 from a bundle provided which includes also the java se 11.0. I tried to execute a simple hello world with success. My next step is to create a button in the index.html. On button click event i want to call the generator which will only log out a hello world to the console.log of the running server.

index.html
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Example Web Editor</title>
	<link rel="stylesheet" type="text/css" href="xtext/2.23.0/xtext-ace.css"/>
	<link rel="stylesheet" type="text/css" href="style.css"/>
	<script src="webjars/requirejs/2.3.6/require.min.js"></script>
	<script type="text/javascript">
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("index.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex);
		require.config({
			baseUrl: baseUrl,
			paths: {
				"jquery": "webjars/jquery/3.4.1/jquery.min",
				"ace/ext/language_tools": "webjars/ace/1.3.3/src/ext-language_tools",
				"xtext/xtext-ace": "xtext/2.23.0/xtext-ace"
			}
		});
		require(["webjars/ace/1.3.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				xtext.createEditor({
					baseUrl: baseUrl,
					syntaxDefinition: "xtext-resources/generated/mode-mydsl"
				});
				$("#generate-button").click(function() {
					//do smothing  
				alert("clicked ")	
				//editor.xtextServices.enableGeneratorService();
				//editor.xtextServices.saveResource();
				//var gen = editor.xtextServices.generate();
				editor.xtextServices.generate();
			});
			});
		});
	</script>
</head>
<body>
<div ><button id='generate-button'>generate button </button></div>
<div class="container">
	<div class="header">
		<h1>Example MyDsl Web Editor</h1>
	</div>
	<div class="content">
		<div id="xtext-editor" data-editor-xtext-lang="mydsl"></div>
	</div>
</div>

</body>
</html>




MyDslGenerator.xtend
/*
 * generated by Xtext 2.23.0
 */
package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.xtext.example.mydsl.myDsl.Greeting

/**
 * Generates code from your model files on save.
 * 
 * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
 */
class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		fsa.generateFile('greetings.txt', 'People to greet: ' + 
			resource.allContents
				.filter(Greeting)
				.map[name]
				.join(', '));
				
		println("this is the generator.xtend");

var JsonGenerator jg = new JsonGenerator();
	jg.generateJson()
	}
}


JsonGenerator.java
package org.xtext.example.mydsl.generator;

public class JsonGenerator {

	public void generateJson() {
		 System.out.println("Starting genetator");
	  throw new UnsupportedOperationException("TODO: auto-generated method stub");
	 
	}
	
}



I don't now there is something missing in this call process. The problem is that i don't see if the methods are executed or the problem comes to the console . Is there any other connection point missing ?

Best Regards
Michael
Re: generator denies to run [message #1832371 is a reply to message #1832370] Thu, 17 September 2020 08:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
did you check this one

https://www.eclipse.org/forums/index.php?t=msg&th=1073968&goto=1720505&#msg_1720505

besides that i recomment you to debug the server


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generator denies to run [message #1832379 is a reply to message #1832371] Thu, 17 September 2020 10:20 Go to previous messageGo to next message
M T is currently offline M TFriend
Messages: 22
Registered: February 2016
Junior Member
Hi Christian,

thanks for your quick answer.
I have made these changes as you suggested

index.html
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Example Web Editor</title>
	<link rel="stylesheet" type="text/css" href="xtext/2.23.0/xtext-ace.css"/>
	<link rel="stylesheet" type="text/css" href="style.css"/>
	<script src="webjars/requirejs/2.3.6/require.min.js"></script>
	<script type="text/javascript">
	var editor;
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("index.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex);
		require.config({
			baseUrl: baseUrl,
			paths: {
				"jquery": "webjars/jquery/3.4.1/jquery.min",
				"ace/ext/language_tools": "webjars/ace/1.3.3/src/ext-language_tools",
				"xtext/xtext-ace": "xtext/2.23.0/xtext-ace"
			}
		});
		require(["webjars/ace/1.3.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				editor=xtext.createEditor({
					baseUrl: baseUrl,
					syntaxDefinition: "xtext-resources/generated/mode-mydsl"
				});
					jQuery('#generate-button').bind("click", function(e){
					
					jQuery('#generator-result').html('<iframe style="width:1000px; height:200px;" src="http://' + location.host + '/xtext-service/generate?resource=example1.mydsl2"></iframe>');
					alert(location.host + '/xtext-service/generate?resource')
					e.preventDefault();
				});
			});
		});
	</script>
</head>
<body>

<div class="container">
	<div class="header">
		<h1>Example MyDsl Web Editor</h1>
	</div>
	<div class="content">
		<div id="xtext-editor" data-editor-xtext-lang="mydsl" data-editor-resource-id="example1.mydsl2"></div>
	</div>
	
	<div class="button-wrapper">
		<button id="generate-button" value="Generate" title="Generate">Generate</button>
		<div id="generator-result">
			Result
		</div>
	</div>
</div>

</body>
</html>



MyDslGenerator.xtend
/*
 * generated by Xtext 2.23.0
 */
package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.xtext.example.mydsl.myDsl.Greeting

/**
 * Generates code from your model files on save.
 * 
 * See [url]https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation[/url]
 */
class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		fsa.generateFile('/DEFAULT_ARTIFACT', 'People to greet: ' + 
			resource.allContents
				.filter(typeof(Greeting))
				.map[name]
				.join(', '))
				
				println("this is the generator.xtend");
	}
}


style.css
div.button-wrapper {
	display: block;
	position: absolute;
	top: 90px;
	bottom: 0;
	left: 640px;
	right: 0;
	padding: 4px;
	border: 1px solid #aaa;
}



Now i get this message inside the Iframe.
HTTP ERROR 400 Unable to identify the Xtext language for resource example1.mydsl2. URI: /xtext-service/generate STATUS: 400 MESSAGE: Unable to identify the Xtext language for resource example1.mydsl2. SERVLET: XtextServices Powered by Jetty:// 9.4.22.v20191022

Also in the console of the browser appears an error message
jquery.min.js:2
GET http://localhost:8082/xtext-service/generate?resource=example1.mydsl2 400 (Bad Request)
Failed to load resource: the server responded with a status of 400 (Bad Request)


The resource extension should be similar to the language being used in my dsl example ? In my case the xtext file is "MyDsl.xtext" . Also i can't get it work to display the message "this is the generator.xtend" in the console log of the sever.

Best regards
MIchael

[Updated on: Thu, 17 September 2020 10:21]

Report message to a moderator

Re: generator denies to run [message #1832381 is a reply to message #1832379] Thu, 17 September 2020 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
sure mydsl2 is your extension? and example1 the filename?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 17 September 2020 10:28]

Report message to a moderator

Re: generator denies to run [message #1832383 is a reply to message #1832381] Thu, 17 September 2020 10:38 Go to previous messageGo to next message
M T is currently offline M TFriend
Messages: 22
Registered: February 2016
Junior Member
Sorry but i am a little bit confused .
Christian you mean that in my case the resource should have at list the extension "xtext" (because of my dsl language named "MyDsl.xtext")
If i get it right, the name can be anything because of a file creation (for example resource name with extension can be " myresource.xtext").
If this is the case ,then the generated file should be created in the same folder, where the generator is laying also. Correct ?

Best Regards,
Michael

[Updated on: Thu, 17 September 2020 10:41]

Report message to a moderator

Re: generator denies to run [message #1832384 is a reply to message #1832383] Thu, 17 September 2020 10:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
you define the file extension in the GenerateMyDsl.mwe2 file

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generator denies to run [message #1832385 is a reply to message #1832384] Thu, 17 September 2020 10:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
and no the file name is the name the server knows the client side file under

<div id="xtext-editor" data-editor-xtext-lang="mydsl2" data-editor-resource-id="example1.mydsl2"></div>

vs

jQuery('#generator-result').html('<iframe src="http://' + location.host + '/xtext-service/generate?resource=example1.mydsl2"></iframe>');


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: generator denies to run [message #1832386 is a reply to message #1832384] Thu, 17 September 2020 10:50 Go to previous messageGo to next message
M T is currently offline M TFriend
Messages: 22
Registered: February 2016
Junior Member
I defined the xtension to be "mydsl".
Now i am getting a 404. The request resource was not found.
Should i first create the file "example1.mydsl" or is it something that the generator do? (Confussed++)

Re: generator denies to run [message #1832387 is a reply to message #1832386] Thu, 17 September 2020 10:51 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
data-editor-resource-id="example1.mydsl">

and: please debug the server


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 17 September 2020 10:51]

Report message to a moderator

Previous Topic:xText ParallelBuilderParticipant issue
Next Topic:Unresolved reference with dsl in jar library
Goto Forum:
  


Current Time: Fri Oct 23 01:16:45 GMT 2020

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

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

Back to the top