1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Collection ; 27 import java.util.Collections ; 28 import java.util.List ; 29 import java.util.Map ; 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.support.ClassPathSupport; 35 import org.openide.filesystems.FileObject; 36 import org.openide.modules.SpecificationVersion; 37 38 41 public final class TestPlatformProvider implements JavaPlatformProvider { 42 43 private JavaPlatform defaultPlatform; 44 private JavaPlatform explicitPlatform; 45 private PropertyChangeSupport support; 46 private boolean hideExplicitPlatform; 47 48 49 public TestPlatformProvider() { 50 this(null, null); 51 } 52 53 public TestPlatformProvider(ClassPath defaultPlatformBootClassPath, ClassPath explicitPlatformBootClassPath) { 54 this.support = new PropertyChangeSupport (this); 55 this.defaultPlatform = new TestPlatform("default_platform", "1.5", defaultPlatformBootClassPath); 56 this.explicitPlatform = new TestPlatform("ExplicitPlatform", "1.4", explicitPlatformBootClassPath); 57 } 58 59 public void removePropertyChangeListener(PropertyChangeListener listener) { 60 this.support.removePropertyChangeListener(listener); 61 } 62 63 public void addPropertyChangeListener(PropertyChangeListener listener) { 64 this.support.addPropertyChangeListener(listener); 65 } 66 67 public JavaPlatform[] getInstalledPlatforms() { 68 if (this.hideExplicitPlatform) { 69 return new JavaPlatform[] { 70 this.defaultPlatform, 71 }; 72 } else { 73 return new JavaPlatform[] { 74 this.defaultPlatform, 75 this.explicitPlatform, 76 }; 77 } 78 } 79 80 public JavaPlatform getDefaultPlatform() { 81 return this.defaultPlatform; 82 } 83 84 public void setExplicitPlatformVisible(boolean value) { 85 this.hideExplicitPlatform = !value; 86 this.support.firePropertyChange(PROP_INSTALLED_PLATFORMS,null,null); 87 } 88 89 private static class TestPlatform extends JavaPlatform { 90 91 private final String systemName; 92 private final Map properties; 93 private final ClassPath bootClassPath; 94 private final String specVersion; 95 96 public TestPlatform(String systemName, String specVersion, ClassPath bootCP) { 97 this.systemName = systemName; 98 this.specVersion = specVersion; 99 if (bootCP == null) { 100 try { 101 this.bootClassPath = ClassPathSupport.createClassPath(new URL [] { 102 new URL ("jar:file:/c:/java/" + systemName + "/jre/lib/rt.jar!/"), 105 }); 106 } catch (MalformedURLException e) { 107 throw new AssertionError (e); 108 } 109 } else { 110 this.bootClassPath = bootCP; 111 } 112 this.properties = Collections.singletonMap("platform.ant.name",this.systemName); 113 } 114 115 public FileObject findTool(String toolName) { 116 return null; 117 } 118 119 public String getVendor() { 120 return "me"; 121 } 122 123 public ClassPath getStandardLibraries() { 124 return null; 125 } 126 127 public Specification getSpecification() { 128 return new Specification("j2se", new SpecificationVersion(specVersion)); 129 } 130 131 public ClassPath getSourceFolders() { 132 return null; 133 } 134 135 public Map getProperties() { 136 return this.properties; 137 } 138 139 public List getJavadocFolders() { 140 return null; 141 } 142 143 public Collection getInstallFolders() { 144 return null; 145 } 146 147 public String getDisplayName() { 148 return this.systemName; 149 } 150 151 public ClassPath getBootstrapLibraries() { 152 return this.bootClassPath; 153 } 154 } 155 } 156 | Popular Tags |