org.tmatesoft.svn.core.io.SVNRepository Java Examples

The following examples show how to use org.tmatesoft.svn.core.io.SVNRepository. 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: SvnFilterTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write filtered file.
 */
@Test()
public void write() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    // Add filter to file.
    createFile(repo, "/.gitattributes", "/*.z\t\t\tfilter=gzip\n", propsEolNative);
    // On file read now we must have uncompressed content.
    createFile(repo, "/data.z", CONTENT_FOO, propsEolNative);
    checkFileContent(repo, "/data.z", CONTENT_FOO);
    // Modify file.
    modifyFile(repo, "/data.z", CONTENT_BAR, repo.getLatestRevision());
    checkFileContent(repo, "/data.z", CONTENT_BAR);
  }
}
 
Example #2
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 #3
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 #4
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public static SVNRepository connectToSVNInstance(String url, String usr, String pass){
	SvnUtil.setupLibrary();
    SVNRepository repository = null;
    try {
    	repository = SvnUtil.createRepository(url);
    } 
    catch (SVNException svne) {
        System.err.println("error while creating an SVNRepository for location '"+ url + "': " + svne.getMessage());
        return null;
    }
    
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(usr, pass);
    repository.setAuthenticationManager(authManager);
    
    try {
    	SvnUtil.verifySVNLocation(repository, url);
	} catch (SVNException e) {
		e.printStackTrace();
	}
    
    return repository;
}
 
Example #5
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 commitDirWithoutProperties() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();
    try {
      final long latestRevision = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Create directory: /foo", null, false, null);
      editor.openRoot(-1);
      editor.addDir("/foo", null, latestRevision);
      // Empty file.
      final String filePath = "/foo/.gitattributes";
      editor.addFile(filePath, null, -1);
      sendDeltaAndClose(editor, filePath, null, "*.txt\t\t\ttext\n");
      // Close dir
      editor.closeDir();
      editor.closeDir();
      editor.closeEdit();
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertTrue(e.getMessage().contains(SVNProperty.INHERITABLE_AUTO_PROPS));
    }
  }
}
 
Example #6
Source File: SvnTestHelper.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
public static void createFile(@NotNull SVNRepository repo, @NotNull String filePath, @NotNull byte[] content, @Nullable Map<String, String> props) throws SVNException, IOException {
  final ISVNEditor editor = repo.getCommitEditor("Create 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.addFile(filePath, null, -1);
  if (props != null) {
    for (Map.Entry<String, String> entry : props.entrySet()) {
      editor.changeFileProperty(filePath, entry.getKey(), SVNPropertyValue.create(entry.getValue()));
    }
  }
  sendDeltaAndClose(editor, filePath, null, content);
  for (int i = 0; i < depth; ++i) {
    editor.closeDir();
  }
  Assert.assertNotEquals(editor.closeEdit(), SVNCommitInfo.NULL);
}
 
Example #7
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 #8
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 #9
Source File: SvnProctor.java    From proctor with Apache License 2.0 6 votes vote down vote up
@Override
public void verifySetup() throws StoreException {
    final Long latestRevision = getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<Long>() {
        @Override
        public Long execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception {
            return repo.getLatestRevision();
        }

        @Override
        public StoreException handleException(final Exception e) throws StoreException {
            throw new StoreException("Failed to get latest revision for svn-path: " + svnUrl, e);
        }
    });
    if (latestRevision <= 0) {
        throw new StoreException("Found non-positive revision (" + latestRevision + ") for svn-path: " + svnUrl);
    }
}
 
Example #10
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 symlinkBinary() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    final String content = "link foo/bar.txt";
    createFile(repo, "/.gitattributes", "*.bin binary", propsEolNative);
    createFile(repo, "/non-link.bin", content, propsBinary);
    createFile(repo, "/link.bin", content, propsSymlink);

    checkFileProp(repo, "/non-link.bin", propsBinary);
    checkFileProp(repo, "/link.bin", propsSymlink);

    checkFileContent(repo, "/non-link.bin", content);
    checkFileContent(repo, "/link.bin", content);
  }
}
 
Example #11
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 #12
Source File: MCRMetadataVersion.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves this version of the metadata
 * 
 * @return the metadata document as it was in this version
 * @throws MCRUsageException
 *             if this is a deleted version, which can not be retrieved
 */
public MCRContent retrieve() throws IOException {
    if (type == Type.deleted) {
        String msg = "You can not retrieve a deleted version, retrieve a previous version instead";
        throw new MCRUsageException(msg);
    }
    try {
        SVNRepository repository = vm.getStore().getRepository();
        MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream();
        repository.getFile(vm.getStore().getSlotPath(vm.getID()), revision, null, baos);
        baos.close();
        return new MCRByteContent(baos.getBuffer(), 0, baos.size(), getDate().getTime());
    } catch (SVNException e) {
        throw new IOException(e);
    }
}
 
Example #13
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 commitFileWithProperties() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "sample.txt", "", propsEolNative);
    checkFileProp(repo, "/sample.txt", propsEolNative);

    createFile(repo, ".gitattributes", "*.txt\t\t\ttext eol=lf\n", propsEolNative);
    createFile(repo, "with-props.txt", "", propsEolLf);
    try {
      createFile(repo, "none-props.txt", "", null);
    } catch (SVNException e) {
      Assert.assertTrue(e.getMessage().contains(SVNProperty.EOL_STYLE));
    }
  }
}
 
Example #14
Source File: SvnFilterTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copy file with filter change.
 */
@Test()
public void copy() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    // Add filter to file.
    createFile(repo, "/.gitattributes", "/*.z\t\t\tfilter=gzip\n", propsEolNative);
    // Create source file.
    createFile(repo, "/data.txt", CONTENT_FOO, propsEolNative);
    // Copy source file with "raw" filter to destination with "gzip" filter.
    {
      final long rev = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Copy file commit", null, false, null);
      editor.openRoot(-1);
      editor.addFile("data.z", "data.txt", rev);
      editor.closeFile("data.z", null);
      editor.closeDir();
      editor.closeEdit();
    }
    // On file read now we must have uncompressed content.
    checkFileContent(repo, "/data.z", CONTENT_FOO);
  }
}
 
Example #15
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check to stealing lock.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void lockForce(@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);
    compareLock(oldLock, repo.getLock("example.txt"));

    SVNLock badLock = lock(repo, "example.txt", latestRevision, false, SVNErrorCode.FS_PATH_ALREADY_LOCKED);
    Assert.assertNull(badLock);
    compareLock(oldLock, repo.getLock("example.txt"));

    SVNLock newLock = lock(repo, "example.txt", latestRevision, true, null);
    Assert.assertNotNull(newLock);
    compareLock(newLock, repo.getLock("example.txt"));
  }
}
 
Example #16
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 keep locks.
 */
@Test(dataProvider = "all", dataProviderClass = SvnTesterDataProvider.class)
public void modifyLockedRemoveLock(@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, false, null);
      editor.openRoot(-1);
      editor.openFile("/example.txt", latestRevision);
      sendDeltaAndClose(editor, "/example.txt", "", "Source content");
      editor.closeDir();
      editor.closeEdit();
    }
    Assert.assertNull(repo.getLock("/example.txt"));
  }
}
 
Example #17
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 #18
Source File: SvnTesterExternal.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() throws Exception {
  final SVNRepository repo = openSvnRepository(url);
  long revision = repo.getLatestRevision();
  try {
    final SVNLock[] locks = repo.getLocks(suffix);
    if (locks.length > 0) {
      final SVNURL root = repo.getRepositoryRoot(true);
      final Map<String, String> locksMap = new HashMap<>();
      for (SVNLock lock : locks) {
        final String relativePath = SVNURLUtil.getRelativeURL(url, root.appendPath(lock.getPath(), false), false);
        locksMap.put(relativePath, lock.getID());
      }
      repo.unlock(locksMap, true, null);
    }
    final ISVNEditor editor = repo.getCommitEditor("Remove subdir for test", null, false, null);
    editor.openRoot(-1);
    editor.deleteEntry(suffix, revision);
    editor.closeEdit();
  } finally {
    repo.closeSession();
  }
}
 
Example #19
Source File: ReplayTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
private void checkReplaySelf(@NotNull ReplayMethod replayMethod) throws Exception {
  try (
      SvnTestServer src = SvnTestServer.createMasterRepository();
      SvnTestServer dst = SvnTestServer.createEmpty()
  ) {
    final SVNRepository srcRepo = src.openSvnRepository();
    final SVNRepository dstRepo = dst.openSvnRepository();
    final Repository srcGit = src.getRepository();
    final Repository dstGit = dst.getRepository();

    final long lastRevision = Math.min(200, srcRepo.getLatestRevision());
    log.info("Start replay");
    for (long revision = 1; revision <= lastRevision; revision++) {
      final SVNPropertyValue message = srcRepo.getRevisionPropertyValue(revision, "svn:log");
      final SVNPropertyValue srcHash = srcRepo.getRevisionPropertyValue(revision, SvnConstants.PROP_GIT);
      log.info("  replay commit #{} {}: {}", revision, new String(srcHash.getBytes()), StringHelper.getFirstLine(message.getString()));
      replayMethod.replay(srcRepo, dstRepo, revision);
      log.info("  compare revisions #{}: {}", revision, StringHelper.getFirstLine(message.getString()));
      compareRevision(srcRepo, revision, dstRepo, revision);
      final SVNPropertyValue dstHash = dstRepo.getRevisionPropertyValue(revision, SvnConstants.PROP_GIT);
      compareGitRevision(srcGit, srcHash, dstGit, dstHash);
    }
    log.info("End replay");
  }
}
 
Example #20
Source File: ReplayTest.java    From git-as-svn with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testReplayFileModification() throws Exception {
  try (SvnTesterSvnKit sourceRepo = new SvnTesterSvnKit();
       SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository srcRepo = sourceRepo.openSvnRepository();
    final SVNCommitInfo lastCommit = buildHistory(srcRepo);
    final SVNRepository dstRepo = server.openSvnRepository();

    log.info("Start replay");
    for (long revision = 1; revision <= lastCommit.getNewRevision(); revision++) {
      final SVNPropertyValue message = srcRepo.getRevisionPropertyValue(revision, "svn:log");
      log.info("  replay commit #{}: {}", revision, StringHelper.getFirstLine(message.getString()));
      replayRangeRevision(srcRepo, dstRepo, revision, false);
      log.info("  compare revisions #{}: {}", revision, StringHelper.getFirstLine(message.getString()));
      compareRevision(srcRepo, revision, dstRepo, dstRepo.getLatestRevision());
    }
    log.info("End replay");
  }
}
 
Example #21
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 #22
Source File: MCRVersioningMetadataStore.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void delete(int id) throws IOException {
    String commitMsg = "Deleted metadata object " + getID() + "_" + id + " in store";
    // Commit to SVN
    SVNCommitInfo info;
    try {
        SVNRepository repository = getRepository();
        ISVNEditor editor = repository.getCommitEditor(commitMsg, null);
        editor.openRoot(-1);
        editor.deleteEntry("/" + getSlotPath(id), -1);
        editor.closeDir();

        info = editor.closeEdit();
        LOGGER.info("SVN commit of delete finished, new revision {}", info.getNewRevision());
    } catch (SVNException e) {
        LOGGER.error("Error while deleting {} in SVN ", id, e);
    } finally {
        super.delete(id);
    }
}
 
Example #23
Source File: SvnTesterExternal.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
public SvnTesterExternal(@NotNull SVNURL url, @Nullable ISVNAuthenticationManager authManager) throws SVNException {
  this.url = url;
  this.authManager = authManager;
  this.suffix = UUID.randomUUID().toString();
  final SVNRepository repo = openSvnRepository(url);
  try {
    final ISVNEditor editor = repo.getCommitEditor("Create subdir for test", null, false, null);
    editor.openRoot(-1);
    editor.addDir(suffix, null, -1);
    editor.closeDir();
    editor.closeEdit();
  } finally {
    repo.closeSession();
  }
}
 
Example #24
Source File: SvnTestHelper.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
public static void checkFileContent(@NotNull SVNRepository repo, @NotNull String filePath, @NotNull byte[] content) throws IOException, SVNException {
  final SVNDirEntry info = repo.info(filePath, repo.getLatestRevision());
  Assert.assertEquals(info.getKind(), SVNNodeKind.FILE);
  Assert.assertEquals(info.getSize(), content.length);

  try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
    repo.getFile(filePath, repo.getLatestRevision(), null, stream);
    Assert.assertEquals(stream.toByteArray(), content);
  }
}
 
Example #25
Source File: SubversionRepositoryInitializer.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public SVNRepository initRepository(boolean cached) throws SVNException, MalformedURLException {
	SVNRepository repo = null;
	SVNURL svnUrl = SVNURL.parseURIEncoded(url);
	if (url.startsWith(HTTP_SCHEME + SCHEME_SEPARATOR) || url.startsWith(HTTPS_SCHEME + SCHEME_SEPARATOR)) {
		DAVRepositoryFactory.setup();
		repo = DAVRepositoryFactory.create(svnUrl);
		repo.testConnection();
		if(cached) {
			TmpDirCreator tmpDirCreator = new TmpDirCreator(url);
			File tempDir = tmpDirCreator.getLocalTempDir();
			SVNURL cachedRepoPath = SVNURL.parseURIEncoded(FILE_SCHEME + SCHEME_SEPARATOR + tempDir);
			if(!tempDir.exists()){
				messageOutputStream.println("Caching subversion repository " + svnUrl + " This can take a while...");
				tempDir.mkdirs();
				cachedRepoPath = SVNRepositoryFactory.createLocalRepository(tempDir, true, true);
				tmpDirCreator.writeIdFileToTempDir();
				SVNRepository targetRepo = SVNRepositoryFactory.create(cachedRepoPath);
				SVNRepositoryReplicator replicator = SVNRepositoryReplicator.newInstance();
				replicator.setReplicationHandler(new ProgressBarReplicationHandler(repo.getLatestRevision()));
				replicator.replicateRepository(repo, targetRepo, -1, -1);
				messageOutputStream.println("\nCaching finished succesfully...");
			}
			svnUrl = cachedRepoPath;
			FSRepositoryFactory.setup();
			repo = FSRepositoryFactory.create(svnUrl);
		}
	} else if (url.startsWith(SVN_SCHEME + SCHEME_SEPARATOR)) {
		SVNRepositoryFactoryImpl.setup();
		repo = SVNRepositoryFactoryImpl.create(svnUrl);
	} else if (url.startsWith(FILE_SCHEME + SCHEME_SEPARATOR)) {
		FSRepositoryFactory.setup();
		repo = FSRepositoryFactory.create(svnUrl);
	} else
		throw new MalformedURLException(String.format("URL %s is not an supported SVN url!", url));
	repo.testConnection();
	return repo;
}
 
Example #26
Source File: SvnLockTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void lockWithDelayedAuth() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty(null, true)) {
    final SVNRepository repo = server.openSvnRepository();
    createFile(repo, "/example.txt", "", propsEolNative);
    final SVNLock lock = lock(repo, "/example.txt", repo.getLatestRevision(), false, null);
    Assert.assertNotNull(lock);
  }
}
 
Example #27
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 #28
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 #29
Source File: ReplayTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private void updateRevision(@NotNull SVNRepository srcRepo, @NotNull SVNRepository dstRepo, long revision) throws SVNException {
  final SVNPropertyValue message = srcRepo.getRevisionPropertyValue(revision, "svn:log");
  final CopyFromSVNEditor editor = new CopyFromSVNEditor(dstRepo.getCommitEditor(message.getString(), null), "/", true);
  srcRepo.update(revision, "", SVNDepth.INFINITY, true, reporter -> {
    reporter.setPath("", null, revision - 1, SVNDepth.INFINITY, false);
    reporter.finishReport();
  }, new FilterSVNEditor(editor, true));
  checkCopyFrom(srcRepo, editor, revision);
}
 
Example #30
Source File: SvnCommitTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check commit up-to-date.
 */
@Test
public void commitFileUpToDateTest() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/README.md", "Old content 1", propsEolNative);
    createFile(repo, "/build.gradle", "Old content 2", propsEolNative);

    final long lastRevision = repo.getLatestRevision();
    modifyFile(repo, "/README.md", "New content 1", lastRevision);
    modifyFile(repo, "/build.gradle", "New content 2", lastRevision);
  }
}