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.codehaus.groovy.eclipse.core.model.GroovyRuntime.java

License:Apache License

/**
 * Removes a classpath entry to a project
 *
 * @param project//w w w  . j a v  a  2s .  co m
 *            The project to remove the entry.
 * @param newEntry
 *            The entry to remove.
 * @throws JavaModelException
 */
public static void removeClassPathEntry(IJavaProject project, IClasspathEntry newEntry)
        throws JavaModelException {
    IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.removeElement(project.getRawClasspath(),
            newEntry);
    project.setRawClasspath(newEntries, null);
}

From source file:org.codehaus.groovy.eclipse.refactoring.test.RefactoringTest.java

License:Open Source License

private void restoreTestProject() throws Exception {
    IJavaProject javaProject = getRoot().getJavaProject();
    if (javaProject.exists()) {
        IClasspathEntry srcEntry = getRoot().getRawClasspathEntry();
        try {/*www.  j ava2 s .c  o  m*/
            IClasspathEntry[] jreEntries = RefactoringTestSetup.getJRELibrariesAsRawClasspathEntry();
            IClasspathEntry[] cpes = javaProject.getRawClasspath();
            ArrayList newCPEs = new ArrayList();
            boolean cpChanged = false;
            for (int i = 0; i < cpes.length; i++) {
                IClasspathEntry cpe = cpes[i];
                boolean isJREEntry = false;
                for (int j = 0; j < jreEntries.length; j++) {
                    if (cpe.equals(jreEntries[j])) {
                        isJREEntry = true;
                        break;
                    }
                }
                if (cpe.equals(srcEntry) || isJREEntry) {
                    newCPEs.add(cpe);
                } else {
                    cpChanged = true;
                }
            }
            if (cpChanged) {
                IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs
                        .toArray(new IClasspathEntry[newCPEs.size()]);
                javaProject.setRawClasspath(newCPEsArray, null);
            }
        } catch (JavaModelException e) {
            System.err.println(
                    "Exception thrown when trying to restore project to original state.  We can probable ignore this.");
            e.printStackTrace();
        }

        Object[] nonJavaResources = javaProject.getNonJavaResources();
        for (int i = 0; i < nonJavaResources.length; i++) {
            Object kid = nonJavaResources[i];
            if (kid instanceof IResource) {
                IResource resource = (IResource) kid;
                if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) {
                    JavaProjectHelper.delete(resource);
                }
            }
        }
    }
}

From source file:org.codehaus.groovy.eclipse.test.TestProject.java

License:Apache License

public static void setClasspath(IProject project, IClasspathEntry[] entries) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    javaProject.setRawClasspath(entries, null);
}

From source file:org.drools.eclipse.wizard.project.NewDroolsProjectWizard.java

License:Apache License

private void setClasspath(IJavaProject project, IProgressMonitor monitor)
        throws JavaModelException, CoreException {
    project.setRawClasspath(new IClasspathEntry[0], monitor);
    addSourceFolders(project, monitor);/*  w w w .j  a va 2 s  .c om*/
    addJRELibraries(project, monitor);
    addDroolsLibraries(project, monitor);
}

From source file:org.drools.eclipse.wizard.project.NewDroolsProjectWizard.java

License:Apache License

private void addSourceFolders(IJavaProject project, IProgressMonitor monitor)
        throws JavaModelException, CoreException {
    List list = new ArrayList();
    list.addAll(Arrays.asList(project.getRawClasspath()));
    addSourceFolder(project, list, "src/main/java", monitor);
    addSourceFolder(project, list, "src/main/rules", monitor);
    project.setRawClasspath((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]), null);
}

From source file:org.drools.eclipse.wizard.project.NewDroolsProjectWizard.java

License:Apache License

private void addJRELibraries(IJavaProject project, IProgressMonitor monitor) throws JavaModelException {
    List list = new ArrayList();
    list.addAll(Arrays.asList(project.getRawClasspath()));
    list.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));
    project.setRawClasspath((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]), monitor);
}

From source file:org.drools.eclipse.wizard.project.NewDroolsProjectWizard.java

License:Apache License

public static void addDroolsLibraries(IJavaProject project, IProgressMonitor monitor)
        throws JavaModelException {
    createDroolsLibraryContainer(project, monitor);
    List list = new ArrayList();
    list.addAll(Arrays.asList(project.getRawClasspath()));
    list.add(JavaCore.newContainerEntry(getClassPathContainerPath()));
    project.setRawClasspath((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]), monitor);
}

From source file:org.dslforge.xtext.generator.DynamicWebProjectFactory.java

License:Open Source License

public void convertToJava(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    try {/* w w w.  j  a v a 2s  .  c  om*/
        IProject project = this.configuration.getProject();
        IJavaProject javaProject = JavaCore.create(project);
        javaProject.setOutputLocation(project.getFolder(BIN).getFullPath(), progress.newChild(1));
        IClasspathEntry[] entries = new IClasspathEntry[5];
        ClasspathComputer.setComplianceOptions(javaProject, JRE_VERSION);
        entries[0] = ClasspathComputer.createJREEntry(JRE_VERSION);
        entries[1] = ClasspathComputer.createContainerEntry();
        entries[2] = JavaCore.newSourceEntry(project.getFolder(SRC).getFullPath());
        entries[3] = JavaCore.newSourceEntry(project.getFolder(SRC_GEN).getFullPath());
        entries[4] = JavaCore.newSourceEntry(project.getFolder(SRC_JS).getFullPath());
        javaProject.setRawClasspath(entries, progress.newChild(1));
    } catch (CoreException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.dyno.visual.swing.base.JavaUtil.java

License:Open Source License

public static boolean setupLayoutLib(IJavaProject javaProject, IProgressMonitor monitor) {
    if (javaProject != null) {
        try {/*from  www . j a v a 2  s .  c o m*/
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            boolean layout_exists = false;
            for (IClasspathEntry entry : entries) {
                if (entry.getPath().equals(VS_LAYOUTEXT))
                    layout_exists = true;
            }
            if (!layout_exists) {
                IClasspathEntry varEntry = JavaCore.newContainerEntry(VS_LAYOUTEXT, false);
                IClasspathEntry[] newClasspath = new IClasspathEntry[entries.length + 1];
                System.arraycopy(entries, 0, newClasspath, 0, entries.length);
                newClasspath[entries.length] = varEntry;
                javaProject.setRawClasspath(newClasspath, monitor);
            }
        } catch (Exception e) {
            VisualSwingPlugin.getLogger().error(e);
            return false;
        }
    }
    return true;
}

From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.buildsystem.core.ErrorLibraryBuildSystemConfigurer.java

License:Open Source License

/**
 * Reorder classpath.// ww w.  ja v  a 2s.  c o  m
 *
 * @param project the project
 * @param monitor the monitor
 * @throws JavaModelException the java model exception
 */
public static void reorderClasspath(IProject project, IProgressMonitor monitor) throws JavaModelException {
    final IJavaProject javaProject = JavaCore.create(project);

    final List<IClasspathEntry> entries = JDTUtil.rawClasspath(javaProject, true);
    Collections.sort(entries, ClasspathComparator.INSTANCE);

    javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), monitor);
}