Search in sources :

Example 1 with TCopyEvent

use of net.nemerosa.ontrack.extension.svn.db.TCopyEvent in project ontrack by nemerosa.

the class SVNSyncServiceImpl method sync.

protected void sync(Branch branch, JobRunListener runListener) {
    // Number of created builds
    AtomicInteger createdBuilds = new AtomicInteger();
    // Gets the configuration property
    SVNSyncProperty syncProperty = propertyService.getProperty(branch, SVNSyncPropertyType.class).getValue();
    // Gets the project configurations for SVN
    SVNProjectConfigurationProperty projectConfigurationProperty = propertyService.getProperty(branch.getProject(), SVNProjectConfigurationPropertyType.class).getValue();
    // Gets the branch configurations for SVN
    SVNBranchConfigurationProperty branchConfigurationProperty = propertyService.getProperty(branch, SVNBranchConfigurationPropertyType.class).getValue();
    // SVN repository configuration
    SVNRepository repository = svnService.getRepository(projectConfigurationProperty.getConfiguration().getName());
    // Link
    ConfiguredBuildSvnRevisionLink<?> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink(branchConfigurationProperty.getBuildRevisionLink());
    // Gets the base path
    svnService.getBasePath(repository, branchConfigurationProperty.getCuredBranchPath()).ifPresent(basePath -> {
        // Tags path
        String tagsPath = basePath + "/tags";
        // Gets the list of tags from the copy events, filtering them
        List<TCopyEvent> copies = eventDao.findCopies(// In this repository
        repository.getId(), // from path...
        branchConfigurationProperty.getCuredBranchPath(), // to path with prefix...
        tagsPath, // filter the target path with...
        (copyEvent) -> getBuildNameFromPath(tagsPath, revisionLink, copyEvent.copyToLocation()).isPresent());
        // Creates the builds (in a transaction)
        for (TCopyEvent copy : copies) {
            Optional<Build> build = transactionTemplate.execute(status -> createBuild(tagsPath, syncProperty, branch, copy, revisionLink, repository));
            // Completes the information collection (build created)
            if (build.isPresent()) {
                int count = createdBuilds.incrementAndGet();
                runListener.message("Running build synchronisation from SVN for branch %s/%s: %d build(s) created", branch.getProject().getName(), branch.getName(), count);
            }
        }
    });
}
Also used : TCopyEvent(net.nemerosa.ontrack.extension.svn.db.TCopyEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository)

Example 2 with TCopyEvent

use of net.nemerosa.ontrack.extension.svn.db.TCopyEvent in project ontrack by nemerosa.

the class AbstractTagBasedSvnRevisionLink method getRevision.

@Override
public OptionalLong getRevision(T data, Build build, SVNBranchConfigurationProperty branchConfigurationProperty) {
    // Gets the tag path
    Optional<String> oTagPath = getTagPath(data, build, branchConfigurationProperty);
    // If present
    if (oTagPath.isPresent()) {
        String tagPath = oTagPath.get();
        SVNRepository svnRepository = svnService.getRequiredSVNRepository(build.getBranch());
        // Gets the copy event for this build
        TCopyEvent lastCopyEvent = svnService.getLastCopyEvent(svnRepository.getId(), tagPath, Long.MAX_VALUE);
        // Gets the revision
        return lastCopyEvent != null ? OptionalLong.of(lastCopyEvent.getCopyFromRevision()) : OptionalLong.empty();
    } else {
        return OptionalLong.empty();
    }
}
Also used : SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) TCopyEvent(net.nemerosa.ontrack.extension.svn.db.TCopyEvent)

Aggregations

SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)2 TCopyEvent (net.nemerosa.ontrack.extension.svn.db.TCopyEvent)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1