1 19 package org.netbeans.modules.java; 20 21 import java.beans.PropertyChangeListener ; 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Collections ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.regex.Pattern ; 30 import org.netbeans.api.java.classpath.ClassPath; 31 import org.netbeans.api.java.platform.JavaPlatform; 32 import org.netbeans.api.java.platform.Specification; 33 import org.netbeans.modules.java.platform.JavaPlatformProvider; 34 import org.netbeans.spi.java.classpath.ClassPathProvider; 35 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileStateInvalidException; 39 import org.openide.filesystems.FileUtil; 40 import org.openide.modules.SpecificationVersion; 41 42 46 public class TestJavaPlatformProviderImpl implements JavaPlatformProvider { 47 48 49 public TestJavaPlatformProviderImpl() { 50 } 51 52 public JavaPlatform[] getInstalledPlatforms() { 53 return new JavaPlatform[] {getDefaultPlatform()}; 54 } 55 56 private static DefaultPlatform DEFAULT = new DefaultPlatform(); 57 58 public JavaPlatform getDefaultPlatform() { 59 return DEFAULT; 60 } 61 62 public void addPropertyChangeListener(PropertyChangeListener listener) { 63 } 64 65 public void removePropertyChangeListener(PropertyChangeListener listener) { 66 } 67 68 private static final class DefaultPlatform extends JavaPlatform { 69 private static ClassPath EMPTY = ClassPathSupport.createClassPath(Collections.EMPTY_LIST); 70 71 public String getDisplayName() { 72 return "default"; 73 } 74 75 public Map getProperties() { 76 return Collections.emptyMap(); 77 } 78 79 private static ClassPath bootClassPath; 80 81 private static synchronized ClassPath getBootClassPath() { 82 if (bootClassPath == null) { 83 try { 84 String cp = System.getProperty("sun.boot.class.path"); 85 List <URL > urls = new ArrayList <URL >(); 86 String [] paths = cp.split(Pattern.quote(System.getProperty("path.separator"))); 87 88 for (String path : paths) { 89 File f = new File (path); 90 91 if (!f.canRead()) 92 continue; 93 94 FileObject fo = FileUtil.toFileObject(f); 95 96 if (FileUtil.isArchiveFile(fo)) { 97 fo = FileUtil.getArchiveRoot(fo); 98 } 99 100 if (fo != null) { 101 urls.add(fo.getURL()); 102 } 103 } 104 105 bootClassPath = ClassPathSupport.createClassPath((URL [])urls.toArray(new URL [0])); 106 } catch (FileStateInvalidException e) { 107 ErrorManager.getDefault().notify(e); 108 } 109 } 110 111 return bootClassPath; 112 } 113 114 public ClassPath getBootstrapLibraries() { 115 return getBootClassPath(); 116 } 117 118 public ClassPath getStandardLibraries() { 119 return EMPTY; 120 } 121 122 public String getVendor() { 123 return ""; 124 } 125 126 private Specification spec = new Specification("j2se", new SpecificationVersion("1.5")); 127 128 public Specification getSpecification() { 129 return spec; 130 } 131 132 public Collection getInstallFolders() { 133 throw new UnsupportedOperationException (); 134 } 135 136 public FileObject findTool(String toolName) { 137 return null; } 139 140 public ClassPath getSourceFolders() { 141 return EMPTY; 142 } 143 144 public List getJavadocFolders() { 145 return Collections.emptyList(); 146 } 147 148 } 149 150 } 151 | Popular Tags |