Example #1
0
  public void createTempletInProject(
      ProjectTempletXmlManager templetXmlManager,
      ProjectTempletManager manager,
      List<TempletVMNode> lstVm,
      String mainFunction,
      IProject newProjectHandle,
      String projectType) {

    if (null == lstVm) {
      return;
    }

    String projectPath = newProjectHandle.getLocation().toFile().getAbsolutePath();
    String vmfile = "";
    String outfile = "";
    for (TempletVMNode vmnode : lstVm) {

      vmfile = PathTools.getPlugPath(PYTHON_PLUGIN_ID) + File.separator + vmnode.getVmFileName();
      outfile = projectPath + File.separator + vmnode.getOuturl();
      if (vmnode.getVmName().contains("apiResourceTemplet")) {

        // 获取用户选择的模板示例
        manager.addFile(
            newProjectLocationWizardPage.getOpsCustomLocationFieldPath().toOSString()
                + File.separator
                + vmnode.getExampleapifile());
        manager.createTempletByUrl(
            vmnode.getExampleapi(), outfile, vmfile, projectType, PYTHON_PLUGIN_ID);
        continue;
      }
      // 获取用户的mainfunction函数
      if (vmnode.getVmName().contains("mainfunction")) {
        manager.createMainFunVm(mainFunction, outfile, vmfile, PYTHON_PLUGIN_ID);
        continue;
      }
      manager.createOtherVm(outfile, vmfile, null, PYTHON_PLUGIN_ID);
    }
  }
Example #2
0
  /**
   * This method can be overridden to provide a custom creation of the project.
   *
   * <p>It should create the project, configure the folders in the pythonpath (source folders and
   * external folders if applicable), set the project type and project interpreter.
   */
  protected void createAndConfigProject(
      final IProject newProjectHandle,
      final IProjectDescription description,
      final String projectNatureType,
      final String projectType,
      final String projectInterpreter,
      IProgressMonitor monitor,
      Object... additionalArgsToConfigProject)
      throws CoreException {

    // 新建工程模板类
    ProjectTempletXmlManager templetXmlManager =
        new ProjectTempletXmlManager(PYTHON_PLUGIN_ID, projectType);
    if (choseOpsTempletWizardPage.getSelectedTempletName() != null) {

      // 设置用户选择的模板例程
      templetXmlManager.setSelectedElement(choseOpsTempletWizardPage.getSelectedTempletName());
    }

    // 获取需要建立的所有的文件夹,MAP<文件夹名称,是否是ispackage>
    final Map<String, String> folders = templetXmlManager.getBuilderFolder();

    // 获取内置的ops2.0资源所在的目录
    final List<String> resourse = templetXmlManager.getBuilderResource();

    // 获取需要由模板文件velocity重新生成的工程模板
    List<TempletVMNode> vm = templetXmlManager.getBuilderVm();

    // 获取当前工程中需要拷贝的文件
    Map<String, String> files = templetXmlManager.getBuliderFile();

    ICallback<List<IContainer>, IProject> getSourceFolderHandlesCallback =
        new ICallback<List<IContainer>, IProject>() {

          public List<IContainer> call(IProject projectHandle) {
            final int sourceFolderConfigurationStyle =
                projectPage.getSourceFolderConfigurationStyle();
            List<IContainer> ret = new ArrayList<IContainer>();
            switch (sourceFolderConfigurationStyle) {
              case IWizardNewProjectNameAndLocationPage
                  .PYDEV_NEW_PROJECT_CREATE_PROJECT_AS_SRC_FOLDER:
                // if the user hasn't selected to create a source folder, use the project itself for
                // that.
                ret = new ArrayList<IContainer>();
                ret.add(projectHandle);
                return ret;

              case IWizardNewProjectNameAndLocationPage.PYDEV_NEW_PROJECT_NO_PYTHONPATH:
                return new ArrayList<IContainer>();

              default:
                IContainer src = projectHandle.getFolder("src");
                ret = new ArrayList<IContainer>();
                ret.add(src);
                if (folders != null) {
                  for (Entry<String, String> entry : folders.entrySet()) {
                    if ("true".equals(entry.getValue())) {
                      IContainer folder = projectHandle.getFolder(entry.getKey());
                      ret.add(folder);
                    }
                  }
                }
                return ret;
            }
          }
        };

    // old pydev version 3.7
    // PyStructureConfigHelpers.createPydevProject(description, newProjectHandle, monitor,
    // projectNatureType,
    //        projectInterpreter, getSourceFolderHandlesCallback, null);

    // new pydev version 3.8.2
    PyStructureConfigHelpers.createPydevProject(
        description,
        newProjectHandle,
        monitor,
        projectNatureType,
        projectInterpreter,
        getSourceFolderHandlesCallback,
        null,
        null);

    ProjectTempletManager templetManager = new ProjectTempletManager(PYTHON_PLUGIN_ID);
    templetManager.setTempletXmlManager(templetXmlManager);
    createTempletInProject(
        templetXmlManager,
        templetManager,
        vm,
        projectPage.getMainFunctionName(),
        newProjectHandle,
        projectType);
    createFileInProject(files, newProjectHandle);
    createFolder(folders, newProjectHandle);
    newProjectHandle.refreshLocal(0, monitor);
    // 创建工程的模板xml文件路径
    String templetXmlPath = PathTools.getTempletFilePath(PYTHON_PLUGIN_ID);
    // 在当前工程存储创建工程的pluginID
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_CREATE_PLUGID, PYTHON_PLUGIN_ID);

    // 在当前工程存储工程模板路径
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_TEMPLET_XML_PATH, templetXmlPath);

    ProjectConfigXmlManager projectConfigXmlManager =
        new ProjectConfigXmlManager(
            newProjectHandle.getLocation().toOSString()
                + File.separator
                + OpsManagerProjectTool.PROJECT_CONFIG_FILENAME);
    String opspath = newProjectLocationWizardPage.getOpsCustomLocationFieldPath().toOSString();
    String schemaApiPath = opspath + File.separator + ".." + File.separator + "document";
    projectConfigXmlManager.initXmlConfig(
        opspath, newProjectLocationWizardPage.getSchemaPath(), schemaApiPath, projectType);
    projectConfigXmlManager.setProjectMonitorState("off");
    Boolean isnetworkMonitor = projectConfigXmlManager.isMonitorTrunOn();
    projectConfigXmlManager.configOPSPath(monitor, newProjectHandle);

    // 在工程区存储schemafile存放类
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.SCHEMAFILE_CONFIG, templetManager);

    // 在工程区存储当前工程的配置文件
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_CONFIG, projectConfigXmlManager);

    // 在工程区存储当前工程的配置文件
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_TEMPLET, templetXmlManager);

    // 在工程区存储当前工程的配置文件
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_TYPE, projectType);

    // 在当前工程区存储网络监视状态
    OpsManagerProjectTool.saveManagerInToProject(
        newProjectHandle, OpsManagerProjectTool.PROJECT_MONITOR_STATE, isnetworkMonitor);
  }