1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.IOException ; 16 import java.io.InputStream ; 17 import java.util.ArrayList ; 18 import java.util.Dictionary ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Properties ; 22 import java.util.zip.ZipEntry ; 23 import java.util.zip.ZipFile ; 24 25 import org.eclipse.core.resources.IWorkspaceRunnable; 26 import org.eclipse.core.runtime.CoreException; 27 import org.eclipse.core.runtime.IProgressMonitor; 28 import org.eclipse.debug.core.ILaunchConfiguration; 29 import org.eclipse.jdt.launching.IVMInstall; 30 import org.eclipse.jdt.launching.JavaRuntime; 31 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 32 import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; 33 import org.eclipse.osgi.service.resolver.State; 34 import org.eclipse.pde.core.plugin.IPluginModelBase; 35 import org.eclipse.pde.core.plugin.PluginRegistry; 36 import org.eclipse.pde.internal.core.BundleValidationOperation; 37 import org.eclipse.pde.internal.core.TargetPlatformHelper; 38 import org.osgi.framework.Constants; 39 40 41 public abstract class LaunchValidationOperation implements IWorkspaceRunnable { 42 43 44 private BundleValidationOperation fOperation; 45 protected ILaunchConfiguration fLaunchConfiguration; 46 47 public LaunchValidationOperation(ILaunchConfiguration configuration) { 48 fLaunchConfiguration = configuration; 49 } 50 51 public void run(IProgressMonitor monitor) throws CoreException { 52 fOperation = new BundleValidationOperation(getModels(), getPlatformProperties()); 53 fOperation.run(monitor); 54 } 55 56 protected abstract IPluginModelBase[] getModels() throws CoreException; 57 58 protected Dictionary [] getPlatformProperties() throws CoreException { 59 IExecutionEnvironment[] envs = getMatchingEnvironments(); 60 if (envs.length == 0) 61 return new Dictionary [] {TargetPlatformHelper.getTargetEnvironment()}; 62 63 ArrayList result = new ArrayList (envs.length); 65 for (int i = 0; i < envs.length; i++) { 66 Properties profileProps = getJavaProfileProperties(envs[i].getId()); 67 if (profileProps != null) { 68 Dictionary props = TargetPlatformHelper.getTargetEnvironment(); 69 String systemPackages = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES); 70 if (systemPackages != null) 71 props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); 72 String ee = profileProps.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT); 73 if (ee != null) 74 props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee); 75 result.add(props); 76 } 77 } 78 if (result.size() > 0) 79 return (Dictionary [])result.toArray(new Dictionary [result.size()]); 80 return new Dictionary [] {TargetPlatformHelper.getTargetEnvironment()}; 81 82 } 83 84 private IExecutionEnvironment[] getMatchingEnvironments() throws CoreException { 85 IVMInstall install = VMHelper.getVMInstall(fLaunchConfiguration); 86 if (install == null) 87 return new IExecutionEnvironment[0]; 88 89 IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); 90 IExecutionEnvironment[] envs = manager.getExecutionEnvironments(); 91 List result = new ArrayList (envs.length); 92 for (int i = 0; i < envs.length; i++) { 93 IExecutionEnvironment env = envs[i]; 94 IVMInstall[] compatible = env.getCompatibleVMs(); 95 for (int j = 0; j < compatible.length; j++) { 96 if (compatible[j].equals(install)) { 97 result.add(env); 98 break; 99 } 100 } 101 } 102 return (IExecutionEnvironment[])result.toArray(new IExecutionEnvironment[result.size()]); 103 } 104 105 private Properties getJavaProfileProperties(String ee) { 106 IPluginModelBase model = PluginRegistry.findModel("system.bundle"); if (model == null) 108 return null; 109 110 File location = new File (model.getInstallLocation()); 111 String filename = ee.replace('/', '_') + ".profile"; InputStream is = null; 113 ZipFile zipFile = null; 114 try { 115 if (location.isDirectory()) { 117 File file = new File (location, filename); 118 if (file.exists()) 119 is = new FileInputStream (file); 120 } else { 121 zipFile = null; 122 try { 123 zipFile = new ZipFile (location, ZipFile.OPEN_READ); 124 ZipEntry entry = zipFile.getEntry(filename); 125 if (entry != null) 126 is = zipFile.getInputStream(entry); 127 } catch (IOException e) { 128 } 130 } 131 if (is != null) { 132 Properties profile = new Properties (); 133 profile.load(is); 134 return profile; 135 } 136 } catch (IOException e) { 137 } finally { 139 if (is != null) 140 try { 141 is.close(); 142 } catch (IOException e) { 143 } 145 if (zipFile != null) 146 try { 147 zipFile.close(); 148 } catch (IOException e) { 149 } 151 } 152 return null; 153 } 154 155 public boolean hasErrors() { 156 return fOperation.hasErrors(); 157 } 158 159 public Map getInput() { 160 return fOperation.getResolverErrors(); 161 } 162 163 public boolean isEmpty() { 164 return fOperation.getState().getHighestBundleId() == -1; 165 } 166 167 protected State getState() { 168 return fOperation.getState(); 169 } 170 171 } 172 | Popular Tags |