7.4 KiB
Legacy Project Wizard API
Implementing a custom project creation wizard.
Plugins targeting versions 2024.2 and newer should implement the .
Project Wizard
Working with the project wizard can be illustrated with the RedLine SmallTalk plugin. See also .
Implementing a New Module Type
Additional support for specific tools and technologies is usually done via implementing some certain module type, which is attached to the project.
A new module type should be derived from the class ModuleType
.
Custom Project Wizard
The main utilities to configure a custom project wizard can be found in the package lang-api.ide.util.projectWizard
.
These classes and interfaces serve the following purposes:
- Modification of the configuration wizard view
- Adding new steps to the wizard
- Providing additional settings for project creation
- Handling activities during project creation
- Initial environment configuration
Module Type
To create a new module type, add an extension:
<moduleType
id="MY_MODULE"
implementationClass="st.redline.smalltalk.module.MyModuleType"/>
to the plugin.xml
.
A custom module type should extend the
ModuleType
generic from
ModuleBuilder
.
The following module type implementation of a custom module type shows how this instance can be registered and implemented.
Implementing Module Builder
To set up a new module environment, ModuleBuilder
should be extended and registered as an extension point like the following snippet shows:
<extensions defaultExtensionNs="com.intellij">
<moduleBuilder
builderClass="org.jetbrains.plugins.ruby.rails.facet.versions.MyModuleBuilder"/>
</extensions>
Functionality which is mandatory to implement consists of:
void setupRootModel(ModifiableRootModel)
- sets up a root model for the new moduleModuleType getModuleType()
- returns a module type
See JavaModuleBuilder
to understand better how to implement a module builder.
If your module type is based on the Java module and meant to support Java as well, extending JavaModuleBuilder
is enough.
No extension point needs to be registered.
Refer to the SmallTalk module type to see how JavaModuleBuilder
can be derived.
Starting with the 2022.1 release, IntelliJ-based IDEs use the refreshed project wizard, and some module builder base classes return
false
fromisAvailable()
when the new wizard is enabled. If your module builder is not visible in 2022.1, make sure that yourModuleBuilder.isAvailable()
returnstrue
.
{style="note"}
Implementing Module Builder Listener
Module builder listener reacts on a new module creation, which could be done either as a part of the project creation process or as adding a new module to the already existing project.
To provide a certain behavior right after a module has been created, a module builder must implement ModuleBuilderListener.moduleCreated(Module)
.
Examples of the tasks executed right after a module has been created may include configuring module roots, looking up for an SDK and setting it up, adding a specific facet if required, etc. For more details, please see the following SmallTalk custom module type implementation.
Adding New Wizard Steps
Adding new steps to the module wizard can be done by overriding AbstractModuleBuilder.createWizardSteps(WizardContext, ModulesProvider)
.
See an example module builder.
If this method returns a non-empty array of ModuleWizardStep
objects, new steps will be shown in their indexing order while creating a new module.
The following implementation for the SmallTalk project type illustrates how a custom wizard step can be created.
The RsModuleWizardStep
class is derived from ModuleWizardStep
, which has two methods to be overridden:
JComponent getComponent()
- defines the step's UIvoid updateDataModel()
- commits data from UI intoModuleBuilder
andWizardContext
Facet
Facets in IntelliJ are the way to store multiple kinds of module-specific settings, for example, to make a language support or framework available in some given module. To understand facets better from the end-user's point of view, see the documentation section.
Implementing Project Structure Detector
To support the creation of your module when a project is imported from existing sources, extend ProjectStructureDetector
.
To detect the files your module supports, implement ProjectStructureDetector.detectRoots()
.
Refer to the Smalltalk project structure detector to see an example implementation.
But detecting the files is not enough, you also need to create a module for the project if appropriate by implementing setupProjectStructure()
.
Here is an example that creates a module if no other modules exist in the project structure.
@Override
public void setupProjectStructure(
@NotNull Collection<DetectedProjectRoot> roots,
@NotNull ProjectDescriptor projectDescriptor,
@NotNull ProjectFromSourcesBuilder builder) {
List<ModuleDescriptor> modules = projectDescriptor.getModules();
if (modules.isEmpty()) {
modules = new ArrayList<>();
for (DetectedProjectRoot root : roots) {
modules.add(new ModuleDescriptor(root.getDirectory(),
MyModuleType.getInstance(), ContainerUtil.emptyList()));
}
projectDescriptor.setModules(modules);
}
}