org.eclipse.jdt.core.IClasspathContainer Java Examples

The following examples show how to use org.eclipse.jdt.core.IClasspathContainer. 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: JanusClasspathContainerInitializer.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(
		final IPath containerPath,
		final IJavaProject javaProject,
		final IClasspathContainer containerSuggestion) throws CoreException {
	if (containerSuggestion instanceof JanusClasspathContainer) {
		((JanusClasspathContainer) containerSuggestion).reset();
	}
	super.requestClasspathContainerUpdate(containerPath, javaProject, containerSuggestion);
	final Job job = new Job(Messages.JanusClasspathContainerInitializer_0) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				JavaCore.setClasspathContainer(
						containerPath,
						new IJavaProject[] {javaProject},
						new IClasspathContainer[] {containerSuggestion},
						monitor);
			} catch (CoreException ex) {
				return JanusEclipsePlugin.getDefault().createStatus(IStatus.ERROR, ex);
			}
			return JanusEclipsePlugin.getDefault().createOkStatus();
		}
	};
	job.schedule();
}
 
Example #2
Source File: SdkClasspathContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(IPath containerPath,
    IJavaProject project, IClasspathContainer containerSuggestion)
    throws CoreException {

  SdkClasspathContainer<T> sdkClasspathContainer = null;
  T sdk = resolveSdkFromContainerPath(containerPath, project);
  if (sdk != null) {
    String description = getDescription(containerPath, project);
    sdkClasspathContainer = updateClasspathContainer(containerPath, sdk,
        description, project, containerSuggestion);
  }

  // Container will be set to null if it could not be resolved which will
  // result in a classpath error for the project.
  JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
      new IClasspathContainer[] {sdkClasspathContainer}, null);
}
 
Example #3
Source File: SdkClasspathContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void initialize(IPath containerPath, final IJavaProject javaProject)
    throws CoreException {
  SdkClasspathContainer<T> sdkClasspathContainer = null;
  final T sdk = resolveSdkFromContainerPath(containerPath, javaProject);
  if (sdk != null) {
    String description = getDescription(containerPath, javaProject);
    sdkClasspathContainer = createClasspathContainer(containerPath, sdk,
        description, javaProject);
  }

  // Container will be set to null if it could not be resolved which will
  // result in a classpath error for the project.
  JavaCore.setClasspathContainer(containerPath,
      new IJavaProject[] {javaProject},
      new IClasspathContainer[] {sdkClasspathContainer}, null);
}
 
Example #4
Source File: ClasspathUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Replace an {@link IClasspathEntry#CPE_CONTAINER} entry with the given
 * container ID, with its corresponding resolved classpath entries.
 *
 * @param javaProject java project
 * @param containerId container ID to replace
 * @return true if a container was replaced
 *
 * @throws JavaModelException
 */
public static boolean replaceContainerWithClasspathEntries(
    IJavaProject javaProject, String containerId) throws JavaModelException {
  IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
  int containerIndex = ClasspathUtilities.indexOfClasspathEntryContainer(
      classpathEntries, containerId);
  if (containerIndex != -1) {
    List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>(
        Arrays.asList(classpathEntries));
    IClasspathEntry classpathContainerEntry = newClasspathEntries.remove(containerIndex);
    IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(
        classpathContainerEntry.getPath(), javaProject);
    if (classpathContainer != null) {
      newClasspathEntries.addAll(containerIndex,
          Arrays.asList(classpathContainer.getClasspathEntries()));
      ClasspathUtilities.setRawClasspath(javaProject, newClasspathEntries);
      return true;
    }
  }
  return false;
}
 
Example #5
Source File: GWTRuntimeContainerInitializerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void testInitialize() throws Exception {
  // Start with gwt-user.jar and gwt-dev-PLAT.jar on the classpath for this
  // test
  removeGWTRuntimeFromTestProject();

  // Add the default GWT runtime to the test project (this implicitly calls
  // the GWTRuntimeContainerInitializer.intialize(...) method.
  IJavaProject project = getTestProject();
  GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(
      project, null, GWTPreferences.getDefaultRuntime(),
      UpdateType.DEFAULT_CONTAINER, null);
  command.execute();
  JobsUtilities.waitForIdle();

  // Verify the bound classpath container
  IClasspathContainer container = JavaCore.getClasspathContainer(
      defaultRuntimePath, project);
  assertEquals(IClasspathContainer.K_APPLICATION, container.getKind());
  assertEquals(defaultRuntimePath, container.getPath());
}
 
Example #6
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void convertContainer(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), project);
		if (container == null) {
			return;
		}

		IClasspathEntry[] entries= container.getClasspathEntries();
		boolean hasChange= false;
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry curr= entries[i];
			IClasspathEntry updatedEntry= getConvertedEntry(curr, project, oldLocationMap);
			if (updatedEntry != null) {
				entries[i]= updatedEntry;
				hasChange= true;
			}
		}
		if (hasChange) {
			BuildPathSupport.requestContainerUpdate(project, container, entries);
		}
	} catch (CoreException e) {
		// ignore
	}
}
 
Example #7
Source File: XtendContainerInitializer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(final IPath containerPath, final IJavaProject project,
		final IClasspathContainer containerSuggestion) throws CoreException {
	super.requestClasspathContainerUpdate(containerPath, project, containerSuggestion);
	new Job("Classpath container update") { //$NON-NLS-1$
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
						new IClasspathContainer[] { containerSuggestion }, monitor);
			} catch (CoreException ex) {
				return new Status(IStatus.ERROR, XtendActivator.getInstance().getBundle().getSymbolicName(), 0,
						"Classpath container update failed", ex); //$NON-NLS-1$
			}
			return Status.OK_STATUS;
		}
	}.schedule();
}
 
Example #8
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isInsideJRE(IJavaElement element) {
	IPackageFragmentRoot root= (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	if (root != null) {
		try {
			IClasspathEntry entry= root.getRawClasspathEntry();
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject());
				return container != null && container.getKind() == IClasspathContainer.K_DEFAULT_SYSTEM;
			}
			return false;
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
		}
	}
	return true; // include JRE in doubt
}
 
Example #9
Source File: JavadocConfigurationPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (initializer == null || container == null) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description);
	return entry;
}
 
Example #10
Source File: NativeLibrariesPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (initializer == null || container == null) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	return entry;
}
 
Example #11
Source File: SourceAttacherJob.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
LibraryClasspathContainer attachSource(IClasspathContainer container) throws Exception {
  if (!(container instanceof LibraryClasspathContainer)) {
    logger.log(Level.FINE, Messages.getString("ContainerClassUnexpected",
        container.getClass().getName(), LibraryClasspathContainer.class.getName()));
    return null;
  }

  LibraryClasspathContainer libraryClasspathContainer = (LibraryClasspathContainer) container;
  IPath sourceArtifactPath = sourceArtifactPathProvider.call();
  List<IClasspathEntry> newClasspathEntries = new ArrayList<>();

  for (IClasspathEntry entry : libraryClasspathContainer.getClasspathEntries()) {
    if (!entry.getPath().equals(libraryPath)) {
      newClasspathEntries.add(entry);
    } else {
      newClasspathEntries.add(JavaCore.newLibraryEntry(
          entry.getPath(), sourceArtifactPath, null /* sourceAttachmentRootPath */,
          entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()));
    }
  }

  return libraryClasspathContainer.copyWithNewEntries(newClasspathEntries);
}
 
Example #12
Source File: SourceAttacherJob.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
  Preconditions.checkState(getRule() != null);
  try {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject);
    LibraryClasspathContainer newContainer = attachSource(container);

    if (newContainer != null) {
      JavaCore.setClasspathContainer(containerPath, new IJavaProject[]{ javaProject },
          new IClasspathContainer[]{ newContainer }, monitor);
      serializer.saveContainer(javaProject, newContainer);
    }
  } catch (Exception ex) {
    // it's not needed to be logged normally
    logger.log(Level.FINE, Messages.getString("SourceAttachmentFailed"), ex);
  }
  return Status.OK_STATUS;  // even if it fails, we should not display an error to the user
}
 
Example #13
Source File: CPUserLibraryElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public CPUserLibraryElement(String name, IClasspathContainer container, IJavaProject project) {
	fName= name;
	fChildren= new ArrayList<CPListElement>();
	if (container != null) {
		IClasspathEntry[] entries= container.getClasspathEntries();
		CPListElement[] res= new CPListElement[entries.length];
		for (int i= 0; i < res.length; i++) {
			IClasspathEntry curr= entries[i];
			CPListElement elem= CPListElement.createFromExisting(this, curr, project);
			//elem.setAttribute(CPListElement.SOURCEATTACHMENT, curr.getSourceAttachmentPath());
			//elem.setAttribute(CPListElement.JAVADOC, JavaUI.getLibraryJavadocLocation(curr.getPath()));
			fChildren.add(elem);
		}
		fIsSystemLibrary= container.getKind() == IClasspathContainer.K_SYSTEM;
	} else {
		fIsSystemLibrary= false;
	}
}
 
Example #14
Source File: CPUserLibraryElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean hasChanges(IClasspathContainer oldContainer) {
	if (oldContainer == null || (oldContainer.getKind() == IClasspathContainer.K_SYSTEM) != fIsSystemLibrary) {
		return true;
	}
	IClasspathEntry[] oldEntries= oldContainer.getClasspathEntries();
	if (fChildren.size() != oldEntries.length) {
		return true;
	}
	for (int i= 0; i < oldEntries.length; i++) {
		CPListElement child= fChildren.get(i);
		if (!child.getClasspathEntry().equals(oldEntries[i])) {
			return true;
		}
	}
	return false;
}
 
Example #15
Source File: NewMavenBasedAppEngineProjectWizardTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
static IClasspathEntry[] getAppEngineServerRuntimeClasspathEntries(IProject project) {
  IJavaProject javaProject = JavaCore.create(project);
  IPath containerPath = new Path(
      "org.eclipse.jst.server.core.container/com.google.cloud.tools.eclipse.appengine.standard.runtimeClasspathProvider");
  try {
    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
          && containerPath.isPrefixOf(entry.getPath())) {
        // resolve and return the entries
        IClasspathContainer container =
            JavaCore.getClasspathContainer(entry.getPath(), javaProject);
        return container.getClasspathEntries();
      }
    }
  } catch (JavaModelException ex) {
    fail(ex.toString());
    /* NOTREACHED */
  }
  fail("AppEngine Server Runtime classpath container not found");
  return null;
}
 
Example #16
Source File: SARLClasspathContainerInitializer.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(
		final IPath containerPath,
		final IJavaProject javaProject,
		final IClasspathContainer containerSuggestion) throws CoreException {
	if (containerSuggestion instanceof SARLClasspathContainer) {
		((SARLClasspathContainer) containerSuggestion).reset();
	}
	super.requestClasspathContainerUpdate(containerPath, javaProject, containerSuggestion);
	final Job job = new Job(Messages.SARLClasspathContainerInitializer_0) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				JavaCore.setClasspathContainer(
						containerPath,
						new IJavaProject[] {javaProject},
						new IClasspathContainer[] {containerSuggestion},
						monitor);
			} catch (CoreException ex) {
				return SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, ex);
			}
			return SARLEclipsePlugin.getDefault().createOkStatus();
		}
	};
	job.schedule();
}
 
Example #17
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void updateContainerClasspath(IJavaProject jproject, IPath containerPath, IClasspathEntry newEntry, String[] changedAttributes, IProgressMonitor monitor) throws CoreException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (container == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Container " + containerPath + " cannot be resolved", null));  //$NON-NLS-1$//$NON-NLS-2$
	}
	IClasspathEntry[] entries= container.getClasspathEntries();
	IClasspathEntry[] newEntries= new IClasspathEntry[entries.length];
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		if (curr.getEntryKind() == newEntry.getEntryKind() && curr.getPath().equals(newEntry.getPath())) {
			newEntries[i]= getUpdatedEntry(curr, newEntry, changedAttributes, jproject);
		} else {
			newEntries[i]= curr;
		}
	}
	requestContainerUpdate(jproject, container, newEntries);
	monitor.worked(1);
}
 
Example #18
Source File: LibraryClasspathContainerInitializerTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialize_ifSerializerReturnsNullContainerResolvedFromScratch()
    throws IOException, CoreException {
  when(serializer.loadContainer(any(IJavaProject.class), any(IPath.class))).thenReturn(null);

  boolean[] called = new boolean[] {false};
  LibraryClasspathContainerInitializer containerInitializer =
      new LibraryClasspathContainerInitializer(TEST_CONTAINER_PATH, serializer, resolverService) {

        @Override
        public void requestClasspathContainerUpdate(
            IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion)
            throws CoreException {
          called[0] = true;
        }
      };
  assertFalse(called[0]);
  containerInitializer.initialize(new Path(TEST_CONTAINER_PATH + "/second.segment"),
                                  testProject.getJavaProject());
  assertTrue(called[0]);
  verifyResolveServiceResolveContainerNotCalled();
}
 
Example #19
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds an entry in a container. <code>null</code> is returned if the entry can not be found
 * @param container 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.
 */
public static IClasspathEntry findEntryInContainer(IClasspathContainer container, IPath libPath) {
	IClasspathEntry[] entries= container.getClasspathEntries();
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr);
		if (resolved != null && libPath.equals(resolved.getPath())) {
			return curr; // return the real entry
		}
	}
	return null; // attachment not possible
}
 
Example #20
Source File: JavaElementLabels.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
	if (container != null) {
		return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(container.getDescription());
	}
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(initializer.getDescription(containerPath, project));
	}
	return BasicElementLabels.getPathLabel(containerPath, false);
}
 
Example #21
Source File: ImportNativeAppEngineStandardProjectTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static boolean hasAppEngineApi(IProject project) throws JavaModelException {
  IJavaProject javaProject = JavaCore.create(project);
  IClasspathContainer masterContainer =
      JavaCore.getClasspathContainer(BuildPath.MASTER_CONTAINER_PATH, javaProject);

  for (IClasspathEntry entry : masterContainer.getClasspathEntries()) {
    if (entry.getPath().lastSegment().startsWith("appengine-api-1.0-sdk")) {
      return true;
    }
  }
  return false;
}
 
Example #22
Source File: JanusClasspathContainerInitializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (CONTAINER_ID.equals(containerPath)) {
		final IClasspathContainer container = new JanusClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath,
				new IJavaProject[] {project},
				new IClasspathContainer[] {container},
				null);
	}
}
 
Example #23
Source File: GWTRuntimeContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected SdkClasspathContainer<GwtSdk> updateClasspathContainer(IPath containerPath, GwtSdk sdk, String description,
    IJavaProject project, IClasspathContainer containerSuggestion) {

  // TODO: Persist the changes to the container

  return new GWTRuntimeContainer(containerPath, sdk, containerSuggestion.getClasspathEntries(), description);
}
 
Example #24
Source File: RuntimeLibraryContainerInitializer.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (!LIBRARY_PATH.equals(containerPath)) {
		return;
	}

	IClasspathContainer container = new RuntimeLibraryContainer(
			containerPath);
	JavaCore.setClasspathContainer(containerPath,
			new IJavaProject[] { project },
			new IClasspathContainer[] { container }, null);
}
 
Example #25
Source File: SARLClasspathContainerInitializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (CONTAINER_ID.equals(containerPath)) {
		final IClasspathContainer container = new SARLClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath,
				new IJavaProject[] {project},
				new IClasspathContainer[] {container},
				null);
	}
}
 
Example #26
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
	if (container != null) {
		return Strings.markLTR(container.getDescription());
	}
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	if (initializer != null) {
		return Strings.markLTR(initializer.getDescription(containerPath, project));
	}
	return BasicElementLabels.getPathLabel(containerPath, false);
}
 
Example #27
Source File: JavaElementLabels.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the styled label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 *
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
		String description= null;
		if (container != null) {
			description= container.getDescription();
		}
		if (description == null) {
			ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
			if (initializer != null) {
				description= initializer.getDescription(containerPath, project);
			}
		}
		if (description != null) {
			StyledString str= new StyledString(description);
			if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
				int index= description.indexOf('[');
				if (index != -1) {
					str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
				}
			}
			return Strings.markLTR(str);
		}
	} catch (JavaModelException e) {
		// ignore
	}
	return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
 
Example #28
Source File: UserLibraryClasspathContainerInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.jdt.core.ClasspathContainerInitializer#requestClasspathContainerUpdate(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathContainer)
 */
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
	if (isUserLibraryContainer(containerPath)) {
		String name = containerPath.segment(1);
		if (containerSuggestion != null) {
			JavaModelManager.getUserLibraryManager().setUserLibrary(name, containerSuggestion.getClasspathEntries(), containerSuggestion.getKind() == IClasspathContainer.K_SYSTEM);
		} else {
			JavaModelManager.getUserLibraryManager().removeUserLibrary(name);
		}
		// update of affected projects was done as a consequence of setUserLibrary() or removeUserLibrary()
	}
}
 
Example #29
Source File: UserLibraryClasspathContainerInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
	if (isUserLibraryContainer(containerPath)) {
		String userLibName = containerPath.segment(1);
		UserLibrary userLibrary = JavaModelManager.getUserLibraryManager().getUserLibrary(userLibName);
		if (userLibrary != null) {
			UserLibraryClasspathContainer container = new UserLibraryClasspathContainer(userLibName);
			JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
		} else if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
			verbose_no_user_library_found(project, userLibName);
		}
	} else if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
		verbose_not_a_user_library(project, containerPath);
	}
}
 
Example #30
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);
	}
}