use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.
the class ExecutionEnvironment method addRules.
/**
* Adds the access rules to each list in the given collection. If the last rule in a
* given collection is the wild card pattern then no more rules are added to that collection.
*
* @param accessRules the list of {@link org.eclipse.jdt.core.IAccessRule}s
* @param collect the array of lists to collect the {@link org.eclipse.jdt.core.IAccessRule}s in
*/
private void addRules(IAccessRule[][] accessRules, ArrayList<List<IAccessRule>> collect) {
for (int i = 0; i < accessRules.length; i++) {
IAccessRule[] libRules = accessRules[i];
List<IAccessRule> list = collect.get(i);
// if the last rule is a **/* pattern, don't add any more rules, as they will have no effect
if (!list.isEmpty()) {
IAccessRule lastRule = list.get(list.size() - 1);
if (lastRule.getPattern().equals(ALL_PATTERN)) {
continue;
}
}
for (int j = 0; j < libRules.length; j++) {
list.add(libRules[j]);
}
}
}
use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.
the class ClasspathEntry method decodeAccessRules.
static IAccessRule[] decodeAccessRules(NodeList list) {
if (list == null)
return null;
int length = list.getLength();
if (length == 0)
return null;
IAccessRule[] result = new IAccessRule[length];
int index = 0;
for (int i = 0; i < length; i++) {
Node accessRule = list.item(i);
if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
Element elementAccessRule = (Element) accessRule;
String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
if (pattern == null)
continue;
String tagKind = elementAccessRule.getAttribute(TAG_KIND);
int kind;
if (TAG_ACCESSIBLE.equals(tagKind))
kind = IAccessRule.K_ACCESSIBLE;
else if (TAG_NON_ACCESSIBLE.equals(tagKind))
kind = IAccessRule.K_NON_ACCESSIBLE;
else if (TAG_DISCOURAGED.equals(tagKind))
kind = IAccessRule.K_DISCOURAGED;
else
continue;
//$NON-NLS-1$
boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER));
result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
}
}
if (index != length)
System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
return result;
}
use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.
the class JREContainer method computeClasspathEntries.
/**
* Computes the classpath entries associated with a VM - one entry per library
* in the context of the given path and project.
*
* @param vm the VM
* @param project the project the resolution is for
* @param environmentId execution environment the resolution is for, or <code>null</code>
* @return classpath entries
*/
private static IClasspathEntry[] computeClasspathEntries(IVMInstallType vm, IJavaProject project, String environmentId) {
//vm.getLibraryLocations();
LibraryLocation[] libs = null;
boolean overrideJavaDoc = false;
if (libs == null) {
libs = getLibraryLocations(vm);
overrideJavaDoc = true;
}
IAccessRule[][] rules = null;
// if (environmentId != null) {
// compute access rules for execution environment
IExecutionEnvironment environment = JavaRuntime.getEnvironment(environmentId);
if (environment != null) {
rules = environment.getAccessRules(vm, libs, project);
}
// }
RuleKey key = null;
if (vm != null && rules != null && environmentId != null) {
key = new RuleKey(vm, environmentId);
RuleEntry entry = fgClasspathEntriesWithRules.get(key);
if (entry != null && entry.equals(rules)) {
return entry.getClasspathEntries();
}
}
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(libs.length);
for (int i = 0; i < libs.length; i++) {
if (!libs[i].getSystemLibraryPath().isEmpty()) {
IPath sourcePath = libs[i].getSystemLibrarySourcePath();
if (sourcePath.isEmpty()) {
sourcePath = null;
}
IPath rootPath = libs[i].getPackageRootPath();
if (rootPath.isEmpty()) {
rootPath = null;
}
// construct the classpath attributes for this library location
IClasspathAttribute[] attributes = JREContainer.buildClasspathAttributes(vm, libs[i], overrideJavaDoc);
IAccessRule[] libRules = null;
if (rules != null) {
libRules = rules[i];
} else {
libRules = EMPTY_RULES;
}
entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, libRules, attributes, false));
}
}
IClasspathEntry[] cpEntries = entries.toArray(new IClasspathEntry[entries.size()]);
if (key != null && rules != null) {
fgClasspathEntriesWithRules.put(key, new RuleEntry(rules, cpEntries));
}
return cpEntries;
}
use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.
the class ClasspathEntryHelper method setClasspathEntry.
//Copied from org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor
private void setClasspathEntry(IClasspathEntry entry) {
this.kind = entry.getEntryKind();
this.path = entry.getPath();
this.exported = entry.isExported();
this.outputLocation = entry.getOutputLocation();
this.accessRules = new ArrayList<>();
for (IAccessRule rule : entry.getAccessRules()) {
this.accessRules.add(rule);
}
this.attributes = new HashMap<>();
for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
attributes.put(attribute.getName(), attribute.getValue());
}
this.sourcePath = entry.getSourceAttachmentPath();
this.sourceRootPath = entry.getSourceAttachmentRootPath();
setInclusionPatterns(entry.getInclusionPatterns());
setExclusionPatterns(entry.getExclusionPatterns());
this.combineAccessRules = entry.combineAccessRules();
String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE);
String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE);
String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE);
String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE);
String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE);
if (groupId != null && artifactId != null && version != null) {
this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier);
}
}
use of org.eclipse.jdt.core.IAccessRule in project che by eclipse.
the class ClasspathEntryHelper method toClasspathEntry.
//Copied from org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor
public IClasspathEntry toClasspathEntry() {
Map<String, String> attributes = new HashMap<String, String>(this.attributes);
if (artifactKey != null) {
attributes.put(ClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId());
attributes.put(ClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId());
attributes.put(ClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion());
attributes.put(ClasspathManager.PACKAGING_ATTRIBUTE, artifactKey.getPackaging());
if (artifactKey.getClassifier() != null) {
attributes.put(ClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier());
}
}
IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()];
int attributeIndex = 0;
for (Map.Entry<String, String> attribute : attributes.entrySet()) {
attributesArray[attributeIndex++] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue());
}
IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]);
IClasspathEntry entry;
switch(kind) {
case IClasspathEntry.CPE_CONTAINER:
entry = //
JavaCore.newContainerEntry(//
path, //
accessRulesArray, //
attributesArray, exported);
break;
case IClasspathEntry.CPE_LIBRARY:
entry = //
JavaCore.newLibraryEntry(//
path, //
sourcePath, //
sourceRootPath, //
accessRulesArray, //
attributesArray, exported);
break;
case IClasspathEntry.CPE_SOURCE:
entry = //
JavaCore.newSourceEntry(//
path, //
getInclusionPatterns(), //
getExclusionPatterns(), //
outputLocation, attributesArray);
break;
case IClasspathEntry.CPE_PROJECT:
entry = //
JavaCore.newProjectEntry(//
path, //
accessRulesArray, //
combineAccessRules, //
attributesArray, exported);
break;
case IClasspathEntry.CPE_VARIABLE:
entry = //
JavaCore.newVariableEntry(//
path, //
sourcePath, //
sourceRootPath, //
accessRulesArray, //
attributesArray, exported);
break;
default:
//$NON-NLS-1$
throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + kind);
}
return entry;
}
Aggregations