Java Code Examples for org.tmatesoft.svn.core.io.SVNRepository#getLatestRevision()

The following examples show how to use org.tmatesoft.svn.core.io.SVNRepository#getLatestRevision() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check to break lock.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void unlockForce(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    SVNLock oldLock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(oldLock);
    unlock(repo, oldLock, false, null);

    SVNLock newLock = lock(repo, "example.txt", latestRevision, true, null);
    Assert.assertNotNull(newLock);
    compareLock(newLock, repo.getLock("example.txt"));

    unlock(repo, oldLock, true, null);
    Assert.assertNull(repo.getLock("example.txt"));
  }
}
 
Example 2
Source File: SvnFilePropertyTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check commit .gitattributes.
 */
@Test
public void commitRootWithProperties() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/.gitattributes", "", propsEolNative);
    {
      long latestRevision = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Modify .gitattributes", null, false, null);
      editor.openRoot(latestRevision);
      editor.changeDirProperty(SVNProperty.INHERITABLE_AUTO_PROPS, SVNPropertyValue.create("*.txt = svn:eol-style=native\n"));
      // Empty file.
      final String filePath = "/.gitattributes";
      editor.openFile(filePath, latestRevision);
      sendDeltaAndClose(editor, filePath, "", "*.txt\t\t\ttext\n");
      // Close dir
      editor.closeDir();
      editor.closeEdit();
    }
  }
}
 
Example 3
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void lockNotFile(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    final ISVNEditor editor = repo.getCommitEditor("Initial state", null, false, null);
    editor.openRoot(-1);
    editor.addDir("/example", null, -1);
    editor.addFile("/example/example.txt", null, -1);
    editor.changeFileProperty("/example/example.txt", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
    sendDeltaAndClose(editor, "/example/example.txt", null, "Source content");
    editor.closeDir();
    editor.closeDir();
    editor.closeEdit();

    final long latestRevision = repo.getLatestRevision();
    lock(repo, "example", latestRevision, false, SVNErrorCode.FS_NOT_FILE);
  }
}
 
Example 4
Source File: SvnFilePropertyTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check commit .gitattributes.
 */
@Test
public void commitDirWithProperties() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    final long latestRevision = repo.getLatestRevision();
    final ISVNEditor editor = repo.getCommitEditor("Create directory: /foo", null, false, null);
    editor.openRoot(-1);
    editor.addDir("/foo", null, latestRevision);
    editor.changeDirProperty(SVNProperty.INHERITABLE_AUTO_PROPS, SVNPropertyValue.create("*.txt = svn:eol-style=native\n"));
    // Empty file.
    final String filePath = "/foo/.gitattributes";
    editor.addFile(filePath, null, -1);
    editor.changeFileProperty(filePath, SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
    sendDeltaAndClose(editor, filePath, null, "*.txt\t\t\ttext\n");
    // Close dir
    editor.closeDir();
    editor.closeDir();
    editor.closeEdit();
  }
}
 
Example 5
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check for commit with remove locks.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void modifyLockedKeepLock(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    // Lock
    final SVNLock lock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(lock);
    {
      final Map<String, String> locks = new HashMap<>();
      locks.put("/example.txt", lock.getID());
      final ISVNEditor editor = repo.getCommitEditor("Initial state", locks, true, null);
      editor.openRoot(-1);
      editor.openFile("/example.txt", latestRevision);
      sendDeltaAndClose(editor, "/example.txt", "", "Source content");
      editor.closeDir();
      editor.closeEdit();
    }
    compareLock(repo.getLock("/example.txt"), lock);
  }
}
 
Example 6
Source File: SvnCommitTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check commit out-of-date.
 */
@Test
public void commitFileOufOfDateTest() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/README.md", "Old content", propsEolNative);

    final long lastRevision = repo.getLatestRevision();

    modifyFile(repo, "/README.md", "New content 1", lastRevision);
    try {
      modifyFile(repo, "/README.md", "New content 2", lastRevision);
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertEquals(e.getErrorMessage().getErrorCode(), SVNErrorCode.WC_NOT_UP_TO_DATE);
    }
  }
}
 
Example 7
Source File: ShutdownTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check simple shutdown:
 * <p>
 * * All old connection have a small time to finish work.
 * * New connection is not accepted.
 */
@Test
public void timeoutShutdown() throws Exception {
  final Map<String, Thread> oldThreads = getAllThreads();
  final SvnTestServer server = SvnTestServer.createEmpty();
  final SVNRepository repo = server.openSvnRepository();
  repo.getLatestRevision();
  final ISVNEditor editor = repo.getCommitEditor("Empty commit", null, false, null);
  editor.openRoot(-1);
  server.startShutdown();
  server.shutdown(FORCE_TIME);
  checkThreads(oldThreads);
  try {
    editor.closeDir();
    editor.closeEdit();
    repo.closeSession();
  } catch (SVNException ignored) {
  }
}
 
Example 8
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Try to remove not-owned lock.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void unlockNotOwner(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    // New lock
    final SVNLock oldLock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(oldLock);
    unlock(repo, oldLock, false, null);

    final SVNLock newLock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(newLock);
    unlock(repo, oldLock, false, SVNErrorCode.FS_NO_SUCH_LOCK);
  }
}
 
Example 9
Source File: SvnCommitTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check file copy.
 * <pre>
 * svn copy README.md@45 README.copy
 * </pre>
 */
@Test
public void copyFileFromRevisionTest() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    final String srcFile = "/README.md";
    final String dstFile = "/README.copy";
    final String expectedContent = "New content 2";

    createFile(repo, srcFile, "Old content 1", propsEolNative);
    modifyFile(repo, srcFile, expectedContent, repo.getLatestRevision());
    final long srcRev = repo.getLatestRevision();
    modifyFile(repo, srcFile, "New content 3", repo.getLatestRevision());

    final ISVNEditor editor = repo.getCommitEditor("Copy file commit", null, false, null);
    editor.openRoot(-1);
    editor.addFile(dstFile, srcFile, srcRev);
    editor.closeFile(dstFile, null);
    editor.closeDir();
    editor.closeEdit();

    // compare content
    checkFileContent(repo, dstFile, expectedContent);
  }
}
 
Example 10
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check for deny modify locking file.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void modifyLocked(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    // Lock
    final SVNLock lock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(lock);

    try {
      modifyFile(repo, "/example.txt", "content", latestRevision);
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertEquals(e.getErrorMessage().getErrorCode(), SVNErrorCode.FS_BAD_LOCK_TOKEN);
    }
  }
}
 
Example 11
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Try to twice remove lock.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void unlockTwice(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    // New lock
    final SVNLock lock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(lock);
    unlock(repo, lock, false, null);
    unlock(repo, lock, false, SVNErrorCode.FS_NO_SUCH_LOCK);
  }
}
 
Example 12
Source File: SvnTestHelper.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
public static void deleteFile(@NotNull SVNRepository repo, @NotNull String filePath) throws SVNException {
  long latestRevision = repo.getLatestRevision();
  final ISVNEditor editor = repo.getCommitEditor("Delete file: " + filePath, null, false, null);
  editor.openRoot(-1);
  int index = 0;
  int depth = 1;
  while (true) {
    index = filePath.indexOf('/', index + 1);
    if (index < 0) {
      break;
    }
    editor.openDir(filePath.substring(0, index), -1);
    depth++;
  }
  editor.deleteEntry(filePath, latestRevision);
  for (int i = 0; i < depth; ++i) {
    editor.closeDir();
  }
  Assert.assertNotEquals(editor.closeEdit(), SVNCommitInfo.NULL);
}
 
Example 13
Source File: SvnGetLocationsTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void locationsSimple() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();
    initRepo(repo);

    final long last = repo.getLatestRevision();
    checkGetLocations(repo, "/baz/test.txt", last, 5, "/baz/test.txt");
    checkGetLocations(repo, "/baz/test.txt", last, 4, "/baz/test.txt");
    checkGetLocations(repo, "/baz/test.txt", last, 3, "/bar/test.txt");
    checkGetLocations(repo, "/baz/test.txt", last, 2, "/bar/test.txt");
    checkGetLocations(repo, "/baz/test.txt", last, 1, "/foo/test.txt");
    checkGetLocations(repo, "/baz/test.txt", last, 0, null);

    checkGetLocations(repo, "/bar/test.txt", 3, 3, "/bar/test.txt");
    checkGetLocations(repo, "/bar/test.txt", 3, 2, "/bar/test.txt");
    checkGetLocations(repo, "/bar/test.txt", 3, 1, "/foo/test.txt");
    checkGetLocations(repo, "/bar/test.txt", 3, 0, null);

    checkGetLocations(repo, "/bar/test.txt", 2, 2, "/bar/test.txt");
    checkGetLocations(repo, "/bar/test.txt", 2, 1, "/foo/test.txt");
    checkGetLocations(repo, "/bar/test.txt", 2, 0, null);

    checkGetLocations(repo, "/foo/test.txt", 1, 1, "/foo/test.txt");
    checkGetLocations(repo, "/foo/test.txt", 1, 0, null);
  }
}
 
Example 14
Source File: SvnGetLocationsTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void segmentsNotFound() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();
    initRepo(repo);

    final long last = repo.getLatestRevision();
    try {
      checkGetSegments(repo, "/baz/test.xml", last, 5, 2);
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertEquals(e.getErrorMessage().getErrorCode(), SVNErrorCode.FS_NOT_FOUND);
    }
  }
}
 
Example 15
Source File: SvnLogTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check file recreate log test.
 */
@Test
public void recreateFile() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();
    // r1 - add single file.
    createFile(repo, "/foo.txt", "", propsEolNative);
    // r2 - modify file.
    modifyFile(repo, "/foo.txt", "New content", repo.getLatestRevision());
    // r3 - remove file.
    deleteFile(repo, "/foo.txt");
    final long delete = repo.getLatestRevision();
    // r4 - recreate file.
    createFile(repo, "/foo.txt", "", propsEolNative);

    // svn log from root
    final long last = repo.getLatestRevision();
    checkLog(repo, last, 0, "/foo.txt",
        new LogEntry(4, "Create file: /foo.txt", "A /foo.txt")
    );

    // svn log from root
    checkLog(repo, delete - 1, 0, "/foo.txt",
        new LogEntry(2, "Modify file: /foo.txt", "M /foo.txt"),
        new LogEntry(1, "Create file: /foo.txt", "A /foo.txt")
    );
  }
}
 
Example 16
Source File: SvnFilePropertyTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check commit .gitattributes.
 */
@Test
public void executable() throws Exception {
  //Map<String, String> props = new HashMap<>()["key":""];
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/non-exec.txt", "", propsEolNative);
    createFile(repo, "/exec.txt", "", propsExecutable);
    checkFileProp(repo, "/non-exec.txt", propsEolNative);
    checkFileProp(repo, "/exec.txt", propsExecutable);
    {
      final long latestRevision = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Create directory: /foo", null, false, null);
      editor.openRoot(-1);

      editor.openFile("/non-exec.txt", latestRevision);
      editor.changeFileProperty("/non-exec.txt", SVNProperty.EXECUTABLE, SVNPropertyValue.create("*"));
      editor.closeFile("/non-exec.txt", null);

      editor.openFile("/exec.txt", latestRevision);
      editor.changeFileProperty("/exec.txt", SVNProperty.EXECUTABLE, null);
      editor.closeFile("/exec.txt", null);

      editor.closeDir();
      editor.closeEdit();
    }
    checkFileProp(repo, "/non-exec.txt", propsExecutable);
    checkFileProp(repo, "/exec.txt", propsEolNative);
  }
}
 
Example 17
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check get locks.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void getLocks(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();
    {
      final ISVNEditor editor = repo.getCommitEditor("Initial state", null, false, null);
      editor.openRoot(-1);
      editor.addDir("/example", null, -1);
      editor.addFile("/example/example.txt", null, -1);
      editor.changeFileProperty("/example/example.txt", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
      sendDeltaAndClose(editor, "/example/example.txt", null, "Source content");
      editor.closeDir();
      editor.addFile("/foo.txt", null, -1);
      editor.changeFileProperty("/foo.txt", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
      sendDeltaAndClose(editor, "/foo.txt", null, "Source content");
      editor.closeDir();
      editor.closeEdit();
    }
    compareLocks(repo.getLocks(""));

    final long latestRevision = repo.getLatestRevision();
    // Lock
    final SVNLock lock1 = lock(repo, "/example/example.txt", latestRevision, false, null);
    Assert.assertNotNull(lock1);
    final SVNLock lock2 = lock(repo, "/foo.txt", latestRevision, false, null);
    Assert.assertNotNull(lock2);

    compareLocks(repo.getLocks(""), lock1, lock2);
  }
}
 
Example 18
Source File: SubversionRepository.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public SubversionRepository(String basePath) throws RepositoryNotAvailableException {
	try {
		SVNRepository repository = new SubversionRepositoryInitializer(basePath).initRepository(CACHED);
		this.basePath = repository.getLocation().toDecodedString();
		long latestRevision = repository.getLatestRevision();
		branchToPathMap.put(TRUNK, basePath + "/" + TRUNK);
		searchEntriesFor(repository, latestRevision, branchToPathMap, BRANCHES);
		searchEntriesFor(repository, latestRevision, tagToPathMap, TAGS);
	} catch (Exception e) {
		throw new RepositoryNotAvailableException(e);
	}
}
 
Example 19
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for deny modify locking file.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void deleteLocked(@NotNull SvnTesterFactory factory) throws Exception {
  try (SvnTester server = factory.create()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/example.txt", "", propsEolNative);
    final long latestRevision = repo.getLatestRevision();

    // Lock
    final SVNLock lock = lock(repo, "example.txt", latestRevision, false, null);
    Assert.assertNotNull(lock);

    final ISVNEditor editor = repo.getCommitEditor("Initial state", null, false, null);
    try {
      editor.openRoot(-1);
      editor.deleteEntry("/example.txt", latestRevision);
      editor.closeDir();
      editor.closeEdit();
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertEquals(e.getErrorMessage().getErrorCode(), SVNErrorCode.FS_BAD_LOCK_TOKEN);
    } finally {
      editor.abortEdit();
    }
  }
}
 
Example 20
Source File: Cmm1400Controller.java    From oslits with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 
 * 라스트 리비젼 조회
 * 
 * @param request
 * @param response
 * @param model
 * @return
 * @throws Exception
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value="/cmm/cmm1000/cmm1400/selectCmm1400LastRevisionAjax.do")
public ModelAndView selectCmm1400LastRevisionAjax(HttpServletRequest request, HttpServletResponse response, ModelMap model ) throws Exception {

	try{

		//리퀘스트에서 넘어온 파라미터를 맵으로 세팅
		Map paramMap = RequestConvertor.requestParamToMap(request,true);

		//SVN Id로 Svn정보 불러오기
		Map svnInfo = stm2000Service.selectStm2000Info(paramMap);
		
		String svnUrl=(String)svnInfo.get("svnRepUrl");
		String userId= (String)svnInfo.get("svnUsrId");
		String svnUsrPw = (String)svnInfo.get("svnUsrPw");	//암호화된 암호
		
		//값이 null
		if(svnUsrPw == null || "".equals(svnUsrPw)){
			model.addAttribute("MSG_CD", Stm2000Controller.SVN_AUTHENTICATION_EXCEPTION);
			return new ModelAndView("jsonView");
		}
		
		//globals.properties에서 salt값 가져오기
		String salt = EgovProperties.getProperty("Globals.lunaops.salt");
		
		//암호 복호화
		String userPw = CommonScrty.decryptedAria(svnUsrPw, salt);
		
		//값이 null
		if(userPw == null || "".equals(userPw)){
			model.addAttribute("MSG_CD", Stm2000Controller.SVN_AUTHENTICATION_EXCEPTION);
			return new ModelAndView("jsonView");
		}
		
		SVNConnector conn = new SVNConnector();
		SVNRepository repository = conn.svnConnect(svnUrl , userId , userPw);

		Long lastRevision = repository.getLatestRevision();

		conn.close(repository);

		model.addAttribute("lastRevision", lastRevision);

		//조회성공메시지 세팅
		model.addAttribute("message", egovMessageSource.getMessage("success.common.select"));
		model.addAttribute("MSG_CD", Stm2000Controller.SVN_OK);
		return new ModelAndView("jsonView", paramMap);
	}
	catch(UserDefineException ude) {
		// 접속실패여부 및 접속실패 메시지 세팅
		model.addAttribute("MSG_CD", Stm2000Controller.SVN_MODULE_USE_EXCEPTION);
		return new ModelAndView("jsonView");
	}
	catch(Exception ex){
		Log.error("selectCmm1400LastRevisionAjax()", ex);
		if(ex instanceof SVNAuthenticationException ){
			model.addAttribute("MSG_CD", Stm2000Controller.SVN_AUTHENTICATION_EXCEPTION);
		}else if(ex instanceof SVNException ){
			model.addAttribute("MSG_CD", Stm2000Controller.SVN_EXCEPTION);
		} else{
			model.addAttribute("MSG_CD", Stm2000Controller.SVN_EXCEPTION);
		}
		
		return new ModelAndView("jsonView");
	}
}