1 11 package org.eclipse.pde.internal.core.util; 12 13 import java.util.LinkedList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.IPackageFragmentRoot; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.core.JavaModelException; 23 import org.eclipse.pde.core.build.IBuild; 24 import org.eclipse.pde.core.build.IBuildEntry; 25 import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; 26 import org.eclipse.pde.internal.core.ibundle.IManifestHeader; 27 28 public class ManifestUtils { 29 30 private ManifestUtils() {} 31 32 public static IPackageFragmentRoot[] findPackageFragmentRoots(IManifestHeader header, IProject project) { 33 IJavaProject javaProject = JavaCore.create(project); 34 35 String [] libs; 36 if (header == null || header.getValue() == null) 37 libs = new String [] {"."}; else 39 libs = header.getValue().split(","); 41 IBuild build = getBuild(project); 42 if (build == null) { 43 try { 44 return javaProject.getPackageFragmentRoots(); 45 } catch (JavaModelException e) { 46 return new IPackageFragmentRoot[0]; 47 } 48 } 49 List pkgFragRoots = new LinkedList (); 50 for (int j = 0; j < libs.length; j++) { 51 String lib = libs[j]; 52 IPackageFragmentRoot root = null; 53 if (!lib.equals(".")) root = javaProject.getPackageFragmentRoot(project.getFile(lib)); 55 if (root != null && root.exists()) { 56 pkgFragRoots.add(root); 57 } else { 58 IBuildEntry entry = build.getEntry("source." + lib); if (entry == null) 60 continue; 61 String [] tokens = entry.getTokens(); 62 for (int i = 0; i < tokens.length; i++) { 63 IResource resource = project.findMember(tokens[i]); 64 if (resource == null) continue; 65 root = javaProject.getPackageFragmentRoot(resource); 66 if (root != null && root.exists()) 67 pkgFragRoots.add(root); 68 } 69 } 70 } 71 return (IPackageFragmentRoot[]) pkgFragRoots.toArray(new IPackageFragmentRoot[pkgFragRoots.size()]); 72 } 73 74 public final static IBuild getBuild(IProject project){ 75 IFile buildProps = project.getFile("build.properties"); if (buildProps.exists()) { 77 WorkspaceBuildModel model = new WorkspaceBuildModel(buildProps); 78 if (model != null) 79 return model.getBuild(); 80 } 81 return null; 82 } 83 84 public static boolean isImmediateRoot(IPackageFragmentRoot root) throws JavaModelException { 85 int kind = root.getKind(); 86 return kind == IPackageFragmentRoot.K_SOURCE 87 || (kind == IPackageFragmentRoot.K_BINARY && !root.isExternal()); 88 } 89 90 } 91 | Popular Tags |