1 5 package org.terracotta.dso; 6 7 import org.apache.commons.io.FileUtils; 8 import org.eclipse.core.runtime.CoreException; 9 import org.eclipse.core.runtime.IPath; 10 import org.eclipse.core.runtime.Path; 11 import org.eclipse.debug.core.ILaunchConfiguration; 12 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 13 import org.eclipse.jdt.launching.JavaRuntime; 14 import org.eclipse.jdt.launching.StandardClasspathProvider; 15 import org.xml.sax.Attributes ; 16 import org.xml.sax.helpers.DefaultHandler ; 17 18 import java.io.File ; 19 import java.io.FileInputStream ; 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import javax.xml.parsers.SAXParser ; 28 import javax.xml.parsers.SAXParserFactory ; 29 30 public class ClasspathProvider extends StandardClasspathProvider { 31 public ClasspathProvider() { 32 super(); 33 } 34 35 public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException { 36 IRuntimeClasspathEntry[] cpe = super.computeUnresolvedClasspath(configuration); 37 IPath jarPath = TcPlugin.getDefault().getLibDirPath().append("tc.jar"); 38 39 if (jarPath.toFile().exists()) { 40 IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[cpe.length + 1]; 41 42 System.arraycopy(cpe, 0, result, 0, cpe.length); 43 result[cpe.length] = JavaRuntime.newArchiveRuntimeClasspathEntry(jarPath.makeAbsolute()); 44 45 return result; 46 } else { 47 ArrayList <IRuntimeClasspathEntry> list = new ArrayList <IRuntimeClasspathEntry>(Arrays.asList(cpe)); 48 IPath[] paths = gatherDevClasspathEntries(); 49 50 for (int i = 0; i < paths.length; i++) { 51 list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(paths[i])); 52 } 53 54 return list.toArray(new IRuntimeClasspathEntry[0]); 55 } 56 } 57 58 public static String makeDevClasspath() { 59 IPath[] paths = gatherDevClasspathEntries(); 60 StringBuffer sb = new StringBuffer (); 61 String sep = System.getProperty("path.separator"); 62 63 for (int i = 0; i < paths.length; i++) { 64 if (i > 0) sb.append(sep); 65 sb.append(paths[i].toOSString()); 66 } 67 68 return sb.toString(); 69 } 70 71 private static Collection <File > listArchives(File dir) { 72 Collection c = FileUtils.listFiles(dir, new String [] { "jar" }, false); 73 Collection <File > result = new HashSet <File >(); 74 Iterator iter = c.iterator(); 75 76 while (iter.hasNext()) { 77 result.add((File ) iter.next()); 78 } 79 80 return result; 81 } 82 83 private static IPath[] gatherDevClasspathEntries() { 84 IPath location = TcPlugin.getDefault().getLocation(); 85 List <IPath> list = new ArrayList <IPath>(); 86 IPath buildPath = location.append(".."); 87 88 String [] dirs = { "deploy", "common", "management", "aspectwerkz", "thirdparty", "dso-common", "dso-common-jdk15", 89 "dso-l1", "dso-l1-jdk15", "dso-l2" }; 90 91 for (int i = 0; i < dirs.length; i++) { 92 list.add(buildPath.append(dirs[i]).append("build.eclipse").append("src.classes")); 93 } 94 95 final List <File > fileList = new ArrayList <File >(); 96 File libDir; 97 98 for (int i = 0; i < dirs.length; i++) { 99 libDir = location.append("..").append(dirs[i]).append("lib").toFile(); 100 101 if (libDir.exists()) { 102 fileList.addAll(listArchives(libDir)); 103 } 104 } 105 106 final File dependencies = location.append("..").append("dependencies").append("lib").toFile(); 107 File ivy = null; 108 File projectDir = null; 109 String dir = null; 110 try { 111 for (int i = 0; i < dirs.length; i++) { 112 dir = dirs[i]; 113 projectDir = location.append("..").append(dir).toFile(); 114 ivy = new File (projectDir + File.separator + "ivy.xml"); 115 if (ivy.exists()) { 116 SAXParserFactory factory = SAXParserFactory.newInstance(); 117 SAXParser parser = factory.newSAXParser(); 118 parser.parse(new FileInputStream (ivy), new DefaultHandler () { 119 public void startElement(String uri, String localName, String qName, Attributes attributes) { 120 if (qName.equals("dependency")) { 121 String jar = attributes.getValue("name") + "-" + attributes.getValue("rev"); 122 File jarFile = new File (dependencies + File.separator + jar + ".jar"); 123 fileList.add(jarFile); 124 } 125 } 126 }); 127 } 128 } 129 } catch (Throwable e) { 130 TcPlugin.getDefault().openError("Problem Parsing ivy.xml file in: " + dir, e); 131 } 132 133 Iterator fileIter = fileList.iterator(); 134 File file; 135 136 while (fileIter.hasNext()) { 137 file = (File ) fileIter.next(); 138 if (!file.getName().startsWith("org.eclipse")) { 139 list.add(new Path(file.getAbsolutePath())); 140 } 141 } 142 143 return list.toArray(new IPath[list.size()]); 144 } 145 } 146 | Popular Tags |