use of org.jboss.pnc.model.ProductMilestone in project pnc by project-ncl.
the class BuildTasksInitializer method fillBuildTaskSet.
/**
* Creates build tasks and sets up the appropriate dependency relations
*
* @param buildSetTask The build set task which will contain the build tasks. This must already have initialized the
* BuildConfigSet, BuildConfigSetRecord, Milestone, etc.
*/
private void fillBuildTaskSet(BuildSetTask buildSetTask, User user, Supplier<String> buildTaskIdProvider, ProductMilestone productMilestone, Set<BuildConfigurationAudited> toBuild, Set<BuildTask> alreadySubmittedBuildTasks, BuildOptions buildOptions) {
for (BuildConfigurationAudited buildConfigAudited : toBuild) {
Optional<BuildTask> taskOptional = alreadySubmittedBuildTasks.stream().filter(bt -> bt.getBuildConfigurationAudited().equals(buildConfigAudited)).findAny();
BuildTask buildTask;
if (taskOptional.isPresent()) {
buildTask = taskOptional.get();
log.debug("Linking BuildConfigurationAudited {} to existing task {}.", buildConfigAudited, buildTask);
} else {
String buildId = buildTaskIdProvider.get();
String buildContentId = ContentIdentityManager.getBuildContentId(buildId);
// Used only for this operation inside the loop
MDCUtils.addBuildContext(buildContentId, buildOptions.isTemporaryBuild(), ExpiresDate.getTemporaryBuildExpireDate(temporaryBuildLifespanDays, buildOptions.isTemporaryBuild()), user.getId().toString());
try {
Optional<String> requestContext = MDCUtils.getRequestContext();
buildTask = BuildTask.build(buildConfigAudited, buildSetTask.getBuildOptions(), user, buildId, buildSetTask, buildSetTask.getStartTime(), productMilestone, buildContentId, requestContext);
log.debug("Created new buildTask {} for BuildConfigurationAudited {}.", buildTask, buildConfigAudited);
} finally {
MDCUtils.removeBuildContext();
}
}
buildSetTask.addBuildTask(buildTask);
}
// Loop again to set dependencies
for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
for (BuildTask checkDepBuildTask : buildSetTask.getBuildTasks()) {
if (buildTask.hasDirectConfigDependencyOn(checkDepBuildTask)) {
buildTask.addDependency(checkDepBuildTask);
}
}
}
}
use of org.jboss.pnc.model.ProductMilestone in project pnc by project-ncl.
the class BuildTask method build.
public static BuildTask build(BuildConfigurationAudited buildConfigurationAudited, BuildOptions buildOptions, User user, String buildTaskId, BuildSetTask buildSetTask, Date submitTime, ProductMilestone productMilestone, String contentId, Optional<String> requestContext) {
Integer buildConfigSetRecordId = null;
if (buildSetTask != null) {
buildConfigSetRecordId = buildSetTask.getBuildConfigSetRecord().map(BuildConfigSetRecord::getId).orElse(null);
}
ProductMilestone milestone = productMilestone;
if (milestone != null && milestone.getEndDate() != null) {
userLog.warn("Not using current milestone {} for build task {}, because the milestone is closed.", productMilestone, buildTaskId);
milestone = null;
}
return new BuildTask(buildConfigurationAudited, buildOptions, user, submitTime, buildSetTask, buildTaskId, buildConfigSetRecordId, milestone, contentId, requestContext);
}
use of org.jboss.pnc.model.ProductMilestone in project pnc by project-ncl.
the class ProductVersionProviderImpl method validateMilestone.
private void validateMilestone(Integer id, ProductVersion entity) {
if (entity.getCurrentProductMilestone() != null) {
Integer newMilestoneId = milestoneMapper.getIdMapper().toEntity(entity.getCurrentProductMilestone().getId());
org.jboss.pnc.model.ProductVersion productVersion = repository.queryById(id);
ProductMilestone currentMilestone = productVersion.getCurrentProductMilestone();
if (currentMilestone == null || currentMilestone.getId() != newMilestoneId) {
ProductMilestone newMilestone = milestoneRepository.queryById(newMilestoneId);
if (newMilestone == null) {
throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " does not exist.");
} else if (newMilestone.getEndDate() != null) {
throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " is closed, so cannot be set as current.");
}
}
}
}
use of org.jboss.pnc.model.ProductMilestone in project pnc by project-ncl.
the class ProductMilestoneProviderTest method testCancelMilestoneCloseProcessShouldFailIfAlreadyClosed.
@Test
public void testCancelMilestoneCloseProcessShouldFailIfAlreadyClosed() {
// given
ProductMilestone closed = ProductMilestoneFactory.getInstance().createNewProductMilestoneFromProductVersion(mock.getProductVersion(), "9.8.7.GA");
closed.setEndDate(new Date());
repositoryList.add(closed);
// when then
assertThatThrownBy(() -> provider.cancelMilestoneCloseProcess(closed.getId().toString())).isInstanceOf(RepositoryViolationException.class);
}
use of org.jboss.pnc.model.ProductMilestone in project pnc by project-ncl.
the class DeliverableAnalyzerManagerImpl method processDeliverables.
private void processDeliverables(int milestoneId, Collection<Build> builds, String distributionUrl) {
ProductMilestone milestone = milestoneRepository.queryById(milestoneId);
for (Build build : builds) {
Function<Artifact, org.jboss.pnc.model.Artifact> artifactParser;
if (build.getBuildSystemType() == null) {
TargetRepository distributionRepository = getDistributionRepository(distributionUrl);
artifactParser = art -> findOrCreateArtifact(art, distributionRepository);
} else {
switch(build.getBuildSystemType()) {
case PNC:
artifactParser = this::getPncArtifact;
break;
case BREW:
TargetRepository brewRepository = getBrewRepository(build);
artifactParser = art -> findOrCreateArtifact(assertBrewArtifacts(art), brewRepository);
break;
default:
throw new UnsupportedOperationException("Unknown build system type " + build.getBuildSystemType());
}
}
build.getArtifacts().stream().map(artifactParser).forEach(milestone::addDeliveredArtifact);
}
milestone.setDeliveredArtifactsImporter(userService.currentUser());
}
Aggregations