Skip to content
Permalink
Browse files

Merge pull request #118 from imod/JENKINS-41078_update_config-provider

JENKINS-41078 support latest config-file-provider plugin (2.15.4)
  • Loading branch information...
felfert committed Feb 14, 2017
2 parents b157af0 + 1208b25 commit ba498e0ac210e3723d5d3be17286e05d978d13cd
@@ -70,7 +70,7 @@ limitations under the License.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.13</version>
<version>2.15.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -15,17 +15,22 @@
*/
package jenkins.plugins.jclouds.compute;

import java.lang.reflect.Field;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import edu.umd.cs.findbugs.annotations.NonNull;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.util.ListBoxModel;

import static hudson.util.ReflectionUtils.*;

import org.jenkinsci.plugins.configfiles.GlobalConfigFiles;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

@@ -56,17 +61,28 @@ static UserData createFromData(final String data, final String name) {
ConfigProvider provider = ConfigProvider.all().get(UserDataScriptProvider.class);
for (ConfigProvider p : ConfigProvider.all()) {
if (p instanceof JCloudsConfig) {
String sig = ((JCloudsConfig)p).getSignature();
String sig = ((JCloudsConfig) p).getSignature();
if (Pattern.compile(sig, Pattern.DOTALL).matcher(data).find()) {
provider = p;
break;
}
}
}
final String id = UUID.randomUUID().toString();
Config c = new Config(id, name, "auto-migrated", data, provider.getProviderId());
provider.save(c);
return new UserData(id);
Config c = provider.newConfig(id);
setField(getConfigField("name"), c, name);
setField(getConfigField("comment"), c, "auto-migrated");
setField(getConfigField("content"), c, data);

// migrated data is stored on global scope
GlobalConfigFiles.get().save(c);
return new UserData(c.id);
}

private static Field getConfigField(String name) {
Field field = findField(Config.class, name);
field.setAccessible(true);
return field;
}

@Extension
@@ -29,4 +29,13 @@ public ContentType getRealContentType() {

public AbstractJCloudsConfigProviderImpl() {
}

/*
* jclouds plugin currently does not support configuration files on folder scope
* - all configurations stored with config-file-proider are on global scope!
*/
@Override
public boolean supportsFolder() {
return false;
}
}
@@ -17,6 +17,7 @@

import hudson.util.ListBoxModel;

import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.jenkinsci.lib.configprovider.ConfigProvider;
@@ -49,6 +50,7 @@
import javax.mail.internet.MimeMultipart;

import jenkins.plugins.jclouds.compute.UserData;
import org.jenkinsci.plugins.configfiles.ConfigFiles;

public class ConfigHelper {

@@ -59,9 +61,11 @@ private ConfigHelper() {

@NonNull
public static String getConfig(@Nullable final String id) {
final Config cfg = Config.getByIdOrNull(id);
if (null != cfg && null != cfg.content) {
return cfg.content;
if(id != null) {
final Config cfg = ConfigFiles.getByIdOrNull(Jenkins.getActiveInstance(), id);
if (null != cfg && null != cfg.content) {
return cfg.content;
}
}
return "";
}
@@ -100,7 +104,7 @@ private static BodyPart buildBody(final Config cfg) {
private static List<Config> getConfigs(@NonNull final List<String> configIds) {
List<Config> ret = new ArrayList<>();
for (final String id : configIds) {
final Config cfg = Config.getByIdOrNull(id);
final Config cfg = ConfigFiles.getByIdOrNull(Jenkins.getActiveInstance(), id);
if (null != cfg) {
ret.add(cfg);
}
@@ -16,6 +16,8 @@
package jenkins.plugins.jclouds.config;

import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -30,8 +32,13 @@ public UserDataBoothook(final String id, final String name, final String comment
super(id, name, comment, content);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(UserDataBoothookProvider.class);
}

@Extension(ordinal = 70)
@ConfigSuitableFor(target=UserData.class)
@ConfigSuitableFor(target = UserData.class)
public static class UserDataBoothookProvider extends AbstractJCloudsConfigProviderImpl {

private static final String SIGNATURE = "^#cloud-boothook[\\r\\n]+";
@@ -63,14 +70,22 @@ public UserDataBoothook getConfigById(final String configId) {
}

@Override
public Config newConfig() {
public UserDataBoothook newConfig() {
String id = getProviderId() + "." + System.currentTimeMillis();
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
return new UserDataBoothook(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

@Override
public UserDataBoothook newConfig(final String id) {
return new UserDataBoothook(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

/**
* used for data migration only (config-file-provider prior 1.15)
*/
@Override
public Config newConfig(final String id) {
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT, getProviderId());
public UserDataBoothook convert(Config config) {
return new UserDataBoothook(config.id, config.name, config.comment, config.content);
}
}

@@ -16,6 +16,8 @@
package jenkins.plugins.jclouds.config;

import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -29,8 +31,13 @@ public UserDataInclude(final String id, final String name, final String comment,
super(id, name, comment, content);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(UserDataIncludeProvider.class);
}

@Extension(ordinal = 70)
@ConfigSuitableFor(target=UserData.class)
@ConfigSuitableFor(target = UserData.class)
public static class UserDataIncludeProvider extends AbstractJCloudsConfigProviderImpl {

private static final String SIGNATURE = "^#include[\\r\\n]+";
@@ -67,14 +74,22 @@ public UserDataInclude getConfigById(final String configId) {
}

@Override
public Config newConfig() {
public UserDataInclude newConfig() {
String id = getProviderId() + "." + System.currentTimeMillis();
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
return new UserDataInclude(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

@Override
public UserDataInclude newConfig(final String id) {
return new UserDataInclude(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

/**
* used for data migration only (config-file-provider prior 1.15)
*/
@Override
public Config newConfig(final String id) {
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT, getProviderId());
public UserDataInclude convert(Config config) {
return new UserDataInclude(config.id, config.name, config.comment, config.content);
}
}
}
@@ -16,6 +16,8 @@
package jenkins.plugins.jclouds.config;

import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -29,8 +31,13 @@ public UserDataIncludeOnce(final String id, final String name, final String comm
super(id, name, comment, content);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(UserDataIncludeOnceProvider.class);
}

@Extension(ordinal = 70)
@ConfigSuitableFor(target=UserData.class)
@ConfigSuitableFor(target = UserData.class)
public static class UserDataIncludeOnceProvider extends AbstractJCloudsConfigProviderImpl {

private static final String SIGNATURE = "^#include-once[\\r\\n]+";
@@ -67,14 +74,22 @@ public UserDataIncludeOnce getConfigById(final String configId) {
}

@Override
public Config newConfig() {
public UserDataIncludeOnce newConfig() {
String id = getProviderId() + "." + System.currentTimeMillis();
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
return new UserDataIncludeOnce(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

@Override
public UserDataIncludeOnce newConfig(final String id) {
return new UserDataIncludeOnce(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

/**
* used for data migration only (config-file-provider prior 1.15)
*/
@Override
public Config newConfig(final String id) {
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT, getProviderId());
public UserDataIncludeOnce convert(Config config) {
return new UserDataIncludeOnce(config.id, config.name, config.comment, config.content);
}
}
}
@@ -16,21 +16,27 @@
package jenkins.plugins.jclouds.config;

import hudson.Extension;
import jenkins.model.Jenkins;
import jenkins.plugins.jclouds.compute.UserData;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.DataBoundConstructor;

import jenkins.plugins.jclouds.compute.UserData;

public class UserDataPartHandler extends Config {

@DataBoundConstructor
public UserDataPartHandler(final String id, final String name, final String comment, final String content) {
super(id, name, comment, content);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(UserDataPartHandlerProvider.class);
}

@Extension(ordinal = 70)
@ConfigSuitableFor(target=UserData.class)
@ConfigSuitableFor(target = UserData.class)
public static class UserDataPartHandlerProvider extends AbstractJCloudsConfigProviderImpl {

private static final String SIGNATURE = "^#part-handler[\\r\\n]+";
@@ -80,14 +86,22 @@ public UserDataPartHandler getConfigById(final String configId) {
}

@Override
public Config newConfig() {
public UserDataPartHandler newConfig() {
String id = getProviderId() + "." + System.currentTimeMillis();
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
return new UserDataPartHandler(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

@Override
public UserDataPartHandler newConfig(final String id) {
return new UserDataPartHandler(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

/**
* used for data migration only (config-file-provider prior 1.15)
*/
@Override
public Config newConfig(final String id) {
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT, getProviderId());
public UserDataPartHandler convert(Config config) {
return new UserDataPartHandler(config.id, config.name, config.comment, config.content);
}
}
}
@@ -16,6 +16,8 @@
package jenkins.plugins.jclouds.config;

import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -29,8 +31,13 @@ public UserDataScript(final String id, final String name, final String comment,
super(id, name, comment, content);
}

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(UserDataScriptProvider.class);
}

@Extension(ordinal = 70)
@ConfigSuitableFor(target=UserData.class)
@ConfigSuitableFor(target = UserData.class)
public static class UserDataScriptProvider extends AbstractJCloudsConfigProviderImpl {

private static final String SIGNATURE = "^#!";
@@ -62,14 +69,22 @@ public UserDataScript getConfigById(final String configId) {
}

@Override
public Config newConfig() {
public UserDataScript newConfig() {
String id = getProviderId() + "." + System.currentTimeMillis();
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
return new UserDataScript(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

@Override
public UserDataScript newConfig(final String id) {
return new UserDataScript(id, DEFAULT_NAME, "", DEFAULT_CONTENT);
}

/**
* used for data migration only (config-file-provider prior 1.15)
*/
@Override
public Config newConfig(final String id) {
return new Config(id, DEFAULT_NAME, "", DEFAULT_CONTENT, getProviderId());
public UserDataScript convert(Config config) {
return new UserDataScript(config.id, config.name, config.comment, config.content);
}
}
}

0 comments on commit ba498e0

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