1111package com .redhat .devtools .intellij .commonUiTestLibrary ;
1212
1313import com .intellij .remoterobot .RemoteRobot ;
14+ import com .intellij .remoterobot .stepsProcessing .StepLogger ;
15+ import com .intellij .remoterobot .stepsProcessing .StepWorker ;
1416import com .intellij .remoterobot .utils .WaitForConditionTimeoutException ;
1517import com .redhat .devtools .intellij .commonUiTestLibrary .fixtures .dialogs .FlatWelcomeFrame ;
1618
2729import java .nio .file .Paths ;
2830import java .time .Duration ;
2931
32+ import static com .intellij .remoterobot .stepsProcessing .StepWorkerKt .step ;
3033import static com .intellij .remoterobot .utils .RepeatUtilsKt .waitFor ;
3134
3235/**
@@ -48,23 +51,27 @@ public class UITestRunner {
4851 * @return instance of the RemoteRobot
4952 */
5053 public static RemoteRobot runIde (IdeaVersion ideaVersion , int port ) {
51- UITestRunner .ideaVersion = ideaVersion ;
52- makeSureAllTermsAndConditionsAreAccepted ();
54+ StepWorker .registerProcessor (new StepLogger ());
5355
54- String osName = System . getProperty ( "os.name" ). toLowerCase ();
55- String fileExtension = osName . contains ( "windows" ) ? ".bat" : "" ;
56- ProcessBuilder pb = new ProcessBuilder ( "." + File . separator + "gradlew" + fileExtension , "runIdeForUiTests" , "-PideaVersion=" + ideaVersion . toString (), "-Drobot-server.port=" + port );
56+ return step ( "Start IntelliJ Idea ('" + ideaVersion . toString () + "') listening on port " + port , () -> {
57+ UITestRunner . ideaVersion = ideaVersion ;
58+ makeSureAllTermsAndConditionsAreAccepted ( );
5759
58- try {
59- ideProcess = pb .start ();
60- waitUntilIntelliJStarts (port );
61- remoteRobot = getRemoteRobotConnection (port );
62- } catch (IOException | InterruptedException e ) {
63- e .printStackTrace ();
64- }
60+ String osName = System .getProperty ("os.name" ).toLowerCase ();
61+ String fileExtension = osName .contains ("windows" ) ? ".bat" : "" ;
62+ ProcessBuilder pb = new ProcessBuilder ("." + File .separator + "gradlew" + fileExtension , "runIdeForUiTests" , "-PideaVersion=" + ideaVersion .toString (), "-Drobot-server.port=" + port );
6563
66- remoteRobot .find (FlatWelcomeFrame .class , Duration .ofSeconds (10 )).clearWorkspace ();
67- return remoteRobot ;
64+ try {
65+ ideProcess = pb .start ();
66+ waitUntilIntelliJStarts (port );
67+ remoteRobot = getRemoteRobotConnection (port );
68+ } catch (IOException | InterruptedException e ) {
69+ e .printStackTrace ();
70+ }
71+
72+ remoteRobot .find (FlatWelcomeFrame .class , Duration .ofSeconds (10 )).clearWorkspace ();
73+ return remoteRobot ;
74+ });
6875 }
6976
7077 /**
@@ -81,12 +88,14 @@ public static RemoteRobot runIde(IdeaVersion ideaVersion) {
8188 * Close the IntelliJ Idea IDE from the 'Welcome to IntelliJ IDEA' dialog
8289 */
8390 public static void closeIde () {
84- if (remoteRobot .isWin ()) {
85- remoteRobot .find (FlatWelcomeFrame .class , Duration .ofSeconds (10 )).runJs ("const horizontal_offset = component.getWidth() - 24;\n " +
86- "robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 2);" );
87- } else {
88- ideProcess .destroy ();
89- }
91+ step ("Close IntelliJ Idea" , () -> {
92+ if (remoteRobot .isWin ()) {
93+ remoteRobot .find (FlatWelcomeFrame .class , Duration .ofSeconds (10 )).runJs ("const horizontal_offset = component.getWidth() - 24;\n " +
94+ "robot.click(component, new Point(horizontal_offset, 14), MouseButton.LEFT_BUTTON, 2);" );
95+ } else {
96+ ideProcess .destroy ();
97+ }
98+ });
9099 }
91100
92101 /**
@@ -115,16 +124,22 @@ public static RemoteRobot getRemoteRobot() {
115124 * @throws InterruptedException may be thrown in Thread.sleep()
116125 */
117126 public static RemoteRobot getRemoteRobotConnection (int port ) throws InterruptedException {
118- RemoteRobot remoteRobot = new RemoteRobot ("http://127.0.0.1:" + port );
119- for (int i = 0 ; i < 60 ; i ++) {
120- try {
121- remoteRobot .find (FlatWelcomeFrame .class );
122- } catch (WaitForConditionTimeoutException e ) {
123- Thread .sleep (1000 );
127+ return step ("Create an instance of the RemoteRobot listening on port " + port , () -> {
128+ RemoteRobot remoteRobot = new RemoteRobot ("http://127.0.0.1:" + port );
129+ for (int i = 0 ; i < 60 ; i ++) {
130+ try {
131+ remoteRobot .find (FlatWelcomeFrame .class );
132+ } catch (WaitForConditionTimeoutException e ) {
133+ try {
134+ Thread .sleep (1000 );
135+ } catch (InterruptedException e2 ) {
136+ e2 .printStackTrace ();
137+ }
138+ }
124139 }
125- }
126140
127- return remoteRobot ;
141+ return remoteRobot ;
142+ });
128143 }
129144
130145 /**
@@ -155,51 +170,63 @@ private static void makeSureAllTermsAndConditionsAreAccepted() {
155170 String osName = System .getProperty ("os.name" ).toLowerCase ();
156171
157172 if (osName .contains ("linux" )) {
158- String prefsXmlSourceLocation = "prefs.xml" ;
159- String prefsXmlDir = System .getProperty ("user.home" ) + "/.java/.userPrefs/jetbrains/_!(!!cg\" p!(}!}@\" j!(k!|w\" w!'8!b!\" p!':!e@==" ;
160- createDirectoryHierarchy (prefsXmlDir );
161- copyFileFromJarResourceDir (prefsXmlSourceLocation , prefsXmlDir + "/prefs.xml" );
162-
163- String acceptedSourceLocation = "accepted" ;
164- String acceptedDir = System .getProperty ("user.home" ) + "/.local/share/JetBrains/consentOptions" ;
165- createDirectoryHierarchy (acceptedDir );
166- copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "/accepted" );
173+ step ("Copy the 'prefs.xml' file to the appropriate location" , () -> {
174+ String prefsXmlSourceLocation = "prefs.xml" ;
175+ String prefsXmlDir = System .getProperty ("user.home" ) + "/.java/.userPrefs/jetbrains/_!(!!cg\" p!(}!}@\" j!(k!|w\" w!'8!b!\" p!':!e@==" ;
176+ createDirectoryHierarchy (prefsXmlDir );
177+ copyFileFromJarResourceDir (prefsXmlSourceLocation , prefsXmlDir + "/prefs.xml" );
178+ });
179+
180+ step ("Copy the 'accepted' file to the appropriate location" , () -> {
181+ String acceptedSourceLocation = "accepted" ;
182+ String acceptedDir = System .getProperty ("user.home" ) + "/.local/share/JetBrains/consentOptions" ;
183+ createDirectoryHierarchy (acceptedDir );
184+ copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "/accepted" );
185+ });
167186 } else if (osName .contains ("os x" )) {
168- String plistSourceLocation = "com.apple.java.util.prefs.plist" ;
169- String plistDir = System .getProperty ("user.home" ) + "/Library/Preferences" ;
170- copyFileFromJarResourceDir (plistSourceLocation , plistDir + "/com.apple.java.util.prefs.plist" );
171-
172- String acceptedSourceLocation = "accepted" ;
173- String acceptedDir = System .getProperty ("user.home" ) + "/Library/Application Support/JetBrains/consentOptions" ;
174- createDirectoryHierarchy (acceptedDir );
175- copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "/accepted" );
176-
177- // run the 'killall cfprefsd' cmd to force OS X to reload preferences files
178- ProcessBuilder pb = new ProcessBuilder ("killall" , "cfprefsd" );
179- try {
180- Process p = pb .start ();
181- p .waitFor ();
182- } catch (IOException | InterruptedException e ) {
183- e .printStackTrace ();
184- }
187+ step ("Copy the 'com.apple.java.util.prefs.plist' file to the appropriate location" , () -> {
188+ String plistSourceLocation = "com.apple.java.util.prefs.plist" ;
189+ String plistDir = System .getProperty ("user.home" ) + "/Library/Preferences" ;
190+ copyFileFromJarResourceDir (plistSourceLocation , plistDir + "/com.apple.java.util.prefs.plist" );
191+ });
192+
193+ step ("Copy the 'accepted' file to the appropriate location" , () -> {
194+ String acceptedSourceLocation = "accepted" ;
195+ String acceptedDir = System .getProperty ("user.home" ) + "/Library/Application Support/JetBrains/consentOptions" ;
196+ createDirectoryHierarchy (acceptedDir );
197+ copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "/accepted" );
198+
199+ // run the 'killall cfprefsd' cmd to force OS X to reload preferences files
200+ ProcessBuilder pb = new ProcessBuilder ("killall" , "cfprefsd" );
201+ try {
202+ Process p = pb .start ();
203+ p .waitFor ();
204+ } catch (IOException | InterruptedException e ) {
205+ e .printStackTrace ();
206+ }
207+ });
185208 } else if (osName .contains ("windows" )) {
186- String acceptedSourceLocation = "accepted" ;
187- String acceptedDir = System .getProperty ("user.home" ) + "\\ AppData\\ Roaming\\ JetBrains\\ consentOptions" ;
188- createDirectoryHierarchy (acceptedDir );
189- copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "\\ accepted" );
190-
191- String registryPath = "HKCU:\\ Software\\ JavaSoft\\ Prefs\\ jetbrains\\ privacy_policy" ;
192- ProcessBuilder pb1 = new ProcessBuilder ("powershell.exe" , "New-Item" , "-Path" , registryPath , "-Force" );
193- ProcessBuilder pb2 = new ProcessBuilder ("powershell.exe" , "New-ItemProperty" , "-Path" , registryPath , "-Name" , "accepted_version" , "-Value" , "'2.1'" );
194-
195- try {
196- Process p1 = pb1 .start ();
197- p1 .waitFor ();
198- Process p2 = pb2 .start ();
199- p2 .waitFor ();
200- } catch (IOException | InterruptedException e ) {
201- e .printStackTrace ();
202- }
209+ step ("Copy the 'accepted' file to the appropriate location" , () -> {
210+ String acceptedSourceLocation = "accepted" ;
211+ String acceptedDir = System .getProperty ("user.home" ) + "\\ AppData\\ Roaming\\ JetBrains\\ consentOptions" ;
212+ createDirectoryHierarchy (acceptedDir );
213+ copyFileFromJarResourceDir (acceptedSourceLocation , acceptedDir + "\\ accepted" );
214+ });
215+
216+ step ("Create appropriate registry entries" , () -> {
217+ String registryPath = "HKCU:\\ Software\\ JavaSoft\\ Prefs\\ jetbrains\\ privacy_policy" ;
218+ ProcessBuilder pb1 = new ProcessBuilder ("powershell.exe" , "New-Item" , "-Path" , registryPath , "-Force" );
219+ ProcessBuilder pb2 = new ProcessBuilder ("powershell.exe" , "New-ItemProperty" , "-Path" , registryPath , "-Name" , "accepted_version" , "-Value" , "'2.1'" );
220+
221+ try {
222+ Process p1 = pb1 .start ();
223+ p1 .waitFor ();
224+ Process p2 = pb2 .start ();
225+ p2 .waitFor ();
226+ } catch (IOException | InterruptedException e ) {
227+ e .printStackTrace ();
228+ }
229+ });
203230 }
204231 }
205232
0 commit comments