Skip to content

Commit

Permalink
JENKINS-40737 unify data migration
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed Jan 4, 2017
1 parent 6cb26ce commit e9a1e69
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 31 deletions.
Expand Up @@ -2,6 +2,7 @@

import hudson.BulkChange;
import hudson.XmlFile;
import hudson.model.ItemGroup;
import hudson.model.listeners.SaveableListener;

import java.io.File;
Expand Down Expand Up @@ -40,6 +41,7 @@ public AbstractConfigProviderImpl() {

/**
* only used for data migration
* @see org.jenkinsci.plugins.configfiles.ConfigFiles
*/
@Deprecated
public Map<String, Config> getConfigs() {
Expand All @@ -53,6 +55,11 @@ public Map<String, Config> getConfigs() {
return tmp;
}

/**
* Only used to convert data from the old (< 1.5) storage format to the new >= 1.5.
* New implementations of this extension point do not need to implement this
*/
@Deprecated
public <T extends Config> T convert(Config config) {
return (T) config;
}
Expand Down
Expand Up @@ -47,10 +47,6 @@ public CustomConfig(String id, String name, String comment, String content, Stri
super(id, name, comment, content, providerId);
}

public CustomConfig(Config config){
super(config);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(CustomConfigProvider.class);
Expand All @@ -75,7 +71,7 @@ public String getDisplayName() {

@Override
public <T extends Config> T convert(Config config) {
return (T) new CustomConfig(config);
return (T) new CustomConfig(config.id, config.name, config.comment, config.content, getProviderId());
}

@Override
Expand Down
Expand Up @@ -48,10 +48,6 @@ public GroovyScript(String id, String name, String comment, String content, Stri
super(id, name, comment, content, providerId);
}

public GroovyScript(Config config){
super(config);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(GroovyConfigProvider.class);
Expand All @@ -76,7 +72,7 @@ public String getDisplayName() {

@Override
public <T extends Config> T convert(Config config) {
return (T) new GroovyScript(config);
return (T) new GroovyScript(config.id, config.name, config.comment, config.content, getProviderId());
}

@Override
Expand Down
Expand Up @@ -36,9 +36,8 @@ of this software and associated documentation files (the "Software"), to deal

/**
* A config/provider to handle the special case of a Json file
*
*
* @author Dominik Bartholdi (imod)
*
*/
public class JsonConfig extends Config {
private static final long serialVersionUID = 1L;
Expand All @@ -52,16 +51,10 @@ public JsonConfig(String id, String name, String comment, String content, String
super(id, name, comment, fixJsonContent(content), providerId);
}

public JsonConfig(@NonNull Config config) {
super(config);
}


/**
* as the form submission with stapler is done in json too, we have to do "deescape" the formated content of the json file.
*
* @param content
* the json body of the file
*
* @param content the json body of the file
* @return deescaped json
*/
private static String fixJsonContent(String content) {
Expand Down Expand Up @@ -116,7 +109,7 @@ public Config newConfig(@NonNull String id) {

@Override
public <T extends Config> T convert(Config config) {
return (T) new JsonConfig(config.id, config.name,config.comment,config.content,getProviderId());
return (T) new JsonConfig(config.id, config.name, config.comment, config.content, getProviderId());
}
}

Expand Down
Expand Up @@ -51,10 +51,6 @@ public MavenToolchainsConfig(String id, String name, String comment, String cont
super(id, name, comment, content, providerId);
}

public MavenToolchainsConfig(Config config) {
super(config);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(MavenToolchainsConfigProvider.class);
Expand Down Expand Up @@ -102,7 +98,7 @@ public Config newConfig(@NonNull String id) {

@Override
public <T extends Config> T convert(Config config) {
return (T) new MavenToolchainsConfig(config);
return (T) new MavenToolchainsConfig(config.id, config.name, config.comment, config.content, getProviderId());
}

private String loadTemplateContent() {
Expand Down
Expand Up @@ -47,10 +47,6 @@ public XmlConfig(String id, String name, String comment, String content, String
super(id, name, comment, content, providerId);
}

public XmlConfig(Config config){
super(config);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(XmlConfigProvider.class);
Expand Down Expand Up @@ -87,7 +83,7 @@ public Config newConfig(@NonNull String id) {

@Override
public <T extends Config> T convert(Config config) {
return (T) new XmlConfig(config);
return (T) new XmlConfig(config.id, config.name, config.comment, config.content, getProviderId());
}

// ======================
Expand Down

0 comments on commit e9a1e69

Please sign in to comment.