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

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

Introduction

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

Prototype

IClasspathEntry[] getRawClasspath() throws JavaModelException;

Source Link

Document

Returns the raw classpath for the project, as a list of classpath entries.

Usage

From source file:com.google.cloud.tools.eclipse.appengine.libraries.BuildPathTest.java

License:Apache License

@Test
public void testAddLibraries_noDuplicates() throws CoreException {
    Library library = new Library("libraryId");
    IClasspathEntry entry = BuildPath.makeClasspathEntry(library);

    IJavaProject project = Mockito.mock(IJavaProject.class);
    IClasspathEntry[] rawClasspath = { entry };
    Mockito.when(project.getRawClasspath()).thenReturn(rawClasspath);

    List<Library> libraries = new ArrayList<>();
    libraries.add(library);//from w  w w .ja v  a  2 s  . c  o m
    IClasspathEntry[] result = BuildPath.addLibraries(project, libraries, new NullProgressMonitor());
    Assert.assertEquals(0, result.length);
}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.BuildPathTest.java

License:Apache License

@Test
public void testAddLibraries_withDuplicates() throws CoreException {
    Library library1 = new Library("library1");
    Library library2 = new Library("library2");
    IClasspathEntry entry = BuildPath.makeClasspathEntry(library1);

    IJavaProject project = Mockito.mock(IJavaProject.class);
    IClasspathEntry[] rawClasspath = { entry };
    Mockito.when(project.getRawClasspath()).thenReturn(rawClasspath);

    List<Library> libraries = new ArrayList<>();
    libraries.add(library1);//w w  w.  ja  v  a 2  s .  c o  m
    libraries.add(library2);
    IClasspathEntry[] result = BuildPath.addLibraries(project, libraries, new NullProgressMonitor());
    Assert.assertEquals(1, result.length);
    Assert.assertTrue(result[0].getPath().toString()
            .endsWith("com.google.cloud.tools.eclipse.appengine.libraries/library2"));
}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.LibraryClasspathContainerResolverService.java

License:Apache License

public IStatus resolveAll(IJavaProject javaProject, IProgressMonitor monitor) {
    IStatus status = null;/*from   ww  w.  java  2s.c  o  m*/
    try {
        IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
        SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("TaskResolveLibraries"),
                getTotalwork(rawClasspath));
        for (IClasspathEntry classpathEntry : rawClasspath) {
            if (classpathEntry.getPath().segment(0).equals(Library.CONTAINER_PATH_PREFIX)) {
                status = StatusUtil.merge(status,
                        resolveContainer(javaProject, classpathEntry.getPath(), subMonitor.newChild(1)));
            }
        }
    } catch (CoreException ex) {
        return StatusUtil.error(this, Messages.getString("TaskResolveLibrariesError"), ex);
    }
    return status == null ? Status.OK_STATUS : status;
}

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;// ww  w .  j a v a  2 s.co  m
    }
    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.CreateAppEngineStandardWtpProjectTest.java

License:Apache License

private void assertAppEngineContainerOnClasspath(Library library) throws CoreException {
    assertTrue(project.hasNature(JavaCore.NATURE_ID));
    IJavaProject javaProject = JavaCore.create(project);
    for (IClasspathEntry iClasspathEntry : javaProject.getRawClasspath()) {
        if (iClasspathEntry.getPath().equals(library.getContainerPath())) {
            return;
        }//from w  w  w  .  j  av  a  2s. co m
    }
    fail("Classpath container " + APP_ENGINE_API + " was not added to the build path");
}

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.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.
 * /*w  w  w . ja  va 2s .  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));
}