Permalink
Browse files

mangle standard Java strata as a workaround for 368212

Encode both jar file location and java source name in
m2e strata FileSection. Mangle standard Java strate to
make sure m2e source lookup participant is the only
source of meaningful source name information.

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information...
1 parent ae37e82 commit d99af039d9cf709de9563be52f338f63ba5ad83b @ifedorenko committed Feb 11, 2012
View
18 ...urcelookup.javaagent/src/main/java/com/ifedorenko/m2e/sourcelookup/javaagent/Premain.java
@@ -62,26 +62,34 @@ public static void premain( String agentArgs, Instrumentation inst )
{
public void visitSource( String source, String debug )
{
+ String javaSource = source;
if ( debug != null )
{
System.err.println( "m2e SMAP merge is not supported!" );
System.err.println( debug );
}
else
{
+ // as a workaround for 368212, mangle standard java strata source name
+ // this will force JDT use m2e strata exclusively
+ javaSource = ".";
+
StringBuilder smap = new StringBuilder();
smap.append( "SMAP\n" );
- smap.append( source ).append( "\n" );
- smap.append( "Java\n" );
+ smap.append( javaSource ).append( "\n" );
+ smap.append( "Java\n" ); // default strata name
smap.append( "*S m2e\n" );
smap.append( "*F\n" );
- smap.append( "1 " ).append( location ).append( "\n" );
- smap.append( "*L\n" );// JDT insists on LineSection
+ smap.append( "1 " ).append( source ).append( "\n" );
+ smap.append( "2 " ).append( location ).append( "\n" );
+ // JSR-045, StratumSection
+ // "One FileSection and one LineSection (in either order) must follow the StratumSection"
+ smap.append( "*L\n" );
smap.append( "*E\n" );
debug = smap.toString();
}
- super.visitSource( source, debug );
+ super.visitSource( javaSource, debug );
};
}, 0 );
View
BIN com.ifedorenko.m2e.sourcelookup/com.ifedorenko.m2e.sourcelookup.javaagent.jar
Binary file not shown.
View
23 com.ifedorenko.m2e.sourcelookup/src/com/ifedorenko/m2e/sourcelookup/internal/JDIHelpers.java
@@ -20,6 +20,8 @@
public final class JDIHelpers
{
+ public static final String STRATA_M2E = "m2e";
+
private JDIHelpers()
{
}
@@ -51,14 +53,14 @@ else if ( fElement instanceof IJavaReferenceType )
if ( declaringType != null )
{
- String[] locations = declaringType.getSourceNames( "m2e" );
+ String[] locations = declaringType.getSourceNames( STRATA_M2E );
- if ( locations == null || locations.length < 1 )
+ if ( locations == null || locations.length < 2 )
{
return null;
}
- return locations[0];
+ return locations[1];
}
return null;
@@ -71,8 +73,8 @@ public static String getSourcePath( Object fElement )
if ( fElement instanceof IJavaStackFrame )
{
IJavaStackFrame stackFrame = (IJavaStackFrame) fElement;
- // under JSR 45 source path from the stack frame is more precise than anything derived from the type:
- String sourcePath = stackFrame.getSourcePath();
+ // under JSR 45 source path from the stack frame is more precise than anything derived from the type
+ String sourcePath = stackFrame.getSourcePath( STRATA_M2E );
if ( sourcePath != null )
{
return sourcePath;
@@ -95,9 +97,14 @@ else if ( fElement instanceof IJavaReferenceType )
if ( declaringType != null )
{
- String declaringTypeName = declaringType.getName();
- String[] sourcePaths = declaringType.getSourcePaths( null );
- return sourcePaths != null ? sourcePaths[0] : generateSourceName( declaringTypeName );
+ String[] sourcePaths = declaringType.getSourcePaths( STRATA_M2E );
+
+ if ( sourcePaths != null && sourcePaths.length > 0 && sourcePaths[0] != null )
+ {
+ return sourcePaths[0];
+ }
+
+ return generateSourceName( declaringType.getName() );
}
return null;

0 comments on commit d99af03

Please sign in to comment.