user2000974
user2000974

Reputation: 303

Extending xtext new project wizard

I'm using xtext 2.13/java8 to create a DSL with IDE as described in "Implementing Domain-Specific Languages with Xtext and XTend 2nd edition". The IDE includes a new project wizard, and the DSL includes a code generator that produces java code. The generated java code depends on some helper classes in another support plugin that is provided as part of the DSL project. I can export the update site and install into a fresh eclipse. There, I can create a new DSL project that compiles the DSL file into java. I would like to extend the new project wizard so that I can automatically add the dependency on my support plugin to the generated MANIFEST file in the new project. I can add it manually after the project is created (the plugin is present in the installed feature), but I don't want users to have to do that. org.eclipse.xtext.ui.wizard.AbstractPluginProjectCreator has code that adds the dependencies on logging packages, but I don't see any way to extend or override that logic using any extension points. Is there a way to do this?

Upvotes: 0

Views: 200

Answers (1)

user2000974
user2000974

Reputation: 303

This turned out to be not too hard, though it took a half-day of experimenting to find it.

The xtext project defines a generated MyDSLProjectCreator class in the *.ui plugin under src-gen in the .ui.wizard package that defines the method we need to override:

@Override
protected List<String> getRequiredBundles() {
    return Lists.newArrayList(DSL_PROJECT_NAME);
}

By default, this adds just the DSL project bundle to the dependencies of the new project. I need to add also the support plugins. I can't edit this generated file, but I can extend it, so I defined MyExtendedProjectCreator class in the src folder of the same .ui.wizard package that extends this class (java source):

public class MyExtendedProjectCreator extends MyDslProjectCreator {

@Override
protected List<String> getRequiredBundles() {
    return Lists.newArrayList(DSL_PROJECT_NAME,
            "my.plugin.id");
}

}

To invoke that project creator instead of the default, I had to override another method in the MyDslUiModule class. This can be found in the .ui package under src (xtend file):

@FinalFieldsConstructor
class MyDslUiModule extends AbstractMyDslUiModule {
  public def override Class<? extends IProjectCreator> bindIProjectCreator() {
     MyExtendedProjectCreator;
  }
}

Upvotes: 2

Related Questions