1212import static org .junit .Assert .assertEquals ;
1313import static org .junit .Assert .assertTrue ;
1414
15+ import java .nio .file .Files ;
16+ import java .nio .file .Path ;
17+
1518import org .eclipse .core .resources .IProject ;
1619import org .eclipse .core .resources .IncrementalProjectBuilder ;
1720import org .eclipse .core .runtime .FileLocator ;
2427import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
2528import org .eclipse .debug .core .ILaunchManager ;
2629import org .eclipse .debug .core .model .IProcess ;
30+ import org .eclipse .debug .ui .IDebugUIConstants ;
2731import org .eclipse .jdt .launching .IJavaLaunchConfigurationConstants ;
2832import org .eclipse .m2e .tests .common .AbstractMavenProjectTestCase ;
2933import org .junit .Test ;
@@ -32,26 +36,35 @@ public class RunTest extends AbstractMavenProjectTestCase {
3236
3337 @ Test
3438 public void testRunTwice () throws Exception {
35- IProject project = importProject (FileLocator .toFileURL (getClass ().getResource ("/projects/basicProjectWithDep/pom.xml" )).getPath ());
39+ IProject project = importProject (
40+ FileLocator .toFileURL (getClass ().getResource ("/projects/basicProjectWithDep/pom.xml" )).getPath ());
3641 waitForJobsToComplete (monitor );
3742 project .build (IncrementalProjectBuilder .FULL_BUILD , null );
3843 ILaunchManager launchManager = DebugPlugin .getDefault ().getLaunchManager ();
39- ILaunchConfigurationWorkingCopy launchConfig = launchManager .getLaunchConfigurationType (IJavaLaunchConfigurationConstants .ID_JAVA_APPLICATION ).newInstance (project , "launch" );
44+ ILaunchConfigurationWorkingCopy launchConfig = launchManager
45+ .getLaunchConfigurationType (IJavaLaunchConfigurationConstants .ID_JAVA_APPLICATION )
46+ .newInstance (project , "launch" );
4047 launchConfig .setAttribute (IJavaLaunchConfigurationConstants .ATTR_PROJECT_NAME , project .getName ());
4148 launchConfig .setAttribute (IJavaLaunchConfigurationConstants .ATTR_MAIN_TYPE_NAME , "testMvn.TestClass" );
4249 launchConfig .setAttribute (DebugPlugin .ATTR_WORKING_DIRECTORY , project .getLocation ().toString ());
4350 IJobFunction assertSuccessfulRun = monitor -> {
4451 try {
45- ILaunch launch = launchConfig .launch (ILaunchManager .RUN_MODE , new NullProgressMonitor ());
46- while (!launch .isTerminated ()) {
47- Thread .sleep (300 );
52+ Path file = Files .createTempFile ("RunTest" , ".log" );
53+ try {
54+ launchConfig .setAttribute (IDebugUIConstants .ATTR_CAPTURE_IN_FILE , file .toAbsolutePath ().toString ());
55+ ILaunch launch = launchConfig .launch (ILaunchManager .RUN_MODE , new NullProgressMonitor ());
56+ while (!launch .isTerminated ()) {
57+ Thread .sleep (300 );
58+ }
59+ IProcess process = launch .getProcesses ()[0 ];
60+ String errorOutput = process .getStreamsProxy ().getErrorStreamMonitor ().getContents ();
61+ assertEquals ("" , errorOutput );
62+ assertEquals (0 , process .getExitValue ());
63+ assertEquals ("ok" , Files .readString (file ));
64+ return Status .OK_STATUS ;
65+ } finally {
66+ Files .delete (file );
4867 }
49- IProcess process = launch .getProcesses ()[0 ];
50- String errorOutput = process .getStreamsProxy ().getErrorStreamMonitor ().getContents ();
51- assertEquals ("" , errorOutput );
52- assertEquals (0 , process .getExitValue ());
53- assertEquals ("ok" , process .getStreamsProxy ().getOutputStreamMonitor ().getContents ());
54- return Status .OK_STATUS ;
5568 } catch (Exception e ) {
5669 return Status .error (e .getMessage (), e );
5770 }
0 commit comments