Skip to content
Permalink
Browse files

Config repo change attribute "plugin" to "pluginId" (#3672)

* Add an xsl migration for changing plugin attribute of config-repo to pluginId
* Change the config repo representer to show plugin property as plugin_id (#3671)
  • Loading branch information...
GaneshSPatil committed Aug 22, 2017
1 parent a42ef83 commit dc39953b086ce672a090dcd90e45bd3fe0c3ee76
@@ -57,7 +57,7 @@

public static final String PRODUCT_NAME = "go";

public static final int CONFIG_SCHEMA_VERSION = 94;
public static final int CONFIG_SCHEMA_VERSION = 95;

public static final String APPROVAL_SUCCESS = "success";
public static final String APPROVAL_MANUAL = "manual";
@@ -44,7 +44,7 @@

// TODO something must instantiate this name into proper implementation of ConfigProvider
// which can be a plugin or embedded class
@ConfigAttribute(value = "plugin", allowNull = false)
@ConfigAttribute(value = "pluginId", allowNull = false)
private String configProviderPluginName = "gocd-xml";
// plugin-name which will process the repository tree to return configuration.
// as in https://github.com/gocd/gocd/issues/1133#issuecomment-109014208
@@ -77,7 +77,7 @@
</xsd:unique>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="schemaVersion" type="xsd:int" use="required" fixed="94"/>
<xsd:attribute name="schemaVersion" type="xsd:int" use="required" fixed="95"/>
</xsd:complexType>
<xsd:unique name="uniquePipelines">
<xsd:selector xpath="pipelines"/>
@@ -153,7 +153,7 @@
<xsd:element name="configuration" minOccurs="0" maxOccurs="1" type="configurationType"/>
</xsd:sequence>
<xsd:attribute type="nameType" name="id" use="required"/>
<xsd:attribute type="nameType" name="plugin" use="optional"/>
<xsd:attribute type="nameType" name="pluginId" use="optional"/>
</xsd:complexType>

<xsd:complexType name="scmsType">
@@ -1029,4 +1029,4 @@
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="secure" type="xsd:boolean"/>
</xsd:complexType>
</xsd:schema>
</xsd:schema>

Large diffs are not rendered by default.

@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
~ Copyright 2017 ThoughtWorks, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/cruise/@schemaVersion">
<xsl:attribute name="schemaVersion">95</xsl:attribute>
</xsl:template>

<xsl:template match="/cruise/config-repos/config-repo/@plugin">
<xsl:attribute name="pluginId"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<!-- Copy everything -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
@@ -173,7 +173,7 @@ public void shouldLoadConfigWithConfigRepo() throws Exception {
public void shouldLoadConfigWithConfigRepoAndPluginName() throws Exception {
CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigFileFixture.configWithConfigRepos(
" <config-repos>\n"
+ " <config-repo plugin=\"myplugin\" id=\"repo-id\">\n"
+ " <config-repo pluginId=\"myplugin\" id=\"repo-id\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n"
+ " </config-repo >\n"
+ " </config-repos>\n"
@@ -187,10 +187,10 @@ public void shouldLoadConfigWithConfigRepoAndPluginName() throws Exception {
public void shouldLoadConfigWith2ConfigRepos() throws Exception {
CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigFileFixture.configWithConfigRepos(
" <config-repos>\n"
+ " <config-repo plugin=\"myplugin\" id=\"repo-id1\">\n"
+ " <config-repo pluginId=\"myplugin\" id=\"repo-id1\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n"
+ " </config-repo >\n"
+ " <config-repo plugin=\"myplugin\" id=\"repo-id2\">\n"
+ " <config-repo pluginId=\"myplugin\" id=\"repo-id2\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-refmain-config-part.git\" />\n"
+ " </config-repo >\n"
+ " </config-repos>\n"
@@ -228,7 +228,7 @@ public void shouldLoadConfigWithConfigRepoAndConfiguration() throws Exception {
public void shouldThrowXsdValidationException_WhenNoRepository() throws Exception {
CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigFileFixture.configWithConfigRepos(
" <config-repos>\n"
+ " <config-repo plugin=\"myplugin\">\n"
+ " <config-repo pluginId=\"myplugin\">\n"
+ " </config-repo >\n"
+ " </config-repos>\n"
)).config;
@@ -238,7 +238,7 @@ public void shouldThrowXsdValidationException_WhenNoRepository() throws Exceptio
public void shouldThrowXsdValidationException_When2RepositoriesInSameConfigElement() throws Exception {
CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigFileFixture.configWithConfigRepos(
" <config-repos>\n"
+ " <config-repo plugin=\"myplugin\">\n"
+ " <config-repo pluginId=\"myplugin\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n"
+ " <git url=\"https://github.com/tomzo/gocd-refmain-config-part.git\" />\n"
+ " </config-repo >\n"
@@ -250,10 +250,10 @@ public void shouldThrowXsdValidationException_When2RepositoriesInSameConfigEleme
public void shouldFailValidation_WhenSameMaterialUsedBy2ConfigRepos() throws Exception {
CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigFileFixture.configWithConfigRepos(
" <config-repos>\n"
+ " <config-repo plugin=\"myplugin\" id=\"id1\">\n"
+ " <config-repo pluginId=\"myplugin\" id=\"id1\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n"
+ " </config-repo >\n"
+ " <config-repo plugin=\"myotherplugin\" id=\"id2\">\n"
+ " <config-repo pluginId=\"myotherplugin\" id=\"id2\">\n"
+ " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n"
+ " </config-repo >\n"
+ " </config-repos>\n"
@@ -199,7 +199,7 @@ public void shouldNotDeleteServerTag() throws Exception {
public void shouldWriteConfigRepos() throws Exception {
CruiseConfig config = GoConfigMother.configWithConfigRepo();
xmlWriter.write(config, output, false);
assertThat(output.toString(), containsString("<config-repo plugin=\"myplugin\" id=\"id2\">"));
assertThat(output.toString(), containsString("<config-repo pluginId=\"myplugin\" id=\"id2\">"));
assertThat(output.toString(), containsString("<git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />"));
}

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<cruise xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cruise-config.xsd" schemaVersion="94">
<cruise xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cruise-config.xsd" schemaVersion="95">
<server artifactsdir="artifacts" agentAutoRegisterKey="041b5c7e-dab2-11e5-a908-13f95f3c6ef6" webhookSecret="5f8b5eac-1148-4145-aa01-7b2934b6e1ab" commandRepositoryLocation="default" serverId="dev-id">
<security>
<authConfigs>
@@ -1512,6 +1512,21 @@ public void shouldAddIdOnConfigRepoAsPartOfMigration94() throws Exception {
assertThat(migratedContent, containsString("id="));
}

@Test
public void shouldConvertPluginToPluginIdOnConfigRepoAsPartOfMigration95() throws Exception {
String configXml = "<cruise schemaVersion='94'>" +
"<config-repos>\n" +
" <config-repo plugin=\"json.config.plugin\" id=\"config-repo-1\">\n" +
" <git url=\"https://github.com/tomzo/gocd-json-config-example.git\" />\n" +
" </config-repo>\n" +
"</config-repos>" +
"</cruise>";

assertThat(configXml, not(containsString("pluginId=\"json.config.plugin\"")));
String migratedContent = migrateXmlString(configXml, 94);
assertThat(migratedContent, containsString("pluginId=\"json.config.plugin\""));
}

@Test
public void shouldKeepExistingAuthConfigsWhileMigratingLdapAsPartOfMigration91() throws Exception {
String configXml = "<cruise schemaVersion='90'><server serverId='dev-id'><security>" +
@@ -33,7 +33,7 @@ class ConfigRepoRepresenter < ApiV1::BaseRepresenter

property :id

property :configProviderPluginName, as: :plugin
property :configProviderPluginName, as: :plugin_id

property :materialConfig, as: :material,
decorator: Config::ConfigRepo::Materials::MaterialRepresenter,
@@ -32,7 +32,7 @@
def get_config_repo_json
{
:id => 'repo-1',
:plugin => 'config-repo-json-plugin',
:plugin_id => 'config-repo-json-plugin',
:material => {
:type => 'git',
:attributes => {

0 comments on commit dc39953

Please sign in to comment.
You can’t perform that action at this time.