use of org.eclipse.jdt.core.IClasspathAttribute in project azure-tools-for-java by Microsoft.
the class ClasspathContainerPage method configureClasspathEntries.
/**
* Method adds entries into .classpath file.
*/
private void configureClasspathEntries() {
IJavaProject proj1 = JavaCore.create(getSelectedProject());
IClasspathEntry[] entries;
try {
entries = proj1.getRawClasspath();
IClasspathEntry[] newentries = new IClasspathEntry[entries.length];
for (int i = 0; i < entries.length; i++) {
if (entries[i].toString().contains(Messages.containerID)) {
if (depCheck.getSelection()) {
IClasspathAttribute[] attr = new IClasspathAttribute[1];
attr[0] = JavaCore.newClasspathAttribute(Messages.jstDep, "/WEB-INF/lib");
newentries[i] = JavaCore.newContainerEntry(entry, null, attr, true);
} else {
newentries[i] = JavaCore.newContainerEntry(entry);
}
} else {
newentries[i] = entries[i];
}
}
proj1.setRawClasspath(newentries, null);
} catch (Exception e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project bndtools by bndtools.
the class BndContainerSourceManager method loadAttachedSources.
/**
* Return (a potentially modified) list of {@link IClasspathEntry} instances that will have any previously persisted
* attached sources added.
*/
public static List<IClasspathEntry> loadAttachedSources(final IProject project, final List<IClasspathEntry> classPathEntries) throws CoreException {
if (classPathEntries.isEmpty()) {
return classPathEntries;
}
final Properties props = loadSourceAttachmentProperties(project);
final List<IClasspathEntry> configuredClassPathEntries = new ArrayList<IClasspathEntry>(classPathEntries.size());
for (final IClasspathEntry entry : classPathEntries) {
if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY || entry.getSourceAttachmentPath() != null) {
configuredClassPathEntries.add(entry);
continue;
}
final String key = entry.getPath().toPortableString();
IPath srcPath = null;
IPath srcRoot = null;
// Retrieve the saved source attachment information
if (props != null && props.containsKey(key + PROPERTY_SRC_PATH)) {
srcPath = Path.fromPortableString((String) props.get(key + PROPERTY_SRC_PATH));
if (props.containsKey(key + PROPERTY_SRC_ROOT)) {
srcRoot = Path.fromPortableString((String) props.get(key + PROPERTY_SRC_ROOT));
}
} else {
// If there is no saved source attachment, then try and find a source bundle
Map<String, String> extraProps = new HashMap<String, String>();
for (IClasspathAttribute attr : entry.getExtraAttributes()) {
extraProps.put(attr.getName(), attr.getValue());
}
File sourceBundle = getSourceBundle(entry.getPath(), extraProps);
if (sourceBundle != null) {
srcPath = new Path(sourceBundle.getAbsolutePath());
}
}
if (srcPath != null || srcRoot != null) {
configuredClassPathEntries.add(JavaCore.newLibraryEntry(entry.getPath(), srcPath, srcRoot, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()));
} else {
configuredClassPathEntries.add(entry);
}
}
return configuredClassPathEntries;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project lwjgl by LWJGL.
the class BuildPathSupport method getLWJGLLibraryEntries.
public static IClasspathEntry[] getLWJGLLibraryEntries() {
IPath bundleBase = getBundleLocation(LWJGL_PLUGIN);
if (bundleBase != null) {
IClasspathEntry[] entries = new IClasspathEntry[JAR_FILES.length];
for (int i = 0; i < JAR_FILES.length; i++) {
// $NON-NLS-1$
IPath jarLocation = bundleBase.append(JAR_FILES[i]);
IPath srcLocation = getSourceLocation(SRC_FILES[i]);
String nativeLocation = getNativeLocation();
String javadocLocation = getJavadocLocation(DOC_FILES[i]);
IAccessRule[] accessRules = {};
IClasspathAttribute[] attributes = { //
JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation), JavaCore.newClasspathAttribute(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY, nativeLocation) };
// return JavaCore.newClasspathAttribute(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY, dialog.getNativeLibraryPath());
entries[i] = JavaCore.newLibraryEntry(jarLocation, srcLocation, null, accessRules, attributes, false);
}
return entries;
}
return null;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project xtext-xtend by eclipse.
the class XtendClasspathContainer method addEntry.
private void addEntry(final List<IClasspathEntry> cpEntries, final String bundleId) {
Bundle bundle = Platform.getBundle(bundleId);
if (bundle != null) {
IPath bundlePath = bundlePath(bundle);
IPath sourceBundlePath = calculateSourceBundlePath(bundle, bundlePath);
IClasspathAttribute[] extraAttributes = null;
if (XtendClasspathContainer.XTEXT_XBASE_LIB_BUNDLE_ID.equals(bundleId) || XtendClasspathContainer.XTEND_LIB_BUNDLE_ID.equals(bundleId) || XtendClasspathContainer.XTEND_LIB_MACRO_BUNDLE_ID.equals(bundleId)) {
extraAttributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, calculateJavadocURL()) };
}
cpEntries.add(JavaCore.newLibraryEntry(bundlePath, sourceBundlePath, null, new IAccessRule[] {}, extraAttributes, false));
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImplTest method newModularProject.
private IJavaProject newModularProject(String projectName) throws CoreException, JavaModelException, InvocationTargetException, InterruptedException {
AtomicReference<IJavaProject> result = new AtomicReference<IJavaProject>();
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
IProject project = JavaProjectSetupUtil.createSimpleProject(projectName);
JavaCore.initializeAfterLoad(monitor());
IJavaProject javaProject = JavaCore.create(project);
javaProject.save(null, true);
result.set(javaProject);
addNature(project, JavaCore.NATURE_ID);
JavaProjectSetupUtil.addSourceFolder(javaProject, "src", false);
JavaProjectSetupUtil.addJreClasspathEntry(javaProject, JavaVersion.JAVA11.getBree());
IClasspathEntry defaultEntry = JavaProjectSetupUtil.getJreContainerClasspathEntry(javaProject);
if (defaultEntry == null) {
// Oxygen: No JRE11 available
result.set(null);
return;
}
if (isModular(defaultEntry)) {
return;
}
IClasspathEntry newEntry = JavaCore.newContainerEntry(defaultEntry.getPath(), defaultEntry.getAccessRules(), new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") }, defaultEntry.isExported());
IClasspathEntry[] array = javaProject.getRawClasspath();
for (int i = 0; i < array.length; i++) {
if (array[i] == defaultEntry) {
array[i] = newEntry;
break;
}
}
javaProject.setRawClasspath(array, null);
assertTrue(isModular(JavaProjectSetupUtil.getJreContainerClasspathEntry(javaProject)));
}
}.run(null);
return result.get();
}
Aggregations