Exemple #1
0
 /**
  * Verify the following things about the project: - is a valid project name given - does the
  * project exist - is the project open - is the project a C/C++ project
  */
 public static ICProject verifyCProject(ILaunchConfiguration configuration) throws CoreException {
   String name = getProjectName(configuration);
   if (name == null) {
     abort(
         LaunchMessages.getString("AbstractCLaunchDelegate.C_Project_not_specified"),
         null, //$NON-NLS-1$
         ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROJECT);
     return null;
   }
   ICProject cproject = getCProject(configuration);
   if (cproject == null && name.length() > 0) {
     IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
     if (!proj.exists()) {
       abort(
           LaunchMessages.getFormattedString(
               "AbstractCLaunchDelegate.Project_NAME_does_not_exist", name),
           null, //$NON-NLS-1$
           ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
     } else if (!proj.isOpen()) {
       abort(
           LaunchMessages.getFormattedString(
               "AbstractCLaunchDelegate.Project_NAME_is_closed", name),
           null, //$NON-NLS-1$
           ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
     }
     abort(
         LaunchMessages.getString("AbstractCLaunchDelegate.Not_a_C_CPP_project"),
         null, //$NON-NLS-1$
         ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
   }
   return cproject;
 }
Exemple #2
0
  /**
   * Verify that program name of the configuration can be found as a file.
   *
   * @return Absolute path of the program location
   */
  public static IPath verifyProgramPath(ILaunchConfiguration configuration, ICProject cproject)
      throws CoreException {
    String programName =
        configuration.getAttribute(
            ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
    if (programName == null) {
      abort(
          LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"),
          null, //$NON-NLS-1$
          ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
    }

    IPath programPath = new Path(programName);
    if (programPath.isEmpty()) {
      abort(
          LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"),
          null, //$NON-NLS-1$
          ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
    }

    if (!programPath.isAbsolute() && cproject != null) {
      // Find the specified program within the specified project
      IFile wsProgramPath = cproject.getProject().getFile(programPath);
      programPath = wsProgramPath.getLocation();
    }

    if (!programPath.toFile().exists()) {
      abort(
          LaunchMessages.getString(
              "AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
          new FileNotFoundException(
              LaunchMessages.getFormattedString(
                  "AbstractCLaunchDelegate.PROGRAM_PATH_not_found", //$NON-NLS-1$
                  programPath.toOSString())),
          ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
    }

    return programPath;
  }
Exemple #3
0
  /**
   * Verify that the executable path points to a valid binary file.
   *
   * @return An object representing the binary file.
   */
  public static IBinaryObject verifyBinary(ILaunchConfiguration configuration, IPath exePath)
      throws CoreException {
    ICProject cproject = getCProject(configuration);
    if (cproject != null) {
      ICConfigExtensionReference[] parserRefs =
          CCorePlugin.getDefault().getDefaultBinaryParserExtensions(cproject.getProject());
      for (ICConfigExtensionReference parserRef : parserRefs) {
        try {
          IBinaryParser parser = CoreModelUtil.getBinaryParser(parserRef);
          IBinaryObject exe = (IBinaryObject) parser.getBinary(exePath);
          if (exe != null) {
            return exe;
          }
        } catch (ClassCastException e) {
        } catch (IOException e) {
        }
      }
    }

    IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser();
    try {
      return (IBinaryObject) parser.getBinary(exePath);
    } catch (ClassCastException e) {
    } catch (IOException e) {
    }

    abort(
        LaunchMessages.getString(
            "AbstractCLaunchDelegate.Program_is_not_a_recognized_executable"), //$NON-NLS-1$
        new FileNotFoundException(
            LaunchMessages.getFormattedString(
                "AbstractCLaunchDelegate.Program_is_not_a_recognized_executable", //$NON-NLS-1$
                exePath.toOSString())),
        ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY);

    return null;
  }