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

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

Introduction

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

Prototype

String CLASSPATH_FILE_NAME

To view the source code for org.eclipse.jdt.core IJavaProject CLASSPATH_FILE_NAME.

Click Source Link

Document

Path of the file containing the project's classpath relative to the project's root.

Usage

From source file:org.flowerplatform.editor.java.propertypage.remote.JavaProjectPropertyPageService.java

License:Open Source License

public Object getClasspathEntries(ServiceInvocationContext context, List<PathFragment> path) {
    @SuppressWarnings("unchecked")
    Pair<File, String> node = (Pair<File, String>) GenericTreeStatefulService.getNodeByPathFor(path, null);
    File projectFile = node.a;/*from  w w w  .jav a  2  s . c o  m*/
    File wd = ProjectsService.getInstance().getProjectToWorkingDirectoryAndIProjectMap().get(projectFile).a;

    IProject project = ProjectsService.getInstance().getProjectToWorkingDirectoryAndIProjectMap()
            .get(projectFile).b;
    IJavaProject javaProject = JavaCore.create(project);

    List<String> srcFolders = new ArrayList<String>();
    List<String> projects = new ArrayList<String>();
    List<String> libraries = new ArrayList<String>();

    try {
        if (!project.getFile(IJavaProject.CLASSPATH_FILE_NAME).exists()) {
            return null;
        }
        @SuppressWarnings("restriction")
        IClasspathEntry[][] entries = ((JavaProject) javaProject).readFileEntriesWithException(null);
        for (IClasspathEntry entry : entries[0]) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                srcFolders.add(entry.getPath()
                        .makeRelativeTo(project.getFolder(ProjectsService.LINK_TO_PROJECT).getFullPath())
                        .toFile().getPath());
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                File file = ProjectsService.getInstance().getFileFromProjectWrapperResource(
                        ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()));
                projects.add(CommonPlugin.getInstance().getPathRelativeToFile(file, wd));
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                    && entry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
                IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath());
                File file = ProjectsService.getInstance().getFileFromProjectWrapperResource(resource);
                libraries.add(CommonPlugin.getInstance().getPathRelativeToFile(file, wd));
            }
        }

    } catch (CoreException | IOException e) {
        logger.error("Exception thrown while getting java classpath entries for {}", project.getName(), e);
        return null;
    }
    return new Object[] { srcFolders, projects, libraries };
}

From source file:org.talend.designer.maven.utils.TalendCodeProjectUtil.java

License:Open Source License

@SuppressWarnings("restriction")
private static boolean needRecreate(IProgressMonitor monitor, IProject codeProject) throws CoreException {
    if (codeProject.exists()) { // exist the project for workspace metadata.

        // If the project is not existed physically (in disk). sometime, because delete it manually. Then finally,
        // will cause problem.
        if (!codeProject.getLocation().toFile().exists()) {
            return true;
        }// ww w. j  a v  a 2 s  . c  o m

        // because some cases, the project is not opened.
        if (!codeProject.isOpen()) {
            // if not opened, will have exception when check nature or such
            codeProject.open(monitor);
        }

        codeProject.refreshLocal(IResource.DEPTH_ONE, monitor);

        // not java project
        if (!codeProject.hasNature(JavaCore.NATURE_ID)) {
            return true;
        }

        // like TDI-33044, when creating, kill the studio. the classpath file won't be created.
        if (!codeProject.getFile(IJavaProject.CLASSPATH_FILE_NAME).exists()) {
            return true;
        }

        // IJavaProject javaProject = JavaCore.create(codeProject);
        // javaProject.getRawClasspath(); //test the nature and classpath?

        // no maven nature.
        if (!codeProject.hasNature(IMavenConstants.NATURE_ID)) {
            return true;
        }

        // no pom
        if (!codeProject.getFile(TalendMavenConstants.POM_FILE_NAME).exists()) {
            return true;
        }

        // FIXME pom is not "pom" packaging?
        // will change to "pom" packaging when ProjectPomManager.updateAttributes. so no need check.

    }
    return false;
}