2015-05-11 32 views
2

我用一個自定義的書面安裝程序的常規AntBuilder,例如。解包安裝包。 有一件事我想不通,是如何檢測的解壓任務是否失敗,例如。 我有以下代碼:螞蟻解壓任務:爲什麼它沒有失敗,如果失敗,解壓縮?

... 
AntBuilder antBuilder = new AntBuilder() 
antBuilder.mkdir(dir:installationPath) 
antBuilder.unzip(src:zipFileName, dest:installationPath,overwrite:"yes") 
... 

如果目標路徑(「安裝路徑」)是寫保護,將解壓報告錯誤(「無法展開...」),但任務本身不會失敗。還沒有用於解壓縮的「failOnError」屬性。

有沒有辦法強制解壓任務失敗,如果目標處於寫保護(或驅動器已滿,等)?

回答

1

看來是沒有辦法來捕獲異常。

根據從螞蟻

protected void extractFile(FileUtils fileUtils, File srcF, File dir, 
           InputStream compressedInputStream, 
           String entryName, Date entryDate, 
           boolean isDirectory, FileNameMapper mapper) 
           throws IOException { 

........................... 
........................... 
........................... 


     } catch (FileNotFoundException ex) { 
      log("Unable to expand to file " + f.getPath(), 
        ex, 
        Project.MSG_WARN); 
     } 

    } 

源代碼它默默地捕捉異常,而無需重新拋出它進一步。