Search in sources :

Example 1 with SVNURLFormatException

use of net.nemerosa.ontrack.extension.svn.model.SVNURLFormatException in project ontrack by nemerosa.

the class SVNConfigurationServiceImpl method validate.

@Override
protected ConnectionResult validate(SVNConfiguration configuration) {
    // No trailing slash
    String url = configuration.getUrl();
    if (StringUtils.endsWith(url, "/")) {
        throw new SVNURLFormatException("The Subversion URL must not end with a slash: %s", url);
    }
    try (Transaction ignored = transactionService.start()) {
        // Creates a repository
        SVNRepository repository = SVNRepository.of(0, configuration, null);
        // Configuration URL
        SVNURL svnurl = SVNUtils.toURL(configuration.getUrl());
        // Connection to the root
        if (!svnClient.exists(repository, svnurl, SVNRevision.HEAD)) {
            return ConnectionResult.error(configuration.getUrl() + " does not exist.");
        }
        // Gets base info
        SVNInfo info = svnClient.getInfo(repository, svnurl, SVNRevision.HEAD);
        // Checks the repository root
        if (!Objects.equals(info.getRepositoryRootURL(), svnurl)) {
            return ConnectionResult.error(configuration.getUrl() + " must be the root of the repository.");
        }
        // OK
        return ConnectionResult.ok();
    } catch (Exception ex) {
        return ConnectionResult.error(ex.getMessage());
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNURLFormatException(net.nemerosa.ontrack.extension.svn.model.SVNURLFormatException) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) ConfigurationValidationException(net.nemerosa.ontrack.model.support.ConfigurationValidationException) SVNURLFormatException(net.nemerosa.ontrack.extension.svn.model.SVNURLFormatException)

Aggregations

SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)1 SVNURLFormatException (net.nemerosa.ontrack.extension.svn.model.SVNURLFormatException)1 ConfigurationValidationException (net.nemerosa.ontrack.model.support.ConfigurationValidationException)1 Transaction (net.nemerosa.ontrack.tx.Transaction)1 SVNURL (org.tmatesoft.svn.core.SVNURL)1 SVNInfo (org.tmatesoft.svn.core.wc.SVNInfo)1