Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Change PLUGIN_ID field in generated UI activator
Change PLUGIN_ID field in generated UI activator [message #1797531] Thu, 01 November 2018 09:50 Go to next message
Cornelius Mising name is currently offline Cornelius Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hello,

is there a way to change the PLUGIN_ID field in the generated activator of the UI project?

public class ExampledslActivator extends AbstractUIPlugin {

	public static final String PLUGIN_ID = "exampledsl.ui";
	...
}


It contains the value of eclipsePlugin.name of my mwe2 file but this is not the correct bundle symbolic name in my setup. So, is there any chance to change the generated value so that I do not need to change my bundle symbolic name?


Just for the record: Having a bundle symbolic name that differs from the generated PLUGIN_ID field leads to the following error:

Could not create the Injector for org.example.lang.exampledsl.ui.ExampleDSLExecutableExtensionFactory.
A NullPointerException occurred. This also indicates that bundle org.example.exampledsl.ui was compiled with an outdated version of Xtext. Please consider to regenerate the DSL implementation  with a current version.
Your currently installed version of Xtext is 2.15.0.v20180916-1016.


Took me some time to figure this out.


Cornelius
Re: Change PLUGIN_ID field in generated UI activator [message #1797534 is a reply to message #1797531] Thu, 01 November 2018 10:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
how do you exactly change plugin id in your setup.
the code that generates the activator is at
org.eclipse.xtext.xtext.generator.XtextGeneratorTemplates.createEclipsePluginActivator(IXtextProjectConfig, List<? extends IXtextGeneratorLanguage>)
public static final String PLUGIN_ID = "«projectConfig.eclipsePlugin.name»";

=> if you correctly handle your project config then it works ootb.

alternatively you can bind a custom XtextGeneratorTemplates that customizes the activator generation

you can use a custom binding like

Workflow {

component = XtextGenerator {
configuration = EntitiesGeneratorModule {



public class EntitiesGeneratorModule extends DefaultGeneratorModule {

public Class<? extends XtextGeneratorNaming> bindNaming() {
return StateMachineGeneratorNaming.class;
}

public static class StateMachineGeneratorNaming extends XtextGeneratorNaming {
@Override
public String getWebBasePackage(Grammar grammar) {
if (grammar.getName().equals("org.eclipse.xtext.web.example.entities.Entities")) {
return "org.eclipse.xtext.web.example.jetty";
} else {
return super.getWebBasePackage(grammar);
}
}
}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Change PLUGIN_ID field in generated UI activator [message #1797539 is a reply to message #1797534] Thu, 01 November 2018 13:30 Go to previous messageGo to next message
Cornelius Mising name is currently offline Cornelius Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Thanks for your quick answer.


Christian Dietrich wrote on Thu, 01 November 2018 11:53
how do you exactly change plugin id in your setup.


By "changing" (or even better setting) the Bundle-SymbolicName in the MANIFEST.MF file. Or to be more precise: It is generated by the maven-bundle-plugin that creates my MANIFEST.MF file. But that is behind the scope of this post.


Christian Dietrich wrote on Thu, 01 November 2018 11:53
the code that generates the activator is at
org.eclipse.xtext.xtext.generator.XtextGeneratorTemplates.createEclipsePluginActivator(IXtextProjectConfig, List<? extends IXtextGeneratorLanguage>)
public static final String PLUGIN_ID = "«projectConfig.eclipsePlugin.name»";

=> if you correctly handle your project config then it works ootb.


In my opinion, it is a little too intrusive to expect that the Eclipse project folder of the UI project (= Eclipse project name) and the Bundle-SymbolicName of the OSGi bundle needs to be the same. In the naming schema of my project, the Eclipse ui project is in the folder 'exampledsl.ui' (thus, the property 'projectConfig.eclipsePlugin.name' needs to have this value so that Xtext is able to find the appropriate gen folders) but the Bundle-SymbolicName is 'org.example.lang.exampledsl.ui'.

With the correct config my setup works fine. Despite the hard-coded PLUGIN_ID value. (Besides the flaw that the package of the Activator is some kind of strange. I mentioned this here some time ago: https://www.eclipse.org/forums/index.php/m/1742115/ But this is just cosmetics.) In a previous version of Xtext this problem with the PLUGIN_D didn't exist. So I would like to encourage to consider that the Eclipse project name / folder could differ from the OSGi bundle id. That should be easily possible by introducing an optional config value that let the user set the bundle id (and set the 'name' attribut as default value if not given). Because technically there is no reason for the demand to have the same names / IDs.



Christian Dietrich wrote on Thu, 01 November 2018 11:53
alternatively you can bind a custom XtextGeneratorTemplates that customizes the activator generation

you can use a custom binding like

...


Thank you for this hint. That's nice. I consider this.
Re: Change PLUGIN_ID field in generated UI activator [message #1797540 is a reply to message #1797539] Thu, 01 November 2018 14:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Don't know why setting simply the name does not work for you ...

Well it's always a fight. Until now gazillions of users can live with the default.
Please customize the generator if you don't like it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 01 November 2018 14:30]

Report message to a moderator

Re: Change PLUGIN_ID field in generated UI activator [message #1797545 is a reply to message #1797540] Thu, 01 November 2018 15:56 Go to previous messageGo to next message
Cornelius Mising name is currently offline Cornelius Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Christian Dietrich wrote on Thu, 01 November 2018 15:23
Don't know why setting simply the name does not work for you ...


I don't know what you meen with 'setting simply the name'. To make it a little clearer: The sample Xtext project generated by the Eclipse wizard has the projects in the following folders:

.
├── org.xtext.example.mydsl
├── org.xtext.example.mydsl.ide
└── org.xtext.example.mydsl.ui


The basename in the mwe2 file is set to: baseName = "org.xtext.example.mydsl"


I don't want to have the project folders with the FQN, I just want to have the following folder structure:

.
├── mydsl
├── mydsl.ide
└── mydsl.ui


Therefore I need to set the basename in the mwe2 file to: baseName = "mydsl"

That is fine so far (despite the package name generation of the UI activator I mentioned above that uses the project name as package name instead of the actual package name like all other generated files).


But now, I want to have the OSGi bundle symbolic names the full name, e.g. org.xtext.example.mydsl. There should be nothing wrong with it. There is no reason to force to use the folder of the eclipse name as bundle name. The only part that forces me to do so is the PLUGIN_ID field.



Christian Dietrich wrote on Thu, 01 November 2018 15:23
Well it's always a fight. Until now gazillions of users can live with the default.
Please customize the generator if you don't like it


I didn't want to sound ungrateful. I used to use Xtext with the naming schema descibed above but it does not work anymore with the current version (don't know since which version that is the case). That's why I wanted to know if there is a way to change the PLUGIN_ID (there isn't -- except via an own generator) and encourage to rethink the assumption that eclipse project name/folder are always the same than package name and OSGi bundle symbolic name.

For the moment I just rename the bundle symbolic name for the UI project. That it doesn't fit to the naming schema of my bundles is unaesthetic but not a big problem. It doesn't stop me from using this great open source project. ;-)
Re: Change PLUGIN_ID field in generated UI activator [message #1797551 is a reply to message #1797545] Thu, 01 November 2018 16:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i mean the workflow

eclipsePlugin = {
name = "xxxxx"
root = "yyyyy"
enabled = true
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Change PLUGIN_ID field in generated UI activator [message #1797552 is a reply to message #1797551] Thu, 01 November 2018 16:37 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
alternatively you can subclass org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory
and fix the bad place and use the subclass all over plugin.xml


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Confused: Cyclic resolution of lazy links
Next Topic:Create a value converter
Goto Forum:
  


Current Time: Thu Apr 25 07:04:14 GMT 2024

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

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

Back to the top