@Override public Project getProject() { return getBranch().getProject(); }
@Override public List<PromotionRun> getLastPromotionRunsForBuild(Build build) { // Branch Branch branch = build.getBranch(); // Promotion levels for the branch List<PromotionLevel> promotionLevels = getPromotionLevelListForBranch(branch.getId()); // Gets the last promotion run for each promotion level return promotionLevels.stream() .map(promotionLevel -> getLastPromotionRun(build, promotionLevel)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); }
/** * A SVN change log works always on the same branch. */ @JsonIgnore public Branch getBranch() { return getFrom().getBuild().getBranch(); } }
protected void validateIssues(List<I> issuesList, SCMChangeLog<T> changeLog) { // Same branch only if (changeLog.isSameBranch()) { // Gets the branch Branch branch = changeLog.getFrom().getBuild().getBranch(); // Gets the list of validators for this branch List<Property<?>> properties = propertyService.getProperties(branch).stream() .filter(property -> !property.isEmpty() && property.getType() instanceof SCMChangeLogIssueValidator) .collect(Collectors.toList()); // Validates each issues issuesList.forEach(issue -> validateIssue(issue, properties, changeLog)); } }
public ValidationRun doValidateBuild(Build build, String vsName, ValidationRunStatusID statusId) throws Exception { ValidationStamp vs = doCreateValidationStamp(build.getBranch(), NameDescription.nd(vsName, "")); return doValidateBuild(build, vs, statusId); }
protected Optional<String> getTagPath(T data, Build build, SVNBranchConfigurationProperty branchConfigurationProperty) { // Gets the tag name return getTagName(data, build.getName()) .flatMap(tagName -> { // Repository for the branch SVNRepository svnRepository = svnService.getRequiredSVNRepository(build.getBranch()); // Gets the tag path return svnService.getTagPathForTagName(svnRepository, branchConfigurationProperty.getCuredBranchPath(), tagName); }); }
public EventBuilder withBuild(Build build) { return withBranch(build.getBranch()).with(build).with(build.getSignature()); }
@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(); } }
@Override public List<LinkDefinition<Build>> getLinkDefinitions() { return Arrays.asList( LinkDefinitions.link( "_changeLog", build -> { BuildDiffRequest request = new BuildDiffRequest(); request.setFrom(build.getId()); return MvcUriComponentsBuilder.on(SVNController.class).changeLog(request); }, (build, rc) -> rc.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent() ), LinkDefinitions.page( "_changeLogPage", (build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent(), "extension/svn/changelog" ) ); }
protected String getSVNBuildPath(Build build) { // Gets the build path property value Property<SVNBranchConfigurationProperty> branchConfiguration = propertyService.getProperty( build.getBranch(), SVNBranchConfigurationPropertyType.class ); if (branchConfiguration.isEmpty()) { throw new MissingSVNBranchConfigurationException(build.getBranch().getName()); } else { // Gets the build revision link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink( branchConfiguration.getValue().getBuildRevisionLink() ); // Gets the path to the build return revisionLink.getBuildPath(build, branchConfiguration.getValue()); } }
@Override public void validateBuild(Build build) throws BuildValidationException { propertyService.getProperty(build.getBranch(), SVNBranchConfigurationPropertyType.class).option().ifPresent(property -> { // Gets the configured link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink(property.getBuildRevisionLink()); // Tests the validity of the build name if (!revisionLink.isValidBuildName(build.getName())) { throw new BuildValidationException( String.format( "Build %s does not comply with the SVN configuration", build.getName() ) ); } }); } }
@Override public Optional<Build> getPreviousBuild(Build build) { return getOptional( "SELECT * FROM BUILDS WHERE BRANCHID = :branch AND ID < :id ORDER BY ID DESC LIMIT 1", params("branch", build.getBranch().id()).addValue("id", build.id()), (rs, rowNum) -> toBuild(rs, this::getBranch) ); }
@Override public Optional<Build> getNextBuild(Build build) { return getOptional( "SELECT * FROM BUILDS WHERE BRANCHID = :branch AND ID > :id ORDER BY ID ASC LIMIT 1", params("branch", build.getBranch().id()).addValue("id", build.id()), (rs, rowNum) -> toBuild(rs, this::getBranch) ); }
@Override public OptionalLong getBuildRevision(Build build) { // 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 OptionalLong.empty(); } else { // Gets the branch revision link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink( branchConfigurationProperty.getValue().getBuildRevisionLink() ); // Returns revision information return revisionLink.getRevision(build, branchConfigurationProperty.getValue()); } }
@Override public Event deletePromotionRun(PromotionRun promotionRun) { return Event.of(DELETE_PROMOTION_RUN) .withBranch(promotionRun.getBuild().getBranch()) .with(promotionRun.getBuild()) .with(promotionRun.getPromotionLevel()) .get(); }
@Override public Event deleteBuild(Build build) { return Event.of(DELETE_BUILD) .withBranch(build.getBranch()) .with("build", build.getName()) .with("build_id", build.getId().toString()) .get(); }
@Override public Build newBuild(Build build) { // Creation try { int id = dbCreate( "INSERT INTO BUILDS(BRANCHID, NAME, DESCRIPTION, CREATION, CREATOR) VALUES (:branchId, :name, :description, :creation, :creator)", params("name", build.getName()) .addValue("description", build.getDescription()) .addValue("branchId", build.getBranch().id()) .addValue("creation", dateTimeForDB(build.getSignature().getTime())) .addValue("creator", build.getSignature().getUser().getName()) ); return build.withId(id(id)); } catch (DuplicateKeyException ex) { throw new BuildNameAlreadyDefinedException(build.getName()); } }