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

The following examples show how to use org.eclipse.jdt.core.ClasspathContainerInitializer#canUpdateClasspathContainer() . 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: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus evaluateContainerChildStatus(CPListElementAttribute attrib) {
	if (fProject != null) {
		ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(fPath.segment(0));
		if (initializer != null && initializer.canUpdateClasspathContainer(fPath, fProject)) {
			if (attrib.isBuiltIn()) {
				if (CPListElement.SOURCEATTACHMENT.equals(attrib.getKey())) {
					return initializer.getSourceAttachmentStatus(fPath, fProject);
				} else if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
					return initializer.getAccessRulesStatus(fPath, fProject);
				}
			} else {
				return initializer.getAttributeStatus(fPath, fProject, attrib.getKey());
			}
		}
		return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY, "", null); //$NON-NLS-1$
	}
	return null;
}
 
Example 2
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;
  }
}
 
Example 3
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Helper method that tests if an classpath entry can be found in a
 * container. <code>null</code> is returned if the entry can not be found
 * or if the container does not allows the configuration of source
 * attachments
 * @param jproject The container's parent project
 * @param containerPath The path of the container
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 * @throws JavaModelException thrown if accessing the container failed
 */
public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) {
		return findEntryInContainer(container, libPath);
	}
	return null; // attachment not possible
}