use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.
the class AbstractLiferayComponentTemplate method createResorcesFolder.
protected void createResorcesFolder(IProject project) throws CoreException {
IFolder resourceFolder = liferayProject.getSourceFolder("resources");
if (FileUtil.exists(resourceFolder)) {
return;
}
IJavaProject javaProject = JavaCore.create(project);
List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
List<IClasspathEntry> newRawClasspath = new ArrayList<>();
IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") };
IPath path = project.getFullPath().append("src/main/resources");
IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(path, new IPath[0], new IPath[0], null, attributes);
newRawClasspath.add(resourcesEntry);
for (IClasspathEntry entry : existingRawClasspath) {
newRawClasspath.add(entry);
}
javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
use of org.eclipse.jdt.core.IClasspathAttribute in project webtools.servertools by eclipse.
the class RuntimeClasspathProviderDelegate method save.
/**
* Save source attachment info.
*/
private synchronized void save() {
List<SourceAttachmentUpdate> srcAttachments = sourceAttachments;
if (srcAttachments == null)
return;
String id = extensionId;
String filename = JavaServerPlugin.getInstance().getStateLocation().append(id + ".xml").toOSString();
try {
XMLMemento memento = XMLMemento.createWriteRoot("classpath");
Iterator iterator = srcAttachments.iterator();
while (iterator.hasNext()) {
SourceAttachmentUpdate sau = (SourceAttachmentUpdate) iterator.next();
IMemento child = memento.createChild("source-attachment");
child.putString("runtime-id", sau.runtimeId);
if (sau.entry != null)
child.putString("entry", sau.entry.toPortableString());
if (sau.sourceAttachmentPath != null)
child.putString("source-attachment-path", sau.sourceAttachmentPath.toPortableString());
if (sau.sourceAttachmentRootPath != null)
child.putString("source-attachment-root-path", sau.sourceAttachmentRootPath.toPortableString());
if (sau.attributes != null) {
for (IClasspathAttribute attr : sau.attributes) {
IMemento attrChild = child.createChild("attribute");
attrChild.putString("name", attr.getName());
attrChild.putString("value", attr.getValue());
}
}
}
memento.saveToFile(filename);
} catch (Exception e) {
if (Trace.SEVERE) {
Trace.trace(Trace.STRING_SEVERE, "Error saving source path info", e);
}
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project webtools.servertools by eclipse.
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) {
rtFolder = "/WEB-INF/classes";
} else {
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 webtools.servertools by eclipse.
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>();
// might be a child of a classpath container.
for (int j = 0; j < entries.length; j++) {
IClasspathAttribute attrib = checkForComponentDependencyAttribute(entries[j], DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_NONDEPENDENCY);
// If not a non-dependency (i.e. not excluded), then add this entry.
if (attrib == null) {
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);
// If the resolvedEntry is not present for this path, then it was excluded above due to being a non-dependency
if (resolvedEntry == null) {
continue;
}
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 webtools.servertools by eclipse.
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;
}
Aggregations