2012-07-02 235 views
1

我目前正在研究一個關於計算的項目。我已經完成了我項目的主要部分,還將SVN提交功能集成到了我的代碼中(使用.ini文件讀取特定地址等)SVN提交日誌問題

我可以很容易地提交文件,我正在嘗試的是我想實現實時日誌到我的控制檯。有沒有辦法將日誌實現到控制檯?不是一般的日誌,而是應該是實時的提交日誌。

  • 我使用eclipse for mac,我聽說過關於SVNKit,但我對SVN很差。

預先感謝任何信息

---編輯---

這是代碼從.ini文件讀取SVN命令

public static String iniSVNOkut(String deger, String getObje, String fetchObje){ 

     Ini uzantilariAlIni = null; 

     try 
     { 
      String uzantiAyarlari = "Uzantilar.ini";  

      try 
      { 
       uzantilariAlIni = new Ini(new FileReader(uzantiAyarlari)); 
      } 
      catch (InvalidFileFormatException e) 
      { 
       System.err.print("Hata InvalidFileFormat : " + e.getMessage() + "\n"); 
       e.printStackTrace(); 
      } 
      catch(FileNotFoundException e) 
      { 
       System.err.print("Hata FileNotFoundException : " + e.getMessage() + "\n"); 
       e.printStackTrace(); 
      } 
      catch (IOException e) 
      { 
       System.err.print("Hata IOException : " + e.getMessage() + "\n"); 
       e.printStackTrace(); 
      } 
     return deger = uzantilariAlIni.get(getObje).fetch(fetchObje); 


     } 
     finally 
     { 

     } 

    } 

這是什麼.ini包含

[svnAdresi] 
svnAdresiniAl = svn co http://svn.svnkit.com/repos/svnkit/trunk/ /Users/sample/Documents/workspace/SatirHesaplaGUI/svnTestMAC 

這就是我稱之爲

String svnAdresi; 
     svnAdresi = IniFonksiyon.iniSVNOkut(svnAdresi, "svnAdresi", "svnAdresiniAl"); 
    Runtime cmdCalistir = Runtime.getRuntime(); 

    try 
    { 
     Process islem = cmdCalistir.exec(svnAdresi); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 

回答

2

如果我正確理解你的問題,你想讀取Subversion提交日誌到你的控制檯應用程序。

最簡單的方法是使用SVNKit

下面是我做到的。

private static List<SVNLogEntry> logEntryList; 

    /* 
    * Gets the Subversion log records for the directory 
    */ 
    LogHandler handler = new LogHandler(); 
    String[] paths = { directory }; 
    try { 
     repository.log(paths, latestRevision, 1L, false, true, handler); 
    } catch (SVNException svne) { 
     if (svne.getMessage().contains("not found")) { 
      logEntryList = new ArrayList<SVNLogEntry>(); 
     } else { 
      CobolSupportLog.logError(
        "Error while fetching the repository history: " 
          + svne.getMessage(), svne); 
      return false; 
     } 
    } 

    logEntryList = handler.getLogEntries(); 
  • 目錄 - 字符串指向一個特定的目錄或模塊
  • latestRevision - 從Subversion最大的版本號。在日誌方法調用中放置latestRevision秒會以最近的順序返回日誌記錄。

如果您想按順序排列從1到latestRevision的日誌記錄,那麼1L將放在第二位,而latestRevision將放在第三位。

  • 存儲庫 - 您已經驗證的Subversion存儲庫。

這裏是LogHandler。

public class LogHandler implements ISVNLogEntryHandler { 

    protected static final int REVISION_LIMIT = 5; 

    protected List<SVNLogEntry> logEntryList; 

    public LogHandler() { 
     logEntryList = new ArrayList<SVNLogEntry>(); 
    } 

    public void handleLogEntry(SVNLogEntry logEntry) throws SVNException { 
     logEntryList.add(logEntry); 
    } 

    public List<SVNLogEntry> getLogEntries() { 
     if (logEntryList.size() <= REVISION_LIMIT) { 
      return logEntryList; 
     } else { 
      return logEntryList.subList(0, REVISION_LIMIT); 
     } 
    } 

} 
+1

好的答案,我只是補充一點,您可以指定REVISION_LIMIT直接登錄()方法。然後他們不會被加載到服務器上並通過網絡進行轉換。如果存儲庫有很多修訂,這可能會顯着加快您的實現。 –

+0

非常感謝!那正是我所需要的,如果我們不指定REVISION_LIMIT,那麼它有多重要?由於我正在處理的存儲庫有很多修訂 –

+0

@ Yesilmen:不,如果您不想指定修訂限制,則不必指定修訂限制。在我的應用程序中,我只需要最近的5.對德米特里來說,你是對的。我不記得爲什麼,但我需要一段時間的所有修訂,然後我將代碼限制爲5.我應該把限制放在handleLogEntry方法中。 –