Skip to content

Commit

Permalink
[JENKINS-11176] Fixed the optional @extension for the Promotion Condi…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
Dohbedoh committed May 2, 2016
1 parent 3a0e033 commit b47f6c3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,4 +5,5 @@ target
*.iml
*.ipr
*.iws
*.idea
work
8 changes: 0 additions & 8 deletions src/main/java/hudson/plugins/release/ReleaseWrapper.java
Expand Up @@ -437,14 +437,6 @@ public static void checkReleasePermission(AbstractProject job) {

@Extension
public static final class DescriptorImpl extends BuildWrapperDescriptor {

static {
// check if promoted plugins is installed and if so, register
// promotion condition
if (Hudson.getInstance().getPlugin("promoted-builds") != null) {
ReleasePromotionCondition.registerExtension();
}
}

@Override
public String getDisplayName() {
Expand Down
Expand Up @@ -5,6 +5,7 @@

package hudson.plugins.release.promotion;

import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.promoted_builds.PromotionBadge;
Expand All @@ -30,14 +31,20 @@ public PromotionBadge isMet(AbstractBuild<?, ?> build) {
return null;
}

/**
* Register a new instance of {@link PromotionConditionDescriptor} to this {@link PromotionCondition}
*
* @deprecated Caused duplication of descriptor (see JENKINS-11176). Replaced by the Extension annotation in
* the {@link PromotionConditionDescriptor}.
*/
@Deprecated
public static void registerExtension() {}

public static final class Badge extends PromotionBadge {

}

public static void registerExtension() {
PromotionCondition.all().add(new DescriptorImpl());
}

@Extension(optional = true)
public static final class DescriptorImpl extends PromotionConditionDescriptor {

public boolean isApplicable(AbstractProject<?,?> item) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/hudson/plugins/release/TestReleasePlugin.java
Expand Up @@ -3,6 +3,7 @@
import hudson.PluginWrapper;
import hudson.model.Descriptor;

import hudson.plugins.release.promotion.ReleasePromotionCondition;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
Expand Down Expand Up @@ -33,4 +34,10 @@ public void testDescriptorRegistered() throws Exception
assertNotNull("Must have ReleaseWrapper descriptor", descriptor);
}

@Test
public void testPromotionDescriptorRegistered() throws Exception
{
Descriptor<?> descriptor = Descriptor.find(ReleasePromotionCondition.DescriptorImpl.class.getName());
assertNotNull("Must have ReleaseWrapper descriptor", descriptor);
}
}

0 comments on commit b47f6c3

Please sign in to comment.