我有一个 groovy 脚本,可以将远程目录中的多个文件保存到我的临时目录中,并将它们解析为 xml。它有一个有趣的错误。每次运行时,它都无法在我的临时目录中找到一个文件。下次运行时,它会找到该文件,但找不到新文件。如果我有 20 个文件,它会在第 20 次运行之前找到所有 20 个文件。每次运行后都会清除临时目录。我想知道程序是否还留下了其他工件?
如果我在 16 次运行后清理项目,它仍然会找到前 16 个文件。所以它似乎不是eclipse中的神器。
它在 Eclipse 3、Java 1.5、Windows 7、Groovy 1.0 中运行。
remoteftpFile.findAll {
println "in find"
ftp.getReply();
it.isFile()
}.each {
println "in each"
ftp.getReply();
println it
ftp.getReply();
def tempDestination=PropertiesUtil.getTempDir()
def procDestination=PropertiesUtil.getProcessedDir()
def tempFile = new File(tempDestination+ it.name )
def procFile = new File(procDestination+ it.name )
//set it to delete
ftp.getReply();
println "got tempfile"
def localftpFile = ftp.SaveToDisk(it,tempFile) //Save each file to disk
//************** Handles decryption via gpgexe
println "Decrypting file";
println localftpFile.toString();
def localftpFileStr=localftpFile.toString();
def processedftpFileStr=procFile.toString();
def gpgstring=PropertiesUtil.getGpgString();
def decryptedOutputName = localftpFileStr.substring(0, (localftpFileStr.length()-4));
def decryptedProcOutputName= processedftpFileStr.substring(0, (processedftpFileStr.length()-4));
def decryptedOutputXMLName = decryptedOutputName.substring(0, (decryptedOutputName.length()-4))+".xml";
def decryptedProcOutputXMLName = decryptedProcOutputName.substring(0, (decryptedProcOutputName.length()-4))+".xml";
println decryptedOutputName;
def xmlfile = new File(decryptedOutputName)
def cdmpXmlFile = new File(decryptedOutputXMLName)
def procCdmpXmlFile = decryptedProcOutputXMLName
println gpgstring + " --output ${decryptedOutputName} --decrypt ${localftpFile} "
(new ExternalExecute()).run(gpgstring +" --output ${decryptedOutputName} --decrypt ${localftpFile} ");
Thread.sleep(1000);
//************* Now Parse CSV file(s) into xml using stack overflow solution
println "parsing file"
def reader = new FileReader(xmlfile)
def writer = new FileWriter(cdmpXmlFile)
def csvdata = []
xmlfile.eachLine { line ->
if (line){
csvdata << line.split(',')
}
}
def headers = csvdata[0]
def dataRows = csvdata[1..-1]
def xml = new groovy.xml.MarkupBuilder(writer)
// write 'root' element
xml.root {
dataRows.eachWithIndex { dataRow, index ->
// write 'entry' element with 'id' attribute
entry(id:index+1) {
headers.eachWithIndex { heading, i ->
// write each heading with associated content
"${heading}"(dataRow[i])
}
}
}
}
println "Performing XSL Translation on ${cdmpXmlFile}"
def cdmpXML = new XMLTransformer(xmlTranslate).run(cdmpXmlFile) //Run it on each of the xml files and set the output
new File("C:\\temp\\temp.xml").write(cdmpXML)
new File(procCdmpXmlFile).write(cdmpXML)
println "Done Performing XSL Translation"
println "Uploading Data to CDMP"
def cdmpUp = new UpdateCDMP(updateDB)
cdmpUp.run(cdmpXML)
println "Finished Upload and Import"
//do clean-up backing it up AND removing the files
println "Finished"
println "Closing Buffers"
reader.close();
writer.close();
println "Deleting Local Files"
new File(decryptedOutputName).deleteOnExit();
new File(localftpFile).deleteOnExit();
xmlfile.deleteOnExit();
cdmpXmlFile.deleteOnExit();
println "Deleting " + cdmpXmlFile.getName()
new File("C:\\temp\\temp.xml").deleteOnExit();
}
ftp.close()
}