Search in sources :

Example 11 with SVNRepository

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

the class SVNChangeLogServiceImpl method changeLog.

@Override
@Transactional
public SVNChangeLog changeLog(BuildDiffRequest request) {
    try (Transaction ignored = transactionService.start()) {
        // Gets the two builds
        Build buildFrom = structureService.getBuild(request.getFrom());
        Build buildTo = structureService.getBuild(request.getTo());
        // Ordering of builds
        if (buildFrom.id() > buildTo.id()) {
            Build t = buildFrom;
            buildFrom = buildTo;
            buildTo = t;
        }
        // Gets the two branches, for each build
        Branch branchFrom = buildFrom.getBranch();
        Branch branchTo = buildTo.getBranch();
        // Checks the branch is the same
        if (branchFrom.id() != branchTo.id()) {
            throw new SVNChangeLogDifferentBranchException();
        }
        SVNRepository svnRepository = getSVNRepository(branchFrom);
        return new SVNChangeLog(UUID.randomUUID().toString(), branchFrom.getProject(), svnRepository, getSCMBuildView(svnRepository, buildFrom.getId()), getSCMBuildView(svnRepository, buildTo.getId()));
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with SVNRepository

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

the class BuildSVNInformationExtension method getInformation.

@Override
public Optional<EntityInformation> getInformation(ProjectEntity entity) {
    if (entity instanceof Build) {
        Build build = (Build) entity;
        // Gets the branch SVN information
        Property<SVNBranchConfigurationProperty> branchConfigurationProperty = propertyService.getProperty(build.getBranch(), SVNBranchConfigurationPropertyType.class);
        Property<SVNProjectConfigurationProperty> projectConfigurationProperty = propertyService.getProperty(build.getBranch().getProject(), SVNProjectConfigurationPropertyType.class);
        if (branchConfigurationProperty.isEmpty() || projectConfigurationProperty.isEmpty()) {
            return Optional.empty();
        } else {
            // Loads the repository
            SVNRepository repository = svnService.getRepository(projectConfigurationProperty.getValue().getConfiguration().getName());
            // Gets the build history
            try (Transaction ignored = transactionService.start()) {
                return Optional.of(new EntityInformation(this, svnChangeLogService.getBuildSVNHistory(repository, build)));
            }
        }
    } else {
        return Optional.empty();
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction) SVNProjectConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty) Build(net.nemerosa.ontrack.model.structure.Build) SVNBranchConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository)

Example 13 with SVNRepository

use of net.nemerosa.ontrack.extension.svn.db.SVNRepository 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)

Example 14 with SVNRepository

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

the class AbstractTagBasedSvnRevisionLink method extractBuildName.

protected Optional<String> extractBuildName(T data, String path, Branch branch, SVNBranchConfigurationProperty branchConfigurationProperty) {
    // Repository for the branch
    SVNRepository svnRepository = svnService.getRequiredSVNRepository(branch);
    // Gets the base path
    Optional<String> oBasePath = svnService.getBasePath(svnRepository, branchConfigurationProperty.getCuredBranchPath());
    if (!oBasePath.isPresent()) {
        return Optional.empty();
    }
    String basePath = oBasePath.get();
    // Tag base path
    String tagsBasePath = basePath + "/tags/";
    // Starting correctly
    if (StringUtils.startsWith(path, tagsBasePath)) {
        // Gets the tag part
        String token = StringUtils.substringAfter(path, tagsBasePath);
        // In case of /
        String tagName = StringUtils.substringBefore(token, "/");
        // Extracts the build name from the tag name
        return getBuildName(data, tagName);
    } else // Not a tag
    {
        return Optional.empty();
    }
}
Also used : SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository)

Aggregations

SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)14 Transaction (net.nemerosa.ontrack.tx.Transaction)6 ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)3 SCMBuildView (net.nemerosa.ontrack.extension.scm.model.SCMBuildView)3 Test (org.junit.Test)3 Transactional (org.springframework.transaction.annotation.Transactional)3 TCopyEvent (net.nemerosa.ontrack.extension.svn.db.TCopyEvent)2 SVNBranchConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty)2 SVNProjectConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty)2 SVNURL (org.tmatesoft.svn.core.SVNURL)2 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 EntityInformation (net.nemerosa.ontrack.extension.api.model.EntityInformation)1 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)1 IssueServiceConfigurationRepresentation (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation)1 SCMIssueCommitBranchInfo (net.nemerosa.ontrack.extension.scm.model.SCMIssueCommitBranchInfo)1 SCMUtilsService (net.nemerosa.ontrack.extension.scm.service.SCMUtilsService)1 SVNIssueRevisionDao (net.nemerosa.ontrack.extension.svn.db.SVNIssueRevisionDao)1