Javaã®subversionã©ã¤ãã©ãª SVNKitã試ã ãã®2
主ãªããã±ã¼ã¸
- org.tmatesoft.svn.core.io
- ä½ã¬ãã«ãªAPIã¯ãã¡ã
- org.tmatesoft.svn.core.wc
- ã³ãã³ãã©ã¤ã³ã®svnç¸å½ã®ãã¨ãããããã°ãã
- org.tmatesoft.svn.core.javahl
- javaHL(nativeã®SVNã©ã¤ãã©ãª)ã®pure javaå®è£
ä»åã¯ã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ã¿ã¹ãã¢ã¨ãã¦subversionã使ãããã®ã§ä½ã¬ãã«APIã«ææ¦ããã
æ°ãããã£ã¬ã¯ããªã¨ãã¡ã¤ã«ãã³ããã
åºæ¬çã«æ°è¦ãã¡ã¤ã«ã§ãã£ã¦ãå·®åãéä¿¡ããã¨ããææ³ã®ããã ãã¾ããISVNEditorã¯ã«ã¬ã³ããã£ã¬ã¯ããªãæã£ã¦ãã¦ããã£ã¬ã¯ããªããªã¼ã辿ã£ã¦ããã¤ã¡ã¼ã¸ã ã
DAVRepositoryFactory.setup(); SVNRepositoryFactoryImpl.setup(); FSRepositoryFactory.setup(); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded("svn+ssh://example.com/path/to/repository")); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("hoge", "hogepass"); repository.setAuthenticationManager(authManager); ISVNEditor editor = repository.getCommitEditor("test", new NullWorkspace()); // NullWorkspaceã¯ISVNWorkspaceMediatorã®å®è£ ãä»åã¯å®è£ ã¯ç©ºã£ã½ã editor.openRoot(-1); editor.addDir("dirA", null, -1); editor.addFile("dirA/sample.txt", null, -1); editor.applyTextDelta("dirA/sample.txt", null); // ãã¡ã¤ã«ã®å 容ã¯å·®åã§éä¿¡ããã SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); // 空ã®ãã¡ã¤ã«ããå·®åãä½ã String checksum = deltaGenerator.sendDelta("dirA/sample.txt", new ByteArrayInputStream("sampleData".getBytes()), editor, true); editor.closeFile("dirA/sample.txt", checksum); editor.closeDir(); // ä»ã®ãã£ã¬ã¯ããªãã¯ãã¼ãºã親ãã£ã¬ã¯ããªã¸ç§»åããã editor.closeDir(); // rootãcloseãããã editor.closeEdit();
SVNWCUtil.createDefaultAuthenticationManagerã ããcreateDefaultAuthenticationManager(File configDir)ã¨ãããã£ã¬ã¯ããªãæå®ã§ãããã®ããããããã¯ãé常ã¦ã¼ã¶ã¼ãã£ã¬ã¯ããªã«ããSubversion/auth/ã®äºãæãããã§ãä¸èº«ã¯èªè¨¼æ
å ±ã®ãã£ãã·ã¥ã§ããã(åç
§:クライアント証明のキャッシュ)
ã¢ãããã¼ã => ç·¨é => ã³ããã
repositoryããããããç·¨éãããã¨ãã¦ãããã¡ã¤ã«ã®å¤ãã³ã³ãã³ããåã£ã¦ãã¦ãç·¨éå¾ã«å·®åãä½æãã¦éä¿¡ããã°ï¼¯ï¼«ã
æªè§£æ±ºï¼ãã®éã«èª°ããæ´æ°ï¼ï¼ã³ããããè¡ã£ã¦ã³ãªã¸ã§ã³ãçºçãããã©ããªãï¼
DAVRepositoryFactory.setup(); SVNRepositoryFactoryImpl.setup(); FSRepositoryFactory.setup(); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded("svn+ssh://example.com/path/to/repository")); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("hoge", "hogepass"); repository.setAuthenticationManager(authManager); ByteArrayOutputStream bufOut = new ByteArrayOutputStream(); repository.getFile("dirA/sample.txt", -1, new HashMap(), bufOut); // å¤ãã³ã³ãã³ããupdate byte [] oldData = bufOut.toByteArray(); ISVNEditor editor = repository.getCommitEditor("test", new NullWorkspace()); editor.openRoot(-1); editor.openDir("dirA", -1); editor.openFile("dirA/sample.txt", -1); editor.applyTextDelta("dirA/sample.txt", null); // ãã¡ã¤ã«ã®å 容ã¯å·®åã§éä¿¡ããã SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); // åã£ã¦ããã³ã³ãã³ãããå·®åãä½ã String checksum = deltaGenerator.sendDelta("dirA/sample.txt", new ByteArrayInputStream(oldData), 0, new ByteArrayInputStream("changedData".getBytes()), editor, true); ditor.closeFile("dirA/sample.txt", checksum); ditor.closeDir(); // ä»ã®ãã£ã¬ã¯ããªãã¯ãã¼ãºã親ãã£ã¬ã¯ããªã¸ç§»åããã editor.closeDir(); // rootãcloseãããã editor.closeEdit();