/** * Updates the content of the Gradle classpath container asynchronously on the target project. * <p/> * This method finds the Gradle classpath container on the project and requests the content * update. * * @throws GradlePluginsRuntimeException if the classpath container update request fails * @param project the target project */ public static void requestUpdateOf(IJavaProject project) { ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(CONTAINER_PATH.toString()); try { initializer.requestClasspathContainerUpdate(CONTAINER_PATH, project, null); } catch (CoreException e) { throw new GradlePluginsRuntimeException(e); } }
/** * Returns the label of a classpath container * @param containerPath The path of the container. * @param project The project the container is resolved in. * @return Returns the label of the classpath container * @throws JavaModelException Thrown when the 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 container.getDescription(); } ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); if (initializer != null) { return initializer.getDescription(containerPath, project); } return containerPath.toString(); }
/** * 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); } }
/** * 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); } }
/** * Request a container update. * @param jproject The project of the container * @param container The container to requesta change to * @param newEntries The updated entries * @throws CoreException */ 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); } }
public String getLabel() { if (fContainer != null) return fContainer.getDescription(); IPath path= fClassPathEntry.getPath(); String containerId= path.segment(0); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerId); if (initializer != null) { String description= initializer.getDescription(path, getJavaProject()); return Messages.format(PackagesMessages.ClassPathContainer_unbound_label, description); } return Messages.format(PackagesMessages.ClassPathContainer_unknown_label, path.toString()); }
/** * 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 }
/** * 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 }
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; }
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; }
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; }
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); } }
/** * 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); } }
@Override public String getLabel() { if (fContainer != null) return fContainer.getDescription(); IPath path= fClassPathEntry.getPath(); String containerId= path.segment(0); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerId); if (initializer != null) { String description= initializer.getDescription(path, getJavaProject()); return Messages.format(PackagesMessages.ClassPathContainer_unbound_label, description); } return Messages.format(PackagesMessages.ClassPathContainer_unknown_label, BasicElementLabels.getPathLabel(path, false)); }
@Override public String getLabel() { if (fContainer != null) return fContainer.getDescription(); IPath path= fClassPathEntry.getPath(); String containerId= path.segment(0); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerId); if (initializer != null) { String description= initializer.getDescription(path, getJavaProject()); return Messages.format(PackagesMessages.ClassPathContainer_unbound_label, description); } return Messages.format(PackagesMessages.ClassPathContainer_unknown_label, BasicElementLabels.getPathLabel(path, false)); }
/** * 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); }
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, containerPath.toString())); 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; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName)); return null; } IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath); Assert.isNotNull(entry); return entry; }
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, containerPath.toString())); 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; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName)); return null; } IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath); Assert.isNotNull(entry); setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description); return entry; }
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; }
private static boolean canModifyAccessRules(IBinding binding) { IJavaElement element= binding.getJavaElement(); if (element == null) return false; IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); if (root == null) return false; try { IClasspathEntry classpathEntry= root.getRawClasspathEntry(); if (classpathEntry == null) return false; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) return true; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0)); IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject()); return status.isOK(); } } catch (JavaModelException e) { return false; } return false; }