|
Lines 17-23
Link Here
|
| 17 |
import java.io.FileOutputStream; |
17 |
import java.io.FileOutputStream; |
| 18 |
import java.io.IOException; |
18 |
import java.io.IOException; |
| 19 |
import java.io.InputStream; |
19 |
import java.io.InputStream; |
|
|
20 |
import java.lang.reflect.Method; |
| 21 |
import java.net.MalformedURLException; |
| 20 |
import java.net.URL; |
22 |
import java.net.URL; |
|
|
23 |
import java.net.URLClassLoader; |
| 21 |
import java.net.URLConnection; |
24 |
import java.net.URLConnection; |
| 22 |
import java.util.ArrayList; |
25 |
import java.util.ArrayList; |
| 23 |
import java.util.Arrays; |
26 |
import java.util.Arrays; |
|
Lines 34-41
Link Here
|
| 34 |
import org.eclipse.core.resources.IContainer; |
37 |
import org.eclipse.core.resources.IContainer; |
| 35 |
import org.eclipse.core.resources.IFile; |
38 |
import org.eclipse.core.resources.IFile; |
| 36 |
import org.eclipse.core.resources.IFolder; |
39 |
import org.eclipse.core.resources.IFolder; |
| 37 |
import org.eclipse.core.resources.IProject; |
|
|
| 38 |
import org.eclipse.core.resources.IProjectDescription; |
| 39 |
import org.eclipse.core.resources.IResource; |
40 |
import org.eclipse.core.resources.IResource; |
| 40 |
import org.eclipse.core.resources.IWorkspaceRoot; |
41 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 41 |
import org.eclipse.core.resources.ResourcesPlugin; |
42 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
Lines 46-57
Link Here
|
| 46 |
import org.eclipse.core.runtime.Platform; |
47 |
import org.eclipse.core.runtime.Platform; |
| 47 |
import org.eclipse.debug.core.ILaunchConfiguration; |
48 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 48 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
49 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
| 49 |
import org.eclipse.hyades.trace.internal.ui.TraceConstants; |
|
|
| 50 |
import org.eclipse.hyades.trace.ui.UIPlugin; |
50 |
import org.eclipse.hyades.trace.ui.UIPlugin; |
| 51 |
import org.eclipse.hyades.trace.ui.internal.launcher.IProfileLaunchConfigurationConstants; |
51 |
import org.eclipse.hyades.trace.ui.internal.launcher.IProfileLaunchConfigurationConstants; |
| 52 |
import org.eclipse.hyades.trace.ui.internal.util.FilterSetElement; |
52 |
import org.eclipse.hyades.trace.ui.internal.util.FilterSetElement; |
| 53 |
import org.eclipse.hyades.trace.ui.internal.util.FilterTableElement; |
53 |
import org.eclipse.hyades.trace.ui.internal.util.FilterTableElement; |
| 54 |
import org.eclipse.jdt.core.Flags; |
54 |
import org.eclipse.jdt.core.Flags; |
|
|
55 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 55 |
import org.eclipse.jdt.core.IJavaElement; |
56 |
import org.eclipse.jdt.core.IJavaElement; |
| 56 |
import org.eclipse.jdt.core.IJavaModel; |
57 |
import org.eclipse.jdt.core.IJavaModel; |
| 57 |
import org.eclipse.jdt.core.IJavaProject; |
58 |
import org.eclipse.jdt.core.IJavaProject; |
|
Lines 63-68
Link Here
|
| 63 |
import org.eclipse.jdt.core.JavaModelException; |
64 |
import org.eclipse.jdt.core.JavaModelException; |
| 64 |
import org.eclipse.jdt.core.dom.Statement; |
65 |
import org.eclipse.jdt.core.dom.Statement; |
| 65 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
66 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
|
|
67 |
import org.eclipse.jdt.launching.JavaRuntime; |
| 66 |
import org.eclipse.jdt.ui.jarpackager.JarPackageData; |
68 |
import org.eclipse.jdt.ui.jarpackager.JarPackageData; |
| 67 |
import org.eclipse.jface.preference.IPreferenceStore; |
69 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 68 |
import org.eclipse.jface.text.IRegion; |
70 |
import org.eclipse.jface.text.IRegion; |
|
Lines 71-76
Link Here
|
| 71 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentConstants; |
73 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentConstants; |
| 72 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentUIPlugin; |
74 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentUIPlugin; |
| 73 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.LogHelper; |
75 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.LogHelper; |
|
|
76 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.annotation.Filter; |
| 77 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.annotation.Instrumentation; |
| 74 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.core.InstrumentPoint; |
78 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.core.InstrumentPoint; |
| 75 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.core.InstrumentSelectManager; |
79 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.core.InstrumentSelectManager; |
| 76 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.launcher.deleg.application.InstrumentLaunchConfiguration; |
80 |
import org.eclipse.tptp.platform.instrumentation.ui.internal.launcher.deleg.application.InstrumentLaunchConfiguration; |
|
Lines 871-874
Link Here
|
| 871 |
} |
875 |
} |
| 872 |
return result; |
876 |
return result; |
| 873 |
} |
877 |
} |
|
|
878 |
|
| 879 |
/** |
| 880 |
* Convert annotation info to Filter element, then append it to filter element set |
| 881 |
* ARM,CBE and JMX handler class will used these filter set to generate specific |
| 882 |
* instrumentation file sent to AC to profile. |
| 883 |
* |
| 884 |
* @param configuration launch configuration |
| 885 |
* @param filterSetElement filter element set |
| 886 |
*/ |
| 887 |
public static void appendAnnotationToFilterSet(ILaunchConfiguration configuration,FilterSetElement filterSetElement) throws CoreException { |
| 888 |
List annotationInfoList = configuration.getAttribute( |
| 889 |
InstrumentLaunchConfiguration.ATTR_ANNOTATION_LIST, new ArrayList()); |
| 890 |
for (int i = 0; i < annotationInfoList.size(); i++) { |
| 891 |
String annoationInfo = (String) annotationInfoList.get(i); |
| 892 |
if (annoationInfo == null || annoationInfo.length() < 1) |
| 893 |
continue; |
| 894 |
// AnnotationInfo will follow pattern: |
| 895 |
// PACKAGE_NAME;CLASS_NAME;METHOD_NAME;FILTER |
| 896 |
String[] filterInfoFields = annoationInfo.split(";"); |
| 897 |
InstrumentFilterTableElement filterElement = new InstrumentFilterTableElement( |
| 898 |
filterInfoFields[1], filterInfoFields[2], |
| 899 |
filterInfoFields[3], filterInfoFields[0]); |
| 900 |
if (Filter.INCLUDE.toString().equals(filterInfoFields[3])) {// instrument filter field |
| 901 |
filterSetElement.getChildren().add(0, filterElement); |
| 902 |
} else { |
| 903 |
List filterList = filterSetElement.getChildren(); |
| 904 |
for (int j = 0; j < filterList.size(); j++) { |
| 905 |
InstrumentFilterTableElement element = (InstrumentFilterTableElement) filterList.get(j); |
| 906 |
// insert annotation exclude filter in front of the first exclude filter element |
| 907 |
if (Filter.EXCLUDE.toString().equals(element.getVisibility())) { |
| 908 |
filterList.add(j, filterElement); |
| 909 |
break; |
| 910 |
} |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* handle BtM annotation information from user java project and save these annotation info to launch configuration |
| 918 |
* @param configuration The launch configuration |
| 919 |
*/ |
| 920 |
public static void handleAnnotation( |
| 921 |
ILaunchConfigurationWorkingCopy configuration) throws CoreException { |
| 922 |
// first we must clear annotation list information in launchConfiguration |
| 923 |
configuration.setAttribute(InstrumentLaunchConfiguration.ATTR_ANNOTATION_LIST,(List) null); |
| 924 |
|
| 925 |
// get user java project |
| 926 |
IJavaProject javaProject = getJavaProject(configuration); |
| 927 |
|
| 928 |
// get class loader used to load user project class |
| 929 |
ClassLoader loader = getProjectClassLoader(javaProject); |
| 930 |
if (loader == null) |
| 931 |
return; |
| 932 |
|
| 933 |
List cuList = new ArrayList(getCompilationUnitList(javaProject)); |
| 934 |
List aa = new ArrayList(); |
| 935 |
for (int i = 0; i < cuList.size(); i++) { |
| 936 |
ICompilationUnit cu = (ICompilationUnit) cuList.get(i); |
| 937 |
String packageName = cu.getPackageDeclarations()[0].getElementName(); |
| 938 |
String className = cu.getElementName(); |
| 939 |
className = className.substring(0, className.lastIndexOf(".java")); |
| 940 |
String qualifiedClassName = packageName + "." + className; |
| 941 |
try { |
| 942 |
Class userClass = loader.loadClass(qualifiedClassName); |
| 943 |
Instrumentation classAnnotation = (Instrumentation) userClass.getAnnotation(Instrumentation.class); |
| 944 |
if (classAnnotation != null) |
| 945 |
aa.add(populateAnnonationString(userClass, "*", classAnnotation)); |
| 946 |
Method[] methods = userClass.getDeclaredMethods(); |
| 947 |
for (int j = 0; j < methods.length; j++) { |
| 948 |
Instrumentation methodAnnotation = methods[j].getAnnotation(Instrumentation.class); |
| 949 |
if (methodAnnotation != null) |
| 950 |
aa.add(populateAnnonationString(userClass, methods[j].getName(), methodAnnotation)); |
| 951 |
} |
| 952 |
} catch (ClassNotFoundException e) { |
| 953 |
LogHelper.error(e); |
| 954 |
} |
| 955 |
} |
| 956 |
// save all filter set element extracted from Btm Annotation to LaunchConfiguration |
| 957 |
if (aa.size() > 0) |
| 958 |
configuration.setAttribute(InstrumentLaunchConfiguration.ATTR_ANNOTATION_LIST, aa); |
| 959 |
} |
| 960 |
|
| 961 |
/** |
| 962 |
* populate annotation info to specific format as the follow: |
| 963 |
* PACKAGE_NAME;CLASS_NAME;METHOD_NAME;FILTER_INCLUDE_EXCLUDE. |
| 964 |
* |
| 965 |
* Since <code>ILaunchConfiguration</code> only store object value contain String, |
| 966 |
* here convert Annotation info to String format. |
| 967 |
* |
| 968 |
* @param clz class name contains BtM annotation info |
| 969 |
* @param methodName method name |
| 970 |
* @param btmAnnotation BtM annotation info |
| 971 |
* @return assemble string contains annotation info |
| 972 |
*/ |
| 973 |
private static String populateAnnonationString(Class cl, String methodName, Instrumentation btmAnnotation) { |
| 974 |
|
| 975 |
StringBuffer bf = new StringBuffer(); |
| 976 |
if (btmAnnotation == null) |
| 977 |
return ""; |
| 978 |
|
| 979 |
bf.append(cl.getPackage().getName()).append(";"); |
| 980 |
bf.append(cl.getSimpleName()).append(";"); |
| 981 |
bf.append(methodName).append(";"); |
| 982 |
bf.append(btmAnnotation.value()); |
| 983 |
|
| 984 |
return bf.toString(); |
| 985 |
|
| 986 |
} |
| 987 |
|
| 988 |
/** |
| 989 |
* get the <code>ClassLoader</code> of java project specified |
| 990 |
* |
| 991 |
* this ClassLoader is used to load user project class and BtM annotation definition |
| 992 |
* class. |
| 993 |
* |
| 994 |
* @param project <code>IJavaProject</code> |
| 995 |
* @return <code>ClassLoader</code> of java project |
| 996 |
* @throws CoreException |
| 997 |
*/ |
| 998 |
private static ClassLoader getProjectClassLoader(IJavaProject project)throws CoreException { |
| 999 |
//compute the project classpaths |
| 1000 |
String[] classPaths = JavaRuntime.computeDefaultRuntimeClassPath(project); |
| 1001 |
|
| 1002 |
URL[] urls; |
| 1003 |
try { |
| 1004 |
urls = new URL[classPaths.length]; |
| 1005 |
for (int i = 0; i < classPaths.length; i++) { |
| 1006 |
urls[i] = new File(classPaths[i]).toURL(); |
| 1007 |
} |
| 1008 |
} catch (MalformedURLException e) { |
| 1009 |
return null; |
| 1010 |
} |
| 1011 |
|
| 1012 |
return new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); |
| 1013 |
} |
| 874 |
} |
1014 |
} |