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:com.google.cloud.tools.eclipse.appengine.libraries.BuildPath.java

License:Apache License

/**
 * @return the entries added to the classpath. 
 *     Does not include entries previously present in classpath.
 *//*from   w w w  . j a  v a2s.c  om*/
public static IClasspathEntry[] addLibraries(IJavaProject javaProject, List<Library> libraries,
        IProgressMonitor monitor) throws JavaModelException, CoreException {

    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("adding.app.engine.libraries"), //$NON-NLS-1$
            libraries.size());

    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    List<IClasspathEntry> newRawClasspath = new ArrayList<>(rawClasspath.length + libraries.size());
    newRawClasspath.addAll(Arrays.asList(rawClasspath));
    List<IClasspathEntry> newEntries = new ArrayList<>();
    for (Library library : libraries) {
        IClasspathEntry libraryContainer = makeClasspathEntry(library);
        if (!newRawClasspath.contains(libraryContainer)) {
            newEntries.add(libraryContainer);
            newRawClasspath.add(libraryContainer);
        }
        subMonitor.worked(1);
    }
    javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), subMonitor);

    runContainerResolverJob(javaProject);

    return newEntries.toArray(new IClasspathEntry[0]);
}

From source file:com.google.cloud.tools.eclipse.appengine.newproject.CreateAppEngineStandardWtpProject.java

License:Apache License

private void addAppEngineLibrariesToBuildPath(IProject newProject, List<Library> libraries,
        IProgressMonitor monitor) throws CoreException {
    if (libraries.isEmpty()) {
        return;/*  www.j  a  v  a2s  . com*/
    }
    SubMonitor subMonitor = SubMonitor.convert(monitor, "Adding App Engine libraries", libraries.size());
    IJavaProject javaProject = JavaCore.create(newProject);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = Arrays.copyOf(rawClasspath, rawClasspath.length + libraries.size());
    for (int i = 0; i < libraries.size(); i++) {
        Library library = libraries.get(i);
        IClasspathAttribute[] classpathAttributes;
        if (library.isExport()) {
            classpathAttributes = new IClasspathAttribute[] {
                    UpdateClasspathAttributeUtil.createDependencyAttribute(true /* isWebApp */) };
        } else {
            classpathAttributes = new IClasspathAttribute[] {
                    UpdateClasspathAttributeUtil.createNonDependencyAttribute() };
        }

        IClasspathEntry libraryContainer = JavaCore.newContainerEntry(library.getContainerPath(),
                new IAccessRule[0], classpathAttributes, false);
        newRawClasspath[rawClasspath.length + i] = libraryContainer;
        subMonitor.worked(1);
    }
    javaProject.setRawClasspath(newRawClasspath, monitor);

    runContainerResolverJob(javaProject);
}

From source file:com.google.cloud.tools.eclipse.appengine.newproject.CreateAppEngineStandardWtpProject.java

License:Apache License

private void addJunit4ToClasspath(IProgressMonitor monitor, final IProject newProject)
        throws CoreException, JavaModelException {
    IJavaProject javaProject = JavaCore.create(newProject);
    IClasspathAttribute nonDependencyAttribute = UpdateClasspathAttributeUtil.createNonDependencyAttribute();
    IClasspathEntry junit4Container = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH,
            new IAccessRule[0], new IClasspathAttribute[] { nonDependencyAttribute }, false);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = Arrays.copyOf(rawClasspath, rawClasspath.length + 1);
    newRawClasspath[newRawClasspath.length - 1] = junit4Container;
    javaProject.setRawClasspath(newRawClasspath, monitor);
}

From source file:com.google.cloud.tools.eclipse.appengine.newproject.CreateAppEngineWtpProject.java

License:Apache License

private static void addJunit4ToClasspath(IProgressMonitor monitor, IProject newProject) throws CoreException {
    IJavaProject javaProject = JavaCore.create(newProject);
    IClasspathAttribute nonDependencyAttribute = UpdateClasspathAttributeUtil.createNonDependencyAttribute();
    IClasspathEntry junit4Container = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH,
            new IAccessRule[0], new IClasspathAttribute[] { nonDependencyAttribute }, false);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = Arrays.copyOf(rawClasspath, rawClasspath.length + 1);
    newRawClasspath[newRawClasspath.length - 1] = junit4Container;
    javaProject.setRawClasspath(newRawClasspath, monitor);
}

From source file:com.google.devtools.bazel.e4b.BazelProjectSupport.java

License:Open Source License

private static void createClasspath(IPath root, List<String> paths, IJavaProject javaProject,
        int javaLanguageLevel) throws CoreException {
    String name = root.lastSegment();
    IFolder base = javaProject.getProject().getFolder(name);
    if (!base.isLinked()) {
        base.createLink(root, IResource.NONE, null);
    }/*  ww  w  .j a  va 2 s . c  o m*/
    List<IClasspathEntry> list = new LinkedList<>();
    for (String path : paths) {
        IPath workspacePath = base.getFullPath().append(path);
        list.add(JavaCore.newSourceEntry(workspacePath));
    }
    list.add(JavaCore.newContainerEntry(new Path(BazelClasspathContainer.CONTAINER_NAME)));

    list.add(JavaCore.newContainerEntry(new Path(STANDARD_VM_CONTAINER_PREFIX + javaLanguageLevel)));
    IClasspathEntry[] newClasspath = list.toArray(new IClasspathEntry[0]);
    javaProject.setRawClasspath(newClasspath, null);
}

From source file:com.google.devtools.bazel.e4b.wizard.BazelProjectSupport.java

License:Open Source License

private static void createClasspath(IPath root, List<String> paths, IJavaProject javaProject)
        throws CoreException {
    String name = root.lastSegment();
    IFolder base = javaProject.getProject().getFolder(name);
    if (!base.isLinked()) {
        base.createLink(root, IResource.NONE, null);
    }//  w  w w .j ava  2s  . c  o  m
    List<IClasspathEntry> list = new LinkedList<>();
    for (String path : paths) {
        IPath workspacePath = base.getFullPath().append(path);
        list.add(JavaCore.newSourceEntry(workspacePath));
    }
    list.add(JavaCore.newContainerEntry(new Path(BazelClasspathContainer.CONTAINER_NAME)));
    // TODO(dmarting): we should add otherwise. Best way is to get the bootclasspath from Bazel.
    list.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER/"
            + "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8")));
    IClasspathEntry[] newClasspath = (IClasspathEntry[]) list.toArray(new IClasspathEntry[0]);
    javaProject.setRawClasspath(newClasspath, null);
}

From source file:com.google.gcp.eclipse.testing.ProjectTestUtil.java

License:Open Source License

/**
 * Creates a Java project with the given name and the specified raw classpath.
 *//*w  w  w.j a v  a  2  s . c o  m*/
public static IJavaProject createProject(String projectName, IClasspathEntry[] rawClasspaths)
        throws CoreException {
    IProject project = createSimpleProject(projectName, JAVA_NATURE);
    IJavaProject javaProject = JavaCore.create(project);
    javaProject.setRawClasspath(rawClasspaths, npm());

    return javaProject;
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.CodegenUtils.java

License:Open Source License

public static void setupSourceFolders(IJavaProject javaProject, IFolder sourceFolder, IProgressMonitor monitor)
        throws JavaModelException {
    IProject project = javaProject.getProject();
    // get the list of entries.
    IClasspathEntry[] entries = javaProject.getRawClasspath();

    // remove the project as a source folder (This is the default)
    entries = removeSourceClasspath(entries, project);

    // add the source folder
    // remove it first in case.
    entries = removeSourceClasspath(entries, sourceFolder);
    entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(sourceFolder.getFullPath()));

    javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10));
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.CodegenUtils.java

License:Open Source License

/**
 * Adds the given folder to the project's class path.
 * /*  www . j a v  a2 s .c  o m*/
 * @param javaProject The Java Project to update.
 * @param sourceFolder Template Parameters.
 * @param monitor An existing monitor.
 * @throws JavaModelException if the classpath could not be set.
 */
public static void setupSourceFolders(IJavaProject javaProject, String[] sourceFolders,
        IProgressMonitor monitor) throws JavaModelException {
    IProject project = javaProject.getProject();
    // get the list of entries.
    IClasspathEntry[] entries = javaProject.getRawClasspath();

    // remove the project as a source folder (This is the default)
    entries = removeSourceClasspath(entries, project);

    // add the source folders.
    for (String sourceFolder : sourceFolders) {
        IFolder srcFolder = project.getFolder(sourceFolder);

        // remove it first in case.
        entries = removeSourceClasspath(entries, srcFolder);
        entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(srcFolder.getFullPath()));
    }
    javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10));
}

From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java

License:Open Source License

private void addAptSourceFolder(IProject project, IProgressMonitor monitor) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();

    // add .apt_generated to classpath
    IClasspathAttribute[] attributes = new IClasspathAttribute[] {
            JavaCore.newClasspathAttribute("optional", "true") }; //$NON-NLS-N$
    IFolder aptFolder = project.getFolder(APT_FOLDER);
    IClasspathEntry entry = JavaCore.newSourceEntry(aptFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL,
            ClasspathEntry.EXCLUDE_NONE, null, attributes);
    entries = CodegenUtils.addEntryToClasspath(entries, entry);

    javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10));
}