1 19 20 package org.netbeans.modules.java.platform; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.security.CodeSource ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.StringTokenizer ; 32 import org.netbeans.api.java.classpath.ClassPath; 33 import org.netbeans.api.java.platform.JavaPlatform; 34 import org.netbeans.api.java.platform.Specification; 35 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.modules.Dependency; 39 40 44 public class FallbackDefaultJavaPlatform extends JavaPlatform { 45 46 public FallbackDefaultJavaPlatform() { 47 setSystemProperties(System.getProperties()); 48 } 49 50 public String getDisplayName() { 51 return System.getProperty("java.vm.vendor") + " " + System.getProperty("java.vm.version"); } 53 54 public Map getProperties() { 55 return Collections.singletonMap("platform.ant.name", "default_platform"); 56 } 57 58 private static ClassPath sysProp2CP(String propname) { 59 String sbcp = System.getProperty(propname); 60 if (sbcp == null) { 61 return null; 62 } 63 List roots = new ArrayList (); 64 StringTokenizer tok = new StringTokenizer (sbcp, File.pathSeparator); 65 while (tok.hasMoreTokens()) { 66 File f = new File (tok.nextToken()); 67 if (!f.exists()) { 68 continue; 69 } 70 URL u; 71 try { 72 u = f.toURI().toURL(); 73 } catch (MalformedURLException x) { 74 throw new AssertionError (x); 75 } 76 if (FileUtil.isArchiveFile(u)) { 77 u = FileUtil.getArchiveRoot(u); 78 } 79 roots.add(u); 80 } 81 return ClassPathSupport.createClassPath((URL []) roots.toArray(new URL [roots.size()])); 82 } 83 84 private static ClassPath sampleClass2CP(Class prototype) { 85 CodeSource cs = prototype.getProtectionDomain().getCodeSource(); 86 return ClassPathSupport.createClassPath(cs != null ? new URL [] {cs.getLocation()} : new URL [0]); 87 } 88 89 public ClassPath getBootstrapLibraries() { 90 ClassPath cp = sysProp2CP("sun.boot.class.path"); return cp != null ? cp : sampleClass2CP(Object .class); 93 } 94 95 public ClassPath getStandardLibraries() { 96 ClassPath cp = sysProp2CP("java.class.path"); return cp != null ? cp : sampleClass2CP( Dependency.class); 98 } 99 100 public String getVendor() { 101 return System.getProperty("java.vm.vendor"); 102 } 103 104 public Specification getSpecification() { 105 return new Specification("J2SE", Dependency.JAVA_SPEC); } 107 108 public Collection getInstallFolders() { 109 return Collections.singleton(FileUtil.toFileObject(new File (System.getProperty("java.home")))); } 111 112 public FileObject findTool(String toolName) { 113 return null; } 115 116 public ClassPath getSourceFolders() { 117 return ClassPathSupport.createClassPath(new URL [0]); 118 } 119 120 public List getJavadocFolders() { 121 return Collections.emptyList(); 122 } 123 124 } 125 | Popular Tags |