| 1 8 package com.mountainminds.eclemma.internal.core.instr; 9 10 import java.util.ArrayList ; 11 import java.util.List ; 12 import java.util.Properties ; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.jdt.core.IPackageFragmentRoot; 18 import org.eclipse.jdt.core.JavaModelException; 19 import org.eclipse.osgi.util.NLS; 20 21 import com.mountainminds.eclemma.core.IClassFiles; 22 import com.mountainminds.eclemma.core.IInstrumentation; 23 import com.mountainminds.eclemma.core.ISourceLocation; 24 import com.mountainminds.eclemma.internal.core.CoreMessages; 25 import com.mountainminds.eclemma.internal.core.DebugOptions; 26 import com.mountainminds.eclemma.internal.core.EclEmmaCorePlugin; 27 import com.mountainminds.eclemma.internal.core.DebugOptions.ITracer; 28 import com.vladium.emma.AppLoggers; 29 import com.vladium.emma.instr.InstrProcessor; 30 import com.vladium.emma.instr.InstrProcessor.OutMode; 31 32 38 public class ClassFiles implements IClassFiles { 39 40 private static final ITracer PERFORMANCE = DebugOptions.PERFORMANCETRACER; 41 42 private static final String METADATAFILE_EXT = "em"; 44 private final IPackageFragmentRoot[] roots; 45 private final IPath location; 46 private final boolean binary; 47 48 public ClassFiles(IPackageFragmentRoot[] roots, IPath location) throws JavaModelException { 49 this.roots = roots; 50 this.location = location; 51 boolean b = true; 52 for (int i = 0; i < roots.length; i++) { 53 if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { 54 b = false; 55 break; 56 } 57 } 58 binary = b; 59 } 60 61 public ClassFiles addRoot(IPackageFragmentRoot root) throws JavaModelException { 62 IPackageFragmentRoot[] newroots = new IPackageFragmentRoot[roots.length + 1]; 63 System.arraycopy(roots, 0, newroots, 0, roots.length); 64 newroots[roots.length] = root; 65 return new ClassFiles(newroots, location); 66 } 67 68 70 public boolean isBinary() { 71 return binary; 72 } 73 74 public IPackageFragmentRoot[] getPackageFragmentRoots() { 75 return roots; 76 } 77 78 public IPath getLocation() { 79 return location; 80 } 81 82 public ISourceLocation[] getSourceLocations() throws JavaModelException { 83 List l = new ArrayList (); 84 for (int i = 0; i < roots.length; i++) { 85 ISourceLocation location = SourceLocation.findLocation(roots[i]); 86 if (location != null) { 87 l.add(location); 88 } 89 } 90 ISourceLocation[] array = new ISourceLocation[l.size()]; 91 return (ISourceLocation[]) l.toArray(array); 92 } 93 94 public IInstrumentation instrument(boolean inplace, IProgressMonitor monitor) 95 throws CoreException { 96 PERFORMANCE.startTimer(); 97 monitor.beginTask(NLS.bind(CoreMessages.InstrumentingClassesIn_task, 98 location), 1); 99 IPath outputlocation = EclEmmaCorePlugin.getInstance().getStateFiles() 100 .getInstrDataFolder(location); 101 outputlocation.toFile().mkdirs(); 102 IPath metadatafile = outputlocation.addFileExtension(METADATAFILE_EXT); 103 if (inplace) { 104 InstrMarker.mark(location); 105 outputlocation = EclEmmaCorePlugin.getAbsolutePath(location); 106 } 107 InstrProcessor processor = InstrProcessor.create(); 108 processor.setInstrPath(new String [] { EclEmmaCorePlugin.getAbsolutePath( 109 location).toOSString() }, true); 110 processor.setInstrOutDir(outputlocation.toOSString()); 111 processor.setMetaOutFile(metadatafile.toOSString()); 112 processor.setMetaOutMerge(Boolean.TRUE); 113 processor.setOutMode(inplace ? OutMode.OUT_MODE_OVERWRITE 114 : OutMode.OUT_MODE_COPY); 115 Properties props = new Properties (); 116 props.put(AppLoggers.PROPERTY_VERBOSITY_LEVEL, 117 DebugOptions.EMMAVERBOSITYLEVEL); 118 processor.setPropertyOverrides(props); 119 processor.run(); 120 monitor.done(); 121 PERFORMANCE.stopTimer("instrumenting " + location); return new Instrumentation(this, inplace, outputlocation, metadatafile); 123 } 124 125 } 126 | Popular Tags |