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:org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper.java

License:Open Source License

/**
 * @param javaProject// w w w  . ja  va2s.  co m
 * @param toBeRemoved
 * @throws JavaModelException
 */
public final static void removeFromClasspath(IJavaProject javaProject, IPath toBeRemoved)
        throws JavaModelException {
    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();

    for (IClasspathEntry classpathEntry : oldEntries) {
        if (!classpathEntry.getPath().equals(toBeRemoved)) {
            newEntries.add(classpathEntry);
        }
    }

    IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
    javaProject.setRawClasspath(newEntries.toArray(newEntriesArray), null);
}

From source file:org.eclipse.emf.ecore.xcore.ui.EmptyXcoreProjectWizard.java

License:Open Source License

@Override
public void modifyWorkspace(IProgressMonitor progressMonitor)
        throws CoreException, UnsupportedEncodingException, IOException {
    super.modifyWorkspace(progressMonitor);
    IProjectDescription projectDescription = project.getDescription();
    String[] natureIds = projectDescription.getNatureIds();
    String[] newNatureIds = new String[natureIds.length + 1];
    System.arraycopy(natureIds, 0, newNatureIds, 0, natureIds.length);
    newNatureIds[natureIds.length] = XtextProjectHelper.NATURE_ID;
    projectDescription.setNatureIds(newNatureIds);
    project.setDescription(projectDescription, progressMonitor);

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length + 1];
    for (int i = 0, index = 0, length = newClasspath.length; index < length; ++i, ++index) {
        newClasspath[index] = classpath[i];
        if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = classpath[i].getPath();
            IPath srcGenPath = path.removeLastSegments(1).append(path.lastSegment() + "-gen");
            IClasspathEntry srcGen = JavaCore.newSourceEntry(srcGenPath);
            CodeGenUtil.EclipseUtil.findOrCreateContainer(srcGenPath, true, genModelProjectLocation,
                    progressMonitor);/* w  w  w  . j  a  v  a 2  s .  c  o m*/
            newClasspath[++index] = srcGen;
        }
    }
    javaProject.setRawClasspath(newClasspath, progressMonitor);
}

From source file:org.eclipse.emf.ecore.xcore.ui.quickfix.XcoreClasspathUpdater.java

License:Open Source License

protected boolean addJarToClasspath(IJavaProject javaProject, IPath location, IProgressMonitor monitor)
        throws JavaModelException {
    IClasspathEntry newClasspthEntry = JavaCore.newLibraryEntry(location, null, null);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1];
    for (int i = 0; i < rawClasspath.length; ++i) {
        IClasspathEntry entry = rawClasspath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(location)) {
            return false;
        }/*from   w  w w.ja v a2 s  . c o  m*/
        newRawClasspath[i + 1] = entry;
    }
    newRawClasspath[0] = newClasspthEntry;
    javaProject.setRawClasspath(newRawClasspath, monitor);
    return true;
}

From source file:org.eclipse.emf.search.codegen.engine.AbstractModelSearchCodeGenerator.java

License:Open Source License

/**
 * Create an empty EMF Project with default values.
 * /*from w w  w .  j a  v a 2 s .  c  o  m*/
 * @param projectName the name of the project to create.
 * @return the newly created project
 */
protected static IProject createEMFProject(String projectName) {
    IPath javaSource = new Path(IPath.SEPARATOR + projectName + IPath.SEPARATOR + SOURCE_DIRECTORY);
    IPath projectLocationPath = null;
    IProgressMonitor progressMonitor = new NullProgressMonitor();

    IProject project = null;

    try {
        List<IClasspathEntry> classpathEntries = new UniqueEList<IClasspathEntry>();

        project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        IJavaProject javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = null;
        if (!project.exists()) {
            projectDescription = project.getWorkspace().newProjectDescription(projectName);
            projectDescription.setLocation(projectLocationPath);
            project.create(projectDescription, new NullProgressMonitor());
        } else {
            projectDescription = project.getDescription();
            classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
        }

        boolean isInitiallyEmpty = classpathEntries.isEmpty();

        // add the natures
        String[] natureIds = addDefaultNatures(projectDescription);
        projectDescription.setNatureIds(natureIds);

        // add the builders
        ICommand[] builders = addDefaultBuilders(projectDescription);
        projectDescription.setBuildSpec(builders);

        // open the project and apply the new Descriptions
        project.open(new NullProgressMonitor());
        project.setDescription(projectDescription, new NullProgressMonitor());

        // initialize the directory which will contains the sources
        IContainer sourceContainer = project;
        if (javaSource.segmentCount() > 1) {
            sourceContainer = project.getFolder(javaSource.removeFirstSegments(1).makeAbsolute());
            if (!sourceContainer.exists()) {
                ((IFolder) sourceContainer).create(false, true, new SubProgressMonitor(progressMonitor, 1));
            }
        }

        if (isInitiallyEmpty) {
            IClasspathEntry sourceClasspathEntry = JavaCore.newSourceEntry(javaSource);
            for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) {
                IClasspathEntry classpathEntry = (IClasspathEntry) i.next();
                if (classpathEntry.getPath().isPrefixOf(javaSource)) {
                    i.remove();
                }
            }
            classpathEntries.add(0, sourceClasspathEntry);

            IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(new Path(JavaRuntime.JRELIB_VARIABLE),
                    new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE));
            for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) {
                IClasspathEntry classpathEntry = (IClasspathEntry) i.next();
                if (classpathEntry.getPath().isPrefixOf(jreClasspathEntry.getPath())) {
                    i.remove();
                }
            }
            classpathEntries.add(jreClasspathEntry);
            classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); //$NON-NLS-1$
        }

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

    } catch (CoreException e) {
        IStatus s = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                Messages.getString("AbstractEMFCodeGenerator.PluginCreationError"), e); //$NON-NLS-1$
        Activator.getDefault().getLog().log(s);
    } finally {
        progressMonitor.done();
    }

    return project;
}

From source file:org.eclipse.emf.texo.eclipse.generator.TexoGeneratorApplication.java

License:Open Source License

private IJavaProject createJavaProject() {
    try {/* w ww. j a va 2s  . c o  m*/
        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        final IProgressMonitor progressMonitor = new NullProgressMonitor();

        final IProject project = root.getProject(JAVA_PROJECT_NAME);
        if (project.exists()) {
            project.delete(true, progressMonitor);
        }
        project.create(progressMonitor);
        project.open(progressMonitor);

        // swt the java nature
        final IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = JavaCore.NATURE_ID;
        description.setNatureIds(newNatures);
        project.setDescription(description, progressMonitor);

        // create the javaproject
        final IJavaProject javaProject = JavaCore.create(project);

        // set the classpath
        final Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>();
        entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
        entries.add(JavaRuntime.getDefaultJREContainerEntry());
        javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progressMonitor);

        return javaProject;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.etrice.core.ui.newwizard.ProjectCreator.java

License:Open Source License

public static IProject createETriceProject(IPath javaSource, IPath javaSourceGen, URI projectLocationURI,
        IProject runtimeProject, List<String> naturesToAdd, List<String> buildersToAdd, Monitor monitor) {
    IProgressMonitor progressMonitor = BasicMonitor.toIProgressMonitor(monitor);
    String projectName = javaSource.segment(0);
    IProject project = null;/* w  ww . j  av  a  2 s.  c o  m*/
    try {
        List<IClasspathEntry> classpathEntries = new UniqueEList<IClasspathEntry>();

        progressMonitor.beginTask("", 10);
        progressMonitor.subTask("Creating eTrice project " + projectName + " ("
                + (projectLocationURI != null ? projectLocationURI.toString() : projectName) + ")");
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);

        // Clean up any old project information.
        //
        if (!project.exists()) {
            URI location = projectLocationURI;
            if (location == null) {
                location = URI
                        .createFileURI(workspace.getRoot().getLocation().append(projectName).toOSString());
            }
            location = location.appendSegment(".project");
            File projectFile = new File(location.toString());
            if (projectFile.exists()) {
                projectFile.renameTo(new File(location.toString() + ".old"));
            }
        }

        IJavaProject javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = null;
        if (!project.exists()) {
            projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
            if (projectLocationURI != null) {
                projectDescription.setLocationURI(new java.net.URI(projectLocationURI.toString()));
            }
            project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
            project.open(new SubProgressMonitor(progressMonitor, 1));
        } else {
            projectDescription = project.getDescription();
            project.open(new SubProgressMonitor(progressMonitor, 1));
            if (project.hasNature(JavaCore.NATURE_ID)) {
                classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
            }
        }

        boolean isInitiallyEmpty = classpathEntries.isEmpty();

        {
            ArrayList<IProject> referencedProjects = new ArrayList<IProject>();
            if (runtimeProject != null)
                referencedProjects.add(runtimeProject);
            if (!referencedProjects.isEmpty()) {
                projectDescription.setReferencedProjects(
                        referencedProjects.toArray(new IProject[referencedProjects.size()]));
                for (IProject referencedProject : referencedProjects) {
                    IClasspathEntry referencedProjectClasspathEntry = JavaCore
                            .newProjectEntry(referencedProject.getFullPath());
                    classpathEntries.add(referencedProjectClasspathEntry);
                }
            }
        }

        {
            String[] natureIds = projectDescription.getNatureIds();
            if (natureIds == null) {
                natureIds = new String[0];
            }
            for (String nature : naturesToAdd) {
                natureIds = addNature(nature, natureIds, project);
            }
            projectDescription.setNatureIds(natureIds);

            ICommand[] builders = projectDescription.getBuildSpec();
            if (builders == null) {
                builders = new ICommand[0];
            }
            for (String builder : buildersToAdd) {
                builders = addBuilder(builder, builders, projectDescription);
            }
            projectDescription.setBuildSpec(builders);

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

            createSrcFolder(progressMonitor, project, classpathEntries, javaSource);
            createSrcFolder(progressMonitor, project, classpathEntries, javaSourceGen);

            if (isInitiallyEmpty) {
                IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(
                        new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE),
                        new Path(JavaRuntime.JRESRCROOT_VARIABLE));
                for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) {
                    IClasspathEntry classpathEntry = i.next();
                    if (classpathEntry.getPath().isPrefixOf(jreClasspathEntry.getPath())) {
                        i.remove();
                    }
                }

                String jreContainer = JavaRuntime.JRE_CONTAINER;
                jreContainer += "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6";
                classpathEntries.add(JavaCore.newContainerEntry(new Path(jreContainer)));
            }

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

        if (isInitiallyEmpty) {
            javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"),
                    new SubProgressMonitor(progressMonitor, 1));
        }

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

        if (isInitiallyEmpty) {
            javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"),
                    new SubProgressMonitor(progressMonitor, 1));
        }

    } catch (Exception e) {
        Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e);
    } finally {
        progressMonitor.done();
    }

    return project;
}

From source file:org.eclipse.fx.ide.jdt.ui.internal.wizard.JavaFXProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    boolean res = super.performFinish();
    if (res) {/*from   w  w  w  .j  a v  a  2s .  co  m*/
        final IJavaElement newElement = getCreatedElement();

        IWorkingSet[] workingSets = fFirstPage.getWorkingSets();
        if (workingSets.length > 0) {
            PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets);
        }

        try {
            IJavaProject p = (IJavaProject) newElement;
            IClasspathEntry[] current = p.getRawClasspath();

            int i = current.length + 1;
            if (projectData.mainApp.equals(NewJavaFXProjectWizardPageThree.MOBILE)) {
                i += 1;
            }

            IClasspathEntry[] currentFX = new IClasspathEntry[i];
            System.arraycopy(current, 0, currentFX, 0, current.length);
            currentFX[current.length] = JavaCore.newContainerEntry(JavaFXCore.JAVAFX_CONTAINER_PATH);

            if (projectData.mainApp.equals(NewJavaFXProjectWizardPageThree.MOBILE)) {
                currentFX[current.length + 1] = JavaCore.newContainerEntry(JavaFXCore.MOBILE_CONTAINER_PATH);
            }

            p.setRawClasspath(currentFX, new NullProgressMonitor());
        } catch (JavaModelException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        if (projectData.mainApp.equals(NewJavaFXProjectWizardPageThree.DESKTOP)) {
            final IFile buildFile = fSecondPage.getJavaProject().getProject()
                    .getFile(new Path("build.fxbuild"));
            AntTask task = AntTasksFactory.eINSTANCE.createAntTask();
            task.setBuildDirectory("${project}/build");
            task.setDeploy(AntTasksFactory.eINSTANCE.createDeploy());
            task.getDeploy().setApplication(ParametersFactory.eINSTANCE.createApplication());
            task.getDeploy().getApplication().setName(fFirstPage.getProjectName());
            task.getDeploy().setInfo(ParametersFactory.eINSTANCE.createInfo());
            task.setSignjar(AntTasksFactory.eINSTANCE.createSignJar());

            final XMIResource resource = new XMIResourceImpl();
            resource.getContents().add(task);

            WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
                @Override
                public void execute(IProgressMonitor monitor) {

                    if (!resource.getContents().isEmpty()) {
                        Map<Object, Object> options = new HashMap<Object, Object>();
                        options.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);

                        ByteArrayOutputStream streamOut = null;
                        ByteArrayInputStream streamIn = null;
                        try {
                            streamOut = new ByteArrayOutputStream();
                            resource.save(streamOut, options);
                            streamIn = new ByteArrayInputStream(streamOut.toByteArray());
                            buildFile.create(streamIn, true, monitor);
                        } catch (IOException | CoreException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } finally {
                            options.clear();
                            if (streamOut != null) {
                                try {
                                    streamOut.close();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                            if (streamIn != null) {
                                try {
                                    streamIn.close();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            };
            try {
                new ProgressMonitorDialog(getShell()).run(true, false, operation);
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        try {
            IJavaProject p = fSecondPage.getJavaProject();
            IPackageFragment f = p.getPackageFragments()[0];
            IPath path = f.getPath();

            for (String s : projectData.packageName.split("\\.")) {
                path = path.append(s);
                p.getProject().getWorkspace().getRoot().getFolder(path).create(true, true, null);
            }

            {
                IFile cssFile = p.getProject().getWorkspace().getRoot().getFile(path.append("application.css"));
                ByteArrayInputStream in = new ByteArrayInputStream(
                        "/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */"
                                .getBytes());
                cssFile.create(in, IFile.FORCE | IFile.KEEP_HISTORY, null);
                in.close();
            }

            if (projectData.mainApp.equals(NewJavaFXProjectWizardPageThree.DESKTOP)) {
                IFile mainClass = p.getProject().getWorkspace().getRoot().getFile(path.append("Main.java"));
                ByteArrayInputStream in = new ByteArrayInputStream(
                        new FXProjectMainClassTemplate().generate(projectData).toString().getBytes());
                mainClass.create(in, IFile.FORCE | IFile.KEEP_HISTORY, null);
                in.close();
            } else if (projectData.mainApp.equals(NewJavaFXProjectWizardPageThree.MOBILE)) {
                IFile mainClass = p.getProject().getWorkspace().getRoot().getFile(path.append("Main.java"));
                ByteArrayInputStream in = new ByteArrayInputStream(
                        new FXProjectMainMobileClassTemplate().generate(projectData).toString().getBytes());
                mainClass.create(in, IFile.FORCE | IFile.KEEP_HISTORY, null);
                in.close();
            }

            if (!projectData.declarativeUiType.equals("None")) {
                if (!projectData.declarativeUiController.trim().isEmpty()) {
                    IFile ctrlClass = p.getProject().getWorkspace().getRoot()
                            .getFile(path.append(projectData.declarativeUiController + ".java"));
                    ByteArrayInputStream in = new ByteArrayInputStream(
                            new FXProjectCtrlClassTemplate().generate(projectData).toString().getBytes());
                    ctrlClass.create(in, IFile.FORCE | IFile.KEEP_HISTORY, null);
                    in.close();
                }
                IFile declarativeUi = p.getProject().getWorkspace().getRoot()
                        .getFile(path.append(projectData.declarativeUiName + "."
                                + (projectData.declarativeUiType.endsWith("FXML") ? "fxml" : "fxgraph")));
                ByteArrayInputStream in = new ByteArrayInputStream(
                        (projectData.declarativeUiType.endsWith("FXML")
                                ? new FXProjectFXMLTemplate().generate(projectData).toString().getBytes()
                                : new FXProjectFXGraphTemplate().generate(projectData).toString().getBytes()));
                declarativeUi.create(in, IFile.FORCE | IFile.KEEP_HISTORY, null);
                in.close();
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
        selectAndReveal(fSecondPage.getJavaProject().getProject());

        Display.getDefault().asyncExec(new Runnable() {
            public void run() {
                IWorkbenchPart activePart = getActivePart();
                if (activePart instanceof IPackagesViewPart) {
                    PackageExplorerPart view = PackageExplorerPart.openInActivePerspective();
                    view.tryToReveal(newElement);
                }
            }
        });
    }
    return res;
}

From source file:org.eclipse.fx.ide.ui.preview.LivePreviewSynchronizer.java

License:Open Source License

private void resolveDataProject(IJavaProject project, Set<IPath> outputPath, Set<IPath> listRefLibraries) {
    //      System.err.println("START RESOLVE: " + project.getElementName());
    try {//w  w w.  j  av  a2  s  .c o  m
        IClasspathEntry[] entries = project.getRawClasspath();
        outputPath.add(project.getOutputLocation());
        for (IClasspathEntry e : entries) {
            //            System.err.println(e + " ====> " + e.getEntryKind());
            if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment());
                if (p.exists()) {
                    resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries);
                }
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                //               System.err.println("CPE_LIBRARY PUSHING: " + e.getPath());
                listRefLibraries.add(e.getPath());
            } else if ("org.eclipse.pde.core.requiredPlugins".equals(e.getPath().toString())) {
                IClasspathContainer cpContainer = JavaCore.getClasspathContainer(e.getPath(), project);
                for (IClasspathEntry cpEntry : cpContainer.getClasspathEntries()) {
                    if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                        IProject p = ResourcesPlugin.getWorkspace().getRoot()
                                .getProject(cpEntry.getPath().lastSegment());
                        if (p.exists()) {
                            resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries);
                        }
                    } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        //                     System.err.println("requiredPlugins & CPE_LIBRARY PUSHING: " + e.getPath());
                        listRefLibraries.add(cpEntry.getPath());
                    }
                }
            } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (!e.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")
                        && !e.getPath().toString().startsWith("org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER")) {
                    //                  System.err.println("====> A container");

                    IClasspathContainer cp = JavaCore.getClasspathContainer(e.getPath(), project);
                    for (IClasspathEntry ce : cp.getClasspathEntries()) {
                        //                     System.err.println(ce.getEntryKind() + "=> " + ce);
                        if (ce.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            listRefLibraries.add(ce.getPath());
                        } else if (ce.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                            IProject p = ResourcesPlugin.getWorkspace().getRoot()
                                    .getProject(ce.getPath().lastSegment());
                            if (p.exists()) {
                                resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries);
                            }
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //      System.err.println("END RESOLVE");
}

From source file:org.eclipse.gemoc.execution.concurrent.ccsljavaxdsml.ui.builder.ToggleNatureAction.java

License:Open Source License

public void addSourceFolder(IProject project, String folder) {
    try {//  ww  w . ja v  a2  s .  c  o m
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
        System.arraycopy(entries, 0, newEntries, 0, entries.length);

        IPath srcPath = javaProject.getPath().append(folder);
        IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null);

        boolean entryfound = false;
        for (IClasspathEntry cpe : entries) {
            if (cpe.equals(srcEntry)) {
                entryfound = true;
            }
        }

        if (!entryfound) {
            newEntries[entries.length] = JavaCore.newSourceEntry(srcEntry.getPath());
            javaProject.setRawClasspath(newEntries, null);
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}