use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class LocalDependencyMaterialSourceDao method getPassedStagesAfter.
public List<Modification> getPassedStagesAfter(final String lastRevision, DependencyMaterial material, Pagination pagination) {
StageIdentifier identifier = new StageIdentifier(lastRevision);
List<StageAsDMR> passedStagesAfter = stageDao.getPassedStagesAfter(identifier, pagination.getPageSize(), pagination.getOffset());
List<Modification> mods = new ArrayList<>();
for (StageAsDMR stage : passedStagesAfter) {
StageIdentifier stageIdentifier = stage.getIdentifier();
Modification modification = new Modification(stage.getCompletedDate(), stageIdentifier.stageLocator(), stageIdentifier.getPipelineLabel(), stage.getPipelineId());
mods.add(modification);
}
return mods;
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class LocalDependencyMaterialSourceDao method getPassedStagesByName.
public List<Modification> getPassedStagesByName(DependencyMaterial material, Pagination pagination) {
Stages stages = stageDao.getPassedStagesByName(CaseInsensitiveString.str(material.getPipelineName()), CaseInsensitiveString.str(material.getStageName()), pagination.getPageSize(), pagination.getOffset());
List<Modification> mods = new ArrayList<>();
for (Stage stage : stages) {
StageIdentifier stageIdentifier = stage.getIdentifier();
Modification modification = new Modification(stage.completedDate(), stageIdentifier.stageLocator(), stageIdentifier.getPipelineLabel(), stage.getPipelineId());
mods.add(modification);
}
return mods;
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method modForRev.
private Modification modForRev(final String revision) {
return (Modification) materialRepository.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery("from Modification where revision = ?");
q.setParameter(0, revision);
List list = q.list();
if (list.isEmpty()) {
throw new RuntimeException("you are trying to load revision " + revision + " which doesn't exist");
}
return list.get(0);
}
});
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method pass.
private String pass(final AddedPipeline pipeline, final Date mduAt, final Pipeline instance) {
dbHelper.pass(instance);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
for (Stage stage : instance.getStages()) {
final String dmrRevStr = new StageIdentifier(new PipelineIdentifier(instance.getName(), instance.getCounter(), instance.getName() + instance.getCounter()), stage.getName(), "1").getStageLocator();
Modification modification = new Modification(mduAt, dmrRevStr, instance.getLabel(), instance.getId());
materialRepository.saveMaterialRevision(new MaterialRevision(pipeline.material, modification));
}
}
});
return new StageIdentifier(new PipelineIdentifier(instance.getName(), instance.getCounter(), instance.getName() + instance.getCounter()), pipeline.material.getStageName().toString(), "1").getStageLocator();
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method scheduleWith.
private Pipeline scheduleWith(AddedPipeline pipeline, RevisionsForMaterial... revisions) {
Pipeline oldInstance = triggeredPipelines.get(pipeline.config.name());
Map<Material, List<Modification>> modMap = new HashMap<>();
Map<Modification, Modification> identityMap = new HashMap<>();
MaterialRevisions buildCause = new MaterialRevisions();
int i = 0;
for (Material material : new MaterialConfigConverter().toMaterials(pipeline.config.materialConfigs())) {
List<Modification> modifications = new ArrayList<>();
for (Modification modification : modForRev(revisions[i++])) {
if (!identityMap.containsKey(modification)) {
identityMap.put(modification, modification);
}
modifications.add(identityMap.get(modification));
}
MaterialInstance modificationsMaterialInstance = modifications.get(0).getMaterialInstance();
if (modMap.containsKey(material)) {
modifications = modMap.get(material);
} else {
modMap.put(material, modifications);
}
MaterialInstance configuredMaterialInstance = materialRepository.findOrCreateFrom(material);
if (!configuredMaterialInstance.equals(modificationsMaterialInstance)) {
throw new RuntimeException("Please fix the revision order to match material configuration order. Revision given for: " + modificationsMaterialInstance + " against configured material: " + configuredMaterialInstance);
}
if (oldInstance == null) {
buildCause.addRevision(new MaterialRevision(material, modifications));
} else {
MaterialRevision oldRev = oldInstance.getBuildCause().getMaterialRevisions().findRevisionFor(material);
List<Modification> modificationsSince = materialRepository.findModificationsSince(material, oldRev);
List<Modification> newRange = new ArrayList<>();
for (Modification newMod : modificationsSince) {
newRange.add(0, newMod);
if (newMod.equals(modifications)) {
break;
}
}
buildCause.addRevision(new MaterialRevision(material, newRange));
}
}
return dbHelper.schedulePipelineWithAllStages(pipeline.config, BuildCause.createWithModifications(buildCause, "loser"));
}
Aggregations