use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class ModuleTraverser method getComponentClasspathDependencies.
/*
* Derived from ClasspathDependencyUtil.getComponentClasspathDependencies()
*/
private static Map getComponentClasspathDependencies(final IJavaProject javaProject, final boolean isWebApp) throws CoreException {
// get the raw entries
final Map referencedRawEntries = getRawComponentClasspathDependencies(javaProject);
final Map<IClasspathEntry, IClasspathAttribute> validRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>();
// filter out non-valid referenced raw entries
final Iterator i = referencedRawEntries.keySet().iterator();
while (i.hasNext()) {
final IClasspathEntry entry = (IClasspathEntry) i.next();
final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry);
if (isValid(entry, attrib, isWebApp, javaProject.getProject())) {
validRawEntries.put(entry, attrib);
}
}
// if we have no valid raw entries, return empty map
if (validRawEntries.isEmpty()) {
return Collections.EMPTY_MAP;
}
// XXX Would like to replace the code below with use of a public JDT API that returns
// the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995)
// The code must currently leverage IPackageFragmentRoot to determine this
// mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior
// call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to
// support retrieval using the resolved IPackageFragmentRoot
// retrieve the resolved classpath
final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
final Map<IPath, IClasspathEntry> pathToResolvedEntry = new HashMap<IPath, IClasspathEntry>();
// store in a map from path to entry
for (int j = 0; j < entries.length; j++) {
pathToResolvedEntry.put(entries[j].getPath(), entries[j]);
}
final Map<IClasspathEntry, IClasspathAttribute> referencedEntries = new LinkedHashMap<IClasspathEntry, IClasspathAttribute>();
// grab all IPackageFragmentRoots
final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
for (int j = 0; j < roots.length; j++) {
final IPackageFragmentRoot root = roots[j];
final IClasspathEntry rawEntry = root.getRawClasspathEntry();
// is the raw entry valid?
IClasspathAttribute attrib = validRawEntries.get(rawEntry);
if (attrib == null) {
continue;
}
final IPath pkgFragPath = root.getPath();
final IClasspathEntry resolvedEntry = pathToResolvedEntry.get(pkgFragPath);
final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry, DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY);
// dependency attribute for it to be included
if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) {
// filter out resolved entry if it doesn't pass the validation rules
if (isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp, javaProject.getProject())) {
if (resolvedAttrib != null) {
// if there is an attribute on the sub-entry, use that
attrib = resolvedAttrib;
}
referencedEntries.put(resolvedEntry, attrib);
}
}
}
return referencedEntries;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class ModuleTraverser method traverseWebComponentLocalEntries.
private static void traverseWebComponentLocalEntries(WorkbenchComponent comp, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException {
IProject warProject = StructureEdit.getContainingProject(comp);
if (warProject == null || !warProject.hasNature(JavaCore.NATURE_ID)) {
return;
}
IJavaProject project = JavaCore.create(warProject);
List res = comp.getResources();
for (Iterator itorRes = res.iterator(); itorRes.hasNext(); ) {
ComponentResource childComp = (ComponentResource) itorRes.next();
IClasspathEntry cpe = getClasspathEntry(project, childComp.getSourcePath());
if (cpe == null)
continue;
visitor.visitWebResource(childComp.getRuntimePath(), getOSPath(warProject, project, cpe.getOutputLocation()));
}
// Include tagged classpath entries
Map classpathDeps = getComponentClasspathDependencies(project, true);
for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext(); ) {
IClasspathEntry entry = (IClasspathEntry) iterator.next();
IClasspathAttribute attrib = (IClasspathAttribute) classpathDeps.get(entry);
boolean isClassFolder = isClassFolderEntry(entry);
String rtFolder = attrib.getValue();
if (rtFolder == null) {
if (isClassFolder) {
// $NON-NLS-1$
rtFolder = "/WEB-INF/classes";
} else {
// $NON-NLS-1$
rtFolder = "/WEB-INF/lib";
}
}
IPath entryPath = entry.getPath();
IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
if (entryRes != null) {
entryPath = entryRes.getLocation();
}
// TODO Determine if different handling is needed for some use cases
if (isClassFolder) {
visitor.visitWebResource(new Path(rtFolder), getOSPath(warProject, project, entry.getPath()));
} else {
visitor.visitArchiveComponent(new Path(rtFolder), entryPath);
}
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class ModuleTraverser method checkForComponentDependencyAttribute.
/*
* Derived from ClasspathDependencyUtil.checkForComponentDependencyAttribute()
*/
private static IClasspathAttribute checkForComponentDependencyAttribute(final IClasspathEntry entry, final int attributeType) {
if (entry == null) {
return null;
}
final IClasspathAttribute[] attributes = entry.getExtraAttributes();
for (int i = 0; i < attributes.length; i++) {
final IClasspathAttribute attribute = attributes[i];
final String name = attribute.getName();
if (name.equals(CLASSPATH_COMPONENT_DEPENDENCY)) {
if (attributeType == DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY || attributeType == DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY) {
return attribute;
}
} else if (name.equals(CLASSPATH_COMPONENT_NON_DEPENDENCY)) {
if (attributeType == DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY || attributeType == DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_NONDEPENDENCY) {
return attribute;
}
}
}
return null;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
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 ProjectUtil method _fixExtProjectClasspathEntries.
private static void _fixExtProjectClasspathEntries(IProject project) {
try {
boolean fixedAttr = false;
IJavaProject javaProject = JavaCore.create(project);
List<IClasspathEntry> newEntries = new ArrayList<>();
IClasspathEntry[] entries = javaProject.getRawClasspath();
for (IClasspathEntry entry : entries) {
IClasspathEntry newEntry = null;
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
List<IClasspathAttribute> newAttrs = new ArrayList<>();
IClasspathAttribute[] attrs = entry.getExtraAttributes();
if (ListUtil.isNotEmpty(attrs)) {
for (IClasspathAttribute attr : attrs) {
IClasspathAttribute newAttr = null;
if ("owner.project.facets".equals(attr.getName()) && "liferay.plugin".equals(attr.getValue())) {
newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext");
fixedAttr = true;
} else {
newAttr = attr;
}
newAttrs.add(newAttr);
}
newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttrs.toArray(new IClasspathAttribute[0]));
}
}
if (newEntry == null) {
newEntry = entry;
}
newEntries.add(newEntry);
}
if (fixedAttr) {
IProgressMonitor monitor = new NullProgressMonitor();
javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor);
try {
javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (Exception e) {
ProjectCore.logError(e);
}
}
fixExtProjectSrcFolderLinks(project);
} catch (Exception ex) {
ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex);
}
}
Aggregations