Search in sources :

Example 26 with IClasspathAttribute

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);
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 27 with IClasspathAttribute

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;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File)

Example 28 with IClasspathAttribute

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;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 29 with IClasspathAttribute

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));
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 30 with IClasspathAttribute

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();
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject)

Aggregations

IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)52 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)37 IPath (org.eclipse.core.runtime.IPath)26 ArrayList (java.util.ArrayList)17 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 Path (org.eclipse.core.runtime.Path)11 HashMap (java.util.HashMap)9 CoreException (org.eclipse.core.runtime.CoreException)9 IAccessRule (org.eclipse.jdt.core.IAccessRule)9 File (java.io.File)6 LinkedHashMap (java.util.LinkedHashMap)6 IProject (org.eclipse.core.resources.IProject)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 Bundle (org.osgi.framework.Bundle)5 Iterator (java.util.Iterator)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 URL (java.net.URL)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)3