org.tmatesoft.svn.core.SVNLogEntry Java Examples

The following examples show how to use org.tmatesoft.svn.core.SVNLogEntry. 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: SvnPersisterCoreImpl.java    From proctor with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the most recent log entry startRevision.
 * startRevision should not be HEAD because the path @HEAD could be deleted.
 *
 * @param path
 * @param startRevision
 * @return
 * @throws SVNException
 */
private SVNLogEntry getMostRecentLogEntry(final SVNClientManager clientManager, final String path, final SVNRevision startRevision) throws SVNException {
    final String[] targetPaths = {path};

    final SVNLogClient logClient = clientManager.getLogClient();
    final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler();

    final int limit = 1;
    // In order to get history is "descending" order, the startRevision should be the one closer to HEAD
    // The path@head could be deleted - must use 'pegRevision' to get history at a deleted path
    logClient.doLog(svnUrl, targetPaths,
                /* pegRevision */ startRevision,
                /* startRevision */ startRevision,
                /* endRevision */ SVNRevision.create(1),
                /* stopOnCopy */ false,
                /* discoverChangedPaths */ false,
                /* includeMergedRevisions */ false,
                limit,
                new String[]{SVNRevisionProperty.AUTHOR}, handler);
    if (handler.getLogEntries().isEmpty()) {
        return null;
    } else {
        return handler.getLogEntries().get(0);
    }
}
 
Example #2
Source File: SvnClient.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * Performs a search in the repository root.
 *
 */
public Map<String, String> searchCommitLog(String _str, Date _asOf) {
	final Map<String,String> hits = new HashMap<String,String>();
	try {
		// Update revision log
		this.updateCommitLog(_asOf);

		for (SVNLogEntry logEntry : this.logEntries) {
			if (logEntry.getMessage()!=null && logEntry.getMessage().contains(_str)) {
				SvnClient.log.info("Revision '" + logEntry.getRevision() + "' : " + logEntry.getMessage().trim());
				hits.put(String.valueOf(logEntry.getRevision()), logEntry.getMessage().trim());
			}
		}

	} catch (SVNException e) {
		SvnClient.log.error("Error while searching commit log: " + e.getMessage());
	}
	return hits;
}
 
Example #3
Source File: SvnClient.java    From steady with Apache License 2.0 6 votes vote down vote up
public Map<String, String> getCommitLogEntries(Set<String> _revs) {//String[] _ids) {
	final Map<String,String> hits = new HashMap<String,String>();
	try {
		// Update revision log (null indicates to retrieve all log entries as of rev. 0)
		this.updateCommitLog(null);

		String id = null;
		for (SVNLogEntry logEntry : this.logEntries) {
			id = String.valueOf(logEntry.getRevision());
			for(String sid: _revs) {
				if(!sid.equals("") && sid.equals(id)) {
					hits.put(sid, logEntry.getMessage().trim());
					continue;
				}
			}
		}
	} catch (SVNException e) {
		SvnClient.log.error("Error while searching commit log: " + e.getMessage());
	}
	return hits;
}
 
Example #4
Source File: SvnProctor.java    From proctor with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public String getLatestVersion() throws StoreException {
    return getSvnCore().doWithClientAndRepository(new SvnPersisterCore.SvnOperation<String>() {
        @Override
        public String execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception {
            final String[] targetPaths = {};
            final SVNRevision svnRevision = SVNRevision.HEAD;
            final SVNLogClient logClient = clientManager.getLogClient();
            final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler();

            // In order to get history is "descending" order, the startRevision should be the one closer to HEAD
            logClient.doLog(svnUrl, targetPaths, /* pegRevision */ SVNRevision.HEAD, svnRevision, SVNRevision.create(1),
                    /* stopOnCopy */ false, /* discoverChangedPaths */ false, /* includeMergedRevisions */ false,
                    /* limit */ 1,
                    new String[]{SVNRevisionProperty.LOG}, handler);
            final SVNLogEntry entry = handler.getLogEntries().size() > 0 ? handler.getLogEntries().get(0) : null;
            return entry == null ? "-1" : String.valueOf(entry.getRevision());
        }

        @Override
        public StoreException handleException(final Exception e) throws StoreException {
            throw new StoreException.ReadException("Unable to get latest revision", e);
        }
    });
}
 
Example #5
Source File: SubversionBranch.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public List<Commit> getCommits(long startRevision) throws CommitsNotAvailableException {
  	List<Commit> result = new ArrayList<Commit>();
  	try {
	Collection<?> col = repo.log( new String[] { "" } , null , startRevision, repo.getLatestRevision() , true , true );
	Iterator<?> colIt = col.iterator();
	while(colIt.hasNext()){
		SVNLogEntry entry = (SVNLogEntry) colIt.next();
		result.add(new SubversionCommit(entry, repo, name));
	}
} catch (SVNException e) {
	throw new CommitsNotAvailableException(e);
}
      Collections.sort(result);
      return result;
  }
 
Example #6
Source File: SvnProctor.java    From proctor with Apache License 2.0 5 votes vote down vote up
private List<Revision> getSVNLogs(final SVNClientManager clientManager,
                                  final String[] paths,
                                  final SVNRevision startRevision,
                                  final int start, final int limit) throws StoreException.ReadException {
    try {
        final SVNLogClient logClient = clientManager.getLogClient();
        final FilterableSVNLogEntryHandler handler = new FilterableSVNLogEntryHandler();

        // In order to get history is "descending" order, the startRevision should be the one closer to HEAD
        logClient.doLog(svnUrl, paths, /* pegRevision */ SVNRevision.HEAD, startRevision, SVNRevision.create(1),
                /* stopOnCopy */ false, /* discoverChangedPaths */ false, /* includeMergedRevisions */ false,
                /* limit */ start + limit,
                new String[]{SVNRevisionProperty.LOG, SVNRevisionProperty.AUTHOR, SVNRevisionProperty.DATE}, handler);

        final List<SVNLogEntry> entries = handler.getLogEntries();

        final List<Revision> revisions;
        if (entries.size() <= start) {
            revisions = Collections.emptyList();
        } else {
            final int end = Math.min(start + limit, entries.size());

            revisions = Lists.newArrayListWithCapacity(end - start);

            for (int i = 0; i < end - start; i++) {
                final SVNLogEntry entry = entries.get(start + i);
                revisions.add(new Revision(String.valueOf(entry.getRevision()), entry.getAuthor(), entry.getDate(), entry.getMessage()));
            }
        }
        return revisions;
    } catch (final SVNException e) {
        throw new StoreException.ReadException("Unable to get older revisions");
    }
}
 
Example #7
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 #8
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 #9
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 #10
Source File: SvnManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * TODO: Cache the log?
 */
@Override
public String getFirstRevision(VcsRepository repository) throws Exception {
	SVNRepository svnRepository = getSVNRepository((SvnRepository) repository);
	Collection<?> c = svnRepository.log(new String[]{""}, null, 0, Long.valueOf(getCurrentRevision(repository)), true, true);
	
	for (Object o : c) {
		return String.valueOf(((SVNLogEntry) o).getRevision());
	}
	return null;
}
 
Example #11
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 #12
Source File: SvnClient.java    From steady with Apache License 2.0 5 votes vote down vote up
private SVNLogEntry getLogEntry(String _rev) {
	SVNLogEntry e = null;
	final long rev = Long.valueOf(_rev);
	for (SVNLogEntry logEntry : this.logEntries)
		if (logEntry.getRevision() == rev) {
			e = logEntry;
			break;
		}
	return e;
}
 
Example #13
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;
	}
 
Example #14
Source File: ProgressBarReplicationHandler.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
@Override
public void revisionReplicating(SVNRepositoryReplicator source, SVNLogEntry logEntry) throws SVNException {}
 
Example #15
Source File: SvnPersisterCoreImpl.java    From proctor with Apache License 2.0 4 votes vote down vote up
@Override
public TestVersionResult determineVersions(final String fetchRevision) throws StoreException.ReadException {
    checkShutdownState();

    return doReadWithClientAndRepository(new SvnOperation<TestVersionResult>() {
        @Override
        public TestVersionResult execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception {
            final String testDefPath = testDefinitionsDirectory;
            /*
            final SVNDirEntry info = repo.info(testDefPath, 2);
            if (info == null) {
                LOGGER.warn("No test matrix found in " + testDefPath + " under " + svnPath);
                return null;
            }
            */
            final Long revision = fetchRevision.length() > 0 ? parseRevisionOrDie(fetchRevision) : Long.valueOf(-1);
            final SVNRevision svnRevision = revision.longValue() > 0 ? SVNRevision.create(revision.longValue()) : SVNRevision.HEAD;
            final SVNLogClient logClient = clientManager.getLogClient();
            final FilterableSVNDirEntryHandler handler = new FilterableSVNDirEntryHandler();
            final SVNURL url = SvnPersisterCoreImpl.this.svnUrl.appendPath(testDefPath, false);
            logClient.doList(url,
                             svnRevision,
                             svnRevision,
                             /* fetchlocks */false,
                             SVNDepth.IMMEDIATES,
                             SVNDirEntry.DIRENT_KIND | SVNDirEntry.DIRENT_CREATED_REVISION,
                             handler);


            final SVNDirEntry logEntry = handler.getParent();

            final List<TestVersionResult.Test> tests = Lists.newArrayListWithExpectedSize(handler.getChildren().size());
            for (final SVNDirEntry testDefFile : handler.getChildren()) {
                if (testDefFile.getKind() != SVNNodeKind.DIR) {
                    LOGGER.warn(String.format("svn kind (%s) is not SVNNodeKind.DIR, skipping %s", testDefFile.getKind(), testDefFile.getURL()));
                    continue;
                }
                final String testName = testDefFile.getName();
                final long testRevision;

                /*
                    When a svn directory gets copied using svn cp source-dir destination-dir, the revision
                    returned by svn list --verbose directory is different from that of svn log directory/sub-dir
                    The revision returned by svn list is the revision of the on the source-dir instead of the destination-dir
                    The code below checks to see if the directory at the provided revision exists, if it does it will use this revision.
                    If the directory does does not exist, try and identify the correct revision using svn log.
                 */
                final SVNLogEntry log = getMostRecentLogEntry(clientManager, testDefPath + "/" + testDefFile.getRelativePath(), svnRevision);
                if (log != null && log.getRevision() != testDefFile.getRevision()) {
                    // The difference in the log.revision and the list.revision can occur during an ( svn cp )
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("svn log r" + log.getRevision() + " is different than svn list r" + testDefFile.getRevision() + " for " + testDefFile.getURL());
                    }
                    testRevision = log.getRevision();
                } else {
                    testRevision = testDefFile.getRevision();
                }

                tests.add(new TestVersionResult.Test(testName, String.valueOf(testRevision)));
            }

            final String matrixRevision = String.valueOf(logEntry.getRevision());
            return new TestVersionResult(
                tests,
                logEntry.getDate(),
                logEntry.getAuthor(),
                matrixRevision,
                logEntry.getCommitMessage()
            );
        }

        @Override
        public StoreException handleException(final Exception e) throws StoreException {
            throw new StoreException.ReadException("Unable to read from SVN", e);
        }
    });
}
 
Example #16
Source File: SubversionCommit.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
public SubversionCommit(SVNLogEntry entry, SVNRepository repo, String fromBranch) {
	this.entry = entry;
	this.repo = repo;
	this.fromBranch = fromBranch;
}
 
Example #17
Source File: FilterableSVNLogEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
FilterableSVNLogEntryHandler() {
    this(Predicates.<SVNLogEntry>alwaysTrue());
}
 
Example #18
Source File: FilterableSVNLogEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
private FilterableSVNLogEntryHandler(final Predicate<SVNLogEntry> logentryFilter) {
    this.logentryFilter = logentryFilter;
}
 
Example #19
Source File: FilterableSVNLogEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLogEntry(SVNLogEntry entry) throws SVNException {
    if (logentryFilter.apply(entry)) {
        logEntries.add(entry);
    }
}
 
Example #20
Source File: FilterableSVNLogEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
public List<SVNLogEntry> getLogEntries() {
    return logEntries;
}
 
Example #21
Source File: MCRMetadataVersion.java    From mycore with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new metadata version info object
 * 
 * @param vm
 *            the metadata document this version belongs to
 * @param logEntry
 *            the log entry from SVN holding data on this version
 * @param type
 *            the type of commit
 */
MCRMetadataVersion(MCRVersionedMetadata vm, SVNLogEntry logEntry, char type) {
    this.vm = vm;
    revision = logEntry.getRevision();
    user = logEntry.getAuthor();
    date = logEntry.getDate();
    this.type = Type.fromValue(type);
}