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.xtend.performance.tests.PerformanceTestProjectSetup.java

License:Open Source License

public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) {

    IProject project = null;/*from w w  w.j a v a2 s. c o  m*/
    IJavaProject javaProject = null;
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);
        deleteProject(project);

        javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectName);
        project.create(projectDescription, null);
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        projectDescription.setNatureIds(projectNatures);

        final ICommand java = projectDescription.newCommand();
        java.setBuilderName(JavaCore.BUILDER_ID);

        final ICommand manifest = projectDescription.newCommand();
        manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

        final ICommand schema = projectDescription.newCommand();
        schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

        projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });

        project.open(null);
        project.setDescription(projectDescription, null);

        classpathEntries.add(JavaCore.newContainerEntry(new Path(
                "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5")));
        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                null);

        makeJava5Compliant(javaProject);

        javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
        createManifest(projectName, project);
        //         project.build(IncrementalProjectBuilder.FULL_BUILD, null);
        refreshExternalArchives(javaProject);
        refresh(javaProject);
    } catch (final Exception exception) {
        throw new RuntimeException(exception);
    }
    return javaProject;
}

From source file:org.eclipse.xtend.shared.ui.test.TestEnvironment.java

License:Open Source License

public void setClasspath(final IPath projectPath, final IClasspathEntry[] entries) throws JavaModelException {
    checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$
    final IJavaProject javaProject = JavaCore.create(getProject(projectPath));
    javaProject.setRawClasspath(entries, null);
}

From source file:org.eclipse.xtend.shared.ui.wizards.EclipseHelper.java

License:Open Source License

public static IProject createExtXptProject(final String projectName, final List<String> srcFolders,
        final List<IProject> referencedProjects, final Set<String> requiredBundles,
        final List<String> exportedPackages, final IProgressMonitor progressMonitor, final Shell theShell) {
    IProject project = null;/*from  ww w .  j  a  va 2s . co  m*/
    try {
        progressMonitor.beginTask("", 10);
        progressMonitor.subTask(Messages.EclipseHelper_TaskTitle + projectName);
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);

        // Clean up any old project information.
        if (project.exists()) {
            final boolean[] result = new boolean[1];
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                public void run() {
                    result[0] = MessageDialog.openQuestion(theShell,
                            Messages.EclipseHelper_OvewritePrompt + projectName,
                            Messages.EclipseHelper_Warning1 + projectName + Messages.EclipseHelper_Warning2);
                }
            });
            if (result[0]) {
                project.delete(true, true, new SubProgressMonitor(progressMonitor, 1));
            } else {
                return null;
            }
        }

        IJavaProject javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectName);
        projectDescription.setLocation(null);
        project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        if (referencedProjects.size() != 0) {
            projectDescription
                    .setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()]));
            for (IProject referencedProject : referencedProjects) {
                IClasspathEntry referencedProjectClasspathEntry = JavaCore
                        .newProjectEntry(referencedProject.getFullPath());
                classpathEntries.add(referencedProjectClasspathEntry);
            }
        }

        projectDescription.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature",
                XtendXpandNature.NATURE_ID });

        ICommand java = projectDescription.newCommand();
        java.setBuilderName(JavaCore.BUILDER_ID);

        ICommand manifest = projectDescription.newCommand();
        manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

        ICommand schema = projectDescription.newCommand();
        schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

        ICommand extxpt = projectDescription.newCommand();
        extxpt.setBuilderName(XtendXpandBuilder.getBUILDER_ID());

        projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema, extxpt });

        project.open(new SubProgressMonitor(progressMonitor, 1));
        project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1));

        Collections.reverse(srcFolders);
        for (String src : srcFolders) {
            IFolder srcContainer = project.getFolder(src);
            if (!srcContainer.exists()) {
                srcContainer.create(false, true, new SubProgressMonitor(progressMonitor, 1));
            }
            IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath());
            classpathEntries.add(0, srcClasspathEntry);
        }

        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")));
        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                new SubProgressMonitor(progressMonitor, 1));

        javaProject.setOutputLocation(new Path("/" + projectName + "/bin"),
                new SubProgressMonitor(progressMonitor, 1));
        createManifest(projectName, requiredBundles, exportedPackages, progressMonitor, project);
        createBuildProps(progressMonitor, project);
    } catch (Exception exception) {
        exception.printStackTrace();
        XtendLog.logError(exception);
    } finally {
        progressMonitor.done();
    }

    return project;
}

From source file:org.eclipse.xtext.builder.impl.Bug486584Test.java

License:Open Source License

@Test
public void testNoFullBuildIfAttachmentChangeOnly() throws CoreException {
    IJavaProject project = setupProject();
    assertFalse(getEvents().isEmpty());//w w  w  .  j av a2 s . com
    getEvents().clear();
    IFile libaryFile = copyAndGetXtendExampleJar(project);
    IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(libaryFile.getFullPath(), null, null);
    addToClasspath(project, libraryEntry);
    waitForBuild();
    assertFalse(getEvents().isEmpty());
    getEvents().clear();

    IClasspathEntry[] classpath = project.getRawClasspath();
    for (int i = 0; i < classpath.length; ++i) {
        IPath entryPath = classpath[i].getPath();
        if (libraryEntry.getPath().equals(entryPath)) {
            IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length];
            System.arraycopy(classpath, 0, newClasspath, 0, classpath.length);

            classpath[i] = JavaCore.newLibraryEntry(libaryFile.getFullPath(), libaryFile.getFullPath(), null);
            project.setRawClasspath(classpath, null);

        }
    }
    waitForBuild();
    assertTrue(getEvents().isEmpty());
}

From source file:org.eclipse.xtext.builder.impl.Bug486584Test.java

License:Open Source License

@Test
public void testFullBuildWhenClasspathChanged_3() throws CoreException, IOException {
    IJavaProject project = setupProject();
    IFile libaryFile = copyAndGetXtendExampleJar(project);
    IPath rawLocation = libaryFile.getRawLocation();
    IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(rawLocation, null, null);
    addToClasspath(project, libraryEntry);
    waitForBuild();//from  ww  w .j  a  va 2  s  . c  o  m
    assertFalse(getEvents().isEmpty());
    getEvents().clear();
    File file = rawLocation.toFile();
    Files.touch(file);
    project.setRawClasspath(project.getRawClasspath(), null);
    project.getProject().getFile("src/dummy.txt").create(new StringInputStream(""), false, null);
    project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
    waitForBuild();
    assertFalse(getEvents().isEmpty());

}

From source file:org.eclipse.xtext.builder.JDTAwareEclipseResourceFileSystemAccess2.java

License:Open Source License

/**
 * @param prototype settings will be copied from the prototype and the new entry is inserted after that one.
 *//*from  w w w  .  ja  v  a 2 s . c o  m*/
private void insertClasspathEntry(IContainer folder, IClasspathEntry prototype, IJavaProject project)
        throws JavaModelException {
    IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), prototype.getInclusionPatterns(),
            prototype.getExclusionPatterns(), prototype.getOutputLocation(), prototype.getExtraAttributes());
    IClasspathEntry[] classPath = project.getRawClasspath();
    IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
    int i = 0;
    for (IClasspathEntry entry : classPath) {
        newClassPath[i++] = entry;
        if (entry.equals(prototype)) {
            newClassPath[i++] = newEntry;
        }
    }
    // should not happen, but to be sure
    if (i == newClassPath.length - 1 && newClassPath[i] == null) {
        LOG.warn("Cannot find classpath entry '" + prototype + "'");
        newClassPath[i] = newEntry;
    }
    project.setRawClasspath(newClassPath, getMonitor());
}

From source file:org.eclipse.xtext.builder.JDTAwareEclipseResourceFileSystemAccess2.java

License:Open Source License

private void addClasspathEntry(IContainer folder, IJavaProject project) throws JavaModelException {
    IClasspathEntry srcFolderClasspathEntry = JavaCore.newSourceEntry(folder.getFullPath());
    IClasspathEntry[] classPath = project.getRawClasspath();
    IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
    System.arraycopy(classPath, 0, newClassPath, 0, classPath.length);
    newClassPath[newClassPath.length - 1] = srcFolderClasspathEntry;
    project.setRawClasspath(newClassPath, getMonitor());
}

From source file:org.eclipse.xtext.common.types.access.jdt.MockJavaProjectProvider.java

License:Open Source License

public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) {

    IProject project = null;/* w w w . j  a va2s  .c  om*/
    IJavaProject javaProject = null;
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);
        deleteProject(project);

        javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectName);
        project.create(projectDescription, null);
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        projectDescription.setNatureIds(projectNatures);

        final ICommand java = projectDescription.newCommand();
        java.setBuilderName(JavaCore.BUILDER_ID);

        final ICommand manifest = projectDescription.newCommand();
        manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

        final ICommand schema = projectDescription.newCommand();
        schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

        projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });

        project.open(null);
        project.setDescription(projectDescription, null);

        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                null);
        JavaProjectSetupUtil.addJreClasspathEntry(javaProject);

        makeJava5Compliant(javaProject);

        javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
        createManifest(projectName, project);

        refreshExternalArchives(javaProject);
        refresh(javaProject);
    } catch (final Exception exception) {
        throw new RuntimeException(exception);
    }
    return javaProject;
}

From source file:org.eclipse.xtext.junit4.ui.util.JavaProjectSetupUtil.java

License:Open Source License

public static void removeFromClasspath(IJavaProject from, int entryKind, IPath path) throws CoreException {
    List<IClasspathEntry> classpath = Lists.newArrayList(from.getRawClasspath());
    Iterator<IClasspathEntry> iterator = classpath.iterator();
    while (iterator.hasNext()) {
        IClasspathEntry entry = iterator.next();
        if (entry.getEntryKind() == entryKind) {
            if (entry.getPath().equals(path))
                iterator.remove();/*  ww  w.java  2  s .  c  om*/
        }
    }
    from.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), monitor());
}

From source file:org.eclipse.xtext.junit4.ui.util.JavaProjectSetupUtil.java

License:Open Source License

public static void deleteClasspathEntry(IJavaProject javaProject, IPath path) throws JavaModelException {
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    for (int i = 0; i < classpath.length; ++i) {
        IPath entryPath = classpath[i].getPath();
        if (path.equals(entryPath)) {
            IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length - 1];
            System.arraycopy(classpath, 0, newClasspath, 0, i);
            System.arraycopy(classpath, i + 1, newClasspath, i, classpath.length - i - 1);
            javaProject.setRawClasspath(newClasspath, null);

        }/*www  .  jav a2 s  .  c  om*/
    }
}