Java Code Examples for org.eclipse.jdt.core.ClasspathContainerInitializer#requestClasspathContainerUpdate()

The following examples show how to use org.eclipse.jdt.core.ClasspathContainerInitializer#requestClasspathContainerUpdate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceAttachmentCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void updateContainerClasspath(IJavaProject javaProject, IPath containerPath, IClasspathEntry newEntry) throws CoreException {
	IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject);
	List<IClasspathEntry> newEntries = updateElements(container.getClasspathEntries(), newEntry, (entry) -> {
		return entry.getEntryKind() == newEntry.getEntryKind() && entry.getPath().equals(newEntry.getPath());
	});
	IClasspathContainer updatedContainer = new UpdatedClasspathContainer(container, newEntries.toArray(new IClasspathEntry[0]));
	ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		initializer.requestClasspathContainerUpdate(containerPath, javaProject, updatedContainer);
	}
}
 
Example 2
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Request a container update.
 * @param jproject The project of the container
 * @param container The container to request a change to
 * @param newEntries The updated entries
 * @throws CoreException if the request failed
 */
public static void requestContainerUpdate(IJavaProject jproject, IClasspathContainer container, IClasspathEntry[] newEntries) throws CoreException {
	IPath containerPath= container.getPath();
	IClasspathContainer updatedContainer= new UpdatedClasspathContainer(container, newEntries);
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		initializer.requestClasspathContainerUpdate(containerPath, jproject, updatedContainer);
	}
}
 
Example 3
Source File: CloudLibrariesPage.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Override
public boolean finish() {
  List<Library> libraries = getSelectedLibraries();
  try {
    if (isMavenProject) {
      // remove any library that wasn't selected
      Set<Library> removed = new HashSet<>(getAvailableLibraries());
      removed.removeAll(libraries);
      // No need for an Analytics ping here; addMavenLibraries will do it.
      BuildPath.updateMavenLibraries(project.getProject(), libraries, removed,
          new NullProgressMonitor());
    } else {
      if (!libraries.isEmpty()) {
        AnalyticsLibraryPingHelper.sendLibrarySelectionPing(
            AnalyticsEvents.NATIVE_PROJECT, libraries);
      }

      /*
       * FIXME: BuildPath.addNativeLibrary() is too heavy-weight here. ClasspathContainerWizard,
       * our wizard, is responsible for installing the classpath entry returned by getSelection(),
       * which will perform the library resolution. We just need to save the selected libraries
       * so that they are resolved later.
       */
      BuildPath.saveLibraryList(project, libraries, new NullProgressMonitor());
      Library masterLibrary =
          BuildPath.collectLibraryFiles(project, libraries, new NullProgressMonitor());
      // skip computeEntry() if we have an existing entry: unnecessary and simplifies testing too
      if (originalEntry == null) {
        newEntry = BuildPath.computeEntry(project, masterLibrary, new NullProgressMonitor());
        Verify.verifyNotNull(newEntry); // new entry should be created
      } else {
        // request update of existing entry
        ClasspathContainerInitializer initializer =
            JavaCore.getClasspathContainerInitializer(
                LibraryClasspathContainer.CONTAINER_PATH_PREFIX);
        // this is always true for our initializer
        if (initializer.canUpdateClasspathContainer(originalEntry.getPath(), project)) {
          // existing entry needs to be updated
          initializer.requestClasspathContainerUpdate(
              originalEntry.getPath(), project, null /*containerSuggestion*/);
        }
      }
    }
    return true;
  } catch (CoreException ex) {
    StatusUtil.setErrorStatus(this, "Error updating container definition", ex); //$NON-NLS-1$
    return false;
  }
}