Skip to content

Commit

Permalink
fix JENKINS-40964 update to latest config-file-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvanlaatum committed Jan 21, 2017
1 parent 60629e8 commit e266800
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Expand Up @@ -124,7 +124,9 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.7.1</version>
<version>2.15.4</version>
<!--<version>2.13</version>-->
<!--<version>2.7.1</version>-->
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -218,7 +220,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.0.7</version>
<version>2.1.4</version>
<scope>test</scope>
</dependency>

Expand Down
Expand Up @@ -81,7 +81,7 @@ private FormValidation checkForManagedFile(final String value) {
Collection<ConfigProvider> providers = getTemplateConfigProviders();
for(ConfigProvider provider : providers) {
for(Config c : provider.getAllConfigs()) {
if(c.name.equalsIgnoreCase(value) && provider.isResponsibleFor(c.id)) {
if(c.name.equalsIgnoreCase(value)) {
return FormValidation.ok();
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/hudson/plugins/emailext/GroovyTemplateConfig.java
@@ -1,14 +1,22 @@
package hudson.plugins.emailext;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.AbstractConfigProviderImpl;
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 javax.annotation.Nonnull;

public class GroovyTemplateConfig extends Config {

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

@DataBoundConstructor
public GroovyTemplateConfig(String id, String name, String comment, String content) {
super(id, name, comment, content);
Expand All @@ -17,10 +25,6 @@ public GroovyTemplateConfig(String id, String name, String comment, String conte
@Extension(optional=true)
public static final class GroovyTemplateConfigProvider extends AbstractConfigProviderImpl {

public GroovyTemplateConfigProvider() {
load();
}

@Override
public ContentType getContentType() {
return ContentType.DefinedType.GROOVY;
Expand All @@ -31,15 +35,10 @@ public String getDisplayName() {
return Messages.GroovyTemplateConfigProvider_DisplayName();
}

@NonNull
@Override
public Config newConfig() {
String id = getProviderId() + System.currentTimeMillis();
public Config newConfig(@Nonnull String id) {
return new GroovyTemplateConfig(id, "Groovy Email Template", "", "");
}

@Override
protected String getXmlFileName() {

This comment has been minimized.

Copy link
@imod

imod Feb 10, 2017

Member

@davidvanlaatum because this method was removed (also for JellyTemplateConfigProvider), config-file-provider plugin is not able to migrate the old data to the new datastructure. It is not able to find the old file

This comment has been minimized.

Copy link
@davidvanlaatum

davidvanlaatum Feb 11, 2017

Author Contributor

ok. I can put it back

This comment has been minimized.

Copy link
@imod

imod Feb 11, 2017

Member

This comment has been minimized.

Copy link
@davidvanlaatum

davidvanlaatum Feb 12, 2017

Author Contributor

I have already released v2.55 with those methods restored

This comment has been minimized.

Copy link
@imod

imod Feb 13, 2017

Member

oh, I did not see that - unfortunate, this does not completely fix the issue yet... although the file can now be found, it is never loaded - you wold need to call load(); in the constructor again. Sorry for the incomplete advice :(

This comment has been minimized.

Copy link
@davidvanlaatum

davidvanlaatum Feb 13, 2017

Author Contributor

ok ill release another version

This comment has been minimized.

Copy link
@imod

imod Feb 13, 2017

Member

just hold on a bit - I'll do some more test and let you know - ok? or even better, can you do a beta release then I will test it.

This comment has been minimized.

Copy link
@davidvanlaatum

davidvanlaatum Feb 13, 2017

Author Contributor

ok I have committed the constructor. On the other hand if you want to send a pull request that might be easier

return "email-ext-groovy-config-files.xml";
}
}
}
}
23 changes: 11 additions & 12 deletions src/main/java/hudson/plugins/emailext/JellyTemplateConfig.java
@@ -1,13 +1,21 @@
package hudson.plugins.emailext;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.AbstractConfigProviderImpl;
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 javax.annotation.Nonnull;

public class JellyTemplateConfig extends Config {

@Override
public ConfigProvider getDescriptor() {
return Jenkins.getActiveInstance().getDescriptorByType(JellyTemplateConfigProvider.class);
}
@DataBoundConstructor
public JellyTemplateConfig(String id, String name, String comment, String content) {
super(id, name, comment, content);
Expand All @@ -16,10 +24,6 @@ public JellyTemplateConfig(String id, String name, String comment, String conten
@Extension(optional=true)
public static final class JellyTemplateConfigProvider extends AbstractConfigProviderImpl {

public JellyTemplateConfigProvider() {
load();
}

@Override
public ContentType getContentType() {
return ContentType.DefinedType.XML;
Expand All @@ -30,15 +34,10 @@ public String getDisplayName() {
return Messages.JellyTemplateConfigProvider_DisplayName();
}

@NonNull
@Override
public Config newConfig() {
String id = getProviderId() + System.currentTimeMillis();
public Config newConfig(@Nonnull String id) {
return new JellyTemplateConfig(id, "Jelly Email Template", "", "");
}

@Override
protected String getXmlFileName() {
return "email-ext-jelly-config-files.xml";
}
}
}
Expand Up @@ -144,7 +144,7 @@ private InputStream getManagedFile(String fileName) throws UnsupportedEncodingEx
ExtensionList<ConfigProvider> providers = ConfigProvider.all();
ConfigProvider provider = providers.get(getProviderClass ());
for (Config c : provider.getAllConfigs()) {
if (c.name.equalsIgnoreCase(fileName) && provider.isResponsibleFor(c.id)) {
if (c.name.equalsIgnoreCase(fileName)) {
config = c;
break;
}
Expand Down
Expand Up @@ -49,7 +49,6 @@ public void after() throws Exception {
};

@Test
@WithPlugin("config-file-provider.hpi")
public void configRoundTrip() throws Exception {
EmailExtStep step1 = new EmailExtStep("subject", "body");
step1.setTo("mickeymouse@disney.com");
Expand Down
Expand Up @@ -1066,7 +1066,6 @@ public void testProjectDisable() throws Exception {

@Test
@Issue("JENKINS-15442")
@WithPlugin("config-file-provider.hpi")
public void testConfiguredStateNoTriggers()
throws Exception {
FreeStyleProject prj = j.createFreeStyleProject("JENKINS-15442");
Expand Down

0 comments on commit e266800

Please sign in to comment.