@@ -119,16 +119,20 @@ def copyAntBuildFiles():
119119 shutil .copy (str (github / "Ant-Common.xml" ), str (destination ))
120120
121121
122+
123+
122124class CodeFileOptions (object ):
123125 """docstring for CodeFileOptions"""
124126 def __init__ (self , codeFile ):
127+ "Should probably use regular expressions for parsing instead"
125128 self .codeFile = codeFile
126129
127130 self .cmdargs = None
128131 if "{Args:" in self .codeFile .code :
129132 for line in self .codeFile .lines :
130133 if "{Args:" in line :
131- self .cmdargs = line .split ("{Args:" )[1 ].strip ()[:- 1 ]
134+ self .cmdargs = line .split ("{Args:" )[1 ].strip ()
135+ self .cmdargs = self .cmdargs .rsplit ("}" , 1 )[0 ]
132136
133137 self .runbyhand = "{RunByHand}" in self .codeFile .code
134138
@@ -141,6 +145,43 @@ def __init__(self, codeFile):
141145
142146 self .throwsexception = "{ThrowsException}" in self .codeFile .code
143147
148+ self .alternatemainclass = None
149+ if "{main: " in self .codeFile .code :
150+ for line in self .codeFile .lines :
151+ if "{main:" in line :
152+ self .alternatemainclass = line .split ("{main:" )[1 ].strip ()
153+ self .alternatemainclass = self .alternatemainclass .rsplit ("}" , 1 )[0 ]
154+
155+
156+ def classFile (self ):
157+ start = """ <jrun cls="%s" """
158+ if self .alternatemainclass :
159+ return start % self .alternatemainclass
160+ if self .codeFile .package :
161+ return start % (self .codeFile .packageName () + '.' + self .codeFile .name )
162+ return start % self .codeFile .name
163+
164+ def dirPath (self ):
165+ if self .codeFile .package :
166+ return """dirpath="%s" """ % self .codeFile .relpath
167+ return ""
168+
169+ def arguments (self ):
170+ if self .cmdargs :
171+ return """arguments='%s' """ % self .cmdargs
172+ return ""
173+
174+ def failOnError (self ):
175+ if self .throwsexception :
176+ return """failOnError='false' """
177+ return ""
178+
179+ def createRunCommand (self ):
180+ return self .classFile () + self .dirPath () + self .arguments () + self .failOnError () + "/>\n "
181+
182+
183+
184+
144185class CodeFile :
145186 def __init__ (self , javaFile , chapterDir ):
146187 self .chapter_dir = chapterDir
@@ -162,32 +203,11 @@ def __init__(self, javaFile, chapterDir):
162203 self .relpath = '../' + '/' .join (self .tagLine .split ('/' )[:- 1 ])
163204 self .name = javaFile .name .split ('.' )[0 ]
164205 self .options = CodeFileOptions (self )
165- # self.cmdargs = None
166- # if "{Args:" in self.code:
167- # for line in self.lines:
168- # if "{Args:" in line:
169- # self.cmdargs = line.split("{Args:")[1].strip()[:-1]
170- # self.runbyhand = "{RunByHand}" in self.code
171- # self.exclude = None
172- # if "{CompileTimeError}" in self.code:
173- # self.exclude = self.name + ".java"
174- # if self.subdirs:
175- # self.exclude = '/'.join(self.subdirs) + '/' + self.exclude
176- # print(self.exclude)
177- # self.throwsexception = "{ThrowsException}" in self.code
178206
179207 def run_command (self ):
180208 if not self .main :
181209 return ""
182- if self .package :
183- if self .options .cmdargs :
184- return """ <jrun cls="%s" dirpath="%s" arguments='%s'/>\n """ % (self .packageName () + '.' + self .name , self .relpath , self .options .cmdargs )
185- else :
186- return """ <jrun cls="%s" dirpath="%s"/>\n """ % (self .packageName () + '.' + self .name , self .relpath )
187- if self .options .cmdargs :
188- return """ <jrun cls="%s" arguments='%s'/>\n """ % (self .name , self .options .cmdargs )
189- else :
190- return """ <jrun cls="%s"/>\n """ % self .name
210+ return self .options .createRunCommand ()
191211
192212 def __repr__ (self ):
193213 result = self .tagLine
@@ -207,6 +227,8 @@ def checkPackage(self):
207227 return path == packagePath
208228
209229
230+
231+
210232class Chapter :
211233 def __init__ (self , dir ):
212234 self .dir = dir
@@ -241,6 +263,8 @@ def makeBuildFile(self):
241263 buildxml .write (buildFile )
242264
243265
266+
267+
244268def createAntFiles ():
245269 chapters = [Chapter (fd ) for fd in destination .glob ("*" ) if fd .is_dir () if not (fd / "build.xml" ).exists ()]
246270 for chapter in chapters :
0 commit comments