use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigurationAuditedRepositoryImpl method searchIdRevForBuildConfigurationName.
@Override
public List<IdRev> searchIdRevForBuildConfigurationName(String buildConfigurationName) {
buildConfigurationName = buildConfigurationName.replaceAll("\\*", "%");
List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(AuditEntity.property("name").like(buildConfigurationName)).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
return result.stream().map(o -> {
BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
}).collect(Collectors.toList());
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigurationAuditedRepositoryImpl method searchIdRevForBuildConfigurationNameOrProjectName.
@Override
public List<IdRev> searchIdRevForBuildConfigurationNameOrProjectName(List<Project> projectsMatchingName, String name) {
AuditDisjunction disjunction = AuditEntity.disjunction();
projectsMatchingName.forEach(project -> disjunction.add(AuditEntity.relatedId("project").eq(project.getId())));
disjunction.add(AuditEntity.property("name").like(name));
List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(disjunction).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
return result.stream().map(o -> {
BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
}).collect(Collectors.toList());
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class DefaultDatastore method requiresRebuild.
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean requiresRebuild(BuildConfigurationAudited buildConfigurationAudited, boolean checkImplicitDependencies, boolean temporaryBuild, AlignmentPreference alignmentPreference, Set<Integer> processedDependenciesCache, Consumer<BuildRecord> nonRebuildCauseSetter) {
IdRev idRev = buildConfigurationAudited.getIdRev();
// Step 1 - Check the existence of a build with the same revision
BuildRecord latestSuccessfulBuildRecord = buildRecordRepository.getAnyLatestSuccessfulBuildRecordWithRevision(idRev, temporaryBuild);
if (latestSuccessfulBuildRecord == null) {
logger.debug("Rebuild of buildConfiguration.idRev: {} required as there is no successful BuildRecord.", idRev);
return true;
}
// Step 2 - Check the existence of more recent builds with different revision
if (!isLatestSuccessBRFromThisBCA(buildConfigurationAudited, temporaryBuild)) {
return true;
}
// Step 3 - check implicit dependencies
if (checkImplicitDependencies) {
logger.debug("Checking if BCA: {} has implicit dependencies that need rebuild", idRev);
boolean rebuild = hasARebuiltImplicitDependency(latestSuccessfulBuildRecord, temporaryBuild, alignmentPreference, processedDependenciesCache);
logger.debug("Implicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
if (rebuild) {
return true;
}
}
// Step 4 - check explicit dependencies
Set<BuildConfiguration> dependencies = buildConfigurationAudited.getBuildConfiguration().getDependencies();
boolean rebuild = hasARebuiltExplicitDependency(latestSuccessfulBuildRecord, dependencies, temporaryBuild, alignmentPreference);
logger.debug("Explicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
if (!rebuild) {
nonRebuildCauseSetter.accept(latestSuccessfulBuildRecord);
}
return rebuild;
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigProviderTest method testGetRevision.
@Test
public void testGetRevision() {
// With
final Integer revision = 1;
BuildConfigurationAudited bca = BuildConfigurationAudited.fromBuildConfiguration(bc, revision);
when(buildConfigurationAuditedRepository.queryById(new IdRev(bc.getId(), revision))).thenReturn(bca);
// When
BuildConfigurationRevision bcr = provider.getRevision(bc.getId().toString(), revision);
// Then
assertThat(bcr).isNotNull();
assertThat(bcr.getId()).isEqualTo(bc.getId().toString());
assertThat(bcr.getRev()).isEqualTo(revision);
assertThat(bcr.getName()).isEqualTo(bc.getName());
assertThat(bcr.getProject().getId()).isEqualTo(bc.getProject().getId().toString());
assertThat(bcr.getCreationTime()).isEqualTo(bc.getCreationTime().toInstant());
assertThat(bcr.getBuildType()).isEqualTo(bc.getBuildType());
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class ArtifactProviderTest method testGetRevision.
@Test
public void testGetRevision() {
// With
final Integer revision = 1;
ArtifactAudited aa = ArtifactAudited.fromArtifact(artifact1, revision);
when(artifactAuditedRepository.queryById(new IdRev(artifact1.getId(), revision))).thenReturn(aa);
// When
ArtifactRevision ar = provider.getRevision(artifact1.getId().toString(), revision);
// Then
assertThat(ar).isNotNull();
assertThat(ar.getId()).isEqualTo(artifact1.getId().toString());
assertThat(ar.getRev()).isEqualTo(revision);
}
Aggregations