Search in sources :

Example 86 with Modification

use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.

the class StageServiceIntegrationTest method checkin.

private Modification checkin(Material material, String rev, String comment, String user, String email, Date checkinTime) {
    Modification commit = checkinWithComment(rev, comment, user, email, checkinTime);
    // saved now, used later
    dbHelper.addRevisionsWithModifications(material, commit);
    return commit;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification)

Example 87 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 88 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)

Example 89 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 90 with Modification

use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.

the class MaterialDatabaseDependencyUpdaterTest method shouldCreateEntriesForCompletedPipelines.

@Test
public void shouldCreateEntriesForCompletedPipelines() 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();
    assertThat(modification.size(), is(1));
    assertThat(modification.get(0).getRevision(), is("pipeline-name/9/stage-name/0"));
    assertThat(modification.get(0).getPipelineLabel(), is("LABEL-9"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

Modification (com.thoughtworks.go.domain.materials.Modification)246 Test (org.junit.Test)176 Date (java.util.Date)76 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)65 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)54 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)40 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)38 ArrayList (java.util.ArrayList)35 File (java.io.File)25 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)21 Modifications (com.thoughtworks.go.domain.materials.Modifications)21 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 Material (com.thoughtworks.go.domain.materials.Material)20 Username (com.thoughtworks.go.server.domain.Username)17 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)16 HashMap (java.util.HashMap)16 StringContains.containsString (org.hamcrest.core.StringContains.containsString)15 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)14 Stage (com.thoughtworks.go.domain.Stage)13 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)13