Java Code Examples for org.tmatesoft.svn.core.SVNLogEntryPath#getType()

The following examples show how to use org.tmatesoft.svn.core.SVNLogEntryPath#getType() . 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: SvnClient.java    From steady with Apache License 2.0 5 votes vote down vote up
public Set<FileChange> getFileChanges(String _rev) {
	final Set<FileChange> changes = new HashSet<FileChange>();
	try {
		// Update revision log (using this.asOf as argument will result in an actual SVN call only if it has not been done before)
		this.updateCommitLog(this.asOf);

		// Determine prev. revision
		final long l = Long.valueOf(_rev).longValue()-1;
		final String prev_rev = new Long(l).toString();

		// Get changed paths for revision
		SVNLogEntry entry = this.getLogEntry(_rev);
		final Map<String, SVNLogEntryPath> changedPaths = entry.getChangedPaths();

		// Loop all changed path and the check the corresponding files out
		SVNLogEntryPath entryPath = null;
		String rel_path = null;
		File oldf = null, newf = null;
		for (Map.Entry<String, SVNLogEntryPath> p : changedPaths.entrySet()) {
			entryPath = p.getValue();
			rel_path = p.getKey();

			// Checkout file(s), depending on the modification type
			switch(entryPath.getType()) {
			case 'M': oldf = this.checkoutFile(prev_rev, rel_path); newf = this.checkoutFile(_rev, rel_path); break;
			case 'A': oldf = null; newf = this.checkoutFile(_rev, rel_path); break;
			case 'D': oldf = this.checkoutFile(prev_rev, rel_path); newf = null; break;
			default:  oldf = null; newf = null; break;
			}

			// If one of them exists and is not a directory, create a new FileChange
			if( (oldf!=null && !oldf.isDirectory()) || (newf!=null && !newf.isDirectory()) )
				changes.add(new FileChange(this.rootRepo.getLocation().toString(), rel_path, oldf, newf));
		}
	} catch (Exception e) {
		SvnClient.log.error("Error while getting file changes: " + e.getMessage());
	}
	return changes;
}
 
Example 2
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Lists all versions of this metadata object available in the subversion
 * repository
 *
 * @return all stored versions of this metadata object
 */
@SuppressWarnings("unchecked")
public List<MCRMetadataVersion> listVersions() throws IOException {
    try {
        List<MCRMetadataVersion> versions = new ArrayList<>();
        SVNRepository repository = getStore().getRepository();
        String path = getFilePath();
        String dir = getDirectory();

        Collection<SVNLogEntry> entries = null;
        try {
            entries = repository.log(new String[] { dir }, null, 0, repository.getLatestRevision(), true, true);
        } catch (Exception ioex) {
            LOGGER.error("Could not get versions", ioex);
            return versions;
        }

        for (SVNLogEntry entry : entries) {
            SVNLogEntryPath svnLogEntryPath = entry.getChangedPaths().get(path);
            if (svnLogEntryPath != null) {
                char type = svnLogEntryPath.getType();
                versions.add(new MCRMetadataVersion(this, entry, type));
            }
        }
        return versions;
    } catch (SVNException svnExc) {
        throw new IOException(svnExc);
    }
}
 
Example 3
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
public MCRMetadataVersion getRevision(long revision) throws IOException {
    try {
        if (revision < 0) {
            revision = getLastPresentRevision();
            if (revision < 0) {
                LOGGER.warn("Metadata object {} in store {} has no last revision!", getID(), getStore().getID());
                return null;
            }
        }
        SVNRepository repository = getStore().getRepository();
        String path = getFilePath();
        String dir = getDirectory();
        @SuppressWarnings("unchecked")
        Collection<SVNLogEntry> log = repository.log(new String[] { dir }, null, revision, revision, true, true);
        for (SVNLogEntry logEntry : log) {
            SVNLogEntryPath svnLogEntryPath = logEntry.getChangedPaths().get(path);
            if (svnLogEntryPath != null) {
                char type = svnLogEntryPath.getType();
                return new MCRMetadataVersion(this, logEntry, type);
            }
        }
        LOGGER.warn("Metadata object {} in store {} has no revision ''{}''!", getID(), getStore().getID(),
            getRevision());
        return null;
    } catch (SVNException svnExc) {
        throw new IOException(svnExc);
    }
}
 
Example 4
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
    SVNLogEntryPath svnLogEntryPath = logEntry.getChangedPaths().get(path);
    if (svnLogEntryPath != null) {
        char type = svnLogEntryPath.getType();
        if (deleted || type != SVNLogEntryPath.TYPE_DELETED) {
            lastRevision = logEntry.getRevision();
            //no other way to stop svnkit from logging
            throw new LastRevisionFoundException();
        }
    }
}
 
Example 5
Source File: SvnManager.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
	public VcsRepositoryDelta getDelta(VcsRepository repository, String startRevision, String endRevision) throws Exception {
		SvnRepository _svnRepository = (SvnRepository) repository;
		SVNRepository svnRepository = getSVNRepository(_svnRepository);

		VcsRepositoryDelta delta = new VcsRepositoryDelta();
		delta.setRepository(repository);
		
		String userProviderURL = _svnRepository.getUrl();
		String rootURL = svnRepository.getRepositoryRoot(false).toDecodedString();
		
		String overLappedURL = makeRelative(rootURL, userProviderURL);
		if (!overLappedURL.startsWith("/")) {
			overLappedURL = "/" + overLappedURL;
		}
		
//		if (!startRevision.equals(endRevision)) {
			Collection<?> c = svnRepository.log(new String[]{""}, null, Long.valueOf(startRevision), Long.valueOf(endRevision), true, true);

			for (Object o : c) {
				SVNLogEntry svnLogEntry = (SVNLogEntry) o;

				VcsCommit commit = new VcsCommit();
				
				commit.setAuthor(svnLogEntry.getAuthor());
				commit.setAuthorEmail(svnLogEntry.getAuthor());
				commit.setMessage(svnLogEntry.getMessage());
				commit.setRevision(svnLogEntry.getRevision() + "");
				commit.setDelta(delta);
				commit.setJavaDate(svnLogEntry.getDate());
				delta.getCommits().add(commit);
				
				Map<String, SVNLogEntryPath> changedPaths = svnLogEntry.getChangedPaths();
				for (String path : changedPaths.keySet()) {
					SVNLogEntryPath svnLogEntryPath = changedPaths.get(path);

//					String[] exts = {".cxx",".h",".hxx",".cpp",".cpp",".html"};
					
//					System.err.println(path);
//					if (svnLogEntryPath.getKind() == SVNNodeKind.FILE) {
						String[] blacklist = {".png",".jpg",".bmp",".zip",".jar",".gz",".tar"};
						
						if (path.lastIndexOf(".") <= 0) continue;
						String ext = path.substring(path.lastIndexOf("."), path.length());
//						System.err.println(ext + " in " + blacklist + " == " + !Arrays.asList(blacklist).contains(ext));
						if (!Arrays.asList(blacklist).contains(ext)){
						
							VcsCommitItem commitItem = new VcsCommitItem();
							commit.getItems().add(commitItem);
							commitItem.setCommit(commit);
							
							String relativePath = makeRelative(overLappedURL, path);
							if (!relativePath.startsWith("/")) {
								relativePath = "/" + relativePath;
							}
							commitItem.setPath(relativePath);
							
							if (svnLogEntryPath.getType() == 'A') {
								commitItem.setChangeType(VcsChangeType.ADDED);
							} else if (svnLogEntryPath.getType() == 'M') {
								commitItem.setChangeType(VcsChangeType.UPDATED);
							} else if (svnLogEntryPath.getType() == 'D') {
								commitItem.setChangeType(VcsChangeType.DELETED);
							} else if (svnLogEntryPath.getType() == 'R') {
								commitItem.setChangeType(VcsChangeType.REPLACED);
							} else {
								System.err.println("Found unrecognised svn log entry type: " + svnLogEntryPath.getType());
								commitItem.setChangeType(VcsChangeType.UNKNOWN);
							}
						}
//					}
				}
			}
//		}

		return delta;
	}