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

The following examples show how to use org.tmatesoft.svn.core.io.SVNRepository#getFile() . 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: SvnManager.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
	public String getContents(VcsCommitItem item) throws Exception {
		
		SVNRepository repository = getSVNRepository((SvnRepository) item.getCommit().getDelta().getRepository());
		
		SVNProperties fileProperties = new SVNProperties();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		
		repository.getFile(item.getPath(), Long.valueOf(item.getCommit().getRevision()), fileProperties, baos);
        
		//TODO: Store mimetype?
		//TODO: Think about adding a notion of a filter
//		String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
     
//		System.err.println("File being read from SVN: " + item.getPath());
		
        StringBuffer sb = new StringBuffer();
		BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
		String line;
		while((line =reader.readLine())!= null ){
			//TODO: Think about a platform-wide new line character
			sb.append(line + "\r\n");
		}
		return sb.toString();
	}
 
Example 2
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 3
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the version stored in the local filesystem to the latest version
 * from Subversion repository HEAD.
 */
public void update() throws Exception {
    SVNRepository repository = getStore().getRepository();
    MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream();
    long rev = repository.getFile(getFilePath(), -1, null, baos);
    revision = () -> Optional.of(rev);
    baos.close();
    new MCRByteContent(baos.getBuffer(), 0, baos.size(), this.getLastModified().getTime()).sendTo(path);
}
 
Example 4
Source File: SvnTestHelper.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
public static void modifyFile(@NotNull SVNRepository repo, @NotNull String filePath, @NotNull byte[] newData, long fileRev, @Nullable Map<String, String> locks) throws SVNException, IOException {
  final ByteArrayOutputStream oldData = new ByteArrayOutputStream();
  repo.getFile(filePath, fileRev, null, oldData);

  final ISVNEditor editor = repo.getCommitEditor("Modify file: " + filePath, locks, false, null);
  try {
    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.openFile(filePath, fileRev);
    sendDeltaAndClose(editor, filePath, oldData.toByteArray(), newData);
    for (int i = 0; i < depth; ++i) {
      editor.closeDir();
    }
    Assert.assertNotEquals(editor.closeEdit(), SVNCommitInfo.NULL);
  } finally {
    editor.abortEdit();
  }
}
 
Example 5
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 6
Source File: SvnTestHelper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
public static void checkFileProp(@NotNull SVNRepository repo, @NotNull String filePath, @Nullable Map<String, String> expected) throws SVNException {
  SVNProperties props = new SVNProperties();
  repo.getFile(filePath, repo.getLatestRevision(), props, null);
  checkProp(props, expected);
}