Пример #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);
    }
  }
Пример #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);
  }
Пример #3
0
  /**
   * Creates a new project resource with the entered name.
   *
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  protected IProject createNewProject(final Object... additionalArgsToConfigProject) {
    // get a project handle
    final IProject newProjectHandle = projectPage.getProjectHandle();

    // get a project descriptor
    IPath defaultPath = Platform.getLocation();
    IPath newPath = newProjectLocationWizardPage.getLocationPath();
    if (defaultPath.equals(newPath)) {
      newPath = null;
    } else {
      // The user entered the path and it's the same as it'd be if he chose the default path.
      IPath withName = defaultPath.append(newProjectHandle.getName());
      if (newPath.toFile().equals(withName.toFile())) {
        newPath = null;
      }
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description =
        workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocation(newPath);

    // update the referenced project if provided
    if (referencePage != null) {
      IProject[] refProjects = referencePage.getReferencedProjects();
      if (refProjects.length > 0) {
        description.setReferencedProjects(refProjects);
      }
    }

    final String projectNatureType = projectPage.getProjectType();
    final String projectType = projectPage.getProjectCreateType();

    final String projectInterpreter = projectPage.getProjectInterpreter();
    // define the operation to create a new project
    WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {
          protected void execute(IProgressMonitor monitor) throws CoreException {

            createAndConfigProject(
                newProjectHandle,
                description,
                projectNatureType,
                projectType,
                projectInterpreter,
                monitor,
                additionalArgsToConfigProject);
          }
        };

    // run the operation to create a new project
    try {
      getContainer().run(true, true, op);
    } catch (InterruptedException e) {
      return null;
    } catch (InvocationTargetException e) {
      Throwable t = e.getTargetException();
      if (t instanceof CoreException) {
        if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
          MessageDialog.openError(
              getShell(),
              "Unable to create project",
              "Another project with the same name (and different case) already exists.");
        } else {
          ErrorDialog.openError(
              getShell(), "Unable to create project", null, ((CoreException) t).getStatus());
        }
      } else {
        // Unexpected runtime exceptions and errors may still occur.
        Log.log(IStatus.ERROR, t.toString(), t);
        MessageDialog.openError(getShell(), "Unable to create project", t.getMessage());
      }
      return null;
    }

    return newProjectHandle;
  }