开发Intellij插件时如何获取ModuleBuilder实例

时间:2019-04-21 09:09:58

标签: java intellij-idea intellij-plugin

我已经创建了三个步骤来提取要作为模块创建的文件:但是无法创建模块:

Plugin.xml

    <moduleBuilder id="SALESFORCE_MODULE_BUILDER" builderClass="salesforce.plugin.project.SalesForceModuleBuilder" order="first"/>
    <moduleType id="SALESFORCE_MODULE" implementationClass="salesforce.plugin.project.SalesForceModuleType"/>

    <sdkType id="SALESFORCE_SDK" implementation="salesforce.plugin.sdk.SalesForceSdkType"/>

ModuleBuilder:

public class SalesForceModuleBuilder extends JavaModuleBuilder {

    private final Logger logger = Logger.getInstance(getClass());

    private SalesForceWizardStateBean stateBean = new SalesForceWizardStateBean();

    public SalesForceModuleBuilder(){
        super();
    }

    @Override
    public String getName() {
        return "SalesForce Module Builder";
    }

    @Override
    public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException {
        if (myJdk == null){
            modifiableRootModel.inheritSdk();
        } else {
            modifiableRootModel.setSdk(myJdk);
        }

        // Add root folder
        ContentEntry contentEntry = doAddContentEntry(modifiableRootModel);

        // The classes, trigger, pages, and components folder were created by one of the Wizard steps
        // Now, we need to add them as source folders under the root folder
        if (contentEntry != null) {
            for (SalesForceWizardStateBean.FOLDER_NAMES folderName : SalesForceWizardStateBean.FOLDER_NAMES.values()) {
                logger.warn("folderName SalesForceModuleBuilder "+folderName);
                String path = getContentEntryPath() + '/' + folderName.name().toLowerCase();
                logger.warn("path SalesFError creating folderorceModuleBuilder "+path);
                addSourceFolder(contentEntry, path);
            }
        }
        logger.warn("contentEntry check this SalesForceModuleBuilder "+contentEntry.getFile());
        ProjectSettingsPersistentStateComponent projectSettings = ServiceManager.getService(modifiableRootModel.getProject(), ProjectSettingsPersistentStateComponent.class);
        projectSettings.instanceName = stateBean.getSelectedInstance();

    }

    @Override
    public ModuleType getModuleType() {
        return new SalesForceModuleType();
    }

    @Override
    public boolean isSuitableSdkType(SdkTypeId sdkType) {
        return sdkType instanceof SalesForceSdkType;
    }

    private void addSourceFolder(ContentEntry contentEntry, String path) {
        final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(path));
        if (sourceRoot != null) {
            contentEntry.addSourceFolder(sourceRoot, false, "");
        }
    }

    public SalesForceWizardStateBean getStateBean() {
        return stateBean;
    }

}

模块类型包含三个步骤:

@Override
@NotNull
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull SalesForceModuleBuilder moduleBuilder, @NotNull ModulesProvider modulesProvider) {
    ArrayList<ModuleWizardStep> steps = new ArrayList<ModuleWizardStep>();
    steps.add(new SalesForceInstanceSelectionStep(wizardContext.getProject(), moduleBuilder.getStateBean()));
    steps.add(new SalesForceSynchroniseOptionsStep(moduleBuilder.getStateBean()));
    steps.add(new SalesForceSynchroniseStep(moduleBuilder.getStateBean(), moduleBuilder));
    return steps.toArray(new ModuleWizardStep[steps.size()]);
}

出现错误的第三步:

public class SalesForceSynchroniseStep extends ModuleWizardStep {

    private final Logger logger = Logger.getInstance(getClass());
    private SalesForceModuleBuilder moduleBuilder;
    private final SalesForceWizardStateBean stateBean;

    private JButton cancelButton;
    private JTextArea statusArea;
    private JPanel synchronizingPanel;

    private volatile boolean synchronizing = false;
    private volatile boolean synchronizeFinished = false;

    public SalesForceSynchroniseStep(SalesForceWizardStateBean stateBean, SalesForceModuleBuilder moduleBuilder) {
        this.stateBean = stateBean;
        this.moduleBuilder = moduleBuilder;
    }

    @Override
    public JComponent getComponent() {
        return synchronizingPanel;
    }

    @Override
    public void updateDataModel() {
        // nothing to do here
    }

    @Override
    public void _init() {
        if (synchronizeFinished) {
            // this gets called when we enter AND exits the step (?!?!), so ignore the second call on exit
            return;
        }
        synchronizing = true;
        createFolders();
        SynchronizeSwingWorker swingWorker = new SynchronizeSwingWorker(statusArea, stateBean, new SynchronizeSwingWorker.DoneCallBack() {
            @Override
            public void done() {
                synchronizing = false;
                synchronizeFinished = true;
            }
        });
        swingWorker.execute();
    }

    private void createFolders() {
        String contentEntryPath = moduleBuilder.getContentEntryPath();
        logger.warn("moduleBuilder.getModuleFileDirectory() -> "+moduleBuilder.getModuleFileDirectory());
        for (SalesForceWizardStateBean.FOLDER_NAMES folderName : SalesForceWizardStateBean.FOLDER_NAMES.values()) {
            String folderPath = contentEntryPath + File.separator + folderName.name().toLowerCase();
            logger.warn("folderPath Path " + folderPath);
            logger.warn("contentEntryPath Path " + contentEntryPath);
            boolean result = new File(folderPath).mkdirs();
            if (!result) {
                logger.warn("Error creating folder " + folderName.name().toLowerCase());
            }
            stateBean.addCreatedFolder(folderName, folderPath);
        }

    }

    @Override
    public void _commit(boolean finishChosen) throws CommitStepException {
        if (synchronizing) {
            throw new CommitStepException("Please wait for synchronization to complete.");
        }
    }

}

moduleBuilder.getContentEntryPath(),此行始终返回null,是否缺少我的内容。

所期望的是:同步文件时,它应该创建文件夹并在第三步完成时在模块中对其进行同步:

日志文件(如果有帮助的话):

2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - moduleBuilder.getModuleFileDirectory() -> null 
2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - folderPath Path null\classes 
2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - contentEntryPath Path null 
2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - Error creating folder classes 
2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - folderPath Path null\triggers 
2019-04-21 14:37:29,302 [ 731958]   WARN - ject.SalesForceSynchroniseStep - contentEntryPath Path null 
2019-04-21 14:37:29,303 [ 731959]   WARN - ject.SalesForceSynchroniseStep - Error creating folder triggers 
2019-04-21 14:37:29,303 [ 731959]   WARN - ject.SalesForceSynchroniseStep - folderPath Path null\pages 
2019-04-21 14:37:29,303 [ 731959]   WARN - ject.SalesForceSynchroniseStep - contentEntryPath Path null 
2019-04-21 14:37:29,304 [ 731960]   WARN - ject.SalesForceSynchroniseStep - Error creating folder pages 
2019-04-21 14:37:29,304 [ 731960]   WARN - ject.SalesForceSynchroniseStep - folderPath Path null\components 
2019-04-21 14:37:29,304 [ 731960]   WARN - ject.SalesForceSynchroniseStep - contentEntryPath Path null 
2019-04-21 14:37:29,304 [ 731960]   WARN - ject.SalesForceSynchroniseStep - Error creating folder components 
2019-04-21 14:37:35,832 [ 738488]   INFO - ellij.project.impl.ProjectImpl - 183 project components initialized in 93 ms 
2019-04-21 14:37:35,834 [ 738490]   INFO - le.impl.ModuleManagerComponent - 0 module(s) loaded in 0 ms 
2019-04-21 14:37:37,126 [ 739782]   WARN - roject.SalesForceModuleBuilder - folderName SalesForceModuleBuilder CLASSES 
2019-04-21 14:37:37,126 [ 739782]   WARN - roject.SalesForceModuleBuilder - path SalesFError creating folderorceModuleBuilder C:/Users/Nagendra/Downloads/Simple-Intellij-Plugin-0.1.0/untitled10/classes 
2019-04-21 14:37:37,128 [ 739784]   WARN - roject.SalesForceModuleBuilder - folderName SalesForceModuleBuilder TRIGGERS 
2019-04-21 14:37:37,128 [ 739784]   WARN - roject.SalesForceModuleBuilder - path SalesFError creating folderorceModuleBuilder C:/Users/Nagendra/Downloads/Simple-Intellij-Plugin-0.1.0/untitled10/triggers 
2019-04-21 14:37:37,128 [ 739784]   WARN - roject.SalesForceModuleBuilder - folderName SalesForceModuleBuilder PAGES 
2019-04-21 14:37:37,128 [ 739784]   WARN - roject.SalesForceModuleBuilder - path SalesFError creating folderorceModuleBuilder C:/Users/Nagendra/Downloads/Simple-Intellij-Plugin-0.1.0/untitled10/pages 
2019-04-21 14:37:37,129 [ 739785]   WARN - roject.SalesForceModuleBuilder - folderName SalesForceModuleBuilder COMPONENTS 
2019-04-21 14:37:37,129 [ 739785]   WARN - roject.SalesForceModuleBuilder - path SalesFError creating folderorceModuleBuilder C:/Users/Nagendra/Downloads/Simple-Intellij-Plugin-0.1.0/untitled10/components 
2019-04-21 14:37:37,130 [ 739786]   WARN - roject.SalesForceModuleBuilder - contentEntry check this SalesForceModuleBuilder file://C:/Users/Nagendra/Downloads/Simple-Intellij-Plugin-0.1.0/untitled10

0 个答案:

没有答案