Ejemplo n.º 1
0
  /**
   * Creating a copy of IMakeTarget in a different project.
   *
   * @param name - name of new target.
   * @param makeTarget - make target.
   * @param project - project where to assign the make target.
   * @return newly created make target.
   * @throws CoreException if there is a problem with creating or copying the target.
   */
  private static IMakeTarget cloneTarget(String name, IMakeTarget makeTarget, IProject project)
      throws CoreException {
    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
    String[] ids = makeTargetManager.getTargetBuilders(project);
    String builderId = ids[0];

    IMakeTarget newMakeTarget = makeTargetManager.createTarget(project, name, builderId);
    copyTargetData(makeTarget, newMakeTarget);
    if (makeTarget
        .getName()
        .equals(makeTarget.getBuildAttribute(IMakeTarget.BUILD_TARGET, ""))) { // $NON-NLS-1$
      newMakeTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, name);
    }
    return newMakeTarget;
  }
Ejemplo n.º 2
0
  /**
   * Create {@code MakeTarget} from basic data elements available during copy/paste or drag/drop
   * operations. The other data will be set to default.
   *
   * @param name - name of make target being created.
   * @param targetStr - build target.
   * @param command - make command. ("make" by default).
   * @param container - container where to place the target.
   * @return newly created {@link IMakeTarget}.
   * @throws CoreException if there was a problem creating new make target.
   */
  public static IMakeTarget createMakeTarget(
      String name, String targetStr, String command, IContainer container) throws CoreException {
    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();

    IProject project = container.getProject();
    String[] ids = makeTargetManager.getTargetBuilders(project);
    String builderId = ids[0];

    // IMakeTarget attributes
    IMakeTarget newMakeTarget = makeTargetManager.createTarget(project, name, builderId);
    if (targetStr != null) {
      newMakeTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, targetStr);
    }

    // IMakeCommonBuildInfo attributes
    String projectBuildCommand = getProjectBuildCommand(project);
    if (command != null && command.length() > 0 && !command.equals(projectBuildCommand)) {
      newMakeTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, command);
      newMakeTarget.setUseDefaultBuildCmd(false);
    } else {
      newMakeTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, projectBuildCommand);
      newMakeTarget.setUseDefaultBuildCmd(true);
    }

    return newMakeTarget;
  }
Ejemplo n.º 3
0
 @Override
 public boolean visit(IResourceProxy proxy) throws CoreException {
   try {
     if (proxy.getType() != IResource.FOLDER && proxy.getType() != IResource.PROJECT) {
       return false;
     }
     IContainer container = (IContainer) proxy.requestResource();
     monitor.subTask(container.getProjectRelativePath().toString());
     QualifiedName qName =
         new QualifiedName("org.eclipse.cdt.make", "goals"); // $NON-NLS-1$ //$NON-NLS-2$
     String goal = container.getPersistentProperty(qName);
     if (goal != null) {
       goal = goal.trim();
       IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
       String[] builder = manager.getTargetBuilders(container.getProject());
       IMakeTarget target = manager.createTarget(container.getProject(), goal, builder[0]);
       target.setBuildAttribute(IMakeTarget.BUILD_TARGET, goal);
       manager.addTarget(container, target);
       container.setPersistentProperty(qName, null);
     }
     return true;
   } finally {
     if (--nextProgress <= 0) {
       // we have exhausted the current increment, so report progress
       monitor.worked(1);
       worked++;
       if (worked >= halfWay) {
         // we have passed the current halfway point, so double the
         // increment and reset the halfway point.
         currentIncrement *= 2;
         halfWay += (TOTAL_WORK - halfWay) / 2;
       }
       // reset the progress counter to another full increment
       nextProgress = currentIncrement;
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * Copy/move one make target to the specified container.
   *
   * @param makeTarget - make target.
   * @param container - container to copy/move to.
   * @param operation - copying operation. Should be one of {@link org.eclipse.swt.dnd.DND}
   *     operations.
   * @param shell - shell to display user warnings.
   * @param offerOverwriteDialog - whether overwrite dialog is provided.
   * @throws CoreException on the failure of {@link IMakeTargetManager} or {@link IMakeTarget}
   *     operation.
   * @see DND#DROP_NONE
   * @see DND#DROP_COPY
   * @see DND#DROP_MOVE
   * @see DND#DROP_LINK
   * @see DND#DROP_DEFAULT
   */
  public static void copyOneTarget(
      IMakeTarget makeTarget,
      IContainer container,
      final int operation,
      Shell shell,
      boolean offerOverwriteDialog)
      throws CoreException {

    IMakeTargetManager makeTargetManager = MakeCorePlugin.getDefault().getTargetManager();
    IMakeTarget exists = makeTargetManager.findTarget(container, makeTarget.getName());
    if (exists != null) {
      int userAnswer = IDialogConstants.CANCEL_ID;
      if (offerOverwriteDialog) {
        userAnswer = overwriteMakeTargetDialog(makeTarget.getName(), shell);
      } else {
        userAnswer = RENAME_ID;
      }
      if (userAnswer == IDialogConstants.YES_ID || userAnswer == IDialogConstants.YES_TO_ALL_ID) {
        copyTargetData(makeTarget, exists);
        if (operation == DND.DROP_MOVE) {
          makeTargetManager.removeTarget(makeTarget);
        }
      } else if (userAnswer == RENAME_ID || userAnswer == RENAME_TO_ALL_ID) {
        String name = generateUniqueName(makeTarget.getName(), container);
        IMakeTarget newMakeTarget = cloneTarget(name, makeTarget, container.getProject());
        newMakeTarget.setContainer(container);
        int dialogReturnCode = Window.OK;
        if (userAnswer == RENAME_ID) {
          MakeTargetDialog dialog;
          try {
            dialog = new MakeTargetDialog(shell, newMakeTarget);
            dialogReturnCode = dialog.open();
          } catch (CoreException e) {
            MakeUIPlugin.errorDialog(
                shell,
                MakeUIPlugin.getResourceString("AddBuildTargetAction.exception.internal"),
                e.toString(),
                e); //$NON-NLS-1$
          }
        } else if (userAnswer == RENAME_TO_ALL_ID) {
          makeTargetManager.addTarget(container, newMakeTarget);
        }
        if (operation == DND.DROP_MOVE && dialogReturnCode != Window.CANCEL) {
          makeTargetManager.removeTarget(makeTarget);
        }
      }
    } else {
      makeTargetManager.addTarget(
          container, cloneTarget(makeTarget.getName(), makeTarget, container.getProject()));
      if (operation == DND.DROP_MOVE) {
        makeTargetManager.removeTarget(makeTarget);
      }
    }
  }
Ejemplo n.º 5
0
  /**
   * Populate destination make target with data from source make target.
   *
   * @param source - source make target.
   * @param destination - destination make target.
   * @throws CoreException if there is a problem populating the target.
   *     <p>See MakeTarget
   */
  private static void copyTargetData(IMakeTarget source, IMakeTarget destination)
      throws CoreException {

    // IMakeTarget attributes
    // destination.project and destination.targetBuilderID are not changed
    destination.setRunAllBuilders(source.runAllBuilders());
    destination.setAppendProjectEnvironment(source.appendProjectEnvironment());
    destination.setBuildAttribute(
        IMakeTarget.BUILD_TARGET,
        source.getBuildAttribute(IMakeTarget.BUILD_TARGET, "")); // $NON-NLS-1$

    // IMakeCommonBuildInfo attributes
    // Ignore IMakeCommonBuildInfo.BUILD_LOCATION in order not to pick
    // location of another project (or another folder)
    if (!source.isDefaultBuildCmd()) {
      destination.setBuildAttribute(
          IMakeCommonBuildInfo.BUILD_COMMAND,
          source.getBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, DEFAULT_BUILD_COMMAND));
      destination.setBuildAttribute(
          IMakeCommonBuildInfo.BUILD_ARGUMENTS,
          source.getBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, "")); // $NON-NLS-1$
    }
    destination.setStopOnError(source.isStopOnError());
    destination.setUseDefaultBuildCmd(source.isDefaultBuildCmd());
    destination.setEnvironment(source.getEnvironment());
    destination.setAppendEnvironment(source.appendEnvironment());
    // setErrorParsers() is not supported in MakeTarget yet
  }