KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > core > launching > EclipseLauncher


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: EclipseLauncher.java 399 2007-08-30 19:12:38Z mtnminds $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.core.launching;
9
10 import java.io.File JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
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 /**
29  * Laucher for the Eclipse runtime workbench.
30  *
31  * @author Marc R. Hoffmann
32  * @version $Revision: 399 $
33  */

34 public class EclipseLauncher extends CoverageLauncher {
35
36   protected static final String JavaDoc PLUGIN_NATURE = "org.eclipse.pde.PluginNature"; //$NON-NLS-1$
37

38   /** Pre-Eclipse 3.2.0 VM arguments key */
39   protected static final String JavaDoc PRE320VMARGS = "vmargs"; //$NON-NLS-1$
40
protected static final String JavaDoc VMARGS = IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS;
41   
42   public static final String JavaDoc BOOTPATHARG = "-Xbootclasspath/a:"; //$NON-NLS-1$
43

44   /**
45    * Returns the proper key for VM arguments depending on the Eclipse version
46    *
47    * @return launch configuration key for VM arguments
48    */

49   protected String JavaDoc getVMArgsKey() {
50     boolean is320 = EclipseVersion.isGreaterOrEqualTo(EclipseVersion.V320);
51     return is320 ? VMARGS : PRE320VMARGS;
52   }
53   
54   /**
55    * Adds the given single argument to the VM arguments. If it contains white
56    * spaces the argument is included in double quotes.
57    *
58    * @param workingcopy configuration to modify
59    * @param arg additional VM argument
60    * @throws CoreException may be thrown by the launch configuration
61    */

62   protected void addVMArgument(ILaunchConfigurationWorkingCopy workingcopy, String JavaDoc arg) throws CoreException {
63     String JavaDoc vmargskey = getVMArgsKey();
64     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(workingcopy.getAttribute(vmargskey, "")); //$NON-NLS-1$
65
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     // Inplace instrumentation is required for plugin launches, as we can't
78
// modify the classpath
79
return true;
80   }
81   
82   protected void modifyConfiguration(ILaunchConfigurationWorkingCopy workingcopy,
83       ICoverageLaunchInfo info) throws CoreException {
84     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(BOOTPATHARG);
85     sb.append(info.getPropertiesJARFile());
86     sb.append(File.pathSeparatorChar).append(CoverageTools.getEmmaJar().toOSString());
87     addVMArgument(workingcopy, sb.toString());
88   }
89
90   /*
91    * We list all source based class files of all plugins in the workspace.
92    */

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 JavaDoc l = new ArrayList JavaDoc();
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