Interface IClasspathEntry
IPackageFragmentRoot.K_SOURCE
, or binary, IPackageFragmentRoot.K_BINARY
), which is inherited
by each package fragment root and package fragment associated with the entry.
A classpath entry can refer to any of the following:
- Source code in the current project. In this case, the entry identifies a
root folder in the current project containing package fragments and
source files with one of the
Java-like extensions
. The root folder itself represents a default package, subfolders represent package fragments, and files with a Java-like extension (e.g..java
files) represent compilation units. All compilation units will be compiled when the project is built. The classpath entry must specify the absolute path to the root folder. Entries of this kind are associated with theCPE_SOURCE
constant. Source classpath entries can carry inclusion and exclusion patterns for selecting which source files appear as compilation units and get compiled when the project is built. - A binary library in the current project, in another project, or in the external
file system. In this case the entry identifies a JAR (or root folder) containing
package fragments and
.class
files. The classpath entry must specify the absolute path to the JAR (or root folder), and in case it refers to an external JAR, then there is no associated resource in the workbench. Entries of this kind are associated with theCPE_LIBRARY
constant. - A required project. In this case the entry identifies another project in
the workspace. The required project is used as a binary library when compiling
(that is, the builder looks in the output location of the required project
for required
.class
files when building). When performing other "development" operations - such as code assist, code resolve, type hierarchy creation, etc. - the source code of the project is referred to. Thus, development is performed against a required project's source code, and compilation is performed against a required project's last built state. The classpath entry must specify the absolute path to the project. Entries of this kind are associated with theCPE_PROJECT
constant. Note: referencing a required project with a classpath entry refers to the source code or associated.class
files located in its output location. It will also automatically include any other libraries or projects that the required project's classpath refers to, iff the corresponding classpath entries are tagged as being exported (isExported()
). Unless exporting some classpath entries, classpaths are not chained by default - each project must specify its own classpath in its entirety. - A path beginning in a classpath variable defined globally to the workspace.
Entries of this kind are associated with the
CPE_VARIABLE
constant. Classpath variables are created usingJavaCore.setClasspathVariable(String, IPath, org.eclipse.core.runtime.IProgressMonitor)
, and gets resolved, to either a project or library entry, usingJavaCore.getResolvedClasspathEntry(IClasspathEntry)
. It is also possible to register an automatic initializer (ClasspathVariableInitializer
), which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer". After resolution, a classpath variable entry may either correspond to a project or a library entry. - A named classpath container identified by its container path.
A classpath container provides a way to indirectly reference a set of classpath entries through
a classpath entry of kind
CPE_CONTAINER
. Typically, a classpath container can be used to describe a complex library composed of multiple JARs, projects or classpath variables, considering also that containers can be mapped differently on each project. Several projects can reference the same generic container path, but have each of them actually bound to a different container object. The container path is a formed by a first ID segment followed with extra segments, which can be used as additional hints for resolving this container reference. If no container was ever recorded for this container path onto this project (usingJavaCore.setClasspathContainer(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject[], org.eclipse.jdt.core.IClasspathContainer[], org.eclipse.core.runtime.IProgressMonitor)
, then aClasspathContainerInitializer
will be activated if any was registered for this container ID onto the extension point "org.eclipse.jdt.core.classpathContainerInitializer". A classpath container entry can be resolved explicitly usingJavaCore.getClasspathContainer(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject)
and the resulting container entries can contain any non-container entry. In particular, it may contain variable entries, which in turn needs to be resolved before being directly used.
Also note that the container resolution APIs include an IJavaProject argument, so as to allow the same container path to be interpreted in different ways for different projects.
IJavaProject.getResolvedClasspath(boolean)
will have all entries of type
CPE_VARIABLE
and CPE_CONTAINER
resolved to a set of
CPE_SOURCE
, CPE_LIBRARY
or CPE_PROJECT
classpath entries.
Any classpath entry other than a source folder (kind CPE_SOURCE
) can
be marked as being exported. Exported entries are automatically contributed to
dependent projects, along with the project's default output folder, which is
implicitly exported, and any auxiliary output folders specified on source
classpath entries. The project's output folder(s) are always listed first,
followed by the any exported entries.
Classpath entries can be created via methods on JavaCore
.
- See Also:
-
JavaCore.newLibraryEntry(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)
JavaCore.newProjectEntry(org.eclipse.core.runtime.IPath)
JavaCore.newSourceEntry(org.eclipse.core.runtime.IPath)
JavaCore.newVariableEntry(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)
JavaCore.newContainerEntry(org.eclipse.core.runtime.IPath)
ClasspathVariableInitializer
ClasspathContainerInitializer
- Restriction:
- This interface is not intended to be implemented by clients.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Entry kind constant describing a classpath entry representing a name classpath container.static final int
Entry kind constant describing a classpath entry identifying a library.static final int
Entry kind constant describing a classpath entry identifying a required project.static final int
Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.static final int
Entry kind constant describing a classpath entry defined using a path that begins with a classpath variable reference. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether the access rules of the project's exported entries should be combined with this entry's access rules.Returns the possibly empty list of access rules for this entry.int
Returns the kind of files found in the package fragments identified by this classpath entry.int
Returns the kind of this classpath entry.org.eclipse.core.runtime.IPath[]
Returns the set of patterns used to exclude resources or classes associated with this classpath entry.org.eclipse.core.runtime.IPath
getExternalAnnotationPath
(org.eclipse.core.resources.IProject project, boolean resolve) Answer the path for external annotations (for null analysis) associated with this classpath entry.Returns the extra classpath attributes for this classpath entry.org.eclipse.core.runtime.IPath[]
Returns the set of patterns used to explicitly define resources or classes to be included with this classpath entry.org.eclipse.core.runtime.IPath
Returns the full path to the specific location where the builder writes.class
files generated for this source entry (entry kindCPE_SOURCE
).org.eclipse.core.runtime.IPath
getPath()
Returns the path of this classpath entry.Returns the classpath entry that is making a reference to this classpath entry.Deprecated.org.eclipse.core.runtime.IPath
Returns the path to the source archive or folder associated with this classpath entry, ornull
if this classpath entry has no source attachment.org.eclipse.core.runtime.IPath
Returns the path within the source archive or folder where package fragments are located.boolean
Returns whether this entry is exported to dependent projects.default boolean
isTest()
This is a convience method, that returnstrue
if the extra attributes contain an attribute whose name isIClasspathAttribute.TEST
and whose value is 'true'.default boolean
This is a convience method, that returnstrue
if the extra attributes contain an attribute whose name isIClasspathAttribute.WITHOUT_TEST_CODE
and whose value is 'true'.
-
Field Details
-
CPE_LIBRARY
static final int CPE_LIBRARYEntry kind constant describing a classpath entry identifying a library. A library is a folder or JAR containing package fragments consisting of pre-compiled binaries.- See Also:
-
CPE_PROJECT
static final int CPE_PROJECTEntry kind constant describing a classpath entry identifying a required project.- See Also:
-
CPE_SOURCE
static final int CPE_SOURCEEntry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.- See Also:
-
CPE_VARIABLE
static final int CPE_VARIABLEEntry kind constant describing a classpath entry defined using a path that begins with a classpath variable reference.- See Also:
-
CPE_CONTAINER
static final int CPE_CONTAINEREntry kind constant describing a classpath entry representing a name classpath container.- Since:
- 2.0
- See Also:
-
-
Method Details
-
combineAccessRules
boolean combineAccessRules()Returns whether the access rules of the project's exported entries should be combined with this entry's access rules. Returns true for container entries. Returns false otherwise.- Returns:
- whether the access rules of the project's exported entries should be combined with this entry's access rules
- Since:
- 3.1
-
getAccessRules
IAccessRule[] getAccessRules()Returns the possibly empty list of access rules for this entry.- Returns:
- the possibly empty list of access rules for this entry
- Since:
- 3.1
-
getContentKind
int getContentKind()Returns the kind of files found in the package fragments identified by this classpath entry.- Returns:
IPackageFragmentRoot.K_SOURCE
for files containing source code, andIPackageFragmentRoot.K_BINARY
for binary class files. There is no specified value for an entry denoting a variable (CPE_VARIABLE
) or a classpath container (CPE_CONTAINER
).
-
getEntryKind
int getEntryKind()Returns the kind of this classpath entry.- Returns:
- one of:
CPE_SOURCE
- this entry describes a source root in its projectCPE_LIBRARY
- this entry describes a folder or JAR containing binariesCPE_PROJECT
- this entry describes another projectCPE_VARIABLE
- this entry describes a project or library indirectly via a classpath variable in the first segment of the path *CPE_CONTAINER
- this entry describes set of entries referenced indirectly via a classpath container
-
getExclusionPatterns
org.eclipse.core.runtime.IPath[] getExclusionPatterns()Returns the set of patterns used to exclude resources or classes associated with this classpath entry.For source classpath entries, exclusion patterns allow specified portions of the resource tree rooted at this source entry's path to be filtered out. If no exclusion patterns are specified, this source entry includes all relevent files. Each path specified must be a relative path, and will be interpreted relative to this source entry's path. File patterns are case-sensitive. A file matched by one or more of these patterns is excluded from the corresponding package fragment root. Exclusion patterns have higher precedence than inclusion patterns; in other words, exclusion patterns can remove files for the ones that are to be included, not the other way around.
Note that there is no need to supply a pattern to exclude ".class" files because a source entry filters these out automatically.
The pattern mechanism is similar to Ant's. Each pattern is represented as a relative path. The path segments can be regular file or folder names or simple patterns involving standard wildcard characters.
'*' matches 0 or more characters within a segment. So
*.java
matches.java
,a.java
andFoo.java
, but notFoo.properties
(does not end with.java
).'?' matches 1 character within a segment. So
?.java
matchesa.java
,A.java
, but not.java
orxyz.java
(neither have just one character before.java
).Combinations of *'s and ?'s are allowed.
The special pattern '**' matches zero or more segments. In a source entry, a path like
tests/
that ends in a trailing separator is interpreted astests/**
, and would match everything under the folder namedtests
.Example patterns in source entries (assuming that "java" is the only
Java-like extension
):-
tests/**
(or simplytests/
) matches all files under a root folder namedtests
. This includestests/Foo.java
andtests/com/example/Foo.java
, but notcom/example/tests/Foo.java
(not under a root folder namedtests
). -
tests/*
matches all files directly below a root folder namedtests
. This includestests/Foo.java
andtests/FooHelp.java
but nottests/com/example/Foo.java
(not directly under a folder namedtests
) orcom/Foo.java
(not under a folder namedtests
). -
**/tests/**
matches all files under any folder namedtests
. This includestests/Foo.java
,com/examples/tests/Foo.java
, andcom/examples/tests/unit/Foo.java
, but notcom/example/Foo.java
(not under a folder namedtests
).
- Returns:
- the possibly empty list of resource exclusion patterns
associated with this classpath entry, or
null
if this kind of classpath entry does not support exclusion patterns - Since:
- 2.1
-
-
getExtraAttributes
IClasspathAttribute[] getExtraAttributes()Returns the extra classpath attributes for this classpath entry. Returns an empty array if this entry has no extra attributes.- Returns:
- the possibly empty list of extra classpath attributes for this classpath entry
- Since:
- 3.1
-
getInclusionPatterns
org.eclipse.core.runtime.IPath[] getInclusionPatterns()Returns the set of patterns used to explicitly define resources or classes to be included with this classpath entry.For source classpath entries, when no inclusion patterns are specified, the source entry includes all relevent files in the resource tree rooted at this source entry's path. Specifying one or more inclusion patterns means that only the specified portions of the resource tree are to be included. Each path specified must be a relative path, and will be interpreted relative to this source entry's path. File patterns are case-sensitive. A file matched by one or more of these patterns is included in the corresponding package fragment root unless it is excluded by one or more of this entrie's exclusion patterns. Exclusion patterns have higher precedence than inclusion patterns; in other words, exclusion patterns can remove files for the ones that are to be included, not the other way around.
See
getExclusionPatterns()
for a discussion of the syntax and semantics of path patterns. The absence of any inclusion patterns is semantically equivalent to the explicit inclusion pattern**
.Example patterns in source entries:
-
The inclusion pattern
src/**
by itself includes all files under a root folder namedsrc
. -
The inclusion patterns
src/**
andtests/**
includes all files under the root folders namedsrc
andtests
. -
The inclusion pattern
src/**
together with the exclusion patternsrc/**/Foo.java
includes all files under a root folder namedsrc
except for ones namedFoo.java
.
- Returns:
- the possibly empty list of resource inclusion patterns
associated with this classpath entry, or
null
if this kind of classpath entry does not support inclusion patterns - Since:
- 3.0
-
The inclusion pattern
-
getOutputLocation
org.eclipse.core.runtime.IPath getOutputLocation()Returns the full path to the specific location where the builder writes.class
files generated for this source entry (entry kindCPE_SOURCE
).Source entries can optionally be associated with a specific output location. If none is provided, the source entry will be implicitly associated with its project default output location (see
IJavaProject.getOutputLocation()
).NOTE: A specific output location cannot coincidate with another source/library entry.
- Returns:
- the full path to the specific location where the builder writes
.class
files for this source entry, ornull
if using default output folder - Since:
- 2.1
-
getPath
org.eclipse.core.runtime.IPath getPath()Returns the path of this classpath entry. The meaning of the path of a classpath entry depends on its entry kind:- Source code in the current project (
CPE_SOURCE
) - The path associated with this entry is the absolute path to the root folder. - A binary library in the current project (
CPE_LIBRARY
) - the path associated with this entry is the absolute path to the JAR (or root folder), and in case it refers to an external library, then there is no associated resource in the workbench. - A required project (
CPE_PROJECT
) - the path of the entry denotes the path to the corresponding project resource. - A variable entry (
CPE_VARIABLE
) - the first segment of the path is the name of a classpath variable. If this classpath variable is bound to the path P, the path of the corresponding classpath entry is computed by appending to P the segments of the returned path without the variable. - A container entry (
CPE_CONTAINER
) - the path of the entry is the name of the classpath container, which can be bound indirectly to a set of classpath entries after resolution. The containerPath is a formed by a first ID segment followed with extra segments that can be used as additional hints for resolving this container reference (also seeIClasspathContainer
).
- Returns:
- the path of this classpath entry
- Source code in the current project (
-
getSourceAttachmentPath
org.eclipse.core.runtime.IPath getSourceAttachmentPath()Returns the path to the source archive or folder associated with this classpath entry, ornull
if this classpath entry has no source attachment.Only library and variable classpath entries may have source attachments. For library classpath entries, the result path (if present) locates a source archive or folder. This archive or folder can be located in a project of the workspace or outside the workspace. For variable classpath entries, the result path (if present) has an analogous form and meaning as the variable path, namely the first segment is the name of a classpath variable.
- Returns:
- the path to the source archive or folder, or
null
if none
-
getSourceAttachmentRootPath
org.eclipse.core.runtime.IPath getSourceAttachmentRootPath()Returns the path within the source archive or folder where package fragments are located. An empty path indicates that packages are located at the root of the source archive or folder. Returns a non-null
value if and only ifgetSourceAttachmentPath()
returns a non-null
value.- Returns:
- the path within the source archive or folder, or
null
if not applicable
-
getReferencingEntry
IClasspathEntry getReferencingEntry()Returns the classpath entry that is making a reference to this classpath entry. For entry kindsCPE_LIBRARY
, the return value is the entry that is representing the JAR that includesthis
in the MANIFEST.MF file's Class-Path section. For entry kinds other thanCPE_LIBRARY
, this returnsnull
. For those entries that are on the raw classpath already, this returnsnull
.It is possible that multiple library entries refer to the same entry via the MANIFEST.MF file. In those cases, this method returns the first classpath entry that appears in the raw classpath. However, this does not mean that the other referencing entries do not relate to their referenced entries. See
JavaCore.getReferencedClasspathEntries(IClasspathEntry, IJavaProject)
for more details.- Returns:
- the classpath entry that is referencing this entry or
null
if not applicable. - Since:
- 3.6
-
isExported
boolean isExported()Returns whether this entry is exported to dependent projects. Always returnsfalse
for source entries (kindCPE_SOURCE
), which cannot be exported.- Returns:
true
if exported, andfalse
otherwise- Since:
- 2.0
-
getResolvedEntry
IClasspathEntry getResolvedEntry()Deprecated.This is a helper method, which returns the resolved classpath entry denoted by an entry (if it is a variable entry). It is obtained by resolving the variable reference in the first segment. Returnsnull
if unable to resolve using the following algorithm:- if variable segment cannot be resolved, returns
null
- finds a project, JAR or binary folder in the workspace at the resolved path location
- if none finds an external JAR file or folder outside the workspace at the resolved path location
- if none returns
null
Variable source attachment is also resolved and recorded in the resulting classpath entry.
Note that this deprecated API doesn't handle CPE_CONTAINER entries.- Returns:
- the resolved library or project classpath entry, or
null
if the given path could not be resolved to a classpath entry
- if variable segment cannot be resolved, returns
-
isTest
default boolean isTest()This is a convience method, that returnstrue
if the extra attributes contain an attribute whose name isIClasspathAttribute.TEST
and whose value is 'true'.- Returns:
true
, if if the extra attributes contain a attribute whose name isIClasspathAttribute.TEST
and whose value is 'true'.- Since:
- 3.14
- See Also:
-
isWithoutTestCode
default boolean isWithoutTestCode()This is a convience method, that returnstrue
if the extra attributes contain an attribute whose name isIClasspathAttribute.WITHOUT_TEST_CODE
and whose value is 'true'.- Returns:
true
, if if the extra attributes contain a attribute whose name isIClasspathAttribute.WITHOUT_TEST_CODE
and whose value is 'true'.- Since:
- 3.14
- See Also:
-
getExternalAnnotationPath
org.eclipse.core.runtime.IPath getExternalAnnotationPath(org.eclipse.core.resources.IProject project, boolean resolve) Answer the path for external annotations (for null analysis) associated with this classpath entry. Five shapes of paths are supported:- relative, variable (VAR/relpath): resolve classpath variable VAR and append relpath
- relative, container (CON/relpath): locate relpath among the elements within container CON
- relative, project (relpath): interpret relpath as a relative path within the given project
- absolute, workspace (/Proj/relpath): an absolute path in the workspace
- absolute, filesystem (/abspath): an absolute path in the filesystem
- Parameters:
project
- project whose classpath we are analysingresolve
- if true, any workspace-relative paths will be resolved to filesystem paths.- Returns:
- a path (in the workspace or filesystem-absolute) or null
- Since:
- 3.30
-
JavaCore.getResolvedClasspathEntry(IClasspathEntry)
instead