Beispiel #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);
      }
    }
  }
  @Override
  protected void updateProject(IProgressMonitor monitor)
      throws CoreException, InterruptedException {

    IProject projectHandle = fFirstPage.getProjectHandle();
    IScriptProject create = DLTKCore.create(projectHandle);
    super.init(create, null, false);
    fCurrProjectLocation = getProjectLocationURI();

    boolean installSymfony = true;

    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    try {
      monitor.beginTask(NewWizardMessages.ScriptProjectWizardSecondPage_operation_initialize, 70);
      if (monitor.isCanceled()) {
        throw new OperationCanceledException();
      }

      URI realLocation = fCurrProjectLocation;
      if (fCurrProjectLocation == null) { // inside workspace
        try {
          URI rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocationURI();
          realLocation =
              new URI(
                  rootLocation.getScheme(),
                  null,
                  Path.fromPortableString(rootLocation.getPath())
                      .append(getProject().getName())
                      .toString(),
                  null);
        } catch (URISyntaxException e) {
          Assert.isTrue(false, "Can't happen"); // $NON-NLS-1$
        }
      }

      rememberExistingFiles(realLocation);

      createProject(getProject(), fCurrProjectLocation, new SubProgressMonitor(monitor, 20));

      IBuildpathEntry[] buildpathEntries = null;
      IncludePath[] includepathEntries = null;

      SymfonyProjectWizardFirstPage firstPage = (SymfonyProjectWizardFirstPage) fFirstPage;

      if (firstPage.getDetect()) {

        installSymfony = false;
        includepathEntries = setProjectBaseIncludepath();
        if (!getProject().getFile(FILENAME_BUILDPATH).exists()) {

          IDLTKLanguageToolkit toolkit = DLTKLanguageManager.getLanguageToolkit(getScriptNature());
          final BuildpathDetector detector = createBuildpathDetector(monitor, toolkit);
          buildpathEntries = detector.getBuildpath();

        } else {
          monitor.worked(20);
        }
      } else if (firstPage.hasSymfonyStandardEdition()) {

        // flat project layout
        IPath projectPath = getProject().getFullPath();
        List cpEntries = new ArrayList();
        cpEntries.add(DLTKCore.newSourceEntry(projectPath));

        //				buildpathEntries = (IBuildpathEntry[]) cpEntries
        //						.toArray(new IBuildpathEntry[cpEntries.size()]);
        //				includepathEntries = setProjectBaseIncludepath();

        buildpathEntries = new IBuildpathEntry[0];
        includepathEntries = new IncludePath[0];

        monitor.worked(20);

      } else {
        // flat project layout
        IPath projectPath = getProject().getFullPath();
        List cpEntries = new ArrayList();
        cpEntries.add(DLTKCore.newSourceEntry(projectPath));

        //				buildpathEntries = (IBuildpathEntry[]) cpEntries
        //						.toArray(new IBuildpathEntry[cpEntries.size()]);
        //				includepathEntries = setProjectBaseIncludepath();

        buildpathEntries = new IBuildpathEntry[0];
        includepathEntries = new IncludePath[0];

        monitor.worked(20);
      }
      if (monitor.isCanceled()) {
        throw new OperationCanceledException();
      }

      init(DLTKCore.create(getProject()), buildpathEntries, false);

      // setting PHP4/5 and ASP-Tags :
      setPhpLangOptions();

      configureScriptProject(new SubProgressMonitor(monitor, 30));

      SymfonyProjectWizardFirstPage p = (SymfonyProjectWizardFirstPage) getFirstPage();

      // checking and adding JS nature,libs, include path if needed
      if (p.shouldSupportJavaScript()) {
        addJavaScriptNature(monitor);
      }

      // adding build paths, and language-Container:
      getScriptProject().setRawBuildpath(buildpathEntries, new NullProgressMonitor());
      LanguageModelInitializer.enableLanguageModelFor(getScriptProject());

      // init, and adding include paths:
      getBuildPathsBlock().init(getScriptProject(), new IBuildpathEntry[] {});
      IncludePathManager.getInstance().setIncludePath(getProject(), includepathEntries);

      if (installSymfony) installSymfony(new SubProgressMonitor(monitor, 50));

    } finally {
      monitor.done();
    }
  }