use of net.nemerosa.ontrack.extension.artifactory.property.ArtifactoryPromotionSyncProperty in project ontrack by nemerosa.
the class ArtifactoryPromotionSyncServiceImpl method sync.
private void sync(Branch branch, JobRunListener listener) {
// Gets the sync properties
Property<ArtifactoryPromotionSyncProperty> syncProperty = propertyService.getProperty(branch, ArtifactoryPromotionSyncPropertyType.class);
if (syncProperty.isEmpty()) {
throw new IllegalStateException(String.format("Cannot find sync. property on branch %d", branch.id()));
}
String buildName = syncProperty.getValue().getBuildName();
String buildNameFilter = syncProperty.getValue().getBuildNameFilter();
ArtifactoryConfiguration configuration = syncProperty.getValue().getConfiguration();
String log = String.format("Sync branch %s/%s with Artifactory build %s (%s)", branch.getProject().getName(), branch.getName(), buildName, buildNameFilter);
logger.info("[artifactory-sync] {}", log);
listener.message(log);
// Build name filter
Pattern buildNamePattern = Pattern.compile(replace(replace(buildNameFilter, ".", "\\."), "*", ".*"));
// Gets an Artifactory client
ArtifactoryClient client = artifactoryClientFactory.getClient(configuration);
// Gets all the build numbers for the specified build name
List<String> buildNumbers = client.getBuildNumbers(buildName).stream().filter(name -> buildNamePattern.matcher(name).matches()).collect(Collectors.toList());
// Synchronises the promotion levels for each build
for (String buildNumber : buildNumbers) {
syncBuild(branch, buildName, buildNumber, client, listener);
}
}
use of net.nemerosa.ontrack.extension.artifactory.property.ArtifactoryPromotionSyncProperty in project ontrack by nemerosa.
the class ArtifactoryPromotionSyncServiceImplTest method syncBuildJobs_one_per_configured_branch.
@Test
public void syncBuildJobs_one_per_configured_branch() {
when(propertyService.hasProperty(branch, ArtifactoryPromotionSyncPropertyType.class)).thenReturn(true);
Property<ArtifactoryPromotionSyncProperty> property = Property.of(new ArtifactoryPromotionSyncPropertyType(new ArtifactoryExtensionFeature(), null), new ArtifactoryPromotionSyncProperty(null, "", "", 10));
when(propertyService.getProperty(branch, ArtifactoryPromotionSyncPropertyType.class)).thenReturn(property);
when(structureService.getProjectList()).thenReturn(Collections.singletonList(project));
when(structureService.getBranchesForProject(project.getId())).thenReturn(Collections.singletonList(branch));
// Gets the list of jobs
assertEquals(1, service.collectJobRegistrations().count());
}
Aggregations