use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.
the class JREContainerInitializer method initialize.
@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
if (containerPath.segment(0).equals(JRE_CONTAINER)) {
IClasspathContainer container = new JREContainer(standardVMType, containerPath, project);
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
}
}
use of org.eclipse.jdt.core.IClasspathContainer in project bndtools by bndtools.
the class BndContainerRuntimeClasspathEntryResolver method resolveRuntimeClasspathEntry.
@Override
public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entryToResolve, IJavaProject entryProject) throws CoreException {
if (entryToResolve == null || entryProject == null) {
return new IRuntimeClasspathEntry[0];
}
final List<IRuntimeClasspathEntry> resolvedRuntimeClasspathEntries = new ArrayList<>();
final IClasspathContainer container = JavaCore.getClasspathContainer(entryToResolve.getPath(), entryProject);
if (container == null) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Could not resolve Bnd classpath container", null));
}
final IClasspathEntry[] classpathEntries = container.getClasspathEntries();
List<IJavaProject> projects = resolvingProjects.get();
Integer count = resolvingCount.get();
if (projects == null) {
projects = new ArrayList<>();
resolvingProjects.set(projects);
count = 0;
}
int intCount = count.intValue();
intCount++;
resolvingCount.set(intCount);
try {
for (IClasspathEntry classpathEntry : classpathEntries) {
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(classpathEntry.getPath().segment(0));
final IJavaProject javaProject = JavaCore.create(project);
if (!projects.contains(javaProject)) {
projects.add(javaProject);
final IRuntimeClasspathEntry2 defaultProjectClasspathEntry = (IRuntimeClasspathEntry2) JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
final IRuntimeClasspathEntry[] projectRuntimeClasspathEntries = defaultProjectClasspathEntry.getRuntimeClasspathEntries(null);
for (IRuntimeClasspathEntry projectRuntimeClasspathEntry : projectRuntimeClasspathEntries) {
// instead of resolving all output locations we simply just return the project runtime classpath entry itself
if (projectRuntimeClasspathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
IResource resource = projectRuntimeClasspathEntry.getResource();
if (resource instanceof IProject) {
resolvedRuntimeClasspathEntries.add(projectRuntimeClasspathEntry);
}
} else {
IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeClasspathEntry, javaProject);
for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
resolvedRuntimeClasspathEntries.add(resolvedEntry);
}
}
}
}
} else {
final IRuntimeClasspathEntry runtimeClasspathEntry = new RuntimeClasspathEntry(classpathEntry);
if (!resolvedRuntimeClasspathEntries.contains(runtimeClasspathEntry)) {
resolvedRuntimeClasspathEntries.add(runtimeClasspathEntry);
}
}
}
} finally {
intCount--;
if (intCount == 0) {
resolvingProjects.set(null);
resolvingCount.set(null);
} else {
resolvingCount.set(intCount);
}
}
for (IRuntimeClasspathEntry resolvedRuntimeClasspathEntry : resolvedRuntimeClasspathEntries) {
resolvedRuntimeClasspathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
}
return resolvedRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[0]);
}
use of org.eclipse.jdt.core.IClasspathContainer in project webtools.sourceediting by eclipse.
the class WebContainerInitializer method initialize.
public void initialize(final IPath containerPath, IJavaProject project) throws CoreException {
if (bundles == null) {
try {
IClasspathEntry servlet = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet")).getAbsolutePath()), null, null);
IClasspathEntry jsp = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet.jsp")).getAbsolutePath()), null, null);
bundles = new IClasspathEntry[] { servlet, jsp };
} catch (Exception e) {
bundles = new IClasspathEntry[0];
System.err.println("Couldn't find a necessary bundle " + e);
e.printStackTrace();
Logger.logException(e);
}
}
IClasspathContainer container = new IClasspathContainer() {
public IPath getPath() {
return containerPath;
}
public int getKind() {
return IClasspathContainer.K_APPLICATION;
}
public String getDescription() {
return "JARs for a Java Web Project";
}
public IClasspathEntry[] getClasspathEntries() {
return bundles;
}
};
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, new NullProgressMonitor());
}
use of org.eclipse.jdt.core.IClasspathContainer in project liferay-ide by liferay.
the class CoreUtil method getClasspathProjects.
public static IProject[] getClasspathProjects(IProject project) {
List<IProject> retval = new ArrayList<>();
try {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpathEntries = getClasspathEntries(project);
for (IClasspathEntry classpathEntry : classpathEntries) {
if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
continue;
}
IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntry.getPath(), javaProject);
IClasspathEntry[] containerClasspathEntries = container.getClasspathEntries();
for (IClasspathEntry containerClasspathEntry : containerClasspathEntries) {
if (containerClasspathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
IResource member = getWorkspaceRoot().findMember(containerClasspathEntry.getPath());
if ((member != null) && (member.getType() == IResource.PROJECT)) {
retval.add((IProject) member);
}
}
}
}
} catch (JavaModelException jme) {
}
return retval.toArray(new IProject[0]);
}
use of org.eclipse.jdt.core.IClasspathContainer in project liferay-ide by liferay.
the class PluginClasspathContainerInitializer method requestClasspathContainerUpdate.
@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
String key = PluginClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());
IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
cpDecorations.clearAllDecorations(key);
for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry = entries[i];
IPath srcpath = entry.getSourceAttachmentPath();
IPath srcrootpath = entry.getSourceAttachmentRootPath();
IClasspathAttribute[] attrs = entry.getExtraAttributes();
if ((srcpath != null) || ListUtil.isNotEmpty(attrs)) {
String eid = entry.getPath().toString();
ClasspathDecorations dec = new ClasspathDecorations();
dec.setSourceAttachmentPath(srcpath);
dec.setSourceAttachmentRootPath(srcrootpath);
dec.setExtraAttributes(attrs);
cpDecorations.setDecorations(key, eid, dec);
}
}
cpDecorations.save();
IPath portalDir = null;
String javadocURL = null;
IPath sourceLocation = null;
if (containerSuggestion instanceof PluginClasspathContainer) {
portalDir = ((PluginClasspathContainer) containerSuggestion).getPortalDir();
javadocURL = ((PluginClasspathContainer) containerSuggestion).getJavadocURL();
sourceLocation = ((PluginClasspathContainer) containerSuggestion).getSourceLocation();
} else {
portalDir = ServerUtil.getPortalDir(project);
try {
ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject());
if (liferayRuntime != null) {
javadocURL = liferayRuntime.getJavadocURL();
sourceLocation = liferayRuntime.getSourceLocation();
}
} catch (Exception e) {
ProjectCore.logError(e);
}
}
if (portalDir != null) {
IClasspathContainer newContainer = getCorrectContainer(containerPath, containerPath.segment(1), project, portalDir, javadocURL, sourceLocation);
IJavaProject[] projects = { project };
IClasspathContainer[] containers = { newContainer };
JavaCore.setClasspathContainer(containerPath, projects, containers, null);
}
}
Aggregations