Search in sources :

Example 1 with SVNAdminClient

use of org.tmatesoft.svn.core.wc.admin.SVNAdminClient in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStore method verify.

/**
 * Checks to local SVN repository for errors
 * @throws MCRPersistenceException if 'svn verify' fails
 */
public void verify() throws MCRPersistenceException {
    String replURLStr = repURL.toString();
    if (!repURL.getProtocol().equals("file")) {
        LOGGER.warn("Cannot verify non local SVN repository '{}'.", replURLStr);
        return;
    }
    try {
        SVNRepository repository = getRepository();
        long latestRevision = repository.getLatestRevision();
        if (latestRevision == 0) {
            LOGGER.warn("Cannot verify SVN repository '{}' with no revisions.", replURLStr);
        }
        ISVNAuthenticationManager authenticationManager = repository.getAuthenticationManager();
        SVNAdminClient adminClient = new SVNAdminClient(authenticationManager, null);
        File repositoryRoot = new File(URI.create(replURLStr));
        adminClient.setEventHandler(new ISVNAdminEventHandler() {

            // if more than batchSize revisions print progress
            int batchSize = 100;

            @Override
            public void checkCancelled() throws SVNCancelException {
            }

            @Override
            public void handleEvent(SVNEvent event, double progress) throws SVNException {
            }

            @Override
            public void handleAdminEvent(SVNAdminEvent event, double progress) throws SVNException {
                if (event.getMessage() != null) {
                    if (event.getRevision() % batchSize != 0 || event.getRevision() == 0) {
                        LOGGER.debug(event::getMessage);
                    } else {
                        LOGGER.info("{} ({}% done)", event.getMessage(), (int) (event.getRevision() * 100.0 / latestRevision));
                    }
                }
            }
        });
        adminClient.doVerify(repositoryRoot);
        LOGGER.info("Verified SVN repository '{}'.", replURLStr);
    } catch (Exception e) {
        throw new MCRPersistenceException("SVN repository contains errors and could not be verified: " + replURLStr, e);
    }
}
Also used : ISVNAuthenticationManager(org.tmatesoft.svn.core.auth.ISVNAuthenticationManager) SVNAdminEvent(org.tmatesoft.svn.core.wc.admin.SVNAdminEvent) SVNException(org.tmatesoft.svn.core.SVNException) URISyntaxException(java.net.URISyntaxException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) JDOMException(org.jdom2.JDOMException) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNException(org.tmatesoft.svn.core.SVNException) MCRPersistenceException(org.mycore.common.MCRPersistenceException) IOException(java.io.IOException) ISVNAdminEventHandler(org.tmatesoft.svn.core.wc.admin.ISVNAdminEventHandler) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNEvent(org.tmatesoft.svn.core.wc.SVNEvent) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository) SVNAdminClient(org.tmatesoft.svn.core.wc.admin.SVNAdminClient) File(java.io.File) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 JDOMException (org.jdom2.JDOMException)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)1 SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)1 SVNException (org.tmatesoft.svn.core.SVNException)1 ISVNAuthenticationManager (org.tmatesoft.svn.core.auth.ISVNAuthenticationManager)1 SVNRepository (org.tmatesoft.svn.core.io.SVNRepository)1 SVNEvent (org.tmatesoft.svn.core.wc.SVNEvent)1 ISVNAdminEventHandler (org.tmatesoft.svn.core.wc.admin.ISVNAdminEventHandler)1 SVNAdminClient (org.tmatesoft.svn.core.wc.admin.SVNAdminClient)1 SVNAdminEvent (org.tmatesoft.svn.core.wc.admin.SVNAdminEvent)1