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

The following examples show how to use org.tmatesoft.svn.core.io.SVNRepository#getCommitEditor() . 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
/**
 * Copy file with filter change.
 */
@Test()
public void copyAndModify() 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);
      sendDeltaAndClose(editor, "data.z", CONTENT_FOO, CONTENT_BAR);
      editor.closeDir();
      editor.closeEdit();
    }
    // On file read now we must have uncompressed content.
    checkFileContent(repo, "/data.z", CONTENT_BAR);
  }
}
 
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: 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 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: 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 6
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 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: 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 9
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 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 commitRootWithoutProperties() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/.gitattributes", "", propsEolNative);
    try {
      long latestRevision = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Modify .gitattributes", null, false, null);
      editor.openRoot(latestRevision);
      // Empty file.
      final String filePath = "/.gitattributes";
      editor.openFile(filePath, latestRevision);
      sendDeltaAndClose(editor, filePath, "", "*.txt\t\t\ttext\n");
      // Close dir
      editor.closeDir();
      editor.closeEdit();
      Assert.fail();
    } catch (SVNException e) {
      Assert.assertTrue(e.getMessage().contains(SVNProperty.INHERITABLE_AUTO_PROPS));
    }
  }
}
 
Example 11
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 12
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 13
Source File: WCDepthTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@BeforeMethod
private void before() throws Exception {
  server = SvnTestServer.createEmpty();
  final SVNRepository repository = server.openSvnRepository();
  factory = server.createOperationFactory();
  wc = Files.createDirectories(server.getTempDirectory().resolve("wc"));

  final ISVNEditor editor = repository.getCommitEditor("", null);
  editor.openRoot(-1);
  editor.addDir("/a", null, -1);
  editor.addDir("/a/b", null, -1);

  editor.addFile("/a/b/e", null, -1);
  editor.changeFileProperty("/a/b/e", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
  sendDeltaAndClose(editor, "/a/b/e", null, "e body");

  editor.addDir("/a/b/c", null, -1);

  editor.addFile("/a/b/c/d", null, -1);
  editor.changeFileProperty("/a/b/c/d", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
  sendDeltaAndClose(editor, "/a/b/c/d", null, "d body");

  editor.closeDir();
  editor.closeDir();
  editor.closeDir();
  editor.closeDir();
  editor.closeEdit();
}
 
Example 14
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 15
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 16
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 17
Source File: ReplayTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private void replayRevision(@NotNull SVNRepository srcRepo, @NotNull SVNRepository dstRepo, long revision) throws SVNException {
  SVNProperties revisionProperties = srcRepo.getRevisionProperties(revision, null);
  CopyFromSVNEditor editor = new CopyFromSVNEditor(dstRepo.getCommitEditor(revisionProperties.getStringValue("svn:log"), null), "/", true);
  srcRepo.replay(revision - 1, revision, true, editor);
  editor.closeEdit();
  checkCopyFrom(srcRepo, editor, revision);
}
 
Example 18
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 19
Source File: ShutdownTest.java    From git-as-svn with GNU General Public License v2.0 4 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 simpleShutdown() throws Exception {
  final Map<String, Thread> oldThreads = getAllThreads();
  final SvnTestServer server = SvnTestServer.createEmpty();
  final SVNRepository repo2 = server.openSvnRepository();
  final SVNRepository repo1 = server.openSvnRepository();
  repo1.getLatestRevision();
  final ISVNEditor editor = repo1.getCommitEditor("Empty commit", null, false, null);
  editor.openRoot(-1);
  server.startShutdown();

  /*
   Looks like there's a bug in OpenJDK 13 on Linux.
   1. Thread A calls ServerSocket.accept
   2. Thread B calls ServerSocket.close
   3. Thread B tries to connect to this socket
   4. Thread A always gets SocketException("socket closed")
   5. But *sometimes* TCP connection gets established even though
      there's nothing on server side that can talk to it
   This can be reproduced by removing sleep(1) and running this test multiple times.

   Reproduced on:
   openjdk version "13.0.2" 2020-01-14
   OpenJDK Runtime Environment (build 13.0.2+8)
   OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
  */
  Thread.sleep(1);

  try {
    // Can't create new connection is shutdown mode.
    repo2.getLatestRevision();
    Assert.fail();
  } catch (SVNException ignored) {
  }
  editor.closeDir();
  editor.closeEdit();
  repo1.closeSession();
  repo2.closeSession();
  server.shutdown(SHOWDOWN_TIME);
  checkThreads(oldThreads);
}
 
Example 20
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
void commit(String mode) throws IOException {
    // Commit to SVN
    SVNCommitInfo info;
    try {
        SVNRepository repository = getStore().getRepository();

        // Check which paths already exist in SVN
        String[] paths = store.getSlotPaths(id);
        int existing = paths.length - 1;
        for (; existing >= 0; existing--) {
            if (!repository.checkPath(paths[existing], -1).equals(SVNNodeKind.NONE)) {
                break;
            }
        }

        existing += 1;

        // Start commit editor
        String commitMsg = mode + "d metadata object " + store.getID() + "_" + id + " in store";
        ISVNEditor editor = repository.getCommitEditor(commitMsg, null);
        editor.openRoot(-1);

        // Create directories in SVN that do not exist yet
        for (int i = existing; i < paths.length - 1; i++) {
            LOGGER.debug("SVN create directory {}", paths[i]);
            editor.addDir(paths[i], null, -1);
            editor.closeDir();
        }

        // Commit file changes
        String filePath = paths[paths.length - 1];
        if (existing < paths.length) {
            editor.addFile(filePath, null, -1);
        } else {
            editor.openFile(filePath, -1);
        }

        editor.applyTextDelta(filePath, null);
        SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();

        String checksum;
        try (InputStream in = Files.newInputStream(path)) {
            checksum = deltaGenerator.sendDelta(filePath, in, editor, true);
        }

        if (store.shouldForceXML()) {
            editor.changeFileProperty(filePath, SVNProperty.MIME_TYPE, SVNPropertyValue.create("text/xml"));
        }

        editor.closeFile(filePath, checksum);
        editor.closeDir(); // root

        info = editor.closeEdit();
    } catch (SVNException e) {
        throw new IOException(e);
    }
    revision = () -> Optional.of(info.getNewRevision());
    LOGGER.info("SVN commit of {} finished, new revision {}", mode, getRevision());

    if (MCRVersioningMetadataStore.shouldSyncLastModifiedOnSVNCommit()) {
        setLastModified(info.getDate());
    }
}