@@ -285,7 +285,7 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) {
285285 "surefire.reportNameSuffix" ); //NOI81N
286286 testType = TESTTYPE_INTEGRATION ; //NOI81N
287287 }
288- if (null != reportsDirectory ) {
288+ if (reportsDirectory != null ) {
289289 File outputDir = null ;
290290 File absoluteFile = new File (reportsDirectory );
291291 // configuration might be "target/directory", which is relative
@@ -314,14 +314,15 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) {
314314 }
315315 }
316316 }
317- if (null != outputDir ) {
317+ if (outputDir != null ) {
318318 createSession (outputDir );
319319 OutputVisitor .Context context = visitor .getContext ();
320- if (context != null ) {
321- Project currentProject = context .getCurrentProject ();
322- if (currentProject != null ) {
323- project2outputDirs .put (currentProject , outputDir );
324- }
320+ // may be null when EventSpy is not active
321+ Project project = context != null && context .getCurrentProject () != null
322+ ? context .getCurrentProject ()
323+ : FileOwnerQuery .getOwner (Utilities .toURI (outputDir ));
324+ if (project != null ) {
325+ project2outputDirs .put (project , outputDir );
325326 }
326327 }
327328 }
@@ -351,8 +352,8 @@ private String getReportsDirectory(String groupId, String artifactId, String goa
351352 Object defaultValue = PluginPropertyUtils
352353 .createEvaluator (currentProject )
353354 .evaluate (fallbackExpression );
354- if (defaultValue instanceof String ) {
355- reportsDirectory = ( String ) defaultValue ;
355+ if (defaultValue instanceof String str ) {
356+ reportsDirectory = str ;
356357 }
357358 } catch (ExpressionEvaluationException ex ) {
358359 // NOP could not resolved default value
@@ -376,14 +377,14 @@ private String getReportsDirectory(String groupId, String artifactId, String goa
376377 })
377378 private String createSessionName (String projectId ) {
378379 String name ;
379- if ( testType != null && testType .equals (TESTTYPE_INTEGRATION )) {
380+ if ( TESTTYPE_INTEGRATION .equals (testType )) {
380381 name = Bundle .LBL_TESTTYPE_INTEGRATION (projectId );
381382 } else {
382383 name = Bundle .LBL_TESTTYPE_UNIT (projectId );
383384 }
384385 int index = 2 ;
385386 while (usedNames .contains (name )) {
386- if (testType != null && testType .equals (TESTTYPE_INTEGRATION )) {
387+ if (TESTTYPE_INTEGRATION .equals (testType )) {
387388 name = Bundle .LBL_TESTTYPE_INTEGRATION_INDEXED (projectId , index );
388389 } else {
389390 name = Bundle .LBL_TESTTYPE_UNIT_INDEXED (projectId , index );
@@ -590,7 +591,7 @@ private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
590591 }
591592 }
592593 return false ;
593- }
594+ }
594595
595596 public @ Override void sequenceEnd (String sequenceId , OutputVisitor visitor ) {
596597 if (outputDir2sessions .isEmpty ()) {
@@ -599,22 +600,32 @@ private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
599600 if (runningTestClass != null ) {
600601 generateTest ();
601602 }
603+ File outputDir = null ;
602604 OutputVisitor .Context context = visitor .getContext ();
603- if (context != null ) {
604- Project currentProject = context .getCurrentProject ();
605- if (currentProject != null ) {
606- File outputDir = project2outputDirs .remove (currentProject );
607- if (outputDir != null ) {
608- TestSession session = outputDir2sessions .remove (outputDir );
609- if (session != null ) {
610- CoreManager junitManager = getManagerProvider ();
611- if (junitManager != null ) {
612- junitManager .sessionFinished (session );
613- }
605+ if (context != null && context .getCurrentProject () != null ) {
606+ outputDir = project2outputDirs .remove (context .getCurrentProject ());
607+ } else if (runningTestClass != null ) {
608+ // fallback if EventSpy is not active
609+ Set <File > dirs = runningTestClass2outputDirs .get (runningTestClass );
610+ if (dirs != null ) {
611+ for (File dir : outputDir2sessions .keySet ()) {
612+ if (dirs .contains (dir )) {
613+ outputDir = dir ;
614+ break ;
614615 }
615616 }
616617 }
617618 }
619+ if (outputDir != null ) {
620+ TestSession session = outputDir2sessions .remove (outputDir );
621+ if (session != null ) {
622+ project2outputDirs .remove (session .getProject ());
623+ CoreManager junitManager = getManagerProvider ();
624+ if (junitManager != null ) {
625+ junitManager .sessionFinished (session );
626+ }
627+ }
628+ }
618629 runningTestClass = null ;
619630 }
620631
0 commit comments