1 11 package org.eclipse.ant.internal.ui.launchConfigurations; 12 13 import java.io.File ; 14 import java.io.FilenameFilter ; 15 import java.io.IOException ; 16 import java.net.MalformedURLException ; 17 import java.net.URL ; 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.eclipse.ant.core.AntCorePlugin; 22 import org.eclipse.ant.core.AntCorePreferences; 23 import org.eclipse.ant.core.IAntClasspathEntry; 24 import org.eclipse.ant.internal.ui.AntUIPlugin; 25 import org.eclipse.ant.internal.ui.AntUtil; 26 import org.eclipse.ant.internal.ui.IAntUIConstants; 27 import org.eclipse.core.runtime.CoreException; 28 import org.eclipse.core.runtime.FileLocator; 29 import org.eclipse.core.runtime.IPath; 30 import org.eclipse.core.runtime.Path; 31 import org.eclipse.core.runtime.Platform; 32 import org.eclipse.debug.core.ILaunchConfiguration; 33 import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry; 34 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 35 import org.eclipse.jdt.launching.IVMInstall; 36 import org.eclipse.jdt.launching.JavaRuntime; 37 import org.eclipse.osgi.service.resolver.BundleDescription; 38 import org.osgi.framework.Bundle; 39 import org.w3c.dom.Document ; 40 import org.w3c.dom.Element ; 41 42 48 public class ContributedClasspathEntriesEntry extends AbstractRuntimeClasspathEntry { 49 50 public static final String TYPE_ID = "org.eclipse.ant.ui.classpathentry.extraClasspathEntries"; 52 public static List fgSWTEntries= null; 53 54 57 public ContributedClasspathEntriesEntry() { 58 } 59 60 63 protected void buildMemento(Document document, Element memento) throws CoreException { 64 } 65 66 69 public void initializeFrom(Element memento) throws CoreException { 70 } 71 72 75 public String getTypeId() { 76 return TYPE_ID; 77 } 78 79 82 public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration configuration) throws CoreException { 83 boolean separateVM= AntUtil.isSeparateJREAntBuild(configuration); 84 boolean setInputHandler= configuration.getAttribute(IAntUIConstants.SET_INPUTHANDLER, true); 85 AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences(); 86 IAntClasspathEntry[] antClasspathEntries = prefs.getContributedClasspathEntries(); 87 IAntClasspathEntry[] userEntries = prefs.getAdditionalClasspathEntries(); 88 List rtes = new ArrayList (antClasspathEntries.length + userEntries.length); 89 IAntClasspathEntry entry; 90 for (int i = 0; i < antClasspathEntries.length; i++) { 91 entry= antClasspathEntries[i]; 92 if (!separateVM || (separateVM && !entry.isEclipseRuntimeRequired())) { 93 rtes.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel())); 94 } 95 } 96 boolean haveToolsEntry= false; 97 String path; 98 for (int i = 0; i < userEntries.length; i++) { 99 entry = userEntries[i]; 100 path= entry.getLabel(); 101 IPath toolsPath= new Path(path); 102 if (toolsPath.lastSegment().equals("tools.jar")) { haveToolsEntry= true; 104 addToolsJar(configuration, rtes, path); 107 } else { 108 rtes.add(JavaRuntime.newStringVariableClasspathEntry(path)); 109 } 110 } 111 if (!haveToolsEntry) { 112 addToolsJar(configuration, rtes, null); 113 } 114 115 if (setInputHandler && separateVM) { 116 addSWTJars(rtes); 117 } 118 119 return (IRuntimeClasspathEntry[]) rtes.toArray(new IRuntimeClasspathEntry[rtes.size()]); 120 } 121 122 private void addToolsJar(ILaunchConfiguration configuration, List rtes, String path) { 123 IRuntimeClasspathEntry tools = getToolsJar(configuration); 124 if (tools == null) { 125 if (path != null) { 126 rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(path))); 128 } else { 129 IVMInstall install= JavaRuntime.getDefaultVMInstall(); 131 if (install != null) { 132 IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath())); 133 if (entry != null) { 134 rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath()))); 135 } 136 } 137 } 138 } else { 139 rtes.add(tools); 140 } 141 } 142 143 private void addSWTJars(List rtes) { 144 if (fgSWTEntries == null) { 145 fgSWTEntries= new ArrayList (); 146 Bundle bundle= Platform.getBundle("org.eclipse.swt"); BundleDescription description= Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId()); 148 BundleDescription[] fragments= description.getFragments(); 149 for (int i = 0; i < fragments.length; i++) { 150 Bundle fragmentBundle= Platform.getBundle(fragments[i].getName()); 151 URL bundleURL; 152 try { 153 bundleURL = FileLocator.resolve(fragmentBundle.getEntry("/")); } catch (IOException e) { 155 AntUIPlugin.log(e); 156 continue; 157 } 158 String urlFileName= bundleURL.getFile(); 159 if (urlFileName.startsWith("file:")) { try { 161 urlFileName= new URL (urlFileName).getFile(); 162 if (urlFileName.endsWith("!/")) { urlFileName= urlFileName.substring(0, urlFileName.length() - 2); 164 } 165 } catch (MalformedURLException e) { 166 AntUIPlugin.log(e); 167 continue; 168 } 169 } 170 IPath fragmentPath= new Path(urlFileName); 171 if (fragmentPath.getFileExtension() != null) { fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath)); 173 } else { File bundleFolder= fragmentPath.toFile(); 175 if (!bundleFolder.isDirectory()) { 176 continue; 177 } 178 String [] names= bundleFolder.list(new FilenameFilter () { 179 public boolean accept(File dir, String name) { 180 return name.endsWith(".jar"); } 182 }); 183 for (int j = 0; j < names.length; j++) { 184 String jarName = names[j]; 185 fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath.append(jarName))); 186 } 187 } 188 } 189 } 190 rtes.addAll(fgSWTEntries); 191 } 192 193 200 private IRuntimeClasspathEntry getToolsJar(ILaunchConfiguration configuration) { 201 try { 202 IVMInstall install = JavaRuntime.computeVMInstall(configuration); 203 if (install != null) { 204 IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath())); 205 if (entry != null) { 206 return JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath())); 207 } 208 } 209 } catch (CoreException ce) { 210 } 212 213 return null; 214 } 215 216 219 public String getName() { 220 return AntLaunchConfigurationMessages.ContributedClasspathEntriesEntry_1; 221 } 222 225 public int getType() { 226 return IRuntimeClasspathEntry.OTHER; 227 } 228 231 public boolean isComposite() { 232 return true; 233 } 234 237 public boolean equals(Object obj) { 238 return obj instanceof ContributedClasspathEntriesEntry; 239 } 240 243 public int hashCode() { 244 return getClass().hashCode(); 245 } 246 } 247 | Popular Tags |