<commit_before>
;     Licensed to the Apache Software Foundation (ASF) under one
;     or more contributor license agreements.  See the NOTICE file
;     distributed with this work for additional information
;     regarding copyright ownership.  The ASF licenses this file
;     to you under the Apache License, Version 2.0 (the
;     "License"); you may not use this file except in compliance
;     with the License.  You may obtain a copy of the License at
;
;         http://www.apache.org/licenses/LICENSE-2.0
;
;     Unless required by applicable law or agreed to in writing,
;     software distributed under the License is distributed on an
;     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
;     KIND, either express or implied.  See the License for the
;     specific language governing permissions and limitations
;     under the License.   

; Set variables
Select 
	Case $CmdLine[0] = 4 OR $CmdLine[0] = 5
		Dim Const $eclipse_home = $CmdLine[1]
		Dim Const $tested_jre = $CmdLine[2]
		Dim Const $resultsDir = $CmdLine[3]
		Dim Const $delay_factor = Number($CmdLine[4])
		Dim $jre_options = ""
		If $CmdLine[0] = 5 Then
			$jre_options  = $CmdLine[5]
		EndIf
		If $delay_factor < 1 Then
            ConsoleWrite(@LF & "ERROR: Delay factor < 1! " & @LF & "EHWA FAILED!" & @LF)
            Exit(1)
        EndIf
	Case Else 
		ConsoleWrite("ERROR! Wrong number of input parameters! STOP." & @LF & "EHWA FAILED!" & @LF)
		Sleep(3000)
		Exit(1)
EndSelect
	
; Set options
Opt("WinWaitDelay", 1000) ; wait for 1c
Opt("SendKeyDelay", 200*$delay_factor) ; wait for 150mc
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("TrayIconDebug", 1)

LogWrite(@LF & "--- Automated Eclipse EHWA scenario for Eclipse 3.2.1 ---" & @LF & @LF)

; Check if some Eclipse window is already olpened
Opt("WinTitleMatchMode", 2)
If WinExists("Eclipse SDK") Then
	LogWrite("ERROR! Some Eclipse window is already opened. STOP." & @LF & "EHWA FAILED!" & @LF)
	Sleep(3000)
	Exit(1)
EndIf

LogWrite("Eclipse Home = " & $eclipse_home & @LF)
LogWrite("Tested JRE = " &  $tested_jre & @LF)
LogWrite("Tested JRE options for Eclipse launching = " & $jre_options & @LF)
LogWrite("Delay factor = " & $delay_factor & @LF)

; Start
LogWrite(@LF & "Start:" & @LF)
LogWrite(@TAB & "Run Eclipse" & @LF)
$run =  $tested_jre & "\bin\java.exe "  & $jre_options & " -cp """ & $eclipse_home & "\startup.jar"" -Dosgi.install.area=""" & $eclipse_home & """ org.eclipse.core.launcher.Main -debug > " & $resultsDir & "\eclipse.log 2>&1"
Run(@ComSpec & " /c " & $run, "", @SW_HIDE)


; 1
LogWrite(@TAB & "Wait Eclipse 'Workspace Launcher' window to appear " & @LF)
WinWaitImpl("Workspace Launcher", "", 180)
If Not WinActive("Workspace Launcher") Then WinActivate("Workspace Launcher")
WinWaitActiveImpl("Workspace Launcher", "", 30)
LogWrite(@TAB & "window appeared " & @LF)

; 2
LogWrite(@TAB & "Select " & @WorkingDir & "\workspace as workspace" & @LF)
ControlFocus("Workspace Launcher", "", "Edit1")
ControlSetText("Workspace Launcher", "", "Edit1", @WorkingDir & "\workspace" )
LogWrite(@TAB & "Press OK button" & @LF)
ControlSend("Workspace Launcher", "", "", "{ENTER}")
WinWaitCloseImpl("Workspace Launcher", "", 60)

; 3
LogWrite(@TAB & "Wait 'Java - Eclipse SDK' window to appear " & @LF)
WinWaitImpl("Java - Eclipse SDK", "", 180)
If Not WinActive("Java - Eclipse SDK") Then WinActivate("Java - Eclipse SDK")
WinWaitActiveImpl("Java - Eclipse SDK", "", 30)
LogWrite(@TAB & "window appeared " & @LF)
SleepImpl(1000)
LogWrite(@TAB & "Close Welcome page " & @LF)
;Send("!wvp{ENTER}")
Send("!+{NUMPADSUB}c")
SleepImpl(3000)

; 4
LogWrite(@TAB & "Create new  Java project" & @LF)
Send("!fnr")

; 5
LogWrite(@TAB & "Wait 'New Project' window to appear" & @LF)
WinWaitImpl("New Project","",60)
If Not WinActive("New Project","") Then WinActivate("New Project","")
WinWaitActiveImpl("New Project","",30)
LogWrite(@TAB & "window appeared " & @LF)
LogWrite(@TAB & "Select Java project" & @LF)
ControlFocus("New Project", "", "Edit1")
ControlSend("New Project", "", "Edit1", "{ENTER}")
LogWrite(@TAB & "Press Next button" & @LF)
ControlFocus("New Project", "&Next >", "Button2",)
ControlClick("New Project", "&Next >", "Button2") 
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Next button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
WinWaitCloseImpl("New Project", "", 60)

; 6
LogWrite(@TAB & "Wait 'New Java Project' window to appear " & @LF)
WinWaitImpl("New Java Project","",60)
If Not WinActive("New Java Project") Then WinActivate("New Java Project")
WinWaitActiveImpl("New Java Project","",30)
LogWrite(@TAB & "window appeared, " & @LF)
SleepImpl(1000)
LogWrite(@TAB & "Type EHWA as a project name" & @LF)
ControlFocus("New Java Project", "", "Edit2") 
ControlSetText("New Java Project", "", "Edit2", "EHWA" )
LogWrite(@TAB & "Press Finish button" & @LF)
ControlFocus("New Java Project", "&Finish", "Button27",)
ControlClick("New Java Project", "&Finish", "Button27") 
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Finish button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait while project is being created ... " & @LF)
WinWaitClose("New Java Project", "", 60)
LogWrite(@TAB & "Project was created" & @LF)

; 7
WinWaitImpl("Java - Eclipse SDK", "", 60)
If Not WinActive("Java - Eclipse SDK", "") Then WinActivate("Java - Eclipse SDK","")
WinWaitActiveImpl("Java - Eclipse SDK", "", 30)
LogWrite(@TAB & "Create new Java class" & @LF)
$result=WinMenuSelectItem("Java - Eclipse SDK", "", "&File", "&New", "Class")
if $result=0 Then
	LogWrite(@TAB & "ERROR! Menu 'File -> New -> Class' wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait 'New Java Class' window to appear" & @LF)
WinWaitImpl("New Java Class","",60)
If Not WinActive("New Java Class") Then WinActivate("New Java Class")
WinWaitActiveImpl("New Java Class","",30)
LogWrite(@TAB & "window appeared " & @LF)
SleepImpl(1000)

; 8
LogWrite(@TAB & "Type EHWA as class name" & @LF)
ControlFocus("New Java Class", "", "Edit4")
ControlSetText("New Java Class", "", "Edit4", "EHWA" )

;9
LogWrite(@TAB & "Select 'public static void main(String[] args)' checkbox" & @LF)
ControlFocus("New Java Class", "", "Button15")
ControlCommand("New Java Class", "", "Button15", "Check", "")

; 10
LogWrite(@TAB & "Click Finish button" & @LF)
ControlFocus("New Java Class", "&Finish", "Button19")
ControlClick("New Java Class", "&Finish", "Button19")
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Finish button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait while EHWA class is being created ..." & @LF)
WinWaitClose("New Java Class", "", 60)

; 11
WinWaitImpl("Java - EHWA.java - Eclipse SDK","",60)
If Not WinActive("New Java Class") Then WinActivate("Java - EHWA.java - Eclipse SDK")
WinWaitActiveImpl("Java - EHWA.java - Eclipse SDK","",30)
LogWrite(@TAB & "EHWA class was successfully created" & @LF)
SleepImpl(3000)
LogWrite(@TAB & "Add System.out.println(""Hello, world!""); string in the main method of EHWA class" & @LF)
ControlFocus("Java - EHWA.java - Eclipse SDK", "", "SWT_Window039")
ControlSend("Java - EHWA.java - Eclipse SDK", "", "SWT_Window039", "{DOWN 8}{TAB}")
ControlSend("Java - EHWA.java - Eclipse SDK", "", "SWT_Window039", "System.out.println(""Hello, world{!}"");")
SleepImpl(3000)

; 12
WinWaitImpl("Java - EHWA.java - Eclipse SDK","",60)
If Not WinActive("Java - EHWA.java - Eclipse SDK","") Then WinActivate("Java - EHWA.java - Eclipse SDK","")
WinWaitActiveImpl("Java - EHWA.java - Eclipse SDK","",30)
LogWrite(@TAB & "Save EHWA class " & @LF)
$result=WinMenuSelectItem("Java - EHWA.java - Eclipse SDK", "", "&File", "&Save")
if $result=0 Then<commit_msg>Apply second patch from HARMONY-4159: ([testing] EHWA scenario improvement)<commit_after>
;     Licensed to the Apache Software Foundation (ASF) under one
;     or more contributor license agreements.  See the NOTICE file
;     distributed with this work for additional information
;     regarding copyright ownership.  The ASF licenses this file
;     to you under the Apache License, Version 2.0 (the
;     "License"); you may not use this file except in compliance
;     with the License.  You may obtain a copy of the License at
;
;         http://www.apache.org/licenses/LICENSE-2.0
;
;     Unless required by applicable law or agreed to in writing,
;     software distributed under the License is distributed on an
;     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
;     KIND, either express or implied.  See the License for the
;     specific language governing permissions and limitations
;     under the License.   

; Set variables
Select 
	Case $CmdLine[0] = 4 OR $CmdLine[0] = 5
		Dim Const $eclipse_home = $CmdLine[1]
		Dim Const $tested_jre = $CmdLine[2]
		Dim Const $resultsDir = $CmdLine[3]
		Dim Const $delay_factor = Number($CmdLine[4])
		Dim $jre_options = ""
		If $CmdLine[0] = 5 Then
			$jre_options  = $CmdLine[5]
		EndIf
		If $delay_factor < 1 Then
            ConsoleWrite(@LF & "ERROR: Delay factor < 1! " & @LF & "EHWA FAILED!" & @LF)
            Exit(1)
        EndIf
	Case Else 
		ConsoleWrite("ERROR! Wrong number of input parameters! STOP." & @LF & "EHWA FAILED!" & @LF)
		Sleep(3000)
		Exit(1)
EndSelect
	
; Set options
Opt("WinWaitDelay", 1000) ; wait for 1c
Opt("SendKeyDelay", 200*$delay_factor) ; wait for 150mc
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("TrayIconDebug", 1)

LogWrite(@LF & "--- Automated Eclipse EHWA scenario for Eclipse 3.2.1 ---" & @LF & @LF)

; Check if some Eclipse window is already olpened
Opt("WinTitleMatchMode", 2)
If WinExists("Eclipse SDK") Then
	LogWrite("ERROR! Some Eclipse window is already opened. STOP." & @LF & "EHWA FAILED!" & @LF)
	Sleep(3000)
	Exit(1)
EndIf

LogWrite("Eclipse Home = " & $eclipse_home & @LF)
LogWrite("Tested JRE = " &  $tested_jre & @LF)
LogWrite("Tested JRE options for Eclipse launching = " & $jre_options & @LF)
LogWrite("Delay factor = " & $delay_factor & @LF)

; Start
LogWrite(@LF & "Start:" & @LF)
LogWrite(@TAB & "Run Eclipse" & @LF)
$run =  $tested_jre & "\bin\java.exe "  & $jre_options & " -cp """ & $eclipse_home & "\startup.jar"" -Dosgi.install.area=""" & $eclipse_home & """ org.eclipse.core.launcher.Main -debug > " & $resultsDir & "\eclipse.log 2>&1"
Run(@ComSpec & " /c " & $run, "", @SW_HIDE)


; 1
LogWrite(@TAB & "Wait Eclipse 'Workspace Launcher' window to appear " & @LF)
WinWaitImpl("Workspace Launcher", "", 180)
If Not WinActive("Workspace Launcher") Then WinActivate("Workspace Launcher")
WinWaitActiveImpl("Workspace Launcher", "", 30)
LogWrite(@TAB & "window appeared " & @LF)

; 2
LogWrite(@TAB & "Select " & @WorkingDir & "\workspace as workspace" & @LF)
ControlFocus("Workspace Launcher", "", "Edit1")
ControlSetText("Workspace Launcher", "", "Edit1", @WorkingDir & "\workspace" )
LogWrite(@TAB & "Press OK button" & @LF)
ControlSend("Workspace Launcher", "", "", "{ENTER}")
WinWaitCloseImpl("Workspace Launcher", "", 60)

; 3
LogWrite(@TAB & "Wait 'Java - Eclipse SDK' window to appear " & @LF)
WinWaitImpl("Java - Eclipse SDK", "", 180)
If Not WinActive("Java - Eclipse SDK") Then WinActivate("Java - Eclipse SDK")
WinWaitActiveImpl("Java - Eclipse SDK", "", 30)
LogWrite(@TAB & "window appeared " & @LF)
SleepImpl(1000)
LogWrite(@TAB & "Close Welcome page " & @LF)
;Send("!wvp{ENTER}")
Send("!+{NUMPADSUB}c")
SleepImpl(3000)

; 4
LogWrite(@TAB & "Create new  Java project" & @LF)
Send("!fnr")

; 5
LogWrite(@TAB & "Wait 'New Project' window to appear" & @LF)
WinWaitImpl("New Project","",60)
If Not WinActive("New Project","") Then WinActivate("New Project","")
WinWaitActiveImpl("New Project","",30)
LogWrite(@TAB & "window appeared " & @LF)
LogWrite(@TAB & "Select Java project" & @LF)
ControlFocus("New Project", "", "Edit1")
ControlSend("New Project", "", "Edit1", "{ENTER}")
LogWrite(@TAB & "Press Next button" & @LF)
ControlFocus("New Project", "&Next >", "Button2",)
ControlClick("New Project", "&Next >", "Button2") 
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Next button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
WinWaitCloseImpl("New Project", "", 60)

; 6
LogWrite(@TAB & "Wait 'New Java Project' window to appear " & @LF)
WinWaitImpl("New Java Project","",60)
If Not WinActive("New Java Project") Then WinActivate("New Java Project")
WinWaitActiveImpl("New Java Project","",30)
LogWrite(@TAB & "window appeared, " & @LF)
SleepImpl(1000)
LogWrite(@TAB & "Type EHWA as a project name" & @LF)
ControlFocus("New Java Project", "", "Edit2") 
ControlSetText("New Java Project", "", "Edit2", "EHWA" )
LogWrite(@TAB & "Press Finish button" & @LF)
ControlFocus("New Java Project", "&Finish", "Button27",)
ControlClick("New Java Project", "&Finish", "Button27") 
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Finish button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait while project is being created ... " & @LF)
WinWaitClose("New Java Project", "", 60)
LogWrite(@TAB & "Project was created" & @LF)

; 7
WinWaitImpl("Java - Eclipse SDK", "", 60)
If Not WinActive("Java - Eclipse SDK", "") Then WinActivate("Java - Eclipse SDK","")
WinWaitActiveImpl("Java - Eclipse SDK", "", 30)
LogWrite(@TAB & "Create new Java class" & @LF)
$result=WinMenuSelectItem("Java - Eclipse SDK", "", "&File", "&New", "Class")
if $result=0 Then
	LogWrite(@TAB & "ERROR! Menu 'File -> New -> Class' wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait 'New Java Class' window to appear" & @LF)
WinWaitImpl("New Java Class","",60)
If Not WinActive("New Java Class") Then WinActivate("New Java Class")
WinWaitActiveImpl("New Java Class","",30)
LogWrite(@TAB & "window appeared " & @LF)
SleepImpl(1000)

; 8
LogWrite(@TAB & "Type EHWA as class name" & @LF)
ControlFocus("New Java Class", "", "Edit4")
ControlSetText("New Java Class", "", "Edit4", "EHWA" )

;9
LogWrite(@TAB & "Select 'public static void main(String[] args)' checkbox" & @LF)
ControlFocus("New Java Class", "", "Button15")
ControlCommand("New Java Class", "", "Button15", "Check", "")

; 10
LogWrite(@TAB & "Click Finish button" & @LF)
ControlFocus("New Java Class", "&Finish", "Button19")
ControlClick("New Java Class", "&Finish", "Button19")
If @error=1 Then 	
	LogWrite(@TAB & "ERROR! Finish button wasn't found. STOP." & @LF)
	PrintErrorScreen()
	ExitImpl(1)
EndIf
LogWrite(@TAB & "Wait while EHWA class is being created ..." & @LF)
WinWaitClose("New Java Class", "", 60)

; 11
WinWaitImpl("Java - EHWA.java - Eclipse SDK","",60)
If Not WinActive("New Java Class") Then WinActivate("Java - EHWA.java - Eclipse SDK")
WinWaitActiveImpl("Java - EHWA.java - Eclipse SDK","",30)
LogWrite(@TAB & "EHWA class was successfully created" & @LF)
SleepImpl(3000)
LogWrite(@TAB & "Add System.out.println(""Hello, world!""); string in the main method of EHWA class" & @LF)
WinWaitImpl("Java - EHWA.java - Eclipse SDK","",60)
If Not WinActive("Java - EHWA.java - Eclipse SDK","") Then WinActivate("Java - EHWA.java - Eclipse SDK","")
WinWaitActiveImpl("Java - EHWA.java - Eclipse SDK","",30)
Send("{DOWN 8}{TAB}")
Send("System.out.println(""Hello, world{!}"");")
SleepImpl(3000)

; 12
WinWaitImpl("Java - EHWA.java - Eclipse SDK","",60)
If Not WinActive("Java - EHWA.java - Eclipse SDK","") Then WinActivate("Java - EHWA.java - Eclipse SDK","")
WinWaitActiveImpl("Java - EHWA.java - Eclipse SDK","",30)
LogWrite(@TAB & "Save EHWA class " & @LF)
$result=WinMenuSelectItem("Java - EHWA.java - Eclipse SDK", "", "&File", "&Save")
if $result=0 Then
{'fraction_non_alphanumeric': 0.1678433889602054, 'fraction_numerical': 0.021758664955070603, 'mean_word_length': 4.848723723723723, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4803422', 'n_tokens_mistral': 5718, 'n_tokens_neox': 5138, 'n_words': 1591}