示例#1
0
  /**
   * Initialize a <code>ILaunchConfigurationWorkingCopy</code> either by using an existing one (if
   * found), or using a default configuration (for example, the one used for the most recent
   * launch), or by creating a new one based on the <code>project</code> name and the <code>confName
   * </code>.
   *
   * @throws CoreException if getting an working copy from an existing configuration fails
   */
  private static ILaunchConfigurationWorkingCopy createLaunchConfiguration(
      IProject project, String confName, RunInfo runInfo) {
    ILaunchManager launchManager = getLaunchManager();
    ILaunchConfiguration config =
        ConfigurationHelper.findConfiguration(launchManager, project, confName, runInfo);

    ILaunchConfigurationWorkingCopy configWC = null;
    if (null != config) {
      try {
        configWC = config.getWorkingCopy();
      } catch (CoreException cex) {
        TestNGPlugin.log(
            new Status(
                IStatus.ERROR,
                TestNGPlugin.PLUGIN_ID,
                TestNGPluginConstants.LAUNCH_ERROR,
                "Cannot create working copy of existing launcher " + config.getName(),
                cex));
      }
    }
    if (null == configWC) {
      if (confName == null && runInfo != null) {
        confName = runInfo.getClassName() + "." + runInfo.getMethodName();
      }
      configWC = ConfigurationHelper.createBasicConfiguration(launchManager, project, confName);
    }

    return configWC;
  }
示例#2
0
  /**
   * Saves the working copy (may return <tt>null</tt> if the <code>launchWorkingCopy</code> is
   * <tt>null</tt> or the save fails).
   */
  private static ILaunchConfiguration save(ILaunchConfigurationWorkingCopy launchWorkingCopy) {
    if (null == launchWorkingCopy) return null;

    try {
      return launchWorkingCopy.doSave();
    } catch (CoreException cex) {
      TestNGPlugin.log(cex);
    }

    return null;
  }
示例#3
0
 protected void saveSuiteContent(final File file, final XMLStringBuffer content) {
   FileOutputStream fileOutputStream = null;
   BufferedOutputStream bufferedOutputStream = null;
   OutputStreamWriter osw = null;
   try {
     fileOutputStream = new FileOutputStream(file);
     bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
     // use utf8 to solve special character problem
     osw = new OutputStreamWriter(bufferedOutputStream, Charset.forName("UTF-8"));
     osw.write(content.getStringBuffer().toString());
   } catch (IOException ioException) {
     TestNGPlugin.log(ioException);
   } finally {
     try {
       if (osw != null) osw.close();
       if (bufferedOutputStream != null) bufferedOutputStream.close();
       if (fileOutputStream != null) fileOutputStream.close();
     } catch (Exception e) {
       TestNGPlugin.log(e);
     }
   }
 }
示例#4
0
  /** Launch a compilation unit (a source file) based test. */
  public static void launchCompilationUnitConfiguration(
      IJavaProject ijp, ICompilationUnit icu, String mode) {
    IType[] types = null;
    try {
      types = icu.getTypes();
    } catch (JavaModelException jme) {
      TestNGPlugin.log(
          new Status(
              IStatus.ERROR,
              TestNGPlugin.PLUGIN_ID,
              TestNGPluginConstants.LAUNCH_ERROR,
              "No types in compilation unit " + icu.getElementName(),
              jme));
    }

    if (null == types) return;

    IType mainType = icu.findPrimaryType();
    final String confName = mainType != null ? mainType.getElementName() : icu.getElementName();

    launchTypeBasedConfiguration(ijp, confName, types, mode);
  }
示例#5
0
  public static void launchMapConfiguration(
      IProject project,
      String configName,
      Map launchAttributes,
      ICompilationUnit compilationUnit,
      String launchMode) {
    ILaunchConfigurationWorkingCopy workingCopy =
        createLaunchConfiguration(project, configName, null);

    try {
      launchAttributes.putAll(workingCopy.getAttributes());
    } catch (CoreException ce) {
      TestNGPlugin.log(ce);
    }

    if (null != compilationUnit) {
      Map params = solveParameters(compilationUnit);
      launchAttributes.put(TestNGLaunchConfigurationConstants.PARAMS, params);
    }

    workingCopy.setAttributes(launchAttributes);

    runConfig(workingCopy, launchMode);
  }