org.tmatesoft.svn.core.SVNPropertyValue Java Examples

The following examples show how to use org.tmatesoft.svn.core.SVNPropertyValue. 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: 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 #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 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 #3
Source File: SvnClient.java    From steady with Apache License 2.0 6 votes vote down vote up
public long  getRevisionTimeStamp(String revision){
	long revisionTimeStampMilliSecond = 0;

	try {
		//An "svn:date" revision property that is a date & time stamp representing the time when the revision was created.
		SVNPropertyValue propertyValue = rootRepo.getRevisionPropertyValue(Long.parseLong(revision),SVNRevisionProperty.DATE);
		String stringValue = SVNPropertyValue.getPropertyAsString(propertyValue);
		//SVNDate date = SVNDate.parseDate(stringValue);
		revisionTimeStampMilliSecond  = SVNDate.parseDateAsMilliseconds(stringValue);
		//revisionTimeStampMicroSecond = date.getTimeInMicros();
	} catch (SVNException e) {
		// TODO Auto-generated catch block
		//e.printStackTrace();
		SvnClient.log.error("Error when retrieving time stamp for revision : " + revision + " "+ e.getMessage());
	}
	return revisionTimeStampMilliSecond;
}
 
Example #4
Source File: SvnUpdateTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bug: svn up doesnt remove file #18
 * <pre>
 * bozaro@landfill:/tmp/test/git-as-svn$ echo > test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$ svn add test.txt
 * A         test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$ svn commit -m "Add new file"
 * Добавляю          test.txt
 * Передаю данные .
 * Committed revision 58.
 * bozaro@landfill:/tmp/test/git-as-svn$ svn up -r 57
 * Updating '.':
 * В редакции 57.
 * bozaro@landfill:/tmp/test/git-as-svn$ ls -l test.txt
 * -rw-rw-r-- 1 bozaro bozaro 1 авг.  15 00:50 test.txt
 * bozaro@landfill:/tmp/test/git-as-svn$
 * </pre>
 */
@Test
public void addAndUpdate() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SvnOperationFactory factory = server.createOperationFactory();
    final SVNClientManager client = SVNClientManager.newInstance(factory);
    // checkout
    final SvnCheckout checkout = factory.createCheckout();
    checkout.setSource(SvnTarget.fromURL(server.getUrl()));
    checkout.setSingleTarget(SvnTarget.fromFile(server.getTempDirectory().toFile()));
    checkout.setRevision(SVNRevision.HEAD);
    final long revision = checkout.run();
    // create file
    Path newFile = server.getTempDirectory().resolve("somefile.txt");
    TestHelper.saveFile(newFile, "Bla Bla Bla");
    // add file
    client.getWCClient().doAdd(newFile.toFile(), false, false, false, SVNDepth.INFINITY, false, true);
    // set eof property
    client.getWCClient().doSetProperty(newFile.toFile(), SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE), false, SVNDepth.INFINITY, null, null);
    // commit new file
    client.getCommitClient().doCommit(new File[]{newFile.toFile()}, false, "Add file commit", null, null, false, false, SVNDepth.INFINITY);
    // update for checkout revision
    client.getUpdateClient().doUpdate(server.getTempDirectory().toFile(), SVNRevision.create(revision), SVNDepth.INFINITY, false, false);
    // file must be remove
    Assert.assertFalse(Files.exists(newFile));
  }
}
 
Example #5
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 binary() throws Exception {
  //Map<String, String> props = new HashMap<>()["key":""];
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();

    createFile(repo, "/data.txt", "Test file", propsEolNative);
    createFile(repo, "/data.dat", "Test data\0", propsBinary);
    checkFileProp(repo, "/data.txt", propsEolNative);
    checkFileProp(repo, "/data.dat", propsBinary);
    {
      final long latestRevision = repo.getLatestRevision();
      final ISVNEditor editor = repo.getCommitEditor("Modify files", null, false, null);
      editor.openRoot(-1);

      editor.openFile("/data.txt", latestRevision);
      editor.changeFileProperty("/data.txt", SVNProperty.MIME_TYPE, SVNPropertyValue.create(SVNFileUtil.BINARY_MIME_TYPE));
      editor.changeFileProperty("/data.txt", SVNProperty.EOL_STYLE, null);
      sendDeltaAndClose(editor, "/data.txt", "Test file", "Test file\0");

      editor.openFile("/data.dat", latestRevision);
      editor.changeFileProperty("/data.dat", SVNProperty.MIME_TYPE, null);
      editor.changeFileProperty("/data.dat", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
      sendDeltaAndClose(editor, "/data.dat", "Test data\0", "Test data");

      editor.closeDir();
      editor.closeEdit();
    }
    checkFileProp(repo, "/data.txt", propsBinary);
    checkFileProp(repo, "/data.dat", propsEolNative);
  }
}
 
Example #6
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 #7
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 #8
Source File: DepthTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@NotNull
private SvnTester create(@NotNull SvnTesterFactory factory) throws Exception {
  final SvnTester tester = factory.create();

  final SVNRepository repo = tester.openSvnRepository();
  final ISVNEditor editor = repo.getCommitEditor("", null);
  editor.openRoot(-1);

  editor.changeDirProperty("svn:ignore", SVNPropertyValue.create("sample.txt"));

  editor.addFile("/.gitattributes", null, -1);
  editor.changeFileProperty("/.gitattributes", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
  sendDeltaAndClose(editor, "/.gitattributes", null, "\n");

  editor.addFile("/.gitignore", null, -1);
  editor.changeFileProperty("/.gitignore", SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
  sendDeltaAndClose(editor, "/.gitignore", null, "/sample.txt\n");

  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();

  return tester;
}
 
Example #9
Source File: ExportSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeFileProperty(String path, String name, SVNPropertyValue value) {
  properties.computeIfAbsent(paths.element(), (s) -> new TreeMap<>()).put(name, value.getString());
}
 
Example #10
Source File: SvnFilePropertyTest.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check commit .gitattributes.
 */
@Test
public void commitUpdatePropertiesSubdir() throws Exception {
  try (SvnTestServer server = SvnTestServer.createEmpty()) {
    final SVNRepository repo = server.openSvnRepository();
    {
      final ISVNEditor editor = repo.getCommitEditor("Create directory: /foo", null, false, null);
      editor.openRoot(-1);
      editor.addDir("/foo", null, -1);
      // Empty file.
      final String emptyFile = "/foo/.keep";
      editor.addFile(emptyFile, null, -1);
      editor.changeFileProperty(emptyFile, SVNProperty.EOL_STYLE, SVNPropertyValue.create(SVNProperty.EOL_STYLE_NATIVE));
      sendDeltaAndClose(editor, emptyFile, null, "");
      // Close dir
      editor.closeDir();
      editor.closeDir();
      editor.closeEdit();
    }
    createFile(repo, "/sample.txt", "", propsEolNative);
    createFile(repo, "/foo/sample.txt", "", propsEolNative);
    checkFileProp(repo, "/sample.txt", propsEolNative);
    checkFileProp(repo, "/foo/sample.txt", propsEolNative);

    createFile(repo, "/foo/.gitattributes", "*.txt\t\t\ttext eol=lf\n", propsEolNative);
    // After commit .gitattributes file sample.txt must change property svn:eol-style automagically.
    checkFileProp(repo, "/foo/sample.txt", propsEolLf);
    checkFileProp(repo, "/sample.txt", propsEolNative);
    // After commit .gitattributes directory with .gitattributes must change property svn:auto-props automagically.
    checkDirProp(repo, "/foo", propsAutoProps);
    // After commit .gitattributes file sample.txt must change property svn:eol-style automagically.
    {
      final Set<String> changed = new HashSet<>();
      repo.log(new String[]{""}, repo.getLatestRevision(), repo.getLatestRevision(), true, false, logEntry -> changed.addAll(logEntry.getChangedPaths().keySet()));
      Assert.assertTrue(changed.contains("/foo"));
      Assert.assertTrue(changed.contains("/foo/.gitattributes"));
      Assert.assertTrue(changed.contains("/foo/sample.txt"));
      Assert.assertEquals(changed.size(), 3);
    }
  }
}
 
Example #11
Source File: ExportSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeDirProperty(String name, SVNPropertyValue value) {
  properties.computeIfAbsent(paths.element(), (s) -> new TreeMap<>()).put(name, value.getString());
}
 
Example #12
Source File: SVNEditorWrapper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeFileProperty(String path, String propertyName, SVNPropertyValue propertyValue) throws SVNException {
  if (editor != null) editor.changeFileProperty(path, propertyName, propertyValue);
}
 
Example #13
Source File: SVNEditorWrapper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeDirProperty(String name, SVNPropertyValue value) throws SVNException {
  if (editor != null) editor.changeDirProperty(name, value);
}
 
Example #14
Source File: FilterSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeFileProperty(String path, String propertyName, SVNPropertyValue propertyValue) throws SVNException {
  if (!propertyName.startsWith(SVNProperty.SVN_ENTRY_PREFIX)) {
    super.changeFileProperty(path, propertyName, propertyValue);
  }
}
 
Example #15
Source File: FilterSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeDirProperty(String name, SVNPropertyValue value) throws SVNException {
  if (!name.startsWith(SVNProperty.SVN_ENTRY_PREFIX)) {
    super.changeDirProperty(name, value);
  }
}
 
Example #16
Source File: ReportSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeFileProperty(String path, String name, SVNPropertyValue value) {
  add(path, "change-file-prop: " + name + (value == null ? " (removed)" : ""));
}
 
Example #17
Source File: ReportSVNEditor.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void changeDirProperty(String name, SVNPropertyValue value) {
  add("change-dir-prop: " + name + (value == null ? " (removed)" : ""));
}
 
Example #18
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());
    }
}