49self.configSet=configSet
+ 50# Select the first configuration as a default, for referencing common properties
+ 51self.config=configSet.getConfigurations()[0]
+
54""" Converting a task list into output format and writing it into buildFilePath file. """
+ 55writer=None
+ 56#if 'build.tool' in self.config:
+ 57# Choose appropriate build tool
+ 58# print 'choosing build tool!'
+ 59# pass
+ 60#else:
+ 61# Choose Ant by default for now
+ 62printself.config.keys()
+ 63buildFileDir=os.path.dirname(buildFilePath)
+ 64ifnotos.path.exists(buildFileDir):
+ 65os.makedirs(buildFileDir)
+ 66writer=get_writer(output,open(buildFilePath,'w'))
+ 67writer.write(taskList)
+
74"""
+ 75 This class implements a command definition.
+ 76 It handles command id and stage.
+ 77 All command from one stage should be finished before starting the next stage.
+ 78 """
+
134""" Override this method to convert a specific command into Ant command.
+135 e.g: Delete Class will use delete task from Ant, else convert into perl ... remove filename.__getCommandByStage
+136 """
+137pass
+
157""" Render the delete as an Ant task. """
+158node=doc.createElementNS("","delete")
+159node.setAttributeNS("","verbose","true")
+160node.setAttributeNS("","failonerror","false")
+161ifself._filename!=None:
+162node.setAttributeNS("","file",self._filename)
+163elifself._dir!=None:
+164node.setAttributeNS("","dir",self._dir)
+165returnnode
+
182""" Render the copy as an Ant task. """
+183node=doc.createElementNS("","copy")
+184node.setAttributeNS("","verbose","true")
+185node.setAttributeNS("","failonerror","false")
+186node.setAttributeNS("","file",self.srcFile)
+187node.setAttributeNS("","todir",self.todir)
+188returnnode
+
218"""Base class which contains define an AbstractOutputWriter.
+219
+220 The subclass must implement a convert method which compute a command list into
+221 some output file.
+222 """
+
340""" Writes the command list to Ant format. """
+341doc=xml.dom.minidom.Document()
+342projectnode=doc.createElementNS("","project")
+343projectnode.setAttributeNS("","name",'')
+344projectnode.setAttributeNS("","default","all")
+345doc.appendChild(projectnode)
+346
+347stages=self.__getCommandByStage(cmdList)
+348
+349forstageinstages.keys():
+350projectnode.appendChild(self.__stageToTarget(doc,stage,stages[stage]))
+351
+352target=doc.createElementNS("","target")
+353target.setAttributeNS("","name","all")
+354def__toStage(stage):
+355""" Convert the stage id into and Ant target name. """
+356return"stage%s"%stage
+
363""" Convert a stage into an Ant target. """
+364target=doc.createElementNS("","target")
+365target.setAttributeNS("","name","stage%s"%stage)
+366parallel=doc.createElementNS("","parallel")
+367parallel.setAttributeNS("","threadCount","${number.of.threads}")
+368target.appendChild(parallel)
+369
+370forcmdincmds:
+371parallel.appendChild(self.__commandToAnt(doc,cmd))
+372returntarget
+
376""" Convert a command into an Ant task. """
+377# does the API support Ant task conversion.
+378# else treat it as a cmd
+379ifissubclass(type(cmd),AntTask):
+380returncmd.toAntTask(doc)
+381else:
+382execnode=doc.createElementNS("","exec")
+383execnode.setAttributeNS("","executable",cmd.executable())
+384execnode.setAttributeNS("","dir",cmd.path())
+385arg=doc.createElementNS("","arg")
+386arg.setAttributeNS("","line",cmd.cmd())
+387execnode.appendChild(arg)
+388returnexecnode
+
392""" Reorder a CommandList into a list of stages. """
+393stages={}
+394forcmdincmdList.allCommands():
+395ifnotstages.has_key(cmd.stage()):
+396stages[cmd.stage()]=[]
+397stages[cmd.stage()].append(cmd)
+398
+399returnstages
+
433""" Converts the list of command into Makefile. """
+434stages={}
+435forcmdincmdList.allCommands():
+436ifnotstages.has_key(cmd.stage()):
+437stages[cmd.stage()]=[]
+438stages[cmd.stage()].append(cmd)
+439
+440# Write the all rule
+441def__toStage(stage):
+442""" Convert stage Id into a target name. """
+443return"stage%s"%stage
+
444
+445#self._fileOut.write("all : %s\n" % ' '.join(map(__toStage, max(stages.keys())))
+446iflen(stages.keys())>0:
+447self._fileOut.write("all : stage%s ;\n"%max(stages.keys()))
+448else:
+449self._fileOut.write("all: ;\n")
+450
+451forstageinstages.keys():
+452# Write each stage rule
+453def__toId(cmd):
+454""" Convert command Id into a target name. """
+455self.__commandToTarget(cmd)
+456return"id%s"%cmd.jobId()
+