Пример #1
0
  private void getAllVersions(
      Project project, Property property, List<IRepositoryViewObject> allVersion)
      throws PersistenceException {
    ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(property.getItem());
    Object fullFolder = getFullFolder(project, itemType, property.getItem().getState().getPath());
    if (fullFolder != null) {
      allVersion.addAll(
          getSerializableFromFolder(
              project, fullFolder, property.getId(), itemType, true, false, false, true));
      if (allVersion.size() == 0) {
        // if no item found in current directory, look for all directory
        allVersion.addAll(getAllVersion(project, property.getId(), false));
      }
    } else {
      allVersion.addAll(getAllVersion(project, property.getId(), false));
    }
    if (allVersion.size() == 0 && project.getEmfProject().getReferencedProjects().size() > 0) {
      String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);

      for (ProjectReference refProject :
          (List<ProjectReference>) project.getEmfProject().getReferencedProjects()) {
        if (refProject.getBranch() != null && !parentBranch.equals(refProject.getBranch())) {
          continue;
        }
        org.talend.core.model.properties.Project emfProject = refProject.getReferencedProject();
        getAllVersions(new Project(emfProject), property, allVersion);
        if (allVersion.size() > 0) {
          break;
        }
      }
    }
    // MOD mzhao Temporary return original object. In this case, the object hasn't been updated from
    // svn server.
    if (allVersion.size() == 0) {
      allVersion.add(new RepositoryViewObject(property));
    }
  }
  /** cli Comment method "removeJobLaunch". */
  public static void removeJobLaunch(IRepositoryViewObject objToDelete) {
    if (objToDelete == null) {
      return;
    }
    Property property = objToDelete.getProperty();
    if (property == null || !(property.getItem() instanceof ProcessItem)) {
      return;
    }
    Project project = ProjectManager.getInstance().getProject(property);
    if (project == null) {
      return;
    }
    final String objProjectName = project.getLabel();
    final String objId = property.getId();
    // final String objName = property.getLabel();
    final String objVersion = property.getVersion();

    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    if (launchManager == null) {
      return;
    }
    try {
      ILaunchConfiguration configuration = null;
      for (ILaunchConfiguration config : launchManager.getLaunchConfigurations()) {
        String jobId = config.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
        // String jobName = configuration.getAttribute(TalendDebugUIConstants.JOB_NAME, (String)
        // null);
        String jobVersion = config.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
        String projectName =
            config.getAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, (String) null);
        ILaunchConfigurationType type = config.getType();
        if (type != null
            && TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE.equals(
                type.getIdentifier())
            && objProjectName.equals(projectName)
            && objId.equals(jobId)
            && objVersion.equals(jobVersion)) {
          configuration = config;
          break;
        }
      }
      if (configuration == null) {
        return;
      }
      configuration.delete();
    } catch (CoreException e) {
      // nothing to do
    }
  }
  /** cli Comment method "renameJobLaunch". */
  public static void renameJobLaunch(IRepositoryViewObject obj, String oldLabel) {
    if (obj == null) {
      return;
    }
    Property property = obj.getProperty();
    if (property == null || !(property.getItem() instanceof ProcessItem)) {
      return;
    }
    String newLabel = property.getLabel();
    if (!newLabel.equals(oldLabel)) {
      Project project = ProjectManager.getInstance().getProject(property);
      if (project == null) {
        return;
      }

      final String objProjectName = project.getLabel();
      final String id = property.getId();
      final String version = property.getVersion();

      ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
      if (launchManager == null) {
        return;
      }
      try {
        for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {

          String jobId = configuration.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
          String jobVersion =
              configuration.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
          String projectName =
              configuration.getAttribute(
                  TalendDebugUIConstants.CURRENT_PROJECT_NAME, (String) null);

          // ILaunchConfigurationType type = launchManager
          // .getLaunchConfigurationType(TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE);
          ILaunchConfigurationType type = configuration.getType();
          if (type != null
              && TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE.equals(
                  type.getIdentifier())
              && objProjectName.equals(projectName)
              && id.equals(jobId)
              && version.equals(jobVersion)
              && type != null) {
            String displayName = newLabel + " " + jobVersion; // $NON-NLS-1$
            ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
            workingCopy.setAttribute(TalendDebugUIConstants.JOB_NAME, newLabel);
            // workingCopy.setAttribute(TalendDebugUIConstants.JOB_ID, jobId);
            // update to new version
            workingCopy.setAttribute(TalendDebugUIConstants.JOB_VERSION, jobVersion);
            // workingCopy.setAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, projectName);
            workingCopy.rename(displayName);
            workingCopy.doSave();
            break;
          }
        }
        clearUnusedLaunchs();
      } catch (CoreException e) {
        // nothing to do
      }
    }
  }