Example #1
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);
      }
    }
  }
Example #2
0
    public void resourceChanged(IResourceChangeEvent event) {
      if (event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) {
        Object source = event.getSource();
        try {
          if (source instanceof IProject) {
            IProject project = (IProject) source;
            ProjectIndexerManager.removeProject(project.getFullPath());
            ProjectIndexerManager.indexProject(project);

          } else if (source instanceof IWorkspace) {
            IWorkspace workspace = (IWorkspace) source;
            IProject[] projects = workspace.getRoot().getProjects();

            // remove from index:
            for (IProject project : projects) {
              if (!project.isAccessible()) {
                continue;
              }
              IScriptProject scriptProject = DLTKCore.create(project);
              if (scriptProject.isOpen()) {
                IProjectFragment[] projectFragments = scriptProject.getProjectFragments();
                for (IProjectFragment projectFragment : projectFragments) {
                  ProjectIndexerManager.removeProjectFragment(
                      scriptProject, projectFragment.getPath());
                }
                ProjectIndexerManager.removeProject(project.getFullPath());
              }
            }

            // add to index:
            for (IProject project : projects) {
              if (!project.isAccessible()) {
                continue;
              }
              ProjectIndexerManager.indexProject(project);
            }
          }
        } catch (CoreException e) {
          Logger.logException(e);
        }
      }
    }
Example #3
0
  /*
   * Do the actual modifications on the project
   */
  private void modifyProject(IProject project) throws CoreException, ModelException {
    final PHPNature phpNature = new PHPNature();

    // add the required builders and build paths as defined in the new PHP
    // nature
    phpNature.setProject(project);
    phpNature.configure();

    IScriptProject scriptProject = DLTKCore.create(project);
    // merge the project build path with the old include path
    IBuildpathEntry[] existingPath = scriptProject.getRawBuildpath();

    ArrayList<IBuildpathEntry> newPath = new ArrayList<IBuildpathEntry>();
    if (existingPath != null) {
      newPath.addAll(Arrays.asList(existingPath));
    }
    ProjectBackwardCompatibilityUtil unit = new ProjectBackwardCompatibilityUtil();
    IBuildpathEntry[] oldIncludePath = unit.convertIncludePathForProject(project);
    if (oldIncludePath != null) {
      newPath.addAll(Arrays.asList(oldIncludePath));
    }
    scriptProject.setRawBuildpath(
        newPath.toArray(new IBuildpathEntry[newPath.size()]), new NullProgressMonitor());
  }
  @Override
  public Image getImage(Object element) {
    IModelElement modelElement = null;
    if (element instanceof ExternalProjectFragment) {
      return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY);
    }

    if (element instanceof IncludePath) {
      Object entry = ((IncludePath) element).getEntry();

      // An included PHP project
      if (entry instanceof IBuildpathEntry) {
        int entryKind = ((IBuildpathEntry) entry).getEntryKind();
        if (entryKind == IBuildpathEntry.BPE_PROJECT) {
          return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_PROJECT);
        }
        // A library
        if (entryKind == IBuildpathEntry.BPE_LIBRARY
            || entryKind == IBuildpathEntry.BPE_CONTAINER) {
          return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY);
        }
      }

      if (entry instanceof ExternalProjectFragment) {
        return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY);
      }

      // Folder in the include path, should have same image as in the PHP
      // Explorer .
      if (entry instanceof IFolder) {
        IModelElement createdScriptFolder = DLTKCore.create((IFolder) entry);
        if (null == createdScriptFolder) return getImage(entry);
        return getImage(createdScriptFolder);
      }

      if (entry instanceof IResource) {
        return (getImage((IResource) entry));
      }
      return null;
    }

    if (element instanceof IResource) {
      modelElement = DLTKCore.create((IResource) element);
    } else if (element instanceof IModelElement) {
      modelElement = (IModelElement) element;
    }

    if (modelElement != null) {
      IScriptProject project = modelElement.getScriptProject();
      if (!project.isOnBuildpath(modelElement)) { // not in build path,
        // hence: hollow,
        // non-pakg icons
        if (modelElement.getElementType() == IModelElement.SOURCE_MODULE)
          return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_CUNIT_RESOURCE);
        if (modelElement.getElementType() == IModelElement.PROJECT_FRAGMENT
            || modelElement.getElementType() == IModelElement.SCRIPT_FOLDER)
          return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_FOLDER);
      } else { // in build path ...
        if (modelElement.getElementType() == IModelElement.SCRIPT_FOLDER
            || element instanceof IFolder)
          return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHPFOLDER_ROOT);
      }
    }
    try {
      if (element instanceof IType && PHPFlags.isTrait(((IType) element).getFlags())) {
        return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_TRAIT);
      }
    } catch (ModelException e) {
    }

    if (element != null) {
      for (ILabelProvider provider :
          TreeContentProviderRegistry.getInstance().getLabelProviders()) {
        Image image = provider.getImage(element);

        if (image != null) {
          return image;
        }
      }
    }

    return super.getImage(element);
  }