Search in sources :

Example 16 with Modification

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;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) StageAsDMR(com.thoughtworks.go.domain.StageAsDMR) Modification(com.thoughtworks.go.domain.materials.Modification) ArrayList(java.util.ArrayList)

Example 17 with Modification

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;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) Stages(com.thoughtworks.go.domain.Stages) ArrayList(java.util.ArrayList) Stage(com.thoughtworks.go.domain.Stage)

Example 18 with Modification

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);
        }
    });
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Query(org.hibernate.Query) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) Session(org.hibernate.Session)

Example 19 with Modification

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();
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) TransactionStatus(org.springframework.transaction.TransactionStatus) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 20 with Modification

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"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial)

Aggregations

Modification (com.thoughtworks.go.domain.materials.Modification)242 Test (org.junit.Test)164 Date (java.util.Date)78 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)68 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)55 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)41 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)40 ArrayList (java.util.ArrayList)34 File (java.io.File)25 Modifications (com.thoughtworks.go.domain.materials.Modifications)21 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)20 Material (com.thoughtworks.go.domain.materials.Material)20 HashMap (java.util.HashMap)18 Username (com.thoughtworks.go.server.domain.Username)17 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)15 Pipeline (com.thoughtworks.go.domain.Pipeline)14 Stage (com.thoughtworks.go.domain.Stage)14 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)14 StringContains.containsString (org.hamcrest.core.StringContains.containsString)14