/* (non-Javadoc)
  * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
  */
 public boolean isValid(ILaunchConfiguration launchConfig) {
   setErrorMessage(null);
   setMessage(null);
   // if variables are present, we cannot resolve the directory
   String workingDirPath = getWorkingDirectoryText();
   if (workingDirPath.indexOf("${") >= 0) { // $NON-NLS-1$
     IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
     try {
       manager.validateStringVariables(workingDirPath);
     } catch (CoreException e) {
       setErrorMessage(e.getMessage());
       return false;
     }
   } else if (workingDirPath.length() > 0) {
     IContainer container = getContainer();
     if (container == null) {
       File dir = new File(workingDirPath);
       if (dir.isDirectory()) {
         return true;
       }
       setErrorMessage("Only directories can be selected");
       return false;
     }
   } else if (workingDirPath.length() == 0) {
     setErrorMessage("A non-empty directory must be selected");
     return false;
   }
   return true;
 }
  public ICdtVariable getVariable(String macroName) {

    //		if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE)
    //			return null;
    if (macroName == null || "".equals(macroName)) // $NON-NLS-1$
    return null;

    String varName = null;
    String param = null;
    IStringVariable var = null;
    int index = macroName.indexOf(COLON);
    if (index == -1) varName = macroName;
    else if (index > 0) {
      varName = macroName.substring(0, index);
      param = macroName.substring(index + 1);
    }

    if (varName != null) {
      IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager();
      var = mngr.getValueVariable(varName);
      if (var == null) var = mngr.getDynamicVariable(varName);
    }

    if (var != null) return new EclipseVarMacro(var, param);
    return null;
  }
 /** @since 7.3 */
 protected String resolve(String path) {
   try {
     IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
     path = manager.performStringSubstitution(path, false);
   } catch (Exception e) {
     // if anything happens here just use the non-resolved one
   }
   return path;
 }
 /**
  * Tests that a Java project must exist
  *
  * @throws Exception
  */
 public void testProjectDoesNotExist() throws Exception {
   IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
   try {
     manager.performStringSubstitution("${project_classpath:a_non_existant_project}");
   } catch (CoreException e) {
     return; // expected
   }
   assertNotNull("Test should have thrown an exception due to project does not exist", null);
 }
Exemple #5
0
 /**
  * @return The default repository directory as configured in the preferences, with variables
  *     substituted. An empty string if there was an error during substitution.
  */
 public static String getDefaultRepositoryDir() {
   String dir =
       Activator.getDefault().getPreferenceStore().getString(UIPreferences.DEFAULT_REPO_DIR);
   IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
   try {
     return manager.performStringSubstitution(dir);
   } catch (CoreException e) {
     return ""; //$NON-NLS-1$
   }
 }
 /**
  * Tests that a project name must be specified.
  *
  * @throws Exception
  */
 public void testMissingProjectName() throws Exception {
   IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
   setSelection(null);
   try {
     manager.performStringSubstitution("${project_classpath}");
   } catch (CoreException e) {
     return; // expected
   }
   assertNotNull("Test should have thrown an exception due to missing project name", null);
 }
 /**
  * Expands and returns the arguments attribute of the given launch configuration. Returns <code>
  * null</code> if arguments are not specified.
  *
  * @param configuration launch configuration
  * @return an array of resolved arguments, or <code>null</code> if unspecified
  * @throws CoreException if unable to retrieve the associated launch configuration attribute, or
  *     if unable to resolve any variables
  */
 public static String getArguments(
     ILaunchConfiguration configuration, boolean makeArgumentsVariableSubstitution)
     throws CoreException {
   String arguments = configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, "");
   if (makeArgumentsVariableSubstitution) {
     return VariablesPlugin.getDefault()
         .getStringVariableManager()
         .performStringSubstitution(arguments);
   } else {
     return arguments;
   }
 }
 public void testProjectClasspath() throws Exception {
   IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
   String projectName = get14Project().getElementName();
   String cp = manager.performStringSubstitution("${project_classpath:" + projectName + "}");
   StringBuffer buffer = new StringBuffer();
   // expecting default output location and A.jar
   buffer.append(
       ResourcesPlugin.getWorkspace()
           .getRoot()
           .getFolder(get14Project().getOutputLocation())
           .getLocation()
           .toOSString());
   buffer.append(File.pathSeparatorChar);
   buffer.append(
       get14Project().getProject().getFolder("src").getFile("A.jar").getLocation().toOSString());
   assertEquals("Wrong classpath", buffer.toString(), cp);
 }
 private IFile getIFile(ILaunchConfigurationWorkingCopy configuration) {
   IFile file = null;
   if (fNewFile != null) {
     file = fNewFile;
     fNewFile = null;
   } else {
     IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
     try {
       String location =
           configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
       if (location != null) {
         String expandedLocation = manager.performStringSubstitution(location);
         if (expandedLocation != null) {
           file = AntUtil.getFileForLocation(expandedLocation, null);
         }
       }
     } catch (CoreException e) {
       // do nothing
     }
   }
   return file;
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab#handleWorkspaceLocationButtonSelected()
  */
 @Override
 protected void handleWorkspaceLocationButtonSelected() {
   FileSelectionDialog dialog;
   dialog =
       new FileSelectionDialog(
           getShell(),
           ResourcesPlugin.getWorkspace().getRoot(),
           AntLaunchConfigurationMessages.AntMainTab__Select_a_build_file__1);
   dialog.open();
   IStructuredSelection result = dialog.getResult();
   if (result == null) {
     return;
   }
   Object file = result.getFirstElement();
   if (file instanceof IFile) {
     fNewFile = (IFile) file;
     locationField.setText(
         VariablesPlugin.getDefault()
             .getStringVariableManager()
             .generateVariableExpression(
                 "workspace_loc", fNewFile.getFullPath().toString())); // $NON-NLS-1$
   }
 }
Exemple #11
0
  public static IPath getGDBPath(ILaunchConfiguration configuration) {
    String defaultGdbCommand =
        Platform.getPreferencesService()
            .getString(
                GdbPlugin.PLUGIN_ID,
                IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND,
                IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT,
                null);

    IPath retVal = new Path(defaultGdbCommand);
    try {
      String gdb =
          configuration.getAttribute(
              IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME, defaultGdbCommand);
      gdb =
          VariablesPlugin.getDefault()
              .getStringVariableManager()
              .performStringSubstitution(gdb, false);
      retVal = new Path(gdb);
    } catch (CoreException e) {
    }
    return retVal;
  }
  private void assertVariable(String expected, String variableName, String argument)
      throws CoreException {
    IResource findMember = project.findMember(TEST_FILE);

    SWTBotView explorerView = TestUtil.showExplorerView();
    final ISelectionProvider selectionProvider =
        explorerView.getViewReference().getView(true).getSite().getSelectionProvider();
    final StructuredSelection structuredSelection = new StructuredSelection(findMember);
    PlatformUI.getWorkbench()
        .getDisplay()
        .syncExec(
            new Runnable() {

              @Override
              public void run() {
                selectionProvider.setSelection(structuredSelection);
              }
            });

    IDynamicVariable dynamicVariable =
        VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable(variableName);
    String value = dynamicVariable.getValue(argument);
    assertEquals(expected, value);
  }
  public ICdtVariable[] getVariables() {
    //		if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE)
    //			return null;

    IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager();
    IDynamicVariable vars[] = mngr.getDynamicVariables();
    Map<String, IStringVariable> map = new HashMap<String, IStringVariable>();
    for (IDynamicVariable var : vars) {
      final String name = var.getName();
      if (!isDeadlockProneVariable(name)) {
        map.put(name, var);
      }
    }

    IValueVariable valVars[] = mngr.getValueVariables();
    for (IValueVariable valVar : valVars) map.put(valVar.getName(), valVar);

    Collection<IStringVariable> collection = map.values();
    EclipseVarMacro macros[] = new EclipseVarMacro[collection.size()];
    Iterator<IStringVariable> iter = collection.iterator();
    for (int i = 0; i < macros.length; i++) macros[i] = new EclipseVarMacro(iter.next());

    return macros;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
   */
  @Override
  public boolean isValid(ILaunchConfiguration config) {
    setErrorMessage(null);
    setMessage(null);

    if (!fDontCheckProgram) {
      String programName = fProgText.getText().trim();
      try {
        programName =
            VariablesPlugin.getDefault()
                .getStringVariableManager()
                .performStringSubstitution(programName);
      } catch (CoreException e) {
        // Silently ignore substitution failure (for consistency with "Arguments" and "Work
        // directory" fields)
      }
      if (programName.length() == 0) {
        setErrorMessage(LaunchMessages.getString("CMainTab.Program_not_specified")); // $NON-NLS-1$
        return false;
      }
      if (programName.equals(".") || programName.equals("..")) { // $NON-NLS-1$ //$NON-NLS-2$
        setErrorMessage(LaunchMessages.getString("CMainTab.Program_does_not_exist")); // $NON-NLS-1$
        return false;
      }
      IPath exePath = new Path(programName);
      if (exePath.isAbsolute()) {
        // For absolute paths, we don't need a project, we can debug the binary directly
        // as long as it exists
        File executable = exePath.toFile();
        if (!executable.exists()) {
          setErrorMessage(
              LaunchMessages.getString("CMainTab.Program_does_not_exist")); // $NON-NLS-1$
          return false;
        }
        if (!executable.isFile()) {
          setErrorMessage(
              LaunchMessages.getString("CMainTab.Selection_must_be_file")); // $NON-NLS-1$
          return false;
        }
      } else {
        // For relative paths, we need a proper project
        String projectName = fProjText.getText().trim();
        if (projectName.length() == 0) {
          setErrorMessage(
              LaunchMessages.getString("CMainTab.Project_not_specified")); // $NON-NLS-1$
          return false;
        }
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if (!project.exists()) {
          setErrorMessage(
              LaunchMessages.getString("Launch.common.Project_does_not_exist")); // $NON-NLS-1$
          return false;
        }
        if (!project.isOpen()) {
          setErrorMessage(
              LaunchMessages.getString("CMainTab.Project_must_be_opened")); // $NON-NLS-1$
          return false;
        }
        if (!project.getFile(programName).exists()) {
          setErrorMessage(
              LaunchMessages.getString("CMainTab.Program_does_not_exist")); // $NON-NLS-1$
          return false;
        }
      }
      // Notice that we don't check if exePath points to a valid executable since such
      // check is too expensive to be done on the UI thread.
      // See "https://bugs.eclipse.org/bugs/show_bug.cgi?id=328012".
    }

    if (fCoreText != null) {
      String coreName = fCoreText.getText().trim();
      // We accept an empty string.  This should trigger a prompt to the user
      // This allows to re-use the launch, with a different core file.
      // We also accept an absolute or workspace-relative path, including variables.
      // This allows the user to indicate in which directory the prompt will start (Bug 362039)
      if (!coreName.equals(EMPTY_STRING)) {
        try {
          // Replace the variables
          coreName =
              VariablesPlugin.getDefault()
                  .getStringVariableManager()
                  .performStringSubstitution(coreName, false);
        } catch (CoreException e) {
          setErrorMessage(e.getMessage());
          return false;
        }

        coreName = coreName.trim();
        File filePath = new File(coreName);
        if (!filePath.isDirectory()) {
          IPath corePath = new Path(coreName);
          if (!corePath.toFile().exists()) {
            setErrorMessage(
                LaunchMessages.getString("CMainTab.File_does_not_exist")); // $NON-NLS-1$
            return false;
          }
        }
      }
    }

    return true;
  }