Example usage for org.eclipse.jdt.core IJavaProject setRawClasspath

List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject setRawClasspath.

Prototype

void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;

Source Link

Document

Sets the classpath of this project using a list of classpath entries.

Usage

From source file:org.eclipse.gmt.mod.infra.common.core.internal.utils.ProjectUtils.java

License:Open Source License

public static void addPdeClassPath(final IProject project) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] oldClassPath = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : oldClassPath) {
        if (classpathEntry.getPath().equals(new Path("org.eclipse.pde.core.requiredPlugins"))) { //$NON-NLS-1$
            return;
        }/*from   w  w  w  .j  a va2  s. co  m*/
    }
    IClasspathEntry[] newClassPath = new IClasspathEntry[oldClassPath.length + 1];
    System.arraycopy(oldClassPath, 0, newClassPath, 0, oldClassPath.length);
    newClassPath[oldClassPath.length] = JavaCore
            .newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")); //$NON-NLS-1$
    javaProject.setRawClasspath(newClassPath, new NullProgressMonitor());
}

From source file:org.eclipse.gmt.mod.infra.common.core.internal.utils.ProjectUtils.java

License:Open Source License

/**
 * @author Gregoire DUPE (Mia-Software) - classpath entries modification
 */// w  ww . ja  v  a  2  s .  c  o m
public static void configureAsJavaProject(final IProject project, final IProgressMonitor monitor)
        throws CoreException {
    addNature(project, monitor, JavaCore.NATURE_ID);
    IJavaProject javaProject = JavaCore.create(project);
    // Set output folder
    IPath path = project.getFullPath().append("bin"); //$NON-NLS-1$
    javaProject.setOutputLocation(path, null);
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    // Set source folder
    IFolder sourceFolder = project.getFolder("src"); //$NON-NLS-1$
    if (!sourceFolder.exists()) {
        sourceFolder.create(false, true, monitor);
        classpathEntries.add(JavaCore.newSourceEntry(javaProject.getPath().append(new Path("src")))); //$NON-NLS-1$
    }
    Path jrePath = new Path(
            JavaRuntime.JRE_CONTAINER + "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/" //$NON-NLS-1$
                    + JAVA_VERSION);
    boolean hasJrePath = false;
    IClasspathEntry[] existingClassPath = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : existingClassPath) {
        if (jrePath.equals(classpathEntry.getPath())) {
            hasJrePath = true;
        }
    }
    if (!hasJrePath) {
        // add the jre api to the classpath
        classpathEntries.add(JavaCore.newContainerEntry(jrePath));
        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor);
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Touch classpath. It simply takes the classpath and sets it back in.
 * /*from   www  .  j  av a 2  s .c  o m*/
 * @param javaProject
 * @throws JavaModelException
 * 
 * @since 1.0.0
 */
public static void updateClasspath(IJavaProject javaProject) throws JavaModelException {
    if (javaProject != null)
        javaProject.setRawClasspath(javaProject.getRawClasspath(), new NullProgressMonitor());
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Remove the classpath entry from the project's classpath.
 * /*from   ww w . ja va  2 s  .  c o  m*/
 * @param p
 * @param entry
 * @throws JavaModelException
 * 
 * @since 1.0.0
 */
public static void removeFromJavaClassPath(IProject p, IClasspathEntry entry) throws JavaModelException {
    IJavaProject javaProject = null;
    try {
        javaProject = (IJavaProject) p.getNature(JavaCore.NATURE_ID);
    } catch (CoreException ignore) {
    }
    if (javaProject != null) {
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        javaProject.setRawClasspath(primRemoveFromJavaClassPath(classpath, entry), new NullProgressMonitor());
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Remove the list of entries from the classpath of the project.
 * //from w  ww .j av a2  s. c  om
 * @param p
 *            project
 * @param entries
 *            list of IClassPathEntry's
 * @throws JavaModelException
 * 
 * @since 1.0.0
 */
public static void removeFromJavaClassPath(IProject p, List entries) throws JavaModelException {
    IJavaProject javaProject = null;
    try {
        javaProject = (IJavaProject) p.getNature(JavaCore.NATURE_ID);
    } catch (CoreException ignore) {
    }
    if (javaProject != null) {
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        javaProject.setRawClasspath(primRemoveFromJavaClassPath(classpath, entries), new NullProgressMonitor());
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Append to java class path./*from w ww.  j  a va 2  s .c  om*/
 * <p>
 * Append a list of IClasspathEntry's to the build path of the passed project. Updated to remove existing occurrences of the passed entries before
 * appending.
 * </p>
 * 
 * @param p
 *            project
 * @param appendClasspathEntries
 *            list of entries
 * @throws JavaModelException
 * 
 * @since 1.0.0
 */
public static void appendJavaClassPath(IProject p, List appendClasspathEntries) throws JavaModelException {
    IJavaProject javaProject = null;
    try {
        javaProject = (IJavaProject) p.getNature(JavaCore.NATURE_ID);
    } catch (CoreException ignore) {
    }
    if (javaProject != null) {
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        List newPathList = new ArrayList(classpath.length);
        for (int i = 0; i < classpath.length; i++) {
            IClasspathEntry entry = classpath[i];
            // Skip entries which are in the append list
            if (appendClasspathEntries.indexOf(entry) < 0)
                newPathList.add(entry);
        }
        newPathList.addAll(appendClasspathEntries);
        IClasspathEntry[] newClasspath = (IClasspathEntry[]) newPathList
                .toArray(new IClasspathEntry[newPathList.size()]);
        javaProject.setRawClasspath(newClasspath, new NullProgressMonitor());
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Append classpath entry./*from  ww  w. j  ava 2 s .  c  o m*/
 * <p>
 * Append one IClasspathEntry to the build path of the passed project. If a classpath entry having the same path as the parameter already exists,
 * then does nothing.
 * </p>
 * 
 * @param p
 *            Project
 * @param newEntry
 *            Entry
 * @throws JavaModelException
 * 
 * @since 1.0.0
 */
public static void appendJavaClassPath(IProject p, IClasspathEntry newEntry) throws JavaModelException {
    IJavaProject javaProject = getJavaProject(p);
    if (javaProject == null)
        return;
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List newPathList = new ArrayList(classpath.length);
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        // fix dup class path entry for .JETEmitter project
        // Skip the entry to be added if it already exists
        if (Platform.getOS().equals(Platform.OS_WIN32)) {
            if (!entry.getPath().toString().equalsIgnoreCase(newEntry.getPath().toString()))
                newPathList.add(entry);
            else
                return;
        } else {
            if (!entry.getPath().equals(newEntry.getPath()))
                newPathList.add(entry);
            else
                return;
        }
    }
    newPathList.add(newEntry);
    IClasspathEntry[] newClasspath = (IClasspathEntry[]) newPathList
            .toArray(new IClasspathEntry[newPathList.size()]);
    javaProject.setRawClasspath(newClasspath, new NullProgressMonitor());
}

From source file:org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDelegate.java

License:Open Source License

private void addClasspathEntryToProject(IClasspathEntry classpathEntry, IJavaProject javaProject,
        IProgressMonitor monitor) throws CoreException {

    // add the classpath entry to the classpath if it is not already present
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    if (!ArrayTools.contains(classpath, classpathEntry)) {
        javaProject.setRawClasspath(ArrayTools.add(classpath, classpathEntry), monitor);
    }/*  w w  w  .j  av a2 s.  c om*/
}

From source file:org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory.java

License:Open Source License

private void addClasspathEntry(IJavaProject javaProject, IClasspathEntry entry) throws JavaModelException {
    javaProject.setRawClasspath(ArrayTools.add(javaProject.getRawClasspath(), entry), null);
}

From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java

License:Open Source License

public static void setProjectClasspath(final IJavaProject project, final List<IClasspathEntry> cp)

        throws CoreException

{
    validateClasspathEdit(project);//from w w  w  . j  av  a2 s  .co m
    project.setRawClasspath(cp.toArray(new IClasspathEntry[cp.size()]), null);
}