コード例 #1
0
ファイル: PHPCorePlugin.java プロジェクト: KopjeKoffie/pdt
  /**
   * Initializes DLTKCore internal structures to allow subsequent operations (such as the ones that
   * need a resolved classpath) to run full speed. A client may choose to call this method in a
   * background thread early after the workspace has started so that the initialization is
   * transparent to the user.
   *
   * <p>However calling this method is optional. Services will lazily perform initialization when
   * invoked. This is only a way to reduce initialization overhead on user actions, if it can be
   * performed before at some appropriate moment.
   *
   * <p>This initialization runs accross all Java projects in the workspace. Thus the workspace root
   * scheduling rule is used during this operation.
   *
   * <p>This method may return before the initialization is complete. The initialization will then
   * continue in a background thread.
   *
   * <p>This method can be called concurrently.
   *
   * @param monitor a progress monitor, or <code>null</code> if progress reporting and cancellation
   *     are not desired
   * @exception CoreException if the initialization fails, the status of the exception indicates the
   *     reason of the failure
   * @since 3.1
   */
  public static void initializeAfterLoad(IProgressMonitor monitor) throws CoreException {
    try {
      if (monitor != null) {
        monitor.beginTask(CoreMessages.PHPCorePlugin_initializingPHPToolkit, 125);
      }

      // dummy query for waiting until the indexes are ready
      IDLTKSearchScope scope = SearchEngine.createWorkspaceScope(PHPLanguageToolkit.getDefault());
      try {
        LanguageModelInitializer.cleanup(monitor);
        if (monitor != null) {
          monitor.subTask(CoreMessages.PHPCorePlugin_initializingSearchEngine);
          monitor.worked(25);
        }

        PhpModelAccess.getDefault()
            .findMethods(ID, MatchRule.PREFIX, Modifiers.AccGlobal, 0, scope, monitor);
        if (monitor != null) {
          monitor.worked(25);
        }

        PhpModelAccess.getDefault()
            .findTypes(ID, MatchRule.PREFIX, Modifiers.AccGlobal, 0, scope, monitor);
        if (monitor != null) {
          monitor.worked(25);
        }

        PhpModelAccess.getDefault()
            .findFields(ID, MatchRule.PREFIX, Modifiers.AccGlobal, 0, scope, monitor);
        if (monitor != null) {
          monitor.worked(25);
        }

        PhpModelAccess.getDefault().findIncludes(ID, MatchRule.PREFIX, scope, monitor);
        if (monitor != null) {
          monitor.worked(25);
        }

      } catch (OperationCanceledException e) {
        if (monitor != null && monitor.isCanceled()) {
          throw e;
        }
        // else indexes were not ready: catch the exception so that jars
        // are still refreshed
      }
    } finally {
      if (monitor != null) {
        monitor.done();
      }
      toolkitInitialized = true;
    }
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.dltk.internal.ui.navigator.ScriptExplorerLabelProvider#getText
   * (java.lang.Object)
   *
   * Override the default text - do not display a full path for a folder
   */
  @Override
  public String getText(Object element) {

    if (element instanceof ExternalProjectFragment) {
      ExternalProjectFragment fragment = (ExternalProjectFragment) element;
      String name =
          LanguageModelInitializer.getPathName(
              EnvironmentPathUtils.getLocalPath(fragment.getPath()));
      if (name != null) {
        return name;
      }
      return fragment.toStringWithAncestors();
    }
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=295256
    if (element instanceof IProjectFragment) {
      IProjectFragment fragment = (IProjectFragment) element;
      return fragment.getElementName();
    }
    // end
    if (element instanceof IncludePath) {
      Object entry = ((IncludePath) element).getEntry();

      // An included PHP project
      if (entry instanceof IBuildpathEntry) {
        IBuildpathEntry iBuildpathEntry = (IBuildpathEntry) entry;
        if (iBuildpathEntry.getEntryKind() == IBuildpathEntry.BPE_PROJECT) {
          return iBuildpathEntry.getPath().lastSegment();
        }
        if (iBuildpathEntry.getEntryKind() == IBuildpathEntry.BPE_CONTAINER) {
          return getEntryDescription(element, iBuildpathEntry);
        } else {
          String result =
              LabelProviderUtil.getVariableName(
                  iBuildpathEntry.getPath(), iBuildpathEntry.getEntryKind());
          if (result == null) {
            IPath localPath = EnvironmentPathUtils.getLocalPath(iBuildpathEntry.getPath());
            return localPath.toOSString();
          }
          return result;
        }
      }
      if (entry instanceof ExternalProjectFragment) {
        return ((ExternalProjectFragment) entry).toStringWithAncestors();
      }

      if (entry instanceof IResource) {
        return (((IResource) entry).getFullPath().toString()).substring(1);
      }

      return null;
    }

    if (element != null) {
      for (ILabelProvider provider :
          TreeContentProviderRegistry.getInstance().getLabelProviders()) {
        String label = provider.getText(element);

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

    return super.getText(element);
  }
  @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();
    }
  }