Custom plugin override Import

已完成

Hello,

I have C++ project defined through files named "Project.xml" (always the same name). I have developed java code to create a CMakeLists file from those these. 

In a plugin, I would like to override the default Import feature to behave like this:

  • if the selected import target is a file named "Project.xml" :
  1. run a custom feature to create the CMakeLists file
  2. import the project from the created CMakeLists file
  3. call a custom method with the created project as parameter to persist some values at project level
  • otherwise let CLion process his default import project feature

Is this possible, where to start?

 

The plugin targes only CLion if that has an impact.

0
Avatar
Permanently deleted user

If anyone interested here is the procedure:

Create a class inheriting ProjectOpenProcessor


public class MyProjectOpenProcessor extends ProjectOpenProcessor {

private static final Icon myIcon = CommonsIcons.BMS_ICON_SMALL;

@NotNull
@Override
public String getName() {
return "MyProject";
}

@Override
public Icon getIcon() {
return myIcon;
}

@Override
public boolean canOpenProject(VirtualFile virtualFile) {
return virtualFile != null && virtualFile.isValid() && virtualFile.getName().equals("MyProject.xml");
}

@Nullable
@Override
public Project doOpenProject(@NotNull VirtualFile virtualFile, @Nullable Project project, boolean b) {
if(createOrUpdateCMakeListsFile(virtualFile){
return importProjectFromCMakeLists(virtualFile);
}

return null;
}

private boolean createOrUpdateCMakeListsFile(@NotNull VirtualFile virtualFile) {
....
}

private Project importProjectFromCMakeLists(@NotNull VirtualFile virtualFile) {
\\identify the cMakeListsFile
VirtualFile cMakeListsFile = virtualFile.getParent().getChildren()where......;

ProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstance();
Project newProject = null;

if(cMakeListsFile != null && processor!= null){
newProject = processor.doOpenProject(cMakeListsFile, null, true);
}

return newProject;
}
}

 

Add the following to plugin.xml

<extensions defaultExtensionNs="com.intellij">
<projectOpenProcessor implementation="com.amadeus.bms.plugin.clion.import_wizard.BmsProjectOpenProcessor"/>
</extensions>
0

请先登录再写评论。