Search in sources :

Example 11 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PackageMaterialUpdaterTest method shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed.

@Test
public void shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed() throws Exception {
    PackageMaterial material = MaterialsMother.packageMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    File file = new File("random");
    Modifications modifications = new Modifications();
    materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
    verify(materialRepository, never()).saveOrUpdate(Matchers.<MaterialInstance>any());
    verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 12 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialUpdaterTest method shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed.

@Test
public void shouldNotUpdateMaterialInstanceWhenConfigHas_NOT_Changed() throws Exception {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    File file = new File("random");
    Modifications modifications = new Modifications();
    materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
    verify(materialRepository, never()).saveOrUpdate(Matchers.<MaterialInstance>any());
    verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 13 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialInstanceTest method shouldTestEqualsBasedOnConfiguration.

@Test
public void shouldTestEqualsBasedOnConfiguration() {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1"));
    MaterialInstance materialInstance = material.createMaterialInstance();
    MaterialInstance materialInstanceCopy = material.createMaterialInstance();
    material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2"));
    MaterialInstance newMaterialInstance = material.createMaterialInstance();
    assertThat(materialInstance, is(materialInstanceCopy));
    assertThat(materialInstance, is(not(newMaterialInstance)));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Test(org.junit.Test)

Example 14 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class MaterialDatabaseUpdater method updateMaterialWithNewRevisions.

void updateMaterialWithNewRevisions(Material material) {
    Materials materials = new Materials();
    materialExpansionService.expandForHistory(material, materials);
    for (Material expanded : materials) {
        MaterialInstance expandedInstance = materialRepository.findMaterialInstance(expanded);
        File expandedFolder = folderFor(expanded);
        if (expandedInstance == null) {
            addNewMaterialWithModifications(expandedFolder, expanded, updater(expanded));
        } else {
            insertLatestOrNewModifications(expanded, expandedInstance, expandedFolder, updater(expanded));
        }
    }
}
Also used : Materials(com.thoughtworks.go.config.materials.Materials) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File)

Example 15 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class MaterialDatabaseUpdater method updateMaterial.

public void updateMaterial(final Material material) throws Exception {
    String materialMutex = mutexForMaterial(material);
    HealthStateScope scope = HealthStateScope.forMaterial(material);
    try {
        MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
        if (materialInstance == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format("[Material Update] Material repository not found, creating with latest revision from %s", material));
            }
            synchronized (materialMutex) {
                if (materialRepository.findMaterialInstance(material) == null) {
                    transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

                        @Override
                        public Object doInTransaction(TransactionStatus status) throws Exception {
                            initializeMaterialWithLatestRevision(material);
                            return null;
                        }
                    });
                }
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(String.format("[Material Update] Existing material repository, fetching new revisions from %s in flyweight %s", material, materialInstance.getFlyweightName()));
            }
            synchronized (materialMutex) {
                transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

                    @Override
                    public Object doInTransaction(TransactionStatus status) throws Exception {
                        updateMaterialWithNewRevisions(material);
                        return null;
                    }
                });
            }
        }
        healthService.removeByScope(scope);
    } catch (Exception e) {
        String message = "Modification check failed for material: " + material.getLongDescription();
        String errorDescription = e.getMessage() == null ? "Unknown error" : e.getMessage();
        healthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
        LOGGER.warn(String.format("[Material Update] %s", message), e);
        throw e;
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Aggregations

MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)39 Test (org.junit.Test)28 File (java.io.File)13 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 Modification (com.thoughtworks.go.domain.materials.Modification)9 Modifications (com.thoughtworks.go.domain.materials.Modifications)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)7 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)6 Date (java.util.Date)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)5 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)4 Material (com.thoughtworks.go.domain.materials.Material)4 HashMap (java.util.HashMap)4