use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialChecker method updateChangedRevisions.
public void updateChangedRevisions(CaseInsensitiveString pipelineName, BuildCause buildCause) {
for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
Long latestModificationRunByPipeline = materialRepository.latestModificationRunByPipeline(pipelineName, materialRevision.getMaterial());
Modifications revised = new Modifications();
for (Modification modification : materialRevision.getModifications()) {
if (modification.getId() > latestModificationRunByPipeline)
revised.add(modification);
}
if (!revised.isEmpty()) {
materialRevision.replaceModifications(revised);
materialRevision.markAsChanged();
} else {
materialRevision.markAsNotChanged();
}
}
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialRevisionBuilder method depInstance.
public Tuple depInstance(String pipelineName, int counter, Date modifiedTime, Tuple... buildCause) {
String key = key(pipelineName, counter, modifiedTime);
if (!instanceToRevision.containsKey(key)) {
if (buildCause.length == 0) {
throw new RuntimeException("Cannot create instance without a buildcause. You can retrive it without buildcause once it has been created");
}
DependencyMaterial material = new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(STAGE_NAME));
DependencyMaterialRevision revision = DependencyMaterialRevision.create(pipelineName, counter, "label", STAGE_NAME, 1);
instanceToRevision.put(key, revision.convert(material, modifiedTime));
final long id = getNextId();
org.mockito.Mockito.when(pipelineDao.findPipelineByNameAndCounter(pipelineName, counter)).thenReturn(pipeline(id));
org.mockito.Mockito.when(materialRepository.findMaterialRevisionsForPipeline(id)).thenReturn(buildCauseOfThisPipeline(buildCause));
}
MaterialRevision materialRevision = instanceToRevision.get(key);
Materials materials = new Materials();
for (MaterialRevision revision : buildCauseOfThisPipeline(buildCause)) {
materials.add(revision.getMaterial());
}
PipelineConfig config = new PipelineConfig(new CaseInsensitiveString(pipelineName), materials.convertToConfigs(), new StageConfig(new CaseInsensitiveString(STAGE_NAME), new JobConfigs()));
return new Tuple(new PipelineConfigDependencyGraph(config, dependencyGraphsFor(buildCause)), materialRevision);
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialRevisionBuilder method insertIfNotPresent.
private void insertIfNotPresent(Material material, String key, String revision, Date modifiedTime) {
if (!instanceToRevision.containsKey(key)) {
Modification modification = new Modification("username", "comment", "email", modifiedTime, revision);
instanceToRevision.put(key, new MaterialRevision(material, modification));
}
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class TestFailureSetup method setupPipelineInstnace.
private SavedStage setupPipelineInstnace(final boolean failStage, final String overriddenLabel, final List<Modification> modifications, final TestResultsStubbing test, final Date latestTransitionDate) {
return (SavedStage) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
MaterialInstance materialInstance = materialRepository.findOrCreateFrom(hgMaterial);
for (Modification mod : modifications) {
mod.setMaterialInstance(materialInstance);
}
MaterialRevision rev = new MaterialRevision(hgMaterial, modifications);
materialRepository.saveMaterialRevision(rev);
Pipeline pipeline = PipelineMother.schedule(pipelineConfig, BuildCause.createManualForced(new MaterialRevisions(rev), new Username(new CaseInsensitiveString("loser"))));
if (overriddenLabel != null) {
pipeline.setLabel(overriddenLabel);
}
for (JobInstance instance : pipeline.getStages().get(0).getJobInstances()) {
for (JobStateTransition jobStateTransition : instance.getTransitions()) {
jobStateTransition.setStateChangeTime(latestTransitionDate);
}
}
dbHelper.save(pipeline);
Stage barStage = pipeline.getFirstStage();
if (failStage) {
dbHelper.failStage(barStage, latestTransitionDate);
}
test.stub(barStage);
pipelineTimeline.update();
return new SavedStage(pipeline);
}
});
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldReturnNoNewModificationsIfNoNewPipelineHasBennCompleted.
@Test
public void shouldReturnNoNewModificationsIfNoNewPipelineHasBennCompleted() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null, stages(9));
updater.updateMaterial(dependencyMaterial);
List<Modification> modification = materialRepository.findLatestModification(dependencyMaterial).getMaterialRevision(0).getModifications();
stubStageServiceGetHistoryAfter(dependencyMaterial, 9, stages());
updater.updateMaterial(dependencyMaterial);
List<Modification> newModifications = materialRepository.findModificationsSince(dependencyMaterial, new MaterialRevision(dependencyMaterial, modification));
assertThat(newModifications.size(), is(0));
}
Aggregations