Search in sources :

Example 11 with Transaction

use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.

the class SVNChangeLogServiceImpl method getChangeLogFiles.

@Override
@Transactional
public SVNChangeLogFiles getChangeLogFiles(SVNChangeLog changeLog) {
    // Revisions must have been loaded first
    if (changeLog.getRevisions() == null) {
        changeLog.withRevisions(getChangeLogRevisions(changeLog));
    }
    // In a transaction
    try (Transaction ignored = transactionService.start()) {
        // Index of files, indexed by path
        Map<String, SVNChangeLogFile> files = new TreeMap<>();
        // For each revision
        // Takes into account only the unmerged revisions
        changeLog.getRevisions().getList().stream().filter(changeLogRevision -> changeLogRevision.getLevel() == 0).forEach(changeLogRevision -> {
            long revision = changeLogRevision.getRevision();
            collectFilesForRevision(changeLog.getRepository(), files, revision);
        });
        // List of files
        return new SVNChangeLogFiles(new ArrayList<>(files.values()));
    }
}
Also used : java.util(java.util) SVNBranchConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty) SVNUtils(net.nemerosa.ontrack.extension.svn.support.SVNUtils) SVNProjectConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfiguredBuildSvnRevisionLink(net.nemerosa.ontrack.extension.svn.support.ConfiguredBuildSvnRevisionLink) StringUtils(org.apache.commons.lang3.StringUtils) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) SVNLogEntryCollector(net.nemerosa.ontrack.extension.svn.support.SVNLogEntryCollector) BuildDiffRequest(net.nemerosa.ontrack.extension.api.model.BuildDiffRequest) Transaction(net.nemerosa.ontrack.tx.Transaction) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository) Service(org.springframework.stereotype.Service) SVNBranchConfigurationPropertyType(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationPropertyType) SVNProjectConfigurationPropertyType(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationPropertyType) SCMBuildView(net.nemerosa.ontrack.extension.scm.model.SCMBuildView) IssueServiceConfigurationRepresentation(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation) Collectors(java.util.stream.Collectors) SVNClient(net.nemerosa.ontrack.extension.svn.client.SVNClient) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) Time(net.nemerosa.ontrack.common.Time) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ExportFormat(net.nemerosa.ontrack.extension.issues.export.ExportFormat) AbstractSCMChangeLogService(net.nemerosa.ontrack.extension.scm.service.AbstractSCMChangeLogService) net.nemerosa.ontrack.model.structure(net.nemerosa.ontrack.model.structure) SVNIssueRevisionDao(net.nemerosa.ontrack.extension.svn.db.SVNIssueRevisionDao) net.nemerosa.ontrack.extension.svn.model(net.nemerosa.ontrack.extension.svn.model) TransactionService(net.nemerosa.ontrack.tx.TransactionService) Transactional(org.springframework.transaction.annotation.Transactional) Transaction(net.nemerosa.ontrack.tx.Transaction) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Transaction

use of net.nemerosa.ontrack.tx.Transaction 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 13 with Transaction

use of net.nemerosa.ontrack.tx.Transaction 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 14 with Transaction

use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.

the class GitServiceImpl method getChangeLogIssues.

@Override
public GitChangeLogIssues getChangeLogIssues(GitChangeLog changeLog) {
    // Commits must have been loaded first
    if (changeLog.getCommits() == null) {
        changeLog.withCommits(getChangeLogCommits(changeLog));
    }
    // In a transaction
    try (Transaction ignored = transactionService.start()) {
        // Configuration
        GitConfiguration configuration = getRequiredProjectConfiguration(changeLog.getProject());
        // Issue service
        ConfiguredIssueService configuredIssueService = configuration.getConfiguredIssueService().orElse(null);
        if (configuredIssueService == null) {
            throw new IssueServiceNotConfiguredException();
        }
        // Index of issues, sorted by keys
        Map<String, GitChangeLogIssue> issues = new TreeMap<>();
        // For all commits in this commit log
        for (GitUICommit gitUICommit : changeLog.getCommits().getLog().getCommits()) {
            Set<String> keys = configuredIssueService.extractIssueKeysFromMessage(gitUICommit.getCommit().getFullMessage());
            for (String key : keys) {
                GitChangeLogIssue existingIssue = issues.get(key);
                if (existingIssue != null) {
                    existingIssue.add(gitUICommit);
                } else {
                    Issue issue = configuredIssueService.getIssue(key);
                    if (issue != null) {
                        existingIssue = GitChangeLogIssue.of(issue, gitUICommit);
                        issues.put(key, existingIssue);
                    }
                }
            }
        }
        // List of issues
        List<GitChangeLogIssue> issuesList = new ArrayList<>(issues.values());
        // Issues link
        IssueServiceConfigurationRepresentation issueServiceConfiguration = configuredIssueService.getIssueServiceConfigurationRepresentation();
        // OK
        return new GitChangeLogIssues(issueServiceConfiguration, issuesList);
    }
}
Also used : IssueServiceConfigurationRepresentation(net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) IssueServiceNotConfiguredException(net.nemerosa.ontrack.extension.issues.model.IssueServiceNotConfiguredException) Transaction(net.nemerosa.ontrack.tx.Transaction)

Example 15 with Transaction

use of net.nemerosa.ontrack.tx.Transaction in project ontrack by nemerosa.

the class GitServiceImpl method changeLog.

@Override
@Transactional
public GitChangeLog 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 associated projects
        Project project = buildFrom.getBranch().getProject();
        Project otherProject = buildTo.getBranch().getProject();
        // Checks the project
        if (project.id() != otherProject.id()) {
            throw new BuildDiffRequestDifferenceProjectException();
        }
        // Project Git configuration
        Optional<GitConfiguration> oProjectConfiguration = getProjectConfiguration(project);
        if (oProjectConfiguration.isPresent()) {
            // Forces Git sync before
            boolean syncError;
            GitConfiguration gitConfiguration = oProjectConfiguration.get();
            try {
                syncAndWait(gitConfiguration);
                syncError = false;
            } catch (GitRepositorySyncException ex) {
                applicationLogService.log(ApplicationLogEntry.error(ex, NameDescription.nd("git-sync", "Git synchronisation issue"), gitConfiguration.getRemote()).withDetail("project", project.getName()).withDetail("git-name", gitConfiguration.getName()).withDetail("git-remote", gitConfiguration.getRemote()));
                syncError = true;
            }
            // Change log computation
            return new GitChangeLog(UUID.randomUUID().toString(), project, getSCMBuildView(buildFrom.getId()), getSCMBuildView(buildTo.getId()), syncError);
        } else {
            throw new GitProjectNotConfiguredException(project.getId());
        }
    }
}
Also used : GitRepositorySyncException(net.nemerosa.ontrack.git.exceptions.GitRepositorySyncException) BuildDiffRequestDifferenceProjectException(net.nemerosa.ontrack.extension.api.model.BuildDiffRequestDifferenceProjectException) Transaction(net.nemerosa.ontrack.tx.Transaction) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transaction (net.nemerosa.ontrack.tx.Transaction)15 SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)7 Transactional (org.springframework.transaction.annotation.Transactional)5 ConfiguredIssueService (net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService)3 Issue (net.nemerosa.ontrack.extension.issues.model.Issue)3 IssueServiceConfigurationRepresentation (net.nemerosa.ontrack.extension.issues.model.IssueServiceConfigurationRepresentation)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 SVNBranchConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty)2 SVNProjectConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty)2 SVNLogEntryCollector (net.nemerosa.ontrack.extension.svn.support.SVNLogEntryCollector)2 TransactionService (net.nemerosa.ontrack.tx.TransactionService)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SVNLogEntry (org.tmatesoft.svn.core.SVNLogEntry)2 SVNURL (org.tmatesoft.svn.core.SVNURL)2 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)2 Sets (com.google.common.collect.Sets)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 String.format (java.lang.String.format)1