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.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java

License:Open Source License

public static void removeFromClasspath(IJavaProject jproject, IPath path) throws JavaModelException {
    IClasspathEntry[] oldEntries = jproject.getRawClasspath();
    int nEntries = oldEntries.length;
    List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(nEntries);
    for (int i = 0; i < nEntries; i++) {
        IClasspathEntry curr = oldEntries[i];
        if (!path.equals(curr.getPath())) {
            list.add(curr);// w ww .  ja  v  a 2s  .c  o  m
        }
    }
    IClasspathEntry[] newEntries = list.toArray(new IClasspathEntry[list.size()]);
    jproject.setRawClasspath(newEntries, null);
}

From source file:org.hyperic.hypclipse.internal.wizards.project.NewProjectCreationOperation.java

License:Open Source License

/**
 * Sets project classpath.//from   w ww . j  a  va2  s. c o  m
 * 
 * @param project
 * @param data
 * @throws JavaModelException
 * @throws CoreException
 */
private void setClasspath(IProject project, IFieldData data) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    // Set output folder
    if (data.getOutputFolderName() != null) {
        IPath path = project.getFullPath().append(data.getOutputFolderName());
        javaProject.setOutputLocation(path, null);
    }
    IClasspathEntry[] entries = getClassPathEntries(javaProject, data);
    javaProject.setRawClasspath(entries, null);
}

From source file:org.jactr.eclipse.ui.wizards.templates.BaseACTRContributorTemplateSection.java

License:Open Source License

protected void addClasspathEntries(Collection<String> entries, boolean asSource) throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + entries.size()];

    /*//from www.jav a2  s.c o m
     * first old entry
     */
    newEntries[0] = oldEntries[0];

    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);

    Iterator<String> itr = entries.iterator();
    for (int i = oldEntries.length; itr.hasNext(); i++) {
        IPath path = project.getFullPath().append(itr.next());
        if (asSource)
            newEntries[i] = JavaCore.newSourceEntry(path);
        else
            newEntries[i] = JavaCore.newLibraryEntry(path, null, null, true);
    }

    javaProject.setRawClasspath(newEntries, null);
}

From source file:org.jactr.eclipse.ui.wizards.templates.DefaultACTRContributorTemplateSection.java

License:Open Source License

/**
 * stupid cosmetic bit to reorder the classpath entries so that models/,
 * java/, conf/ appear first/*from   w  w  w  . ja va  2  s . c  om*/
 * 
 * @throws CoreException
 */
private void sortEntries() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    SortedMap<String, IClasspathEntry> sortedMap = new TreeMap<String, IClasspathEntry>(
            Collections.reverseOrder());

    for (IClasspathEntry entry : oldEntries) {
        String name = entry.getPath().lastSegment();
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE
                && entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
            name = "a" + name;
        sortedMap.put(name, entry);
    }

    oldEntries = sortedMap.values().toArray(oldEntries);
    javaProject.setRawClasspath(oldEntries, null);
}

From source file:org.jamon.eclipse.JamonNature.java

License:Mozilla Public License

private void removeTsrc() throws CoreException {
    IFolder tsrc = getTemplateOutputFolder();
    IJavaProject jp = getJavaProject();
    List<IClasspathEntry> e = new ArrayList<IClasspathEntry>(Arrays.asList(jp.getRawClasspath()));
    e.remove(JavaCore.newSourceEntry(tsrc.getFullPath()));
    jp.setRawClasspath(e.toArray(new IClasspathEntry[e.size()]), null);
    if (tsrc.exists()) {
        unsetReadOnly(tsrc);/* w w w.  j a v  a 2  s .  c  o m*/
    }
}

From source file:org.jamon.eclipse.JamonNature.java

License:Mozilla Public License

@Override
public void configure() throws CoreException {
    TemplateBuilder.addToProject(getProject());
    MarkerUpdaterBuilder.addToProject(getProject());
    removeTsrc();//  www .ja va2 s  .  c o  m
    IFolder tsrc = getTemplateOutputFolder();
    createTsrcIfNeeded(tsrc);
    IJavaProject jp = getJavaProject();
    List<IClasspathEntry> e = new ArrayList<IClasspathEntry>(Arrays.asList(jp.getRawClasspath()));
    e.add(JavaCore.newSourceEntry(tsrc.getFullPath()));
    jp.setRawClasspath(e.toArray(new IClasspathEntry[e.size()]), null);
}

From source file:org.jamon.eclipse.JamonNature.java

License:Mozilla Public License

public void revalidateClasspath() throws CoreException {
    IJavaProject jp = getJavaProject();
    jp.setRawClasspath(jp.getRawClasspath(), null);
}

From source file:org.jboss.ide.eclipse.as.classpath.ui.containers.custom.CustomClasspathPreferencePage.java

License:Open Source License

public boolean performOk() {
    String[] changed2 = rootComp.getChanged();
    ArrayList<Object> list;
    IRuntimePathProvider[] arr;/*w w  w.j  av a  2 s . c  o  m*/
    final ArrayList<IProject> projectsNeedRefresh = new ArrayList<IProject>();
    for (int i = 0; i < changed2.length; i++) {
        String runtimeId = changed2[i];
        IRuntimeType rt = ServerCore.findRuntimeType(runtimeId);
        list = rootComp.getDataForComboSelection(changed2[i]);
        arr = (IRuntimePathProvider[]) list.toArray(new IRuntimePathProvider[list.size()]);
        CustomRuntimeClasspathModel.getInstance().savePathProviders(rt, arr);
        IProject[] projectsTargeting = findProjectsTargeting(rt);
        projectsNeedRefresh.addAll(Arrays.asList(projectsTargeting));
    }

    // Save the recently selected
    String lastSelected = rootComp.getCurrentId();
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(JBossServerUIPlugin.PLUGIN_ID);
    prefs.put(LAST_SELECTED_RUNTIME_TYPE, lastSelected);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        // IGNORE this since it is only a setting to remember what was the last selected
        // runtime. This is extremely not necessary to log or inform the user about. 
    }

    MessageDialog dialog = new MessageDialog(getShell(), Messages.CustomClasspathsSettingsChanged, null,
            Messages.CustomClasspathsRequiresRebuild, MessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            2);

    int res = dialog.open();
    if (res == 0) {
        Job j = new WorkspaceJob(Messages.CustomClasspathsWorkspaceJob) {
            public IStatus runInWorkspace(IProgressMonitor monitor) {
                Iterator<IProject> i = projectsNeedRefresh.iterator();
                monitor.beginTask(Messages.CustomClasspathsWorkspaceJob, projectsNeedRefresh.size());
                while (i.hasNext()) {
                    IJavaProject jp = JavaCore.create(i.next());
                    try {
                        // Must reset the classpath to actually force both views and models to refresh
                        // A full build is not enough
                        jp.setRawClasspath(jp.getRawClasspath(), new NullProgressMonitor());
                    } catch (JavaModelException jme) {
                        return jme.getStatus();
                    }
                    CoreUtility.getBuildJob(jp.getProject()).schedule();
                }
                monitor.done();
                return Status.OK_STATUS;
            }
        };
        j.setRule(ResourcesPlugin.getWorkspace().getRoot());
        j.schedule();
    }
    rootComp.clearChanged();
    return true;
}

From source file:org.jboss.ide.eclipse.as.test.classpath.JBIDE1657Test.java

License:Open Source License

public void testJBIDE1657() {
    try {/*from   www  .  jav  a  2s. c  om*/
        IJavaProject jp = JavaCore.create(project);

        // lets try a runtime
        IRuntime createdRuntime = ProjectRuntimeUtil.createRuntime("runtime1", IJBossToolingConstants.AS_42,
                ASTest.JBOSS_AS_HOME);
        ProjectRuntimeUtil.setTargetRuntime(createdRuntime, project);
        IClasspathEntry[] raw1 = jp.getRawClasspath();
        IClasspathEntry[] resolved1 = jp.getResolvedClasspath(false);
        IClasspathEntry[] raw2 = new IClasspathEntry[raw1.length];
        for (int i = 0; i < raw1.length; i++) {
            if (!raw1[i].getPath().segment(0).equals("org.eclipse.jst.server.core.container")) {
                raw2[i] = raw1[i];
            } else {
                IPath containerPath = new Path(
                        "org.jboss.ide.eclipse.as.classpath.core.runtime.ProjectRuntimeInitializer");
                containerPath = containerPath.append("runtime1");
                raw2[i] = JavaCore.newContainerEntry(containerPath);
            }
        }
        jp.setRawClasspath(raw2, new NullProgressMonitor());
        IClasspathEntry[] resolved2 = jp.getResolvedClasspath(false);
        assertEquals("New classpath container path should return the same classpath entries as the old. ",
                resolved1.length, resolved2.length);
        assertTrue("Should be more than one classpath entry", resolved1.length > 0);
    } catch (CoreException ce) {
        ce.printStackTrace();
        fail(ce.getMessage());
    }
}

From source file:org.jboss.ide.eclipse.as.test.classpath.JEEClasspathContainerTest.java

License:Open Source License

protected void addContainer(IJavaProject jproject, IPath path) throws JavaModelException {
    ArrayList tmp = new ArrayList();
    tmp.addAll(Arrays.asList(jproject.getRawClasspath()));
    tmp.add(JavaCore.newContainerEntry(path));
    jproject.setRawClasspath((IClasspathEntry[]) tmp.toArray(new IClasspathEntry[tmp.size()]), null);
}