import os
readyToReturn = 0
ToReturn = ""
+eventMap = []
def GetToken(f):
global readyToReturn
return "EOF"
def ExtractFunctions(F, appName):
+ global eventMap
Temp = GetToken(F)
while (Temp != "EOF"):
if (Temp == "def" or Temp == "private"):
extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n")
extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
extractedFunctionsApp2.write("%s\n" % NameofFunc)
+
+ if (Temp == "subscribe"):
+ counter = 0
+ while (counter < 5 and Temp != "\""):
+ Temp = GetToken(F)
+ counter = counter + 1
+ Temp = GetToken(F)
+ #If counter >= 5 that means it is not found, so it must be appTouch
+ if (counter >= 5):
+ Temp = "appTouch"
+ eventMap.append(Temp)
Temp = GetToken(F)
-
-
+def ExtractEvents(extractedEvents):
+ global eventMap
+ extractedEvents.write("Random random = new Random(42)\n")
+ extractedEvents.write("counter = 1000\n")
+ extractedEvents.write("while(counter > 0) {\n")
+ extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1))
+ extractedEvents.write("\tswitch(eventNumber) {\n")
+ for i in range(len(eventMap)):
+ extractedEvents.write("\t\tcase %d:\n" % i)
+ if eventMap[i] == "lock":
+ event = open("eventSimulator/eventLocked.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ elif eventMap[i] == "unlock":
+ event = open("eventSimulator/eventUnlocked.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ elif eventMap[i] == "contact.open":
+ event = open("eventSimulator/eventContactOpen.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ elif eventMap[i] == "contact.closed":
+ event = open("eventSimulator/eventContactClosed.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ elif eventMap[i] == "nfcTouch":
+ event = open("eventSimulator/eventNfcTouch.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ elif eventMap[i] == "appTouch":
+ event = open("eventSimulator/eventAppTouch.groovy", "r")
+ for line in event:
+ extractedEvents.write(line)
+ event.close()
+ ###TODO: Add more events later
+ extractedEvents.write("\n\t\t\tbreak\n")
+ extractedEvents.write("\t}\n")
+ extractedEvents.write("\tcounter--\n")
+ extractedEvents.write("}\n")
+
#Extract objects to call functions from App1
F1 = open("Extractor/App1/App1.groovy", "r")
extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+")
ExtractFunctions(F2, "App2")
F2.close()
+#Prepare eventSimulator file while parsing the App1 and App2 files
+extractedEvents = open("eventSimulator/eventSimulator.groovy", "w+")
+ExtractEvents(extractedEvents)
+extractedEvents.close()
#Save the extracted methods and app1 in a same file to extract information
extractorFile = open("Extractor/extractorFile.groovy", "w+")