Skip to content
Permalink
Browse files

JENKINS-40737 unify data migration

  • Loading branch information
imod committed Jan 4, 2017
1 parent 6cb26ce commit e9a1e6997968429bdb9953ef95f96b236dfabe09
@@ -2,6 +2,7 @@

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

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

/**
* only used for data migration
* @see org.jenkinsci.plugins.configfiles.ConfigFiles
*/
@Deprecated
public Map<String, Config> getConfigs() {
@@ -53,6 +55,11 @@ public AbstractConfigProviderImpl() {
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;
}
@@ -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);
@@ -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
@@ -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);
@@ -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
@@ -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;
@@ -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) {
@@ -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());
}
}

@@ -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);
@@ -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() {
@@ -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);
@@ -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());
}

// ======================

0 comments on commit e9a1e69

Please sign in to comment.