1 19 package org.netbeans.spi.java.classpath.support; 20 21 import org.netbeans.spi.java.classpath.PathResourceImplementation; 22 import org.netbeans.spi.java.classpath.ClassPathImplementation; 23 import org.netbeans.spi.java.classpath.ClassPathFactory; 24 import org.netbeans.modules.java.classpath.*; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.openide.ErrorManager; 27 import org.openide.filesystems.FileObject; 28 29 import java.net.URL ; 30 import java.util.List ; 31 import java.util.ArrayList ; 32 import org.openide.filesystems.FileStateInvalidException; 33 import org.openide.filesystems.FileUtil; 34 35 39 public class ClassPathSupport { 40 41 private ClassPathSupport () { 42 } 43 44 45 51 public static PathResourceImplementation createResource (URL url) { 52 if (url == null) { 53 throw new NullPointerException ("Cannot pass null URL to ClassPathSupport.createResource"); } 55 boolean assertions = false; 57 assert assertions = true; 58 if (assertions && FileUtil.isArchiveFile(url)) { 59 throw new IllegalArgumentException ("File URL pointing to " + "JAR is not valid classpath entry. Use jar: URL. Was: "+url); } 62 if (!url.toExternalForm().endsWith("/")) { throw new IllegalArgumentException ("URL must be a folder URL (append '/' if necessary): " + url); } 65 return new SimplePathResourceImplementation (url); 66 } 67 68 69 76 public static ClassPathImplementation createClassPathImplementation(List < ? extends PathResourceImplementation> entries) { 77 if (entries == null) { 78 throw new NullPointerException ("Cannot pass null entries"); } 80 return new SimpleClassPathImplementation(entries); 81 } 82 83 84 91 public static ClassPath createClassPath(List <? extends PathResourceImplementation> entries) { 92 if (entries == null) { 93 throw new NullPointerException ("Cannot pass null entries"); } 95 return ClassPathFactory.createClassPath(createClassPathImplementation(entries)); 96 } 97 98 99 106 public static ClassPath createClassPath (FileObject[] roots) { 107 assert roots != null; 108 List <PathResourceImplementation> l = new ArrayList <PathResourceImplementation> (); 109 for (FileObject root : roots) { 110 if (root == null) { 111 continue; 112 } 113 try { 114 URL u = root.getURL(); 115 l.add(createResource(u)); 116 } catch (FileStateInvalidException e) { 117 ErrorManager.getDefault().notify (e); 118 } 119 } 120 return createClassPath (l); 121 } 122 123 124 131 public static ClassPath createClassPath (URL [] roots) { 132 assert roots != null; 133 List <PathResourceImplementation> l = new ArrayList <PathResourceImplementation> (); 134 for (URL root : roots) { 135 if (root == null) 136 continue; 137 l.add (createResource(root)); 138 } 139 return createClassPath(l); 140 } 141 142 143 149 public static ClassPathImplementation createProxyClassPathImplementation (ClassPathImplementation[] delegates) { 150 return new ProxyClassPathImplementation (delegates); 151 } 152 153 154 160 public static ClassPath createProxyClassPath (ClassPath[] delegates) { 161 assert delegates != null; 162 ClassPathImplementation[] impls = new ClassPathImplementation [delegates.length]; 163 for (int i = 0; i < delegates.length; i++) { 164 impls[i] = ClassPathAccessor.DEFAULT.getClassPathImpl (delegates[i]); 165 } 166 return ClassPathFactory.createClassPath (createProxyClassPathImplementation(impls)); 167 } 168 169 } 170 | Popular Tags |