Esempio n. 1
0
  /**
   * Adds the text and move changes to the root change This change is the a more global change, it
   * includes both the file(s) move, the update of it's includes and update all the references, all
   * the files that have includes to the moved file.
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createReferenceUpdatingMoveChange(IProgressMonitor pm, CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();

      createTextChanges(new SubProgressMonitor(pm, 80), rootChange, phpFiles, sourceResources);
      pm.worked(80);

      // update configuration file.
      createRunConfigurationChange(sourceResources, rootChange);

      // There is a tricky thing here.
      // The resource move must be happened after text change, and run
      // configuration changes(this is because the share file under the
      // project)
      // but before the other changes, e.g. break point and etc.
      createMoveChange(sourceResources, rootChange);

      // update associated break point.
      createBreakPointChange(sourceResources, rootChange);

      createBuildPathChange(sourceResources, rootChange);

      createRenameLibraryFolderChange(sourceResources, rootChange);

      pm.worked(20);

    } finally {
      pm.done();
    }
    return rootChange;
  }
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   MultiStatus result =
       new MultiStatus(
           ResourcesPlugin.PI_RESOURCES,
           IResourceStatus.FAILED_SETTING_CHARSET,
           Messages.resources_updatingEncoding,
           null);
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(Messages.resources_charsetUpdating, Policy.totalWork);
     final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(workspace.getRoot());
     try {
       workspace.prepareOperation(rule, monitor);
       workspace.beginOperation(true);
       Map.Entry<IProject, Boolean> next;
       while ((next = getNextChange()) != null) {
         // just exit if the system is shutting down or has been shut down
         // it is too late to change the workspace at this point anyway
         if (systemBundle.getState() != Bundle.ACTIVE) return Status.OK_STATUS;
         IProject project = next.getKey();
         try {
           if (project.isAccessible()) {
             boolean shouldDisableCharsetDeltaJob = next.getValue().booleanValue();
             // flush preferences for non-derived resources
             flushPreferences(
                 getPreferences(project, false, false, true), shouldDisableCharsetDeltaJob);
             // flush preferences for derived resources
             flushPreferences(
                 getPreferences(project, false, true, true), shouldDisableCharsetDeltaJob);
           }
         } catch (BackingStoreException e) {
           // we got an error saving
           String detailMessage = Messages.resources_savingEncoding;
           result.add(
               new ResourceStatus(
                   IResourceStatus.FAILED_SETTING_CHARSET,
                   project.getFullPath(),
                   detailMessage,
                   e));
         }
       }
       monitor.worked(Policy.opWork);
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } catch (CoreException ce) {
     return ce.getStatus();
   } finally {
     monitor.done();
   }
   return result;
 }
Esempio n. 3
0
  /**
   * Adds the move changes to the root change This change is the proper move change, nothing else
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createSimpleMoveChange(final IProgressMonitor pm, final CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();
      createMoveChange(sourceResources, rootChange);
      pm.worked(100);

    } finally {
      pm.done();
    }
    return rootChange;
  }
Esempio n. 4
0
 public ICVSRemoteResource[] getFoldersForTag(
     ICVSRepositoryLocation location, CVSTag tag, IProgressMonitor monitor) throws CVSException {
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(
         NLS.bind(
             CVSUIMessages.RepositoryManager_fetchingRemoteFolders, new String[] {tag.getName()}),
         100);
     if (tag.getType() == CVSTag.HEAD) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     if (tag.getType() == CVSTag.DATE) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     Set result = new HashSet();
     // Get the tags for the location
     RepositoryRoot root = getRepositoryRootFor(location);
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       List tags = Arrays.asList(root.getAllKnownTags(path));
       if (tags.contains(tag)) {
         ICVSRemoteFolder remote =
             root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
         result.add(remote);
       }
     }
     return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
   } finally {
     monitor.done();
   }
 }
  /**
   * Fuehrt einen Restart am Server durch.
   *
   * @param monitor
   * @param selection
   * @param more
   * @return true wenn abbruch
   * @throws ConnectionException
   */
  private boolean restart(
      final IProgressMonitor monitor, final IRestartSelection selection, final boolean more)
      throws ConnectionException {
    monitor.subTask("Invoking restart");
    fConnection
        .getProtocolWriter()
        .writeInvokeRestart(selection.getRestart(), selection.getParameter());
    readAllOutput(monitor);
    monitor.subTask("Reading restart result");
    IResult result = fConnection.getEvaluation().evalResult();
    IRestartSelection restartSelection = callFormEvaluated(result, more);

    if (restartSelection == null) {
      return false;
    } else if (restartSelection.isAborted()) {
      return true;
    } else {
      // rekursiver restart
      return restart(monitor, restartSelection, more);
    }
  }
 public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
   SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
   try {
     MultiStatus overallStatus =
         new MultiStatus(TestActivator.PI_PROV_TESTS, IStatus.OK, null, null);
     for (int i = 0; i < requests.length; i++) {
       overallStatus.add(getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)));
     }
     return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
   } finally {
     subMonitor.done();
   }
 }
  public void validateContent(IProgressMonitor monitor) {
    Element element = getDocumentRoot();
    if (element == null) return;
    String elementName = element.getNodeName();
    if (!"plugin".equals(elementName)
        && !"fragment".equals(elementName)) { // $NON-NLS-1$ //$NON-NLS-2$
      reportIllegalElement(element, CompilerFlags.ERROR);
    } else {
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
      if (severity != CompilerFlags.IGNORE) {
        NamedNodeMap attrs = element.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
          reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity);
        }
      }

      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        if (monitor.isCanceled()) break;
        Element child = (Element) children.item(i);
        String name = child.getNodeName();
        if (name.equals("extension")) { // $NON-NLS-1$
          validateExtension(child);
        } else if (name.equals("extension-point")) { // $NON-NLS-1$
          validateExtensionPoint(child);
        } else {
          if (!name.equals("runtime") && !name.equals("requires")) { // $NON-NLS-1$ //$NON-NLS-2$
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
            if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity);
          } else {
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
            if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity);
          }
        }
      }

      IExtensions extensions = fModel.getExtensions();
      if (extensions != null
          && extensions.getExtensions().length == 0
          && extensions.getExtensionPoints().length == 0)
        report(
            MDECoreMessages.Builders_Manifest_useless_file,
            -1,
            IMarker.SEVERITY_WARNING,
            MDEMarkerFactory.P_USELESS_FILE,
            MDEMarkerFactory.CAT_OTHER);
    }
  }
  /**
   * Ausfuehrung der Evaluierung. Jeder Ausdruck wird ueber die Verbindung ausgewertet und das
   * Ergebnis der Evaluierung wird dem {@link IBackgroundEvaluationListener} mitgeteilt.
   *
   * @param monitor - der ProgressMonitor
   * @see IBackgroundEvaluationListener
   * @sse {@link AbstractJob#run0(IProgressMonitor)}
   */
  @Override
  @SuppressWarnings("NP") // Rueckgabe von non-null Wert wird über Methoden-Contract geregelt
  protected IStatus run0(final IProgressMonitor monitor) throws Exception {
    monitor.subTask("Waiting for connection");
    acquireLock();

    ensureConnected(fConnection);
    callPrepare(fForms.size() > 1);

    monitor.beginTask(fJobName, (fForms.size() + 1) * 1000);

    if (monitor.isCanceled()) {
      return Status.CANCEL_STATUS;
    }

    for (int i = 0, n = fForms.size(); i < n; i++) {

      PackageBoundForm form = fForms.get(i);
      monitor.subTask("Starting evaluation " + i + "/" + fForms.size());
      IEvaluation eval = fConnection.getEvaluation();

      eval.evalStart(form.getPackage(), form.getForm());

      // Output Lesen
      readAllOutput(monitor);

      monitor.subTask("Reading result");
      IResult evalResult = eval.evalResult();

      boolean more = i != n - 1;
      IRestartSelection selection = callFormEvaluated(evalResult, more);

      monitor.worked(1000);

      if (evalResult.getTyp() == TResult.SUCCESS) { // Ergebnis ok
        continue; // alles ok mit ergebnis, mit naechstem weitermachen wenn vorhanden
      } else if (evalResult.getTyp()
          == TResult.READ_ERROR) { // Read error, es darf kein abort gesendet werden
        break;
      } else if (selection != null && selection.isAborted()) {
        abort(); // Ein Fehler, kann nur EVAL_ERROR sein, wurde abgebrochen
        break;
      } else { // EVAL_ERROR und es wurde ein Restart gewaehlt, bzw. war verfuegbar
        boolean abort = restart(monitor, selection, more); // eintritt rekursiver restart
        if (abort) { // restart abgebrochen
          abort(); // abort senden
          break; // und (bulk-)eval komplette beenden
        }
        continue; // restart war erfolgreich -> weiter mit naechstem im bulk
      }
    }

    return new Status(IStatus.OK, LispPluginActivator.ID, IStatus.OK, "Evaluation succeeded", null);
  }
Esempio n. 9
0
  /**
   * Creates the text changes for all the affected files. Updates all the include statements in the
   * current file and all the includes in the "including " files. In case of folders, creates the
   * changes recursively
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @param sourceResources
   * @return the root change after the additions
   * @throws CoreException
   */
  private Change createTextChanges(
      IProgressMonitor pm,
      CompositeChange rootChange,
      Set<IFile> phpFiles,
      IResource[] sourceResources)
      throws CoreException {
    List<ProgramFileChange> changes = new ArrayList<ProgramFileChange>();
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.1"), 100); // $NON-NLS-1$

      // creat text changes:
      // for each file that will be moved, update its includes
      // and update all the files that include it,

      IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources);

      for (Iterator<IFile> it = phpFiles.iterator(); it.hasNext(); ) {
        IFile currentMovedResource = it.next();

        Map<IFile, Program> participantFiles = collectReferencingFiles(currentMovedResource, pm);

        for (Entry<IFile, Program> entry : participantFiles.entrySet()) {
          final IFile file = entry.getKey();
          if (phpFiles.contains(file)) {
            continue;
          }
          final Program program = entry.getValue();

          final ChangeIncludePath rename =
              new ChangeIncludePath(
                  currentMovedResource, file, fMainDestinationPath, false, uniqueSourceResources);
          // aggregate the changes identifiers
          program.accept(rename);

          if (pm.isCanceled()) throw new OperationCanceledException();

          pm.worked(1);

          if (rename.hasChanges()) {
            ProgramFileChange change = new ProgramFileChange(file.getName(), file, program);
            change.setEdit(new MultiTextEdit());
            change.setTextType("php"); // $NON-NLS-1$

            changes.add(change);
            rename.updateChange(change);
          }
        }

        ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(currentMovedResource);

        if (sourceModule instanceof ISourceModule) {

          Program program = null;
          try {
            program = ASTUtils.createProgramFromSource(sourceModule);
          } catch (Exception e) {
          }

          if (program != null) {
            final ChangeIncludePath rename =
                new ChangeIncludePath(
                    currentMovedResource,
                    currentMovedResource,
                    fMainDestinationPath,
                    true,
                    uniqueSourceResources);

            // aggregate the changes identifiers
            program.accept(rename);

            if (pm.isCanceled()) throw new OperationCanceledException();

            pm.worked(1);

            if (rename.hasChanges()) {
              ProgramFileChange change =
                  new ProgramFileChange(
                      currentMovedResource.getName(), currentMovedResource, program);
              change.setEdit(new MultiTextEdit());
              change.setTextType("php"); // $NON-NLS-1$

              changes.add(change);
              rename.updateChange(change);
            }
          }
        }
      }
      pm.worked(70);

    } finally {
      pm.done();
    } // getChildren()

    Map<IFile, List<TextEdit>> changeMap = new HashMap<IFile, List<TextEdit>>();
    Map<IFile, ProgramFileChange> fileMap = new HashMap<IFile, ProgramFileChange>();
    for (ProgramFileChange programFileChange : changes) {
      List<TextEdit> list = changeMap.get(programFileChange.getFile());
      if (list == null) {
        list = new ArrayList<TextEdit>();
        changeMap.put(programFileChange.getFile(), list);
        fileMap.put(programFileChange.getFile(), programFileChange);
      } else {

      }
      list.addAll(Arrays.asList(programFileChange.getEdit().getChildren()));
    }
    for (IFile file : changeMap.keySet()) {
      ProgramFileChange change =
          new ProgramFileChange(file.getName(), file, fileMap.get(file).getProgram());
      change.setEdit(new MultiTextEdit());
      change.setTextType("php"); // $NON-NLS-1$

      List<TextEdit> list = changeMap.get(file);
      Collections.sort(
          list,
          new Comparator<TextEdit>() {
            public int compare(TextEdit o1, TextEdit o2) {
              return o2.getOffset() - o1.getOffset();
            }
          });

      for (TextEdit textEdit : list) {
        if (textEdit instanceof ReplaceEdit) {
          ReplaceEdit replaceEdit = (ReplaceEdit) textEdit;
          change.addEdit(
              new ReplaceEdit(
                  replaceEdit.getOffset(), replaceEdit.getLength(), replaceEdit.getText()));
        }
      }
      rootChange.add(change);
    }
    return rootChange;
  }