Search in sources :

Example 96 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project lwjgl by LWJGL.

the class LWJGLClasspathContainerInitializer method rebindClasspathEntries.

private static void rebindClasspathEntries(IJavaModel model, IPath containerPath) throws JavaModelException {
    List<IJavaProject> affectedProjects = new ArrayList<IJavaProject>();
    IJavaProject[] projects = model.getJavaProjects();
    for (int i = 0; i < projects.length; i++) {
        IJavaProject project = projects[i];
        IClasspathEntry[] entries = project.getRawClasspath();
        for (int k = 0; k < entries.length; k++) {
            IClasspathEntry curr = entries[k];
            if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && containerPath.equals(curr.getPath())) {
                affectedProjects.add(project);
            }
        }
    }
    if (!affectedProjects.isEmpty()) {
        IJavaProject[] affected = (IJavaProject[]) affectedProjects.toArray(new IJavaProject[affectedProjects.size()]);
        IClasspathContainer[] containers = new IClasspathContainer[affected.length];
        for (int i = 0; i < containers.length; i++) {
            containers[i] = getNewContainer(containerPath);
        }
        JavaCore.setClasspathContainer(containerPath, affected, containers, null);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 97 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project lwjgl by LWJGL.

the class LWJGLClasspathContainerPage method update.

protected void update() {
    IStatus status = null;
    IClasspathEntry[] libEntries = BuildPathSupport.getLWJGLLibraryEntries();
    IPath containerPath = LWJGLClasspathContainerInitializer.LWJGL_LIBRARY_PATH;
    containerEntryResult = JavaCore.newContainerEntry(containerPath);
    if (libEntries == null) {
        status = new Status(ERROR, Activator.PLUGIN_ID, "No LWJGL library found");
    } else if (labelResolvedPath != null && !labelResolvedPath.isDisposed()) {
        // implies all other labels to be created and not yet disposed
        if (libEntries != null) {
            Set<String> setLines = new TreeSet<String>();
            IPath path;
            for (IClasspathEntry entry : libEntries) {
                path = entry.getPath();
                if (path != null) {
                    setLines.add(getPathLabel(path));
                }
            }
            setLabel(labelResolvedPath, setLines);
            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                path = entry.getSourceAttachmentPath();
                if (path != null) {
                    setLines.add(getPathLabel(path));
                }
            }
            setLabel(labelResolvedSourcePath, setLines);
            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                if (entry.getExtraAttributes() != null) {
                    for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attr.getName())) {
                            setLines.add(attr.getValue());
                            break;
                        }
                        if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) {
                        }
                    }
                }
            }
            setLabel(labelResolvedDocPath, setLines);
            setLines.clear();
            for (IClasspathEntry entry : libEntries) {
                if (entry.getExtraAttributes() != null) {
                    for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                        if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) {
                            setLines.add(attr.getValue());
                        }
                    }
                }
            }
            setLabel(labelNativePath, setLines);
        } else {
            labelResolvedPath.setText("not found");
            labelResolvedSourcePath.setText("not found");
            labelResolvedDocPath.setText("not found");
        }
    }
    if (status != null)
        updateStatus(status);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IStatus(org.eclipse.core.runtime.IStatus) TreeSet(java.util.TreeSet) Set(java.util.Set) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 98 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project azure-tools-for-java by Microsoft.

the class CreateProjectUtil method createResourceStructForLocalRunScalaProject.

private static void createResourceStructForLocalRunScalaProject(IFolder sourceRootFolder, String rootPath, IProject project) throws CoreException {
    copyFileTo(Scala_Local_Run_Sample, rootPath);
    final IFolder dataFolder = sourceRootFolder.getParent().getFolder(new Path("data"));
    if (!dataFolder.exists()) {
        dataFolder.create(false, true, null);
    }
    copyFileTo(Scala_Local_Run_Sample_Data, dataFolder.getLocation().toFile().getAbsolutePath());
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
    System.arraycopy(entries, 0, newEntries, 0, entries.length);
    IPath dataPath = javaProject.getPath().append("data");
    IClasspathEntry dataEntry = JavaCore.newSourceEntry(dataPath, null);
    newEntries[entries.length] = JavaCore.newSourceEntry(dataEntry.getPath());
    javaProject.setRawClasspath(newEntries, null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder)

Example 99 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project azure-tools-for-java by Microsoft.

the class SDKJarsFilter method getClasspathEntries.

/**
     * Returns the classpath entries.
     */
@Override
public IClasspathEntry[] getClasspathEntries() {
    Bundle bundle = Platform.getBundle(Messages.sdkID);
    //Search the available SDKs
    Bundle[] bundles = Platform.getBundles(Messages.sdkID, null);
    List<IClasspathEntry> listEntries = new ArrayList<IClasspathEntry>();
    if (bundles != null) {
        for (Bundle bundle2 : bundles) {
            if (bundle2.getVersion().toString().startsWith(containerPath.segment(1))) {
                bundle = bundle2;
                break;
            }
        }
        //Get the SDK jar.
        URL sdkJar = FileLocator.find(bundle, new Path(Messages.sdkJar), null);
        URL resSdkJar = null;
        IClasspathAttribute[] attr = null;
        try {
            if (sdkJar != null) {
                resSdkJar = FileLocator.resolve(sdkJar);
            //create classpath attribute for java doc, if present
            }
            if (resSdkJar == null) {
                /* if sdk jar is not present then create an place holder
                	for sdk jar so that it would be shown as missing file */
                URL bundleLoc = new URL(bundle.getLocation());
                StringBuffer strBfr = new StringBuffer(bundleLoc.getPath());
                strBfr.append(File.separator).append(Messages.sdkJar);
                URL jarLoc = new URL(strBfr.toString());
                IPath jarPath = new Path(FileLocator.resolve(jarLoc).getPath());
                File jarFile = jarPath.toFile();
                listEntries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()), null, null, null, attr, true));
            } else {
                File directory = new File(resSdkJar.getPath());
                //create the library entry for sdk jar
                listEntries.add(JavaCore.newLibraryEntry(new Path(directory.getAbsolutePath()), null, null, null, attr, true));
                FilenameFilter sdkJarsFilter = new SDKJarsFilter();
                File[] jars = new File(String.format("%s%s%s", directory.getParent(), File.separator, Messages.depLocation)).listFiles(sdkJarsFilter);
                for (int i = 0; i < jars.length; i++) {
                    if (jars[i].getName().contains(Messages.appInsightMng) || jars[i].getName().contains(Messages.adAuth) || jars[i].getName().contains(Messages.srvExp)) {
                    /*
                			 * Do not add them as they are not part of Azure SDK.
                			 * They are just used for coding purpose.
                			 */
                    } else {
                        listEntries.add(JavaCore.newLibraryEntry(new Path(jars[i].getAbsolutePath()), null, null, null, attr, true));
                    }
                }
            }
        } catch (Exception e) {
            listEntries = new ArrayList<IClasspathEntry>();
            Activator.getDefault().log(Messages.excp, e);
        }
    }
    IClasspathEntry[] entries = new IClasspathEntry[listEntries.size()];
    //Return the classpath entries.
    return listEntries.toArray(entries);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) URL(java.net.URL) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 100 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project azure-tools-for-java by Microsoft.

the class ClasspathContainer method getClasspathEntries.

/**
     * Returns the classpath entries.
     */
@Override
public IClasspathEntry[] getClasspathEntries() {
    Bundle bundle = Platform.getBundle(Messages.sdkID);
    //Search the available SDKs
    Bundle[] bundles = Platform.getBundles(Messages.sdkID, null);
    List<IClasspathEntry> listEntries = new ArrayList<IClasspathEntry>();
    if (bundles != null) {
        for (Bundle bundle2 : bundles) {
            if (bundle2.getVersion().toString().startsWith(containerPath.segment(1))) {
                bundle = bundle2;
                break;
            }
        }
        //Get the SDK jar.
        URL sdkJar = FileLocator.find(bundle, new Path(Messages.sdkJar), null);
        URL resSdkJar = null;
        try {
            if (sdkJar != null) {
                resSdkJar = FileLocator.resolve(sdkJar);
            //create classpath attribute for java doc, if present
            }
            if (resSdkJar == null) {
                //if sdk jar is not present then create an place holder
                //for sdk jar so that it would be shown as missing file
                URL bundleLoc = new URL(bundle.getLocation());
                StringBuffer strBfr = new StringBuffer(bundleLoc.getPath());
                strBfr.append(File.separator).append(Messages.sdkJar);
                URL jarLoc = new URL(strBfr.toString());
                IPath jarPath = new Path(FileLocator.resolve(jarLoc).getPath());
                File jarFile = jarPath.toFile();
                listEntries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()), null, null, null, null, true));
            } else {
                File directory = new File(resSdkJar.getPath());
                //create the library entry for sdk jar
                listEntries.add(JavaCore.newLibraryEntry(new Path(directory.getAbsolutePath()), null, null, null, null, true));
            }
        } catch (Exception e) {
            listEntries = new ArrayList<IClasspathEntry>();
            Activator.getDefault().log(Messages.excp, e);
        }
    }
    IClasspathEntry[] entries = new IClasspathEntry[listEntries.size()];
    //Return the classpath entries.
    return listEntries.toArray(entries);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)115 IPath (org.eclipse.core.runtime.IPath)50 IJavaProject (org.eclipse.jdt.core.IJavaProject)40 ArrayList (java.util.ArrayList)34 Path (org.eclipse.core.runtime.Path)25 JavaModelException (org.eclipse.jdt.core.JavaModelException)20 IProject (org.eclipse.core.resources.IProject)17 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 CoreException (org.eclipse.core.runtime.CoreException)11 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 HashMap (java.util.HashMap)9 IResource (org.eclipse.core.resources.IResource)9 IFile (org.eclipse.core.resources.IFile)8 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)6