use of org.eclipse.jdt.core.IClasspathAttribute in project webtools.servertools by eclipse.
the class ModuleTraverser method getRawComponentClasspathDependencies.
/*
* Derived from ClasspathDependencyUtil.getRawComponentClasspathDependencies()
*/
private static Map getRawComponentClasspathDependencies(final IJavaProject javaProject) throws CoreException {
if (javaProject == null) {
return Collections.EMPTY_MAP;
}
final Map<IClasspathEntry, IClasspathAttribute> referencedRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>();
final IClasspathEntry[] entries = javaProject.getRawClasspath();
for (int i = 0; i < entries.length; i++) {
final IClasspathEntry entry = entries[i];
final IClasspathAttribute attrib = checkForComponentDependencyAttribute(entry, DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY);
if (attrib != null) {
referencedRawEntries.put(entry, attrib);
}
}
return referencedRawEntries;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class LiferayGradleProject method _createResorcesFolder.
private IFolder _createResorcesFolder(IProject project) {
try {
IJavaProject javaProject = JavaCore.create(project);
List<IClasspathEntry> existingRawClasspath;
existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
List<IClasspathEntry> newRawClasspath = new ArrayList<>();
IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") };
IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null, attributes);
for (IClasspathEntry entry : existingRawClasspath) {
newRawClasspath.add(entry);
}
if (!existingRawClasspath.contains(resourcesEntry)) {
newRawClasspath.add(resourcesEntry);
}
javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
IFolder[] sourceFolders = getSourceFolders();
for (IFolder folder : sourceFolders) {
if (folder.getName().equals("resources")) {
return folder;
}
}
} catch (CoreException ce) {
GradleCore.logError(ce);
}
return null;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class PluginClasspathContainer method createClasspathEntry.
protected IClasspathEntry createClasspathEntry(IPath entryPath, IPath sourceLocation, String javadocURL) {
IPath sourceRootPath = null;
IPath sourcePath = null;
IAccessRule[] rules = {};
IClasspathAttribute[] attrs = new IClasspathAttribute[0];
ClasspathDecorations dec = cpDecorations.getDecorations(getDecorationManagerKey(javaProject.getProject(), getPath().toString()), entryPath.toString());
if (dec != null) {
sourcePath = dec.getSourceAttachmentPath();
sourceRootPath = dec.getSourceAttachmentRootPath();
attrs = dec.getExtraAttributes();
}
if (javadocURL != null) {
if (ListUtil.isEmpty(attrs)) {
attrs = new IClasspathAttribute[] { newJavadocAttr(javadocURL) };
} else {
List<IClasspathAttribute> newAttrs = new ArrayList<>();
for (IClasspathAttribute attr : attrs) {
if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attr.getName())) {
newAttrs.add(newJavadocAttr(javadocURL));
} else {
newAttrs.add(attr);
}
}
attrs = newAttrs.toArray(new IClasspathAttribute[0]);
}
}
if ((sourcePath == null) && (sourceLocation != null)) {
sourcePath = sourceLocation;
}
return JavaCore.newLibraryEntry(entryPath, sourcePath, sourceRootPath, rules, attrs, false);
}
use of org.eclipse.jdt.core.IClasspathAttribute 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);
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class SDKClasspathContainerInitializer method requestClasspathContainerUpdate.
@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
String key = SDKClasspathContainer.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;
IPath portalGlobalDir = null;
String javadocURL = null;
IPath sourceLocation = null;
IPath bundleDir = null;
IPath[] bundleDependencyJarPaths = null;
PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());
boolean containerChanged = true;
if (containerSuggestion instanceof SDKClasspathContainer) {
portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();
if ((bundle != null) && bundle.getAppServerPortalDir().equals(portalDir)) {
containerChanged = false;
}
}
if (containerChanged == true) {
if (bundle == null) {
return;
}
portalDir = bundle.getAppServerPortalDir();
portalGlobalDir = bundle.getAppServerLibGlobalDir();
bundleDependencyJarPaths = bundle.getBundleDependencyJars();
}
IPath[] sdkDependencyPaths = _getSDKDependencies(project);
if ((portalDir != null) && (portalGlobalDir != null)) {
IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths);
IJavaProject[] projects = { project };
IClasspathContainer[] containers = { newContainer };
JavaCore.setClasspathContainer(containerPath, projects, containers, null);
}
}
Aggregations