44import java .io .FileInputStream ;
55import java .io .FileOutputStream ;
66import java .io .FileWriter ;
7+ import java .io .IOException ;
78import java .io .PrintWriter ;
89import java .lang .instrument .ClassFileTransformer ;
910import java .lang .instrument .IllegalClassFormatException ;
1011import java .lang .instrument .Instrumentation ;
1112import java .security .ProtectionDomain ;
13+ import java .util .Scanner ;
1214
1315import org .objectweb .asm .ClassReader ;
1416import org .objectweb .asm .ClassWriter ;
@@ -33,7 +35,8 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
3335 ClassReader cr = new ClassReader (classfileBuffer );
3436 if (isIgnoredClass (cr .getClassName ()))
3537 return null ;
36- System .out .println ("Inst: " + cr .getClassName ());
38+ if (DEBUG )
39+ System .out .println ("Inst: " + cr .getClassName ());
3740 ClassWriter cw = new ClassWriter (cr , ClassWriter .COMPUTE_MAXS | ClassWriter .COMPUTE_FRAMES );
3841 NonDeterministicReplayClassVisitor cv = new NonDeterministicReplayClassVisitor (Opcodes .ASM5 , cw );
3942 cr .accept (cv , ClassReader .EXPAND_FRAMES );
@@ -54,7 +57,8 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
5457 ClassReader cr = new ClassReader (classfileBuffer );
5558 if (isIgnoredClass (cr .getClassName ()))
5659 return null ;
57- System .out .println ("Inst: " + cr .getClassName ());
60+ if (DEBUG )
61+ System .out .println ("Inst: " + cr .getClassName ());
5862 ClassWriter cw = new ClassWriter (ClassWriter .COMPUTE_MAXS );
5963 NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor (new SerialVersionUIDAdder (cw ));
6064 CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor (cv );
@@ -124,6 +128,34 @@ public static void premain(String _args, Instrumentation inst) {
124128 ChroniclerJExportRunner .registerShutdownHook ();
125129 } else if (d [0 ].equals ("debug" ))
126130 DEBUG = true ;
131+ else if (d [0 ].equals ("failsafe" )) {
132+ try {
133+ // Read in the log file name based on the maven failsafe
134+ // config.
135+ File config = new File (System .getProperty ("sun.java.command" ).split (" " )[1 ]);
136+ Scanner s = new Scanner (config );
137+ String testClass = null ;
138+ while (s .hasNextLine ()) {
139+ String line = s .nextLine ();
140+ if (line .startsWith ("tc." )) {
141+ testClass = line .split ("=" )[1 ];
142+ break ;
143+ }
144+ }
145+ s .close ();
146+ if (testClass == null )
147+ throw new IOException ("Couldn't find test config" );
148+ if (replay ) {
149+
150+ } else {
151+ System .out .println ("Overriding test class: " + testClass );
152+ ChroniclerJExportRunner .nameOverride = "target/" +testClass + ".crash" ;
153+ }
154+ } catch (IOException ex ) {
155+ ex .printStackTrace ();
156+ System .err .println ("Unable to load in failsafe config" );
157+ }
158+ }
127159 }
128160 }
129161 ClassFileTransformer transformer = new ChroniclerTransformer ();
0 commit comments