public static void getResourcesThatUseRecursive(
      final IResource resource, final ResourceFilter filter, final Collection dependentResources) {
    // search the workspace for any models that import anything beneath the path that is moving
    final Collection allResources = getAllWorkspaceResources(filter);

    // check to see if any of the resources found depend upon the specified resource:
    final IPath targetPath = resource.getFullPath();
    for (final Iterator iter = allResources.iterator(); iter.hasNext(); ) {
      final IResource nextResource = (IResource) iter.next();
      final IPath[] paths = getDependentResourcePaths(nextResource);
      for (final IPath path : paths)
        if (path.equals(targetPath)) {
          final String modelPath = nextResource.getFullPath().toString();
          // If the URI is to the Teiid Designer built-in datatypes resource or to one
          // of the Emf XMLSchema resources then continue since there is no
          // ModelReference to add.
          if (modelPath != null
              && !isGlobalResource(modelPath)
              && !dependentResources.contains(nextResource)) {
            dependentResources.add(nextResource);
            getResourcesThatUseRecursive(nextResource, filter, dependentResources);
          }
          break;
        }
    }
  }
  /**
   * Returns true if the source of the given class file is in the source list
   *
   * @param javaClass .class file tested
   * @param aJavaSourceList Modified .java source files
   * @return True if the corresponding .java file is in the list
   */
  protected boolean sourceChanged(
      final IResource javaClass, final List<IResource> aJavaSourceList) {

    String sourceName;
    try {
      sourceName = javaClass.getFullPath().makeRelativeTo(getProjectOutputPath()).toString();
      int end = sourceName.lastIndexOf('$');
      if (end == -1) {
        end = sourceName.lastIndexOf('.');
      }

      if (end == -1) {
        Activator.logInfo(javaClass.getProject(), "Strange file name : " + sourceName);
        return true;
      }

      sourceName = sourceName.substring(0, end);
      sourceName += ".java";

    } catch (final CoreException e) {
      Activator.logError(javaClass.getProject(), "Error working on file name", e);
      return true;
    }

    for (final IResource javaSource : aJavaSourceList) {
      if (javaSource.getFullPath().toString().contains(sourceName)) {
        return true;
      }
    }

    return false;
  }
  private SubscriberChangeEvent[] handleRemovedRoot(IResource removedRoot) {
    // Determine if any of the roots of the compare are affected
    List removals = new ArrayList(resources.length);
    for (int j = 0; j < resources.length; j++) {
      IResource root = resources[j];
      if (removedRoot.getFullPath().isPrefixOf(root.getFullPath())) {
        // The root is no longer managed by CVS
        removals.add(root);
        try {
          tree.flushVariants(root, IResource.DEPTH_INFINITE);
        } catch (TeamException e) {
          CVSProviderPlugin.log(e);
        }
      }
    }
    if (removals.isEmpty()) {
      return new SubscriberChangeEvent[0];
    }

    // Adjust the roots of the subscriber
    List newRoots = new ArrayList(resources.length);
    newRoots.addAll(Arrays.asList(resources));
    newRoots.removeAll(removals);
    resources = (IResource[]) newRoots.toArray(new IResource[newRoots.size()]);

    // Create the deltas for the removals
    SubscriberChangeEvent[] deltas = new SubscriberChangeEvent[removals.size()];
    for (int i = 0; i < deltas.length; i++) {
      deltas[i] =
          new SubscriberChangeEvent(
              this, ISubscriberChangeEvent.ROOT_REMOVED, (IResource) removals.get(i));
    }
    return deltas;
  }
Exemple #4
0
  private void removeBuildPath(IResource resource, IProject project) {

    IScriptProject projrct = DLTKCore.create(project);
    IPath filePath = resource.getFullPath();

    oldBuildEntries = Arrays.asList(projrct.readRawBuildpath());

    newBuildEntries = new ArrayList<IBuildpathEntry>();

    newBuildEntries.addAll(oldBuildEntries);

    for (int i = 0; i < oldBuildEntries.size(); i++) {
      IBuildpathEntry fEntryToChange = oldBuildEntries.get(i);
      IPath entryPath = fEntryToChange.getPath();

      int mattchedPath = entryPath.matchingFirstSegments(filePath);

      if (mattchedPath == filePath.segmentCount()) {
        newBuildEntries.remove(fEntryToChange);
      } else {
        IBuildpathEntry newEntry =
            RefactoringUtility.createNewBuildpathEntry(
                fEntryToChange, fEntryToChange.getPath(), filePath, ""); // $NON-NLS-1$
        newBuildEntries.remove(fEntryToChange);
        newBuildEntries.add(newEntry);
      }
    }

    oldIncludePath = new ArrayList<IBuildpathEntry>();

    newIncludePathEntries = new ArrayList<IBuildpathEntry>();
    List<IncludePath> includePathEntries =
        Arrays.asList(IncludePathManager.getInstance().getIncludePaths(project));

    for (IncludePath entry : includePathEntries) {
      Object includePathEntry = entry.getEntry();
      IResource includeResource = null;
      if (!(includePathEntry instanceof IBuildpathEntry)) {
        includeResource = (IResource) includePathEntry;
        IPath entryPath = includeResource.getFullPath();

        IBuildpathEntry oldEntry =
            RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
        oldIncludePath.add((IBuildpathEntry) oldEntry);

        if (filePath.isPrefixOf(entryPath) || entryPath.equals(filePath)) {
        } else {
          IBuildpathEntry newEntry =
              RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
          newIncludePathEntries.add(newEntry);
        }
      } else {
        newIncludePathEntries.add((IBuildpathEntry) includePathEntry);
        oldIncludePath.add((IBuildpathEntry) includePathEntry);
      }
    }
  }
 /**
  * Return whether the given resource is either equal to or a descendant of one of the given roots.
  *
  * @param resource the resource to be tested
  * @return whether the given resource is either equal to or a descendant of one of the given roots
  */
 private boolean isDescendantOfRoots(IResource resource) {
   for (int l = 0; l < roots.length; l++) {
     IResource root = roots[l];
     if (root.getFullPath().isPrefixOf(resource.getFullPath())) {
       return true;
     }
   }
   return false;
 }
 private void ensureResourceCovered(IResource resource, List list) {
   IPath path = resource.getFullPath();
   for (Iterator iter = list.iterator(); iter.hasNext(); ) {
     IResource root = (IResource) iter.next();
     if (root.getFullPath().isPrefixOf(path)) {
       return;
     }
   }
   list.add(resource);
 }
Exemple #7
0
  private void buildMetaInf(IPath outputLocation, IProgressMonitor monitor)
      throws CoreException, JavaModelException {
    IProject project = getProject();
    IFolder metaInf = project.getFolder(META_INF);

    if (!metaInf.exists()) {
      error("META-INF folder not found for project: " + getProject().getName()); // $NON-NLS-1$
      return;
    }

    IFolder binFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation);
    if (!binFolder.exists()) {
      binFolder.create(true, true, null);
    } else {
      binFolder.refreshLocal(IResource.DEPTH_ONE, null);
    }
    IFolder binaryMetaInf = binFolder.getFolder(META_INF);
    if (!binaryMetaInf.exists()) {
      binaryMetaInf.create(true, true, null);
    } else {
      binaryMetaInf.refreshLocal(IResource.DEPTH_ONE, null);
    }

    SubProgressMonitor sub = new SubProgressMonitor(monitor, 1);

    IResource[] children = metaInf.members();
    sub.beginTask(Messages.Builder_CopyMetaInfContent, children.length);
    for (IResource iResource : children) {
      if (!iResource.isTeamPrivateMember() && !iResource.isDerived()) {
        IPath target = binaryMetaInf.getFullPath().append(iResource.getName());
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(target);
        if (res != null && res.exists()) {
          if (DEBUG) {
            debug(res.getFullPath().toString() + " exists, deleting"); // $NON-NLS-1$
          }
          res.refreshLocal(IResource.DEPTH_INFINITE, null);
          res.delete(true, null);
          if (DEBUG) {
            debug(res.getFullPath().toString() + " deleted"); // $NON-NLS-1$
          }
        }
        iResource.copy(target, true, null);
        if (DEBUG) {
          debug(
              "Copied "
                  + iResource.getFullPath().toString()
                  + " to "
                  + target.toString()); // $NON-NLS-1$ //$NON-NLS-2$
        }
      }
      sub.worked(1);
    }
    monitor.done();
  }
 private static void addToList(ArrayList result, IResource curr) {
   IPath currPath = curr.getFullPath();
   for (int k = result.size() - 1; k >= 0; k--) {
     IResource other = (IResource) result.get(k);
     IPath otherPath = other.getFullPath();
     if (otherPath.isPrefixOf(currPath)) {
       return; // current entry is a descendant of an entry in the list
     }
     if (currPath.isPrefixOf(otherPath)) {
       result.remove(k); // entry in the list is a descendant of the current entry
     }
   }
   result.add(curr);
 }
Exemple #9
0
 public void checkModificationStamp(RefactoringStatus status, long stampToMatch) {
   if (fKind == DOCUMENT) {
     if (stampToMatch != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP
         && fModificationStamp != stampToMatch) {
       status.addFatalError(
           StringUtils.format("Resource %s has modifications", fResource.getFullPath()));
     }
   } else {
     if (stampToMatch != IResource.NULL_STAMP && fModificationStamp != stampToMatch) {
       status.addFatalError(
           StringUtils.format("Resource %s has modifications", fResource.getFullPath()));
     }
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
   */
  public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context)
      throws CoreException, OperationCanceledException {
    pm.beginTask("", 1); // $NON-NLS-1$
    try {
      RefactoringStatus result = new RefactoringStatus();

      for (int i = 0; i < fResources.length; i++) {
        IResource resource = fResources[i];
        if (!resource.isSynchronized(IResource.DEPTH_INFINITE)) {
          if (resource instanceof IFile) {
            result.addInfo(
                Messages.format(
                    RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_file,
                    BasicElementLabels.getPathLabel(resource.getFullPath(), false)));
          } else {
            result.addInfo(
                Messages.format(
                    RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_container,
                    BasicElementLabels.getPathLabel(resource.getFullPath(), false)));
          }
        }
      }

      checkDirtyResources(result);

      ResourceChangeChecker checker =
          (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
      IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
      for (int i = 0; i < fResources.length; i++) {
        if (fResources[i].isPhantom()) {
          result.addFatalError(
              Messages.format(
                  RefactoringCoreMessages.DeleteResourcesProcessor_delete_error_phantom,
                  BasicElementLabels.getPathLabel(fResources[i].getFullPath(), false)));
        } else if (fDeleteContents && Resources.isReadOnly(fResources[i])) {
          result.addFatalError(
              Messages.format(
                  RefactoringCoreMessages.DeleteResourcesProcessor_delete_error_read_only,
                  BasicElementLabels.getPathLabel(fResources[i].getFullPath(), false)));
        } else {
          deltaFactory.delete(fResources[i]);
        }
      }
      return result;
    } finally {
      pm.done();
    }
  }
Exemple #11
0
 private static IStatus addOutOfSync(IStatus status, IResource resource) {
   IStatus entry =
       new Status(
           IStatus.ERROR,
           ResourcesPlugin.PI_RESOURCES,
           IResourceStatus.OUT_OF_SYNC_LOCAL,
           Messages.format(
               JUnitMessages.Resources_outOfSync,
               BasicElementLabels.getPathLabel(resource.getFullPath(), false)),
           null);
   if (status == null) {
     return entry;
   } else if (status.isMultiStatus()) {
     ((MultiStatus) status).add(entry);
     return status;
   } else {
     MultiStatus result =
         new MultiStatus(
             ResourcesPlugin.PI_RESOURCES,
             IResourceStatus.OUT_OF_SYNC_LOCAL,
             JUnitMessages.Resources_outOfSyncResources,
             null);
     result.add(status);
     result.add(entry);
     return result;
   }
 }
  private void addTextMatches(IResource resource, IProgressMonitor pm) throws JavaModelException {
    try {
      String task = RefactoringCoreMessages.TextMatchUpdater_searching + resource.getFullPath();
      if (resource instanceof IFile) {
        IJavaElement element = JavaCore.create(resource);
        // don't start pm task (flickering label updates; finally {pm.done()} is enough)
        if (!(element instanceof ICompilationUnit)) return;
        if (!element.exists()) return;
        if (!fScope.encloses(element)) return;
        addCuTextMatches((ICompilationUnit) element);

      } else if (resource instanceof IContainer) {
        IResource[] members = ((IContainer) resource).members();
        pm.beginTask(task, members.length);
        pm.subTask(task);
        for (int i = 0; i < members.length; i++) {
          if (pm.isCanceled()) throw new OperationCanceledException();

          addTextMatches(members[i], new SubProgressMonitor(pm, 1));
        }
      }
    } catch (JavaModelException e) {
      throw e;
    } catch (CoreException e) {
      throw new JavaModelException(e);
    } finally {
      pm.done();
    }
  }
  @Override
  public ModelWorkspaceItem getParent(final IResource resource) {
    CoreArgCheck.isNotNull(resource);

    IProject project = resource.getProject();
    if (project.isAccessible() && !ModelerCore.hasModelNature(project)) {
      return null;
    }

    // If the resource is an IProject... return the resource
    if (resource instanceof IProject) {
      return this;
    }

    // If the parent is null, return null
    final IResource parent = resource.getParent();
    if (parent == null) {
      return null;
    }

    // Calculate the parent path from the given resource
    final IPath path = resource.getFullPath();
    final IPath parentPath = path.removeLastSegments(1);

    // Find the workspaceItem for the parent path1
    return getWorkspaceItem(parentPath);
  }
  private String formatFileName(String fileName) {
    String formatFile = null;

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(fileName);

    if (resource == null) {
      return fileName;
    }

    basePath = getBasePath(resource.getProject());
    if (basePath == null && resource.getProject() != null)
      basePath = resource.getProject().getName();
    else if (basePath == null && resource.getProject() == null) {
      basePath = ""; // $NON-NLS-1$
    }

    int type = resource.getType();
    if (type == IResource.FILE || type == IResource.FOLDER) {

      formatFile =
          basePath
              + "/" //$NON-NLS-1$
              + resource.getFullPath().removeFirstSegments(1).toString();
    } else {
      formatFile = basePath + "/"; // $NON-NLS-1$
    }
    if (!formatFile.startsWith("/")) { // $NON-NLS-1$
      formatFile = basePath + "/" + formatFile; // $NON-NLS-1$
    }
    return formatFile;
  }
 private String checkValidSourceFolder(String text) throws CoreException {
   validatedSourceFolder = null;
   if (text == null || text.trim().length() == 0) {
     return "The source folder must be filled.";
   }
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(text));
   if (resource == null) {
     return "The source folder was not found in the workspace.";
   }
   if (!(resource instanceof IContainer)) {
     return "The source folder was found in the workspace but is not a container.";
   }
   IProject project = resource.getProject();
   if (project == null) {
     return "Unable to find the project related to the source folder.";
   }
   IPythonPathNature nature = PythonNature.getPythonPathNature(project);
   if (nature == null) {
     return "The pydev nature is not configured on the project: " + project.getName();
   }
   String full = resource.getFullPath().toString();
   String[] srcPaths = PythonNature.getStrAsStrItems(nature.getProjectSourcePath(true));
   for (String str : srcPaths) {
     if (str.equals(full)) {
       validatedSourceFolder = (IContainer) resource;
       return null;
     }
   }
   return "The selected source folder is not recognized as a valid source folder.";
 }
 /**
  * Determines if the filter matches the provided resource.
  *
  * @param resource the resource.
  * @return true if the filter matches the provided resource and the event should be given to the
  *     file change observer.
  */
 public boolean matches(IResource resource) {
   if (getFilterType() == FileObserverFilterType.ALL) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.FILE
       && resource instanceof IFile
       && getAbsolutePath(getFileFilter()).equals(getAbsolutePath(resource))) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.FOLDER
       && resource instanceof IFile
       && getAbsolutePath(resource).startsWith(getAbsolutePath(getFolderFilter()))) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.CONTENT_TYPE
       && resource instanceof IFile
       && matchesContentType(((IFile) resource).getName())) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.EXTENSION && resource instanceof IFile) {
     String fileExtension = resource.getFullPath().getFileExtension();
     if (matchesExtension(fileExtension)) {
       return true;
     }
   }
   return false;
 }
  private static void processResourceDeltasZip(
      IModuleResourceDelta[] deltas,
      ZipOutputStream zip,
      Map<ZipEntry, String> deleteEntries,
      String deletePrefix,
      String deltaPrefix,
      boolean adjustGMTOffset)
      throws IOException, CoreException {

    for (IModuleResourceDelta delta : deltas) {
      int deltaKind = delta.getKind();

      IResource deltaResource = (IResource) delta.getModuleResource().getAdapter(IResource.class);

      IProject deltaProject = deltaResource.getProject();

      IFolder docroot = CoreUtil.getDocroot(deltaProject);

      IPath deltaPath =
          new Path(deltaPrefix + deltaResource.getFullPath().makeRelativeTo(docroot.getFullPath()));

      if (deltaKind == IModuleResourceDelta.ADDED || deltaKind == IModuleResourceDelta.CHANGED) {
        addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
      } else if (deltaKind == IModuleResourceDelta.REMOVED) {
        addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
      } else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
        IModuleResourceDelta[] children = delta.getAffectedChildren();
        processResourceDeltasZip(
            children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
      }
    }
  }
Exemple #18
0
 /**
  * Retrieves a collection of files that may be committed based on the user's selection when they
  * performed the commit action. That is, even if the user only selected one folder when the action
  * was performed, if the folder contains any files that could be committed, they will be returned.
  *
  * @return a collection of files that is eligible to be committed based on the user's selection
  */
 private Set<String> getSelectedFiles() {
   Set<String> preselectionCandidates = new LinkedHashSet<String>();
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   // iterate through all the files that may be committed
   for (String fileName : files) {
     URI uri = new File(repo.getWorkTree(), fileName).toURI();
     IFile[] workspaceFiles = root.findFilesForLocationURI(uri);
     if (workspaceFiles.length > 0) {
       IFile file = workspaceFiles[0];
       for (IResource resource : selectedResources) {
         // if any selected resource contains the file, add it as a
         // preselection candidate
         if (resource.contains(file)) {
           preselectionCandidates.add(fileName);
           break;
         }
       }
     } else {
       // could be file outside of workspace
       for (IResource resource : selectedResources) {
         if (resource.getFullPath().toFile().equals(new File(uri))) {
           preselectionCandidates.add(fileName);
         }
       }
     }
   }
   return preselectionCandidates;
 }
  private static IPath[] chooseEntries(Shell shell, IPath initialSelection) {
    Class[] acceptedClasses = new Class[] {IFile.class};
    TypedElementSelectionValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, true);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    FilteredElementTreeSelectionDialog dialog =
        new FilteredElementTreeSelectionDialog(
            shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
    dialog.setHelpAvailable(false);
    dialog.setValidator(validator);
    dialog.setTitle(Messages.ArchiveDialogNewTitle);
    dialog.setMessage(Messages.ArchiveDialogNewDescription);
    dialog.addFilter(getDialogViewerFilter());
    dialog.setInput(root);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setInitialFilter("*.jar,*.war,*.rar,*.zip"); // $NON-NLS-1$
    dialog.create();

    if (dialog.open() == Window.OK) {
      Object[] elements = dialog.getResult();
      IPath[] res = new IPath[elements.length];
      for (int i = 0; i < res.length; i++) {
        IResource elem = (IResource) elements[i];
        res[i] = elem.getFullPath();
      }
      return res;
    }
    return null;
  }
  public void newResource(final IResource resource) {
    if (resource instanceof IFile
        && resource.getName().endsWith(".groovy")
        && !resource.getName().endsWith("Tests.groovy")) {
      // Only open resource if is in any source folder
      IJavaProject jp = JdtUtils.getJavaProject(project);
      if (jp != null) {
        try {
          for (IClasspathEntry entry : jp.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
              if (entry.getPath() != null && entry.getPath().isPrefixOf(resource.getFullPath())) {
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {

                          public void run() {
                            SpringUIUtils.openInEditor((IFile) resource, -1);
                          }
                        });
                break;
              }
            }
          }
        } catch (JavaModelException e) {
        }
      }
    }
  }
Exemple #21
0
 private static IStatus addOutOfSync(IStatus status, IResource resource) {
   IStatus entry =
       new Status(
           IStatus.ERROR,
           ResourcesPlugin.PI_RESOURCES,
           IResourceStatus.OUT_OF_SYNC_LOCAL,
           Messages.format(CorextMessages.Resources_outOfSync, resource.getFullPath().toString()),
           null);
   if (status == null) {
     return entry;
   } else if (status.isMultiStatus()) {
     ((MultiStatus) status).add(entry);
     return status;
   } else {
     MultiStatus result =
         new MultiStatus(
             ResourcesPlugin.PI_RESOURCES,
             IResourceStatus.OUT_OF_SYNC_LOCAL,
             CorextMessages.Resources_outOfSyncResources,
             null);
     result.add(status);
     result.add(entry);
     return result;
   }
 }
  private boolean initPath(IResource selection) {
    if (!WebAppUtilities.isWebApp(hostPageProject)) {
      return false;
    }

    IFolder container = null;

    try {
      IFolder warFolder = WebAppUtilities.getWarSrc(hostPageProject);

      // If the selection was a subfolder of war, initialize to that
      if (selection.getType() == IResource.FOLDER) {
        if (warFolder.getFullPath().isPrefixOf(selection.getFullPath())) {
          container = (IFolder) selection;
          return true;
        }
      }

      // Otherwise, use the war folder as the default path
      if (warFolder.exists()) {
        container = warFolder;
        return true;
      }

      return false;

    } finally {
      if (container != null) {
        pathField.setText(container.getFullPath().removeFirstSegments(1).toString());
      }
    }
  }
Exemple #23
0
  public void completeCompile(
      final IProject project,
      final IResource source,
      final OtpErlangObject compilationResult,
      final IBackend backend,
      final OtpErlangList compilerOptions) {
    if (compilationResult == null) {
      MarkerUtils.addProblemMarker(
          source, null, null, "Could not compile file", 0, IMarker.SEVERITY_ERROR);
      return;
    }
    final OtpErlangTuple t = (OtpErlangTuple) compilationResult;
    // ErlLogger.debug("** " + t);

    if ("ok".equals(((OtpErlangAtom) t.elementAt(0)).atomValue())) {
      final String beamf = source.getFullPath().removeFileExtension().lastSegment();
      InternalErlideBuilder.loadModule(project, beamf);
      refreshDirs(project, t.elementAt(2));
    } else {
      // ErlLogger.debug(">>>> compile error... %s\n   %s",
      // resource.getName(), t);
    }

    // process compilation messages
    if (t.elementAt(1) instanceof OtpErlangList) {
      final OtpErlangList l = (OtpErlangList) t.elementAt(1);
      MarkerUtils.addErrorMarkers(source, l);
    } else {
      ErlLogger.warn("bad result from builder: %s", t);
    }

    completeCompileForYrl(project, source, backend, compilerOptions);
  }
  private IMarker addMarker(
      IResource resource,
      String type,
      String message,
      int lineNumber,
      int severity,
      boolean isTransient) {
    IMarker marker = null;
    try {
      if (resource.isAccessible()) {
        if (lineNumber == -1) {
          lineNumber = 1;
        }

        // mkleint: this strongly smells like some sort of workaround for a problem with bad marker
        // cleanup.
        // adding is adding and as such shall always be performed.
        marker = findMarker(resource, type, message, lineNumber, severity, isTransient);
        if (marker != null) {
          // This marker already exists
          return marker;
        }
        marker = resource.createMarker(type);
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.TRANSIENT, isTransient);

        marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
        log.debug("Created marker '{}' on resource '{}'.", message, resource.getFullPath());
      }
    } catch (CoreException ex) {
      log.error("Unable to add marker; " + ex.toString(), ex); // $NON-NLS-1$
    }
    return marker;
  }
  protected boolean checkForClassFileChanges(
      IResourceDelta binaryDelta, ClasspathMultiDirectory md, int segmentCount)
      throws CoreException {
    IResource resource = binaryDelta.getResource();
    // remember that if inclusion & exclusion patterns change then a full build is done
    boolean isExcluded =
        (md.exclusionPatterns != null || md.inclusionPatterns != null)
            && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns);
    switch (resource.getType()) {
      case IResource.FOLDER:
        if (isExcluded && md.inclusionPatterns == null)
          return true; // no need to go further with this delta since its children cannot be
        // included

        IResourceDelta[] children = binaryDelta.getAffectedChildren();
        for (int i = 0, l = children.length; i < l; i++)
          if (!checkForClassFileChanges(children[i], md, segmentCount)) return false;
        return true;
      case IResource.FILE:
        if (!isExcluded
            && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) {
          // perform full build if a managed class file has been changed
          IPath typePath =
              resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
          if (this.newState.isKnownType(typePath.toString())) {
            if (JavaBuilder.DEBUG)
              System.out.println(
                  "MUST DO FULL BUILD. Found change to class file " + typePath); // $NON-NLS-1$
            return false;
          }
          return true;
        }
    }
    return true;
  }
  public void addSelectedFilesToTargetList() {
    ISelection selection = sourceFileViewer.getSelection();

    if (isValidSourceFileViewerSelection(selection)) {
      java.util.List list = null;
      if (selection instanceof IStructuredSelection) {
        list = ((IStructuredSelection) selection).toList();

        if (list != null) {
          list = ((IStructuredSelection) selection).toList();
          for (Iterator i = list.iterator(); i.hasNext(); ) {
            IResource resource = (IResource) i.next();
            if (resource instanceof IFile) {
              // Check if its in the list. Don't add it if it is.
              String resourceName = resource.getFullPath().toString();
              if (selectedListBox.indexOf(resourceName) == -1) selectedListBox.add(resourceName);
            }
          }
          setFiles(selectedListBox.getItems());
        }

        setAddButtonEnabled(false);

        if (selectedListBox.getItemCount() > 0) {
          removeAllButton.setEnabled(true);
          if (isFileMandatory) setPageComplete(true);
          if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true);
          else setRemoveButtonEnabled(false);
        }
      }
    }
  }
  public String getText(Object element) {
    if (!(element instanceof IResource)) return null;

    IResource resource = (IResource) element;
    String text = null;

    if (!resource.exists()) text = SearchMessages.FileLabelProvider_removed_resource_label;
    else {
      IPath path = resource.getFullPath().removeLastSegments(1);
      if (path.getDevice() == null) path = path.makeRelative();
      if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) {
        text = fLabelProvider.getText(resource);
        if (path != null && fOrder == SHOW_LABEL_PATH) {
          fArgs[0] = text;
          fArgs[1] = path.toString();
          text = MessageFormat.format(fgSeparatorFormat, fArgs);
        }
      } else {
        if (path != null) text = path.toString();
        else text = ""; // $NON-NLS-1$
        if (fOrder == SHOW_PATH_LABEL) {
          fArgs[0] = text;
          fArgs[1] = fLabelProvider.getText(resource);
          text = MessageFormat.format(fgSeparatorFormat, fArgs);
        }
      }
    }

    int matchCount = 0;
    AbstractTextSearchResult result = fPage.getInput();
    if (result != null) matchCount = result.getMatchCount(element);
    if (matchCount <= 1) return text;
    String format = SearchMessages.FileLabelProvider_count_format;
    return MessageFormat.format(format, new Object[] {text, new Integer(matchCount)});
  }
  /**
   * Returns a VDB editor given a vdb resource if editor is open
   *
   * @param vdb the vdb
   * @return the vdb editor
   */
  public static VdbEditor getVdbEditorForFile(IResource vdb) {
    if (vdb != null && vdb.exists()) {
      IWorkbenchWindow window = UiPlugin.getDefault().getCurrentWorkbenchWindow();

      if (window != null) {
        final IWorkbenchPage page = window.getActivePage();

        if (page != null) {
          // look through the open editors and see if there is one available for this model file.
          IEditorReference[] editors = page.getEditorReferences();
          for (int i = 0; i < editors.length; ++i) {

            IEditorPart editor = editors[i].getEditor(false);
            if (editor != null) {
              IEditorInput input = editor.getEditorInput();
              if (input instanceof IFileEditorInput) {
                if (vdb.equals(((IFileEditorInput) input).getFile())
                    || vdb.getFullPath()
                        .equals(((IFileEditorInput) input).getFile().getFullPath())) {
                  // found it;
                  if (ModelUtil.isVdbArchiveFile(vdb)) {
                    return (VdbEditor) editor;
                  }
                  break;
                }
              }
            }
          }
        }
      }
    }

    return null;
  }
 /**
  * Possible failures:
  *
  * <ul>
  *   <li>NO_ELEMENTS_TO_PROCESS - the root supplied to the operation is <code>null</code>.
  *   <li>INVALID_NAME - the name provided to the operation is <code>null</code> or is not a valid
  *       script folder name.
  *   <li>READ_ONLY - the root provided to this operation is read only.
  *   <li>NAME_COLLISION - there is a pre-existing resource (file) with the same name as a folder
  *       in the script folder's hierarchy.
  *   <li>ELEMENT_NOT_PRESENT - the underlying resource for the root is missing
  * </ul>
  *
  * @see IScriptModelStatus
  * @see ScriptConventions
  */
 @Override
 public IModelStatus verify() {
   if (getParentElement() == null) {
     return new ModelStatus(IModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
   }
   IPath packageName = this.pkgName == null ? null : this.pkgName.append("."); // $NON-NLS-1$
   String packageNameValue = null;
   if (packageName != null) {
     packageNameValue = packageName.toOSString();
   }
   if (this.pkgName == null
       || (this.pkgName.segmentCount() > 0
           && !Util.isValidFolderNameForPackage(
               (IContainer) getParentElement().getResource(), packageName.toString()))) {
     return new ModelStatus(IModelStatusConstants.INVALID_NAME, packageNameValue);
   }
   IProjectFragment root = (IProjectFragment) getParentElement();
   if (root.isReadOnly()) {
     return new ModelStatus(IModelStatusConstants.READ_ONLY, root);
   }
   IContainer parentFolder = (IContainer) root.getResource();
   int i;
   for (i = 0; i < this.pkgName.segmentCount(); i++) {
     IResource subFolder = parentFolder.findMember(this.pkgName.segment(i));
     if (subFolder != null) {
       if (subFolder.getType() != IResource.FOLDER) {
         return new ModelStatus(
             IModelStatusConstants.NAME_COLLISION,
             Messages.bind(Messages.status_nameCollision, subFolder.getFullPath().toString()));
       }
       parentFolder = (IContainer) subFolder;
     }
   }
   return ModelStatus.VERIFIED_OK;
 }
  public static IPath[] chooseExclusionPattern(
      Shell shell,
      IContainer currentSourceFolder,
      String title,
      String message,
      IPath initialPath,
      boolean multiSelection) {
    Class[] acceptedClasses = new Class[] {IFolder.class, IFile.class};
    ISelectionStatusValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, multiSelection);
    ViewerFilter filter = new TypedViewerFilter(acceptedClasses);

    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();

    IResource initialElement = null;
    if (initialPath != null) {
      IContainer curr = currentSourceFolder;
      int nSegments = initialPath.segmentCount();
      for (int i = 0; i < nSegments; i++) {
        IResource elem = curr.findMember(initialPath.segment(i));
        if (elem != null) {
          initialElement = elem;
        }
        if (elem instanceof IContainer) {
          curr = (IContainer) elem;
        } else {
          break;
        }
      }
    }

    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, lp, cp);
    dialog.setTitle(title);
    dialog.setValidator(validator);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    dialog.setInput(currentSourceFolder);
    dialog.setInitialSelection(initialElement);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setHelpAvailable(false);

    if (dialog.open() == Window.OK) {
      Object[] objects = dialog.getResult();
      int existingSegments = currentSourceFolder.getFullPath().segmentCount();

      IPath[] resArr = new IPath[objects.length];
      for (int i = 0; i < objects.length; i++) {
        IResource currRes = (IResource) objects[i];
        IPath path = currRes.getFullPath().removeFirstSegments(existingSegments).makeRelative();
        if (currRes instanceof IContainer) {
          path = path.addTrailingSeparator();
        }
        resArr[i] = path;
      }
      return resArr;
    }
    return null;
  }