本文整理汇总了Java中org.eclipse.jdt.core.IClasspathEntry.CPE_LIBRARY属性的典型用法代码示例。如果您正苦于以下问题:Java IClasspathEntry.CPE_LIBRARY属性的具体用法?Java IClasspathEntry.CPE_LIBRARY怎么用?Java IClasspathEntry.CPE_LIBRARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.IClasspathEntry
的用法示例。
在下文中一共展示了IClasspathEntry.CPE_LIBRARY属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProjectClassPath
public static void getProjectClassPath(IJavaProject project, List<File> dst) throws Exception {
IRuntimeClasspathEntry [] rentries = JavaRuntime.computeUnresolvedRuntimeClasspath(project);
for (IRuntimeClasspathEntry entry : rentries) {
switch (entry.getType()) {
case IClasspathEntry.CPE_SOURCE:
break;
case IClasspathEntry.CPE_PROJECT:
break;
case IClasspathEntry.CPE_LIBRARY:
break;
case IClasspathEntry.CPE_VARIABLE:
// JRE like entries
IRuntimeClasspathEntry [] variableEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, project);
break;
case IClasspathEntry.CPE_CONTAINER:
IRuntimeClasspathEntry [] containerEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, project);
for (IRuntimeClasspathEntry containerentry : containerEntries) {
dst.add(new File (containerentry.getLocation()));
}
break;
default:
throw new Exception("unsupported classpath entry "+entry);
}
}
}
示例2: filterJREEntries
/**
* Remove all JRE runtime entries from the given set
*
* @param scope
* set to filter
* @return filtered set without JRE runtime entries
*/
public static Set<IPackageFragmentRoot> filterJREEntries(
Collection<IPackageFragmentRoot> scope) throws JavaModelException {
final Set<IPackageFragmentRoot> filtered = new HashSet<IPackageFragmentRoot>();
for (final IPackageFragmentRoot root : scope) {
final IClasspathEntry entry = root.getRawClasspathEntry();
switch (entry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
filtered.add(root);
break;
case IClasspathEntry.CPE_CONTAINER:
IClasspathContainer container = JavaCore.getClasspathContainer(
entry.getPath(), root.getJavaProject());
if (container != null
&& container.getKind() == IClasspathContainer.K_APPLICATION) {
filtered.add(root);
}
break;
}
}
return filtered;
}
示例3: addMavenClasspathEntries
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(), scope, getArtifactClassifier(entry), configuration, monitor);
break;
case IClasspathEntry.CPE_LIBRARY:
resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
break;
// case IClasspathEntry.CPE_SOURCE:
// resolved.add(newSourceClasspathEntry(javaProject, cp[i]));
// break;
}
}
}
示例4: isClasspathEntryForJar
/**
*
* @param javaProject
* @param jar
* @return
* @throws JavaModelException
*/
private boolean isClasspathEntryForJar(IJavaProject javaProject, IResource jar) throws JavaModelException
{
IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
if (classPathEntries != null) {
for (IClasspathEntry classpathEntry : classPathEntries) {
// fix jar files
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
if (classpathEntry.getPath().equals(jar.getFullPath())) {
return true;
}
}
}
}
return false;
}
示例5: addToClassPath
public static void addToClassPath(IResource res, int type, IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException
{
Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(javaProject.getRawClasspath()));
IClasspathEntry entry = null;
switch (type) {
case IClasspathEntry.CPE_SOURCE:
entry = JavaCore.newSourceEntry(res.getFullPath());
break;
case IClasspathEntry.CPE_LIBRARY:
entry = JavaCore.newLibraryEntry(res.getFullPath(), null, null, true);
break;
case IClasspathEntry.CPE_PROJECT:
entry = JavaCore.newProjectEntry(res.getFullPath(), true);
break;
}
entries.add(entry);
setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);
}
示例6: isSwarmEntry
private boolean isSwarmEntry(IClasspathEntry cpe) {
//this is a quick n' very dirty detection
if (cpe.getEntryKind()==IClasspathEntry.CPE_LIBRARY) {
IPath path = cpe.getPath();
String name = path.lastSegment();
return name.startsWith("container-") && containsSwarm(path.toFile());
}
return false;
}
示例7: fixBackofficeJars
/**
* Make sure all the relevant backoffice jars are exported
*
* @param monitor
* @param javaProject
* @throws JavaModelException
*/
private void fixBackofficeJars(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException
{
if (javaProject.getProject().getName().equalsIgnoreCase("backoffice"))
{
List<IClasspathEntry> entries = new LinkedList<IClasspathEntry>();
IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
boolean change = false;
for (IClasspathEntry classpathEntry : classPathEntries) {
// fix jar files
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
if (classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/backoffice-core-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/backoffice-widgets-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitframework-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitcore-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpittesting-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitwidgets-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpit-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zk") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zul-") ||
classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zcommon-"))
{
if (!classpathEntry.isExported())
{
change = true;
IClasspathEntry clonedEntry = JavaCore.newLibraryEntry(classpathEntry.getPath(), classpathEntry.getSourceAttachmentPath(), classpathEntry.getSourceAttachmentRootPath(), classpathEntry.getAccessRules(), classpathEntry.getExtraAttributes(), true);
entries.add(clonedEntry);
continue;
}
}
}
entries.add(classpathEntry);
}
if (change)
{
FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);
}
}
}
示例8: removeJarFilesThatDontExist
private void removeJarFilesThatDontExist(IProgressMonitor monitor, IProject project, IJavaProject javaProject) throws JavaModelException {
IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
List<IClasspathEntry> newClassPathEntries = new LinkedList<IClasspathEntry>();
boolean changedClassPath = false;
for (IClasspathEntry classpathEntry : classPathEntries) {
// fix jar files
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
classpathEntry.getPath();
File classpathEntryFile = classpathEntry.getPath().toFile();
// remove JAR if it doesn't exist, only do this if the jar file is located in this project, we leave jars references from different projects
if (classpathEntryFile.getPath().endsWith(".jar") && classpathEntryFile.getPath().startsWith("/" + project.getName() + "/") && !project.getFile(classpathEntryFile.getPath().replace("/" + project.getName() + "/", "/")).exists()) {
changedClassPath = true;
if (debug)
Activator.log("libary [" + classpathEntry.getPath() + "] not found for project [ " + project.getName() + "]");
}
else {
newClassPathEntries.add(classpathEntry);
}
}
else {
newClassPathEntries.add(classpathEntry);
}
}
// we have a change to the classpath so now push the change
if (changedClassPath) {
if (newClassPathEntries.isEmpty()) {
FixProjectsUtils.setClasspath(new IClasspathEntry[0], javaProject, monitor);
}
else {
FixProjectsUtils.setClasspath(newClassPathEntries.toArray(new IClasspathEntry[newClassPathEntries.size()]), javaProject, monitor);
}
}
}
示例9: addDependencies
private void addDependencies(final IProgressMonitor monitor, final ICanceler canceler, final WorkspaceBuilder builder)
throws JavaModelException,
InterruptedException {
for (final IJavaProject javaProject : this.model.getJavaProjects()) {
final String message = MessageFormat.format("scanne dependencies for project {0}", javaProject.getElementName()); //$NON-NLS-1$
this.logger.log(Level.INFO, message);
monitor.subTask(message);
final Project project = builder.getProject(javaProject.getPath().toPortableString());
if (project == null) {
continue;
}
final Set<ILibrary> libraries = new HashSet<>();
ClasspathCollector.collect(canceler, libraries, project);
for (final IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
if (canceler.isCanceled()) {
throw new InterruptedException();
}
final int entryKind = classpathEntry.getEntryKind();
switch (entryKind) {
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_PROJECT: {
final org.eclipse.core.runtime.IPath path = classpathEntry.getPath();
final Library library = builder.getLibrary(path.toPortableString());
if (library == null || libraries.contains(library)) {
continue;
}
ClasspathCollector.collect(canceler, libraries, library);
if (libraries.contains(project)) {
final String submessage =
MessageFormat.format("dependencies for project {0} builds cycle over library {1}", //$NON-NLS-1$
javaProject.getElementName(), library.getName());
this.logger.log(Level.ERROR, submessage);
this.logger.log(Level.ERROR, ObjectUtilities.toString(library));
throw new JavaModelException(new Exception(submessage), IStatus.ERROR);
}
libraries.add(library);
project.getDependencies().add(new Dependency(library, classpathEntry.isExported()));
break;
}
case IClasspathEntry.CPE_CONTAINER: {
break;
}
case IClasspathEntry.CPE_SOURCE: {
break;
}
case IClasspathEntry.CPE_VARIABLE: {
break;
}
default:
break;
}
project.setClasspath(libraries);
}
}
}
示例10: addProjectEntries
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier,
ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(path.segment(0));
IMavenProjectFacade projectFacade = projectManager.create(project, monitor);
if(projectFacade == null) {
return;
}
ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
if(configuration == null) {
return;
}
IJavaProject javaProject = JavaCore.create(project);
boolean projectResolved = false;
for(IClasspathEntry entry : javaProject.getRawClasspath()) {
IRuntimeClasspathEntry rce = null;
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
if(!projectResolved) {
IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault().getMavenClassifierManager();
IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager
.getClassifierClasspathProvider(projectFacade, classifier);
if(IClasspathManager.CLASSPATH_TEST == scope) {
classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor);
} else {
classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor);
}
projectResolved = true;
}
break;
case IClasspathEntry.CPE_CONTAINER:
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
if(container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) {
switch(container.getKind()) {
case IClasspathContainer.K_APPLICATION:
rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(),
IRuntimeClasspathEntry.USER_CLASSES, javaProject);
break;
// case IClasspathContainer.K_DEFAULT_SYSTEM:
// unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES, javaProject));
// break;
// case IClasspathContainer.K_SYSTEM:
// unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES, javaProject));
// break;
}
}
break;
case IClasspathEntry.CPE_LIBRARY:
rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
break;
case IClasspathEntry.CPE_VARIABLE:
if(!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) {
rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath());
}
break;
case IClasspathEntry.CPE_PROJECT:
IProject res = root.getProject(entry.getPath().segment(0));
if(res != null) {
IJavaProject otherProject = JavaCore.create(res);
if(otherProject != null) {
rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject);
}
}
break;
default:
break;
}
if(rce != null) {
addStandardClasspathEntries(resolved, rce, launchConfiguration);
}
}
}
示例11: processProject
/**
* Worker method to attach the given source archive to the project.
*
* @param monitor
* @param genProject
* @param attach
* @param sourceArchive
*/
private static void processProject(IProgressMonitor monitor, boolean attach, IProject genProject, File sourceArchive)
{
if (!isJavaProject(genProject)) {
Activator.log("Skipping non-java project: " + genProject.getName());
}
// Looks a bit funny, but we are not actually creating a new project.
IJavaProject project = JavaCore.create(genProject);
try
{
IClasspathEntry[] classpathEntries = project.getRawClasspath();
boolean dirty = false;
for (int i=0; i < classpathEntries.length; i++)
{
IClasspathEntry entry = classpathEntries[i];
//Activator.log("Processing: "+entry.getPath()+", kind="+entry.getEntryKind()+", src=" + entry.getSourceAttachmentPath());
// XML example:
// <classpathentry exported="true" kind="lib" path="bin/commerceservicesserver.jar" >
// <attributes>
// <attribute name="javadoc_location" value="https://download.hybris.com/api/5.5.1"/>
// </attributes>
// </classpathentry>
// Logic:
// (1) Filter for kind=lib: entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
// (2) Filter for path ending in server.jar
// (2.bis) Hybris JAR are : ybootstrap.jar or ytomcat.jar or yant.jar
boolean isLibrary = entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY;
String entryFileName = entry.getPath().lastSegment();
boolean isServerJar = entryFileName.endsWith( "server.jar" );
boolean isHybrisJar = entryFileName.equals( "ybootstrap.jar" ) || entryFileName.equals( "ytomcat.jar" ) || entryFileName.equals( "yant.jar" );
boolean isJarWithSource = isServerJar || isHybrisJar;
if( isJarWithSource && isLibrary )
{
IClasspathEntry newEntry = null;
if (attach)
{
Activator.log( "Attaching source: " + sourceArchive + " in: " + genProject.getName() );
newEntry = JavaCore.newLibraryEntry( entry.getPath(), Path.fromOSString( sourceArchive.getAbsolutePath() ),
entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported() );
}
else
{
Activator.log( "Detaching source from: " + genProject.getName() );
newEntry = JavaCore.newLibraryEntry( entry.getPath(), null, null, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported() );
}
classpathEntries[i] = newEntry;
dirty = true;
}
}
// And save it all back if we modified something
if (dirty)
{
project.setRawClasspath( classpathEntries, monitor );
}
}
catch( JavaModelException e )
{
Activator.log("Error getting classpath entries for project (" + genProject.getName() + "): " + e.getMessage()+". Skipping this project.");
}
}