当前位置: 首页>>代码示例>>Java>>正文


Java ClasspathEntry类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.core.ClasspathEntry的典型用法代码示例。如果您正苦于以下问题:Java ClasspathEntry类的具体用法?Java ClasspathEntry怎么用?Java ClasspathEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClasspathEntry类属于org.eclipse.jdt.internal.core包,在下文中一共展示了ClasspathEntry类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexAll

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
/**
 * Trigger addition of the entire content of a project Note: the actual operation is performed in
 * background
 */
public void indexAll(IProject project) {
  //        if (JavaCore.getPlugin() == null) return;

  // Also request indexing of binaries on the classpath
  // determine the new children
  try {
    JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
    JavaProject javaProject = (JavaProject) model.getJavaProject(project);
    // only consider immediate libraries - each project will do the same
    // NOTE: force to resolve CP variables before calling indexer - 19303, so that initializers
    // will be run in the current thread.
    IClasspathEntry[] entries = javaProject.getResolvedClasspath();
    for (int i = 0; i < entries.length; i++) {
      IClasspathEntry entry = entries[i];
      if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
        indexLibrary(
            entry.getPath(), project, ((ClasspathEntry) entry).getLibraryIndexLocation());
    }
  } catch (JavaModelException e) { // cannot retrieve classpath info
  }

  // check if the same request is not already in the queue
  IndexRequest request = new IndexAllProject(project, this);
  if (!isJobWaiting(request)) request(request);
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:IndexManager.java

示例2: addAndCreateSourceEntry

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
/**
 * Create a source entry (including the dir structure) and add it to the raw
 * classpath.
 * 
 * @param javaProject The Java project that receives the source entry
 * @param directoryName The source directory name
 * @param outputDirectoryName The optional output location of this source
 *          directory. Pass null for the default output location.
 */
private static void addAndCreateSourceEntry(IJavaProject javaProject,
    String directoryName, String outputDirectoryName) throws CoreException {
  IFolder srcFolder = javaProject.getProject().getFolder(directoryName);
  ResourceUtils.createFolderStructure(javaProject.getProject(),
      srcFolder.getProjectRelativePath());
  
  IPath workspaceRelOutPath = null;
  if (outputDirectoryName != null) {
    // Ensure output directory exists
    IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName);
    ResourceUtils.createFolderStructure(javaProject.getProject(),
        outFolder.getProjectRelativePath());
    workspaceRelOutPath = outFolder.getFullPath();
  }
  
  JavaProjectUtilities.addRawClassPathEntry(javaProject,
      JavaCore.newSourceEntry(srcFolder.getFullPath(),
          ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath));
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:29,代码来源:GWTCompileRunnerTest.java

示例3: fixTestSourceDirectorySettings

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
private void fixTestSourceDirectorySettings(IProject newProject, IProgressMonitor monitor)
    throws CoreException {
  // 1. Fix the output folder of "src/test/java".
  IPath testSourcePath = newProject.getFolder("src/test/java").getFullPath();

  IJavaProject javaProject = JavaCore.create(newProject);
  IClasspathEntry[] entries = javaProject.getRawClasspath();
  for (int i = 0; i < entries.length; i++) {
    IClasspathEntry entry = entries[i];
    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
        && entry.getPath().equals(testSourcePath)
        && entry.getOutputLocation() == null) {  // Default output location?
      IPath oldOutputPath = javaProject.getOutputLocation();
      IPath newOutputPath = oldOutputPath.removeLastSegments(1).append("test-classes");

      entries[i] = JavaCore.newSourceEntry(testSourcePath, ClasspathEntry.INCLUDE_ALL,
          ClasspathEntry.EXCLUDE_NONE, newOutputPath);
      javaProject.setRawClasspath(entries, monitor);
      break;
    }
  }

  // 2. Remove "src/test/java" from the Web Deployment Assembly sources.
  deployAssemblyEntryRemoveJob =
      new DeployAssemblyEntryRemoveJob(newProject, new Path("src/test/java"));
  deployAssemblyEntryRemoveJob.setSystem(true);
  deployAssemblyEntryRemoveJob.schedule();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:29,代码来源:CreateAppEngineWtpProject.java

示例4: addLibraryEntry

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
protected void addLibraryEntry(IJavaProject project, IPath path, IPath srcAttachmentPath, IPath srcAttachmentPathRoot, IPath[] accessibleFiles, IPath[] nonAccessibleFiles, IClasspathAttribute[] extraAttributes, boolean exported) throws JavaModelException{
	IClasspathEntry[] entries = project.getRawClasspath();
	int length = entries.length;
	System.arraycopy(entries, 0, entries = new IClasspathEntry[length + 1], 0, length);
	entries[length] = JavaCore.newLibraryEntry(
		path,
		srcAttachmentPath,
		srcAttachmentPathRoot,
		ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles),
		extraAttributes,
		exported);
	project.setRawClasspath(entries, null);
}
 
开发者ID:jwloka,项目名称:reflectify,代码行数:14,代码来源:AbstractJavaModelTests.java

示例5: configureProjectClasspath

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
private static void configureProjectClasspath(IJavaProject jProject) throws CoreException, JavaModelException, IOException, URISyntaxException {
	// create bin folder
	try {
		IFolder binFolder = jProject.getProject().getFolder(BINARY_DIRECTORY);
		binFolder.create(false, true, null);
		jProject.setOutputLocation(binFolder.getFullPath(), null);
	} catch (Exception e){
		Log.warning("Could not created bin folder.", e);
	}
	
	// create a set of classpath entries
	List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); 
	
	// adds classpath entry of: <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
	String path = org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER + "/" + org.eclipse.jdt.internal.launching.StandardVMType.ID_STANDARD_VM_TYPE + "/" + "JavaSE-1.8";
	entries.add(JavaCore.newContainerEntry(new Path(path)));
	
	//  add the jreframeworker annotations jar 
	addProjectAnnotationsLibrary(jProject);

	// have to create this manually instead of using JavaCore.newLibraryEntry because JavaCore insists the path be absolute
	IClasspathEntry relativeAnnotationsLibraryEntry = new ClasspathEntry(IPackageFragmentRoot.K_BINARY,
			IClasspathEntry.CPE_LIBRARY, new Path(JREF_PROJECT_RESOURCE_DIRECTORY + "/" + JRE_FRAMEWORKER_ANNOTATIONS_JAR), ClasspathEntry.INCLUDE_ALL, // inclusion patterns
			ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
			null, null, null, // specific output folder
			false, // exported
			ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to combine
			ClasspathEntry.NO_EXTRA_ATTRIBUTES);
	entries.add(relativeAnnotationsLibraryEntry);
	
	// create source folder and add it to the classpath
	IFolder sourceFolder = jProject.getProject().getFolder(SOURCE_DIRECTORY);
	sourceFolder.create(false, true, null);
	IPackageFragmentRoot sourceFolderRoot = jProject.getPackageFragmentRoot(sourceFolder);
	entries.add(JavaCore.newSourceEntry(sourceFolderRoot.getPath()));
	
	// set the class path
	jProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
	
	if(JReFrameworkerPreferences.isVerboseLoggingEnabled()) Log.info("Successfully created JReFrameworker project: " + jProject.getProject().getName());
}
 
开发者ID:JReFrameworker,项目名称:JReFrameworker,代码行数:42,代码来源:JReFrameworker.java

示例6: addProjectLibrary

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
/**
 * Copies a jar into the project at the specified relative path and updates the classpath
 * @param jProject
 * @param libraryToAdd
 * @param relativeDirectoryPath
 * @throws IOException
 * @throws URISyntaxException
 * @throws MalformedURLException
 * @throws CoreException
 */
private static String addProjectLibrary(IJavaProject jProject, File libraryToAdd, String relativeDirectoryPath) throws IOException, URISyntaxException, MalformedURLException, CoreException {
	
	// only add the project library to the classpath if its not already there
	for(IClasspathEntry entry : jProject.getRawClasspath()){
		if(entry.getPath().toFile().getName().endsWith(libraryToAdd.getName())){
			return entry.getPath().toString();
		}
	}
	
    // copy the jar file into the project (if its not already there)
    InputStream libraryInputStream = new BufferedInputStream(new FileInputStream(libraryToAdd));
    File libDirectory;
    if(relativeDirectoryPath == null || relativeDirectoryPath.equals("")){
    	libDirectory = new File(jProject.getProject().getLocation().toFile().getCanonicalPath());
    } else {
    	relativeDirectoryPath = relativeDirectoryPath.replace("/", File.separator).replace("\\", File.separator);
    	libDirectory = new File(jProject.getProject().getLocation().toFile().getCanonicalPath() + File.separator + relativeDirectoryPath);
    }
	libDirectory.mkdirs();
	File library = new File(libDirectory.getCanonicalPath() + File.separatorChar + libraryToAdd.getName());
	if(!library.exists()){
		Files.copy(libraryInputStream, library.toPath());
	}

	// refresh project
	jProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
	
    // create a classpath entry for the library
	IClasspathEntry relativeLibraryEntry;
	if(relativeDirectoryPath != null){
    	relativeDirectoryPath = relativeDirectoryPath.replace(File.separator, "/");
    	// library is at some path relative to project root
    	relativeLibraryEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(
    	        IPackageFragmentRoot.K_BINARY,
    	        IClasspathEntry.CPE_LIBRARY, jProject.getProject().getFile(relativeDirectoryPath + "/" + library.getName()).getLocation(),
    	        ClasspathEntry.INCLUDE_ALL, // inclusion patterns
    	        ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
    	        null, null, null, // specific output folder
    	        false, // exported
    	        ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to combine
    	        ClasspathEntry.NO_EXTRA_ATTRIBUTES);
    } else {
    	// library placed at project root
    	relativeLibraryEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(
    	        IPackageFragmentRoot.K_BINARY,
    	        IClasspathEntry.CPE_LIBRARY, jProject.getProject().getFile(library.getName()).getLocation(),
    	        ClasspathEntry.INCLUDE_ALL, // inclusion patterns
    	        ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
    	        null, null, null, // specific output folder
    	        false, // exported
    	        ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to combine
    	        ClasspathEntry.NO_EXTRA_ATTRIBUTES);
    }

    // add the new classpath entry to the project's existing entries
    IClasspathEntry[] oldEntries = jProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldEntries.length] = relativeLibraryEntry;
    jProject.setRawClasspath(newEntries, null);
    
    // refresh project
 	jProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
 	
 	return relativeLibraryEntry.getPath().toString();
}
 
开发者ID:JReFrameworker,项目名称:JReFrameworker,代码行数:77,代码来源:JReFrameworkerProject.java

示例7: computeClasspathLocations

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
private void computeClasspathLocations(IWorkspaceRoot workspaceRoot, JavaProject javaProject) {

	IPackageFragmentRoot[] roots = null;
	try {
		roots = javaProject.getAllPackageFragmentRoots();
	} catch (JavaModelException e) {
		// project doesn't exist
		this.locations = new ClasspathLocation[0];
		return;
	}
	int length = roots.length;
	ClasspathLocation[] cpLocations = new ClasspathLocation[length];
	int index = 0;
	JavaModelManager manager = JavaModelManager.getJavaModelManager();
	for (int i = 0; i < length; i++) {
		PackageFragmentRoot root = (PackageFragmentRoot) roots[i];
		IPath path = root.getPath();
		try {
			if (root.isArchive()) {
				ZipFile zipFile = manager.getZipFile(path);
				cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
			} else {
				Object target = JavaModel.getTarget(path, true);
				if (target == null) {
					// target doesn't exist any longer
					// just resize cpLocations
					System.arraycopy(cpLocations, 0, cpLocations = new ClasspathLocation[cpLocations.length-1], 0, index);
				} else if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
					cpLocations[index++] = new ClasspathSourceDirectory((IContainer)target, root.fullExclusionPatternChars(), root.fullInclusionPatternChars());
				} else {
					cpLocations[index++] = ClasspathLocation.forBinaryFolder((IContainer) target, false, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
				}
			}
		} catch (CoreException e1) {
			// problem opening zip file or getting root kind
			// consider root corrupt and ignore
			// just resize cpLocations
			System.arraycopy(cpLocations, 0, cpLocations = new ClasspathLocation[cpLocations.length-1], 0, index);
		}
	}
	this.locations = cpLocations;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:43,代码来源:JavaSearchNameEnvironment.java

示例8: addRequiredProject

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
/** Adds a project to the classpath of a project.
 */
public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, IPath[] accessibleFiles, IPath[] nonAccessibleFiles, boolean isExported) throws JavaModelException {
	checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$
	IAccessRule[] accessRules = ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles);
	addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, accessRules, true, new IClasspathAttribute[0], isExported));
}
 
开发者ID:vogellacompany,项目名称:codemodify,代码行数:8,代码来源:TestingEnvironment.java

示例9: getRequiredProjects

import org.eclipse.jdt.internal.core.ClasspathEntry; //导入依赖的package包/类
private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
	JavaProject javaProject = (JavaProject) JavaCore.create(this.project);
	IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot();
	if (javaProject == null || workspaceRoot == null) {
		return ZERO_PROJECT;
	}

	List<IProject> projects = new ArrayList<IProject>();
	ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
	try {
		IClasspathEntry[] entries = javaProject.getExpandedClasspath();
		for (int i = 0, l = entries.length; i < l; i++) {
			IClasspathEntry entry = entries[i];
			IPath path = entry.getPath();
			IProject p = null;
			switch (entry.getEntryKind()) {
				case IClasspathEntry.CPE_PROJECT :
					p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
					if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
						p = null;
					break;
				case IClasspathEntry.CPE_LIBRARY :
					if (includeBinaryPrerequisites && path.segmentCount() > 0) {
						// some binary resources on the class path can come from projects that are not included in the project references
						IResource resource = workspaceRoot.findMember(path.segment(0));
						if (resource instanceof IProject) {
							p = (IProject) resource;
						} else {
							resource = externalFoldersManager.getFolder(path);
							if (resource != null)
								p = resource.getProject();
						}
					}
			}
			if (p != null && !projects.contains(p))
				projects.add(p);
		}
	} catch(JavaModelException e) {
		return ZERO_PROJECT;
	}
	IProject[] result = new IProject[projects.size()];
	projects.toArray(result);
	return result;
}
 
开发者ID:ashishsureka,项目名称:parichayana,代码行数:45,代码来源:ParichayanaBuilder.java


注:本文中的org.eclipse.jdt.internal.core.ClasspathEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。