1 33 34 package edu.rice.cs.drjava.model.repl.newjvm; 35 36 import java.net.URL ; 37 import java.util.LinkedList ; 38 import java.util.List ; 39 import java.lang.ClassLoader ; 40 import edu.rice.cs.drjava.model.ClassPathEntry; 41 import edu.rice.cs.drjava.model.DeadClassLoader; 42 import edu.rice.cs.drjava.model.BrainClassLoader; 43 44 import edu.rice.cs.util.ClassPathVector; 45 46 47 public class ClassPathManager{ 48 49 private LinkedList <ClassPathEntry> projectCP; 50 private LinkedList <ClassPathEntry> buildCP; 51 private LinkedList <ClassPathEntry> projectFilesCP; 52 private LinkedList <ClassPathEntry> externalFilesCP; 53 private LinkedList <ClassPathEntry> extraCP; 54 55 58 public ClassPathManager() { 59 projectCP = new LinkedList <ClassPathEntry>(); 60 buildCP = new LinkedList <ClassPathEntry>(); 61 projectFilesCP = new LinkedList <ClassPathEntry>(); 62 externalFilesCP = new LinkedList <ClassPathEntry>(); 63 extraCP = new LinkedList <ClassPathEntry>(); 64 } 67 68 71 public synchronized void addProjectCP(URL f) { projectCP.add(0, new ClassPathEntry(f)); } 72 73 public synchronized ClassPathEntry[] getProjectCP() { 74 return projectCP.toArray(new ClassPathEntry[projectCP.size()]); 75 } 76 77 78 public synchronized void addBuildDirectoryCP(URL f) { 79 buildCP.addFirst(new ClassPathEntry(f)); 80 } 81 82 public synchronized ClassPathEntry[] getBuildDirectoryCP() { 83 return buildCP.toArray(new ClassPathEntry[buildCP.size()]); 84 } 85 86 87 public synchronized void addProjectFilesCP(URL f) { projectFilesCP.addFirst(new ClassPathEntry(f)); } 88 89 public synchronized ClassPathEntry[] getProjectFilesCP() { 90 return projectFilesCP.toArray(new ClassPathEntry[projectFilesCP.size()]); 91 } 92 93 94 public void addExternalFilesCP(URL f) { externalFilesCP.add(0, new ClassPathEntry(f)); } 95 96 public ClassPathEntry[] getExternalFilesCP() { 97 return externalFilesCP.toArray(new ClassPathEntry[externalFilesCP.size()]); 98 } 99 100 101 public synchronized void addExtraCP(URL f) { extraCP.addFirst(new ClassPathEntry(f)); } 102 103 public ClassPathEntry[] getExtraCP() { return extraCP.toArray(new ClassPathEntry[extraCP.size()]); } 104 105 106 public synchronized ClassLoader getClassLoader() { 107 return new BrainClassLoader(buildClassLoader(projectCP), 108 buildClassLoader(buildCP), 109 buildClassLoader(projectFilesCP), 110 buildClassLoader(externalFilesCP), 111 buildClassLoader(extraCP)); 112 } 113 114 115 private ClassLoader buildClassLoader(List <ClassPathEntry>locpe) { 116 ClassLoader c = new DeadClassLoader(); 117 for(ClassPathEntry cpe: locpe) { c = cpe.getClassLoader(c); } 118 return c; 119 } 120 121 122 public synchronized ClassPathVector getAugmentedClassPath() { 123 ClassPathVector ret = new ClassPathVector(); 124 125 for (ClassPathEntry e: getProjectCP()) { ret.add(e.getEntry()); } 126 127 for (ClassPathEntry e: getBuildDirectoryCP()) { ret.add(e.getEntry()); } 128 129 for (ClassPathEntry e: getProjectFilesCP()) { ret.add(e.getEntry()); } 130 131 for (ClassPathEntry e: getExternalFilesCP()) { ret.add(e.getEntry()); } 132 133 for (ClassPathEntry e: getExtraCP()) { ret.add(e.getEntry()); } 134 return ret; 135 } 136 137 } 138 139 | Popular Tags |