1 8 package com.mountainminds.eclemma.core.launching; 9 10 import java.io.File ; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 18 import org.eclipse.jdt.core.IJavaModel; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.JavaCore; 21 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 22 23 import com.mountainminds.eclemma.core.CoverageTools; 24 import com.mountainminds.eclemma.core.IClassFiles; 25 import com.mountainminds.eclemma.internal.core.EclEmmaCorePlugin; 26 import com.mountainminds.eclemma.internal.core.EclipseVersion; 27 28 34 public class EclipseLauncher extends CoverageLauncher { 35 36 protected static final String PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; 38 39 protected static final String PRE320VMARGS = "vmargs"; protected static final String VMARGS = IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS; 41 42 public static final String BOOTPATHARG = "-Xbootclasspath/a:"; 44 49 protected String getVMArgsKey() { 50 boolean is320 = EclipseVersion.isGreaterOrEqualTo(EclipseVersion.V320); 51 return is320 ? VMARGS : PRE320VMARGS; 52 } 53 54 62 protected void addVMArgument(ILaunchConfigurationWorkingCopy workingcopy, String arg) throws CoreException { 63 String vmargskey = getVMArgsKey(); 64 StringBuffer sb = new StringBuffer (workingcopy.getAttribute(vmargskey, "")); if (sb.length() > 0) { 66 sb.append(' '); 67 } 68 if (arg.indexOf(' ') == -1) { 69 sb.append(arg); 70 } else { 71 sb.append('"').append(arg).append('"'); 72 } 73 workingcopy.setAttribute(vmargskey, sb.toString()); 74 } 75 76 protected boolean hasInplaceInstrumentation(ILaunchConfiguration configuration) { 77 return true; 80 } 81 82 protected void modifyConfiguration(ILaunchConfigurationWorkingCopy workingcopy, 83 ICoverageLaunchInfo info) throws CoreException { 84 StringBuffer sb = new StringBuffer (BOOTPATHARG); 85 sb.append(info.getPropertiesJARFile()); 86 sb.append(File.pathSeparatorChar).append(CoverageTools.getEmmaJar().toOSString()); 87 addVMArgument(workingcopy, sb.toString()); 88 } 89 90 93 public IClassFiles[] getClassFiles(ILaunchConfiguration configuration, boolean includebinaries) throws CoreException { 94 IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); 95 IJavaProject[] projects = model.getJavaProjects(); 96 List l = new ArrayList (); 97 for (int i = 0; i < projects.length; i++) { 98 if (projects[i].getProject().hasNature(PLUGIN_NATURE)) { 99 IClassFiles[] cf = EclEmmaCorePlugin.getInstance().getClassFiles(projects[i]); 100 for (int j = 0; j < cf.length; j++) { 101 if (!cf[j].isBinary()) l.add(cf[j]); 102 } 103 } 104 } 105 return (IClassFiles[]) l.toArray(new IClassFiles[0]); 106 } 107 108 } 109 | Popular Tags |