Search in sources :

Example 11 with Material

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

the class AbstractMaterialTestController method testConnection.

public String testConnection(Request request, Response response) {
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    String type = jsonReader.getString("type");
    String pipelineName = jsonReader.getStringOrDefault("pipeline_name", "");
    String pipelineGroupName = jsonReader.getStringOrDefault("pipeline_group", "");
    haltIfMaterialTypeIsInvalid(type);
    haltIfMaterialTypeDoesNotSupportsCheckConnection(type);
    ScmMaterialConfig scmMaterialConfig = buildSCMMaterialFromRequestBody(request);
    validateMaterialConfig(scmMaterialConfig, pipelineName, pipelineGroupName);
    if (!scmMaterialConfig.errors().isEmpty()) {
        List<String> errorsList = new ArrayList<>();
        scmMaterialConfig.errors().forEach((key, errors) -> errorsList.add(String.format("- %s: %s", key, StringUtils.join(errors, ", "))));
        response.status(422);
        return MessageJson.create(String.format("There was an error with the material configuration.\n%s", StringUtils.join(errorsList, "\n")), jsonWriter(scmMaterialConfig));
    }
    performParamExpansion(scmMaterialConfig, pipelineName);
    Material material = materialConfigConverter.toMaterial(scmMaterialConfig);
    resolveSecrets(pipelineGroupName, material);
    ValidationBean validationBean = material.checkConnection(new CheckConnectionSubprocessExecutionContext(systemEnvironment));
    return handleValidationBeanResponse(validationBean, response);
}
Also used : ArrayList(java.util.ArrayList) JsonReader(com.thoughtworks.go.api.representers.JsonReader) Material(com.thoughtworks.go.domain.materials.Material) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) CheckConnectionSubprocessExecutionContext(com.thoughtworks.go.server.service.CheckConnectionSubprocessExecutionContext) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) ScmMaterialConfig(com.thoughtworks.go.config.materials.ScmMaterialConfig)

Example 12 with Material

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

the class MaterialXmlRepresenter method populate.

public final void populate(ElementBuilder builder, XmlWriterContext ctx) {
    Material material = materialRevision.getMaterial();
    builder.node("material", materialBuilder -> populateMaterial(ctx, material, materialBuilder));
}
Also used : 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) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial)

Example 13 with Material

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

the class PipelineConfigDependencyGraph method isRevisionsOfSharedMaterialsIgnored.

public boolean isRevisionsOfSharedMaterialsIgnored(MaterialRevisions revisions) {
    MaterialConfigs unsharedScmMaterialConfigs = unsharedMaterialConfigs();
    List<PipelineConfigQueueEntry> queue = new ArrayList<>(buildQueue());
    for (MaterialRevision revision : revisions) {
        Material material = revision.getMaterial();
        MaterialConfig materialConfig = material.config();
        if (unsharedScmMaterialConfigs.hasMaterialWithFingerprint(materialConfig) || revision.isDependencyMaterialRevision()) {
            continue;
        }
        if (isThisMaterialIgnored(queue, revision, materialConfig)) {
            return true;
        }
    }
    return false;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) ArrayList(java.util.ArrayList) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 14 with Material

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

the class ConfigRepositoryInitializerTest method shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain.

@Test
void shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain() {
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // config changes..
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 15 with Material

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

the class ConfigRepositoryInitializerTest method shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded.

@Test
void shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded() {
    // add another config repo using another plugin id
    ConfigRepoConfig repoConfig2 = new ConfigRepoConfig();
    repoConfig2.setId("repo2");
    repoConfig2.setPluginId(JSON_PLUGIN_ID);
    repoConfig2.setRepo(MaterialConfigsMother.git("git-repo"));
    repoConfigs.add(repoConfig2);
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    // initialize config
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    // load yaml plugin
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load json plugin
    configRepositoryInitializer.pluginLoaded(jsonPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(2)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load groovy plugin
    configRepositoryInitializer.pluginLoaded(groovyPluginDescriptor);
    // verify nothing happens on more plugin load
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)122 Test (org.junit.jupiter.api.Test)72 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)49 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)47 Modification (com.thoughtworks.go.domain.materials.Modification)29 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)28 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)24 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)19 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)18 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 Materials (com.thoughtworks.go.config.materials.Materials)14 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)13 File (java.io.File)13 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)12 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)12 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)8