Example usage for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.

Prototype

int CPE_LIBRARY

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:org.sonar.ide.eclipse.internal.jdt.JavaProjectConfigurator.java

License:Open Source License

private void configureJavaProject(IJavaProject javaProject, ProjectDefinition sonarProject) {
    Properties properties = sonarProject.getProperties();
    String javaSource = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
    String javaTarget = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);

    properties.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, Java.KEY);
    properties.setProperty("sonar.java.source", javaSource);
    LOG.info("Source Java version: {}", javaSource);
    properties.setProperty("sonar.java.target", javaTarget);
    LOG.info("Target Java version: {}", javaTarget);

    try {/* ww  w . jav a2  s  . c  o m*/
        IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : classPath) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                if (isSourceExcluded(entry)) {
                    break;
                }
                String srcDir = getAbsolutePath(javaProject, entry.getPath());
                LOG.debug("Source directory: {}", srcDir);
                sonarProject.addSourceDir(srcDir);
                if (entry.getOutputLocation() != null) {
                    String binDir = getAbsolutePath(javaProject, entry.getOutputLocation());
                    LOG.debug("Binary directory: {}", binDir);
                    sonarProject.addBinaryDir(binDir);
                }
                break;

            case IClasspathEntry.CPE_LIBRARY:
                String libDir = entry.getPath().toOSString();
                LOG.debug("Library: {}", libDir);
                sonarProject.addLibrary(libDir);
                break;

            default:
                LOG.warn("Unhandled ClassPathEntry : {}", entry);
                break;
            }
        }

        String binDir = getAbsolutePath(javaProject, javaProject.getOutputLocation());
        LOG.debug("Default binary directory: {}", binDir);
        sonarProject.addBinaryDir(binDir);
    } catch (JavaModelException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.sonar.ide.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders./*  ww  w. java2  s  .  c  om*/
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analysed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!isSourceExcluded(entry)) {
                processSourceEntry(entry, javaProject, context, topProject);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            if (topProject || entry.isExported()) {
                final String libDir = resolveLibrary(javaProject, entry);
                if (libDir != null) {
                    LOG.debug("Library: {}", libDir);
                    context.libraries().add(libDir);
                }
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IJavaModel javaModel = javaProject.getJavaModel();
            IJavaProject referredProject = javaModel.getJavaProject(entry.getPath().segment(0));
            if (!context.dependentProjects().contains(referredProject)) {
                LOG.debug("Adding project: {}", referredProject.getProject().getName());
                addClassPathToSonarProject(referredProject, context, false);
                context.dependentProjects().add(referredProject);
            }
            break;
        default:
            LOG.warn("Unhandled ClassPathEntry : {}", entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}

From source file:org.sonarlint.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders.//from w w  w  .  ja va  2  s .co  m
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analysed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!isSourceExcluded(entry)) {
                processSourceEntry(entry, javaProject, context, topProject);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            if (topProject || entry.isExported()) {
                final String libPath = resolveLibrary(javaProject, entry);
                if (libPath != null) {
                    context.libraries().add(libPath);
                }
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IJavaModel javaModel = javaProject.getJavaModel();
            IJavaProject referredProject = javaModel.getJavaProject(entry.getPath().segment(0));
            if (!context.dependentProjects().contains(referredProject)) {
                context.dependentProjects().add(referredProject);
                addClassPathToSonarProject(referredProject, context, false);
            }
            break;
        default:
            SonarLintCorePlugin.getDefault().info("Unhandled ClassPathEntry : " + entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}

From source file:org.sonarlint.eclipse.jdt.internal.JdtUtils.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders.//from   w w  w.j a  va  2s .  c om
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analyzed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private static void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            processSourceEntry(entry, context, topProject);
            break;
        case IClasspathEntry.CPE_LIBRARY:
            processLibraryEntry(entry, javaProject, context, topProject);
            break;
        case IClasspathEntry.CPE_PROJECT:
            processProjectEntry(entry, javaProject, context);
            break;
        default:
            SonarLintLogger.get().info("Unhandled ClassPathEntry : " + entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}

From source file:org.sonatype.m2e.webby.internal.launch.WebbySourcePathProvider.java

License:Open Source License

private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved,
        IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope,
        IProgressMonitor monitor) throws CoreException {
    IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
    MavenJdtPlugin plugin = MavenJdtPlugin.getDefault();
    IClasspathManager buildpathManager = plugin.getBuildpathManager();
    IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor);
    for (IClasspathEntry entry : cp) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_PROJECT:
            addProjectEntries(resolved, entry.getPath());
            break;
        case IClasspathEntry.CPE_LIBRARY:
            resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
            break;
        }/*from  w ww . j  a va 2  s. com*/
    }
}

From source file:org.sonatype.tycho.m2e.internal.launching.PDEBundleClasspathResolver.java

License:Open Source License

@Override
public Map<IPath, Collection<IPath>> getAdditionalClasspathEntries(IJavaProject javaProject) {
    IProgressMonitor monitor = new NullProgressMonitor();

    Map<IPath, Collection<IPath>> result = new LinkedHashMap<IPath, Collection<IPath>>();

    List<IClasspathEntryDescriptor> cp = resolveMavenClasspath(javaProject, monitor);

    IProject project = javaProject.getProject();

    if (cp.isEmpty()) {
        return result;
    }/*from   w ww  . j  a v  a2 s .co  m*/

    IWorkspaceRoot workspace = project.getWorkspace().getRoot();
    Map<ArtifactKey, String> classpathMap = EmbeddedArtifacts.getEmbeddedArtifacts(project);

    for (IClasspathEntryDescriptor entry : cp) {
        String pathStr = getBundlePath(classpathMap, entry);
        if (pathStr != null && !".".equals(pathStr)) // inlined dependencies are not supported at the moment
        {
            IPath path = new Path(pathStr);
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                addClasspathMap(result, path, getBuildOutputLocation(workspace, entry.getPath().segment(0)));
                break;
            case IClasspathEntry.CPE_LIBRARY:
                addClasspathMap(result, path, entry.getPath());
                break;
            }
        }
    }

    return result;
}

From source file:org.sonatype.tycho.m2e.internal.launching.PDEBundleClasspathResolver.java

License:Open Source License

@Override
public Collection<IRuntimeClasspathEntry> getAdditionalSourceEntries(IJavaProject javaProject) {
    // igorf: Returned entries do not have attached sources. I am not actually sure this works.

    IProgressMonitor monitor = new NullProgressMonitor();

    Set<IRuntimeClasspathEntry> resolved = new LinkedHashSet<IRuntimeClasspathEntry>();

    List<IClasspathEntryDescriptor> cp = resolveMavenClasspath(javaProject, monitor);

    if (cp.isEmpty()) {
        return resolved;
    }// w  ww  .j  a v  a2s  .c o m

    Map<ArtifactKey, String> classpathMap = EmbeddedArtifacts.getEmbeddedArtifacts(javaProject.getProject());

    for (IClasspathEntryDescriptor entry : cp) {
        if (isBundleClasspathEntry(classpathMap, entry)) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                addProjectEntries(resolved, entry.getPath(), CLASSPATH_SCOPE, getArtifactClassifier(entry),
                        monitor);
                break;
            case IClasspathEntry.CPE_LIBRARY:
                resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
                break;
            }
        }
    }

    return resolved;
}

From source file:org.springframework.ide.eclipse.boot.core.BootPropertyTester.java

License:Open Source License

private static boolean isBootJar(IClasspathEntry e) {
    if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IPath path = e.getPath();//from w ww  .  j  a  v a2 s  .  c om
        String name = path.lastSegment();
        return name.endsWith(".jar") && name.startsWith("spring-boot");
    }
    return false;
}

From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java

License:Open Source License

/**
 * Load the {@link ConfigMetadataRepository} with the metadata of the current
 * classpath using the {@link #DEFAULT_LOCATION_PATTERN}. If the same config
 * metadata items is held within different resources, the first that is
 * loaded is kept which means the result is not deterministic.
 *//*ww w.  j  a va 2s.c  om*/
public ConfigurationMetadataRepository load(IJavaProject project) throws Exception {
    debug(">> load ConfigurationMetadataRepository for " + project.getElementName());
    IClasspathEntry[] classpath = project.getResolvedClasspath(true);
    for (IClasspathEntry e : classpath) {
        int ekind = e.getEntryKind();
        int ckind = e.getContentKind();
        IPath path = e.getPath();
        if (ekind == IClasspathEntry.CPE_LIBRARY && ckind == IPackageFragmentRoot.K_BINARY) {
            //jar file dependency
            File jarFile = path.toFile();
            if (FileUtil.isJarFile(jarFile)) {
                loadFromJar(jarFile);
            }
        } else if (ekind == IClasspathEntry.CPE_PROJECT) {
            loadFromProjectDependency(e);
        } else {
            debug("Skipped: " + ekind(ekind) + " " + ckind(ckind) + ": " + path);
        }
    }
    loadFromOutputFolder(project);
    debug("<< load ConfigurationMetadataRepository for " + project.getElementName() + ": "
            + repository.getAllProperties().size() + " properties");
    return repository;
}

From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java

License:Open Source License

private String ekind(int ekind) {
    switch (ekind) {
    case IClasspathEntry.CPE_SOURCE:
        return "SRC";
    case IClasspathEntry.CPE_LIBRARY:
        return "LIB";
    case IClasspathEntry.CPE_PROJECT:
        return "PRJ";
    case IClasspathEntry.CPE_VARIABLE:
        return "VAR";
    case IClasspathEntry.CPE_CONTAINER:
        return "CON";
    default:// w w  w . ja  va2 s.  c  o m
        return "" + ekind;
    }
}