1 8 package com.mountainminds.eclemma.internal.core.launching; 9 10 import java.util.ArrayList ; 11 import java.util.HashMap ; 12 import java.util.List ; 13 import java.util.Map ; 14 import java.util.WeakHashMap ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.SubProgressMonitor; 20 import org.eclipse.debug.core.ILaunch; 21 import org.eclipse.debug.core.ILaunchConfiguration; 22 import org.eclipse.osgi.util.NLS; 23 24 import com.mountainminds.eclemma.core.CoverageTools; 25 import com.mountainminds.eclemma.core.IClassFiles; 26 import com.mountainminds.eclemma.core.IInstrumentation; 27 import com.mountainminds.eclemma.core.launching.ICoverageLaunchInfo; 28 import com.mountainminds.eclemma.internal.core.CoreMessages; 29 import com.mountainminds.eclemma.internal.core.EclEmmaCorePlugin; 30 import com.mountainminds.eclemma.internal.core.StateFiles; 31 32 38 public class CoverageLaunchInfo implements ICoverageLaunchInfo { 39 40 private static int idcounter = (int) System.currentTimeMillis(); 41 private static final Map instances = new WeakHashMap (); 42 43 private final String id; 44 private final ILaunchConfiguration configuration; 45 private IPath coveragefile; 46 private IPath propertiesjarfile; 47 private final List instrumentations; 48 private final Map instrumentationpaths; 49 50 public CoverageLaunchInfo(ILaunch launch) { 51 id = Integer.toHexString(idcounter++); 52 instances.put(id, this); 53 configuration = launch.getLaunchConfiguration(); 54 StateFiles statefiles = EclEmmaCorePlugin.getInstance().getStateFiles(); 55 IPath base = statefiles.getLaunchDataFolder().append(id); 56 coveragefile = base.addFileExtension("ec"); statefiles.registerForCleanup(coveragefile); 58 propertiesjarfile = base.addFileExtension("jar"); statefiles.registerForCleanup(propertiesjarfile); 60 instrumentations = new ArrayList (); 61 instrumentationpaths = new HashMap (); 62 instances.put(launch, this); 63 } 64 65 74 public static ICoverageLaunchInfo getInfo(ILaunch launch) { 75 return (ICoverageLaunchInfo) instances.get(launch); 76 } 77 78 80 public IPath getCoverageFile() { 81 return coveragefile; 82 } 83 84 public IPath getPropertiesJARFile() { 85 return propertiesjarfile; 86 } 87 88 public void instrument(IProgressMonitor monitor, boolean inplace) throws CoreException { 89 instrumentations.clear(); 90 instrumentationpaths.clear(); 91 IClassFiles[] classfiles = CoverageTools.getClassFilesForInstrumentation( 92 configuration, inplace); 93 monitor.beginTask(CoreMessages.InstrumentingClasses_task, 94 classfiles.length); 95 for (int i = 0; i < classfiles.length; i++) { 96 if (monitor.isCanceled()) { 97 return; 98 } 99 monitor.subTask(NLS.bind(CoreMessages.InstrumentingClassesIn_task, classfiles[i].getLocation())); 100 addInstrumentation(classfiles[i].instrument(inplace, new SubProgressMonitor(monitor, 1))); 101 } 102 monitor.done(); 103 } 104 105 private void addInstrumentation(IInstrumentation instrumentation) { 106 instrumentations.add(instrumentation); 107 IPath orig = EclEmmaCorePlugin.getAbsolutePath(instrumentation.getClassFiles().getLocation()); 108 instrumentationpaths.put(orig.toOSString(), instrumentation); 109 } 110 111 public IInstrumentation[] getInstrumentations() { 112 IInstrumentation[] a = new IInstrumentation[instrumentations.size()]; 113 return (IInstrumentation[]) instrumentations.toArray(a); 114 } 115 116 public IInstrumentation getInstrumentation(String originalpath) { 117 return (IInstrumentation) instrumentationpaths.get(originalpath); 118 } 119 120 public void dispose() { 121 coveragefile = null; 124 propertiesjarfile = null; 125 } 126 127 } 128 | Popular Tags |