|
|
|
|
|
|
|
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755327 is a reply to message #1755322] |
Thu, 02 March 2017 11:16 |
|
well there is actually a way if you abuse xtext.xbase.testing (you need to add a dependency to that testing bundle at runtime)
val cl = MyDslGenerator.classLoader
println(cl)
val InMemoryJavaCompiler compiler = new InMemoryJavaCompiler(cl, JavaVersion.JAVA8)
val result = compiler.compile(new JavaSource(
"a/Hello.java",
'''
package a;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello Dynamic");
}
}
'''
))
val Class<?> mainClazz = result.classLoader.loadClass("a.Hello")
val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
val String[] args = #[]
mainMethod.invoke(null,#[args])
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
|
|
|
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755380 is a reply to message #1755379] |
Thu, 02 March 2017 17:32 |
|
which xtext version do you use?
how does your generator look like?
the generator that xtext creates out of the box looks like
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
/**
* 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(', '))
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
|
|
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755397 is a reply to message #1755394] |
Thu, 02 March 2017 19:18 |
|
how much experience do you have as a programmer in general?
if google does not find anything you have to have a look at the stoneage old xtext test code yourself
val OnTheFlyJavaCompiler compiler = new OnTheFlyJavaCompiler()
val mainClazz = compiler.compileToClass("a.Hello", '''
package a;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello Dynamic");
}
}
''')
val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
val String[] args = #[]
mainMethod.invoke(null,#[args])
or simpy have a look at the class and the methods and .....
git clone git@github.com:eclipse/xtext.git
cd xtext
git checkout tags/v2.4.3 -b v2.4.3
cd tests
grep -ril "new OnTheFlyJavaCompiler" .
results ./org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompilerTest.java
open it in editor and have a look
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755427 is a reply to message #1755397] |
Fri, 03 March 2017 09:25 |
abdf mncr Messages: 75 Registered: February 2017 |
Member |
|
|
Hii Christian DietrichFriend , I updated my Xtext to last version and the error of pervious imports is resloved , But when runtime new eclipse for writing my Dsl then press CTRL+S i have this error :
Errors occurred during the build.
Errors running builder 'Xtext Project Builder' on project 'Test'.
org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler
and this code error in Console , Did you test it in your machine ?
!ENTRY org.eclipse.osgi 2 0 2017-03-03 10:03:55.175
!MESSAGE While loading class "org.eclipse.egit.ui.internal.ConfigurationChecker$1$1", thread "Thread[Worker-1,5,main]" timed out waiting (5021ms) for thread "Thread[main,6,main]" to finish starting bundle "org.eclipse.egit.ui_4.4.1.201607150455-r [146]". To avoid deadlock, thread "Thread[Worker-1,5,main]" is proceeding but "org.eclipse.egit.ui.internal.ConfigurationChecker$1$1" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="4.4.1.201607150455-r"; osgi.identity="org.eclipse.egit.ui"; singleton:="true" [id=146] STARTED [STARTED]
at org.eclipse.osgi.container.Module.lockStateChange(Module.java:337)
at org.eclipse.osgi.container.Module.start(Module.java:401)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:470)
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.egit.ui.internal.ConfigurationChecker$1.run(ConfigurationChecker.java:45)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.util.concurrent.TimeoutException: Timeout after waiting 5 seconds to acquire the lock.
at org.eclipse.osgi.container.Module.lockStateChange(Module.java:334)
... 13 more
Root exception:
java.util.concurrent.TimeoutException: Timeout after waiting 5 seconds to acquire the lock.
at org.eclipse.osgi.container.Module.lockStateChange(Module.java:334)
at org.eclipse.osgi.container.Module.start(Module.java:401)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:470)
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.egit.ui.internal.ConfigurationChecker$1.run(ConfigurationChecker.java:45)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!ENTRY org.eclipse.oomph.setup.ui 2 0 2017-03-03 10:06:55.172
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
at org.eclipse.oomph.setup.ui.SetupUIPlugin.performStartup(SetupUIPlugin.java:443)
at org.eclipse.oomph.setup.ui.SetupUIPlugin.access$5(SetupUIPlugin.java:414)
at org.eclipse.oomph.setup.ui.SetupUIPlugin$1$1.run(SetupUIPlugin.java:253)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
org.eclipse.osgi.internal.loader.EquinoxClassLoader@24f9a670[org.xtext.example.mydsl:1.0.0.qualifier(id=964)]
!ENTRY org.eclipse.core.resources 4 2 2017-03-03 10:09:45.042
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler
at org.xtext.example.mydsl.generator.MyDslGenerator.doGenerate(MyDslGenerator.java:30)
at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:43)
at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:564)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:549)
at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:534)
at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:280)
at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:238)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:291)
at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:319)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:155)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler cannot be found by org.xtext.example.mydsl_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more
!ENTRY org.eclipse.core.resources 4 75 2017-03-03 10:09:45.297
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.xtext.ui.shared 4 75 2017-03-03 10:09:45.298
!MESSAGE Errors running builder 'Xtext Project Builder' on project 'Test'.
!STACK 0
java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler
at org.xtext.example.mydsl.generator.MyDslGenerator.doGenerate(MyDslGenerator.java:30)
at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:43)
at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:564)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:549)
at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:534)
at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:280)
at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:238)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:291)
at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:319)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:155)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler cannot be found by org.xtext.example.mydsl_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more
!ENTRY org.eclipse.jface 2 0 2017-03-03 10:09:49.860
!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation.
!SUBENTRY 1 org.eclipse.jface 2 0 2017-03-03 10:09:49.861
!MESSAGE A conflict occurred for ALT+CTRL+H:
Binding(ALT+CTRL+H,
ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.open.call.hierarchy,Open Call Hierarchy,
Open a call hierarchy on the selected element,
Category(org.eclipse.ui.category.navigate,Navigate,null,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4a0e955,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
org.eclipse.ui.contexts.window,,,system)
Binding(ALT+CTRL+H,
ParameterizedCommand(Command(org.eclipse.xtext.xbase.ui.hierarchy.OpenCallHierarchy,Open Call Hierarchy,
Open a call hierarchy on the selected element,
Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@117ea0cf,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
org.eclipse.xtext.ui.XtextEditorScope,,,system)
Binding(ALT+CTRL+H,
ParameterizedCommand(Command(org.eclipse.xtext.ui.editor.OpenCallHierarchy,Open Call Hierarchy,
Open call hierarchy for the selected element,
Category(org.eclipse.ui.category.navigate,Navigate,null,true),
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@57dbd55d,
,,true),null),
org.eclipse.ui.defaultAcceleratorConfiguration,
org.eclipse.xtext.ui.XtextEditorScope,,,system)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|