Skip to content

Commit

Permalink
Merge pull request jenkinsci#7 from jenkinsci/fix-action-hierarchy
Browse files Browse the repository at this point in the history
fix action hierarchy
  • Loading branch information
bakito authored Apr 4, 2018
2 parents 3a6ef5d + 056cd02 commit 7df10d4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Serban Iordache
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.jenkinsci.plugins.badge.action;

import hudson.model.Action;
import hudson.model.BuildBadgeAction;
import org.kohsuke.stapler.export.Exported;

import java.io.Serializable;

/**
* An abstract action providing a badge id
*/
public abstract class AbstractAction implements Action, Serializable {
private String id;

public void setId(String id) {
this.id = id;
}

@Exported
public String getId() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,9 @@
package com.jenkinsci.plugins.badge.action;

import hudson.model.BuildBadgeAction;
import org.kohsuke.stapler.export.Exported;

import java.io.Serializable;
import java.lang.annotation.Documented;

/**
* An abstract badge action providing a badge id
*/
public abstract class AbstractBadgeAction implements BuildBadgeAction, Serializable {
private String id;

public void setId(String id) {
this.id = id;
}

@Exported
public String getId() {
return id;
}
public abstract class AbstractBadgeAction extends AbstractAction implements BuildBadgeAction {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean(defaultVisibility = 2)
public class BadgeSummaryAction extends AbstractBadgeAction {
public class BadgeSummaryAction extends AbstractAction {
private static final long serialVersionUID = 1L;

private final String iconPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.jenkinsci.plugins.badge.dsl;

import com.jenkinsci.plugins.badge.action.AbstractAction;
import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.Action;
Expand All @@ -43,18 +44,18 @@ public StepExecution start(StepContext context) {
}


protected abstract Class<? extends AbstractBadgeAction> getActionClass();
protected abstract Class<? extends AbstractAction> getActionClass();


public static class Execution extends SynchronousStepExecution<Void> {

@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Only used when starting.")
private final Class<? extends AbstractBadgeAction> actionClass;
private final Class<? extends AbstractAction> actionClass;

@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Only used when starting.")
private final String id;

Execution(StepContext context, Class<? extends AbstractBadgeAction> actionClass, String id) {
Execution(StepContext context, Class<? extends AbstractAction> actionClass, String id) {
super(context);
this.actionClass = actionClass;
this.id = id;
Expand All @@ -70,7 +71,7 @@ protected Void run() throws IOException, InterruptedException {
}

private boolean matches(Action a) {
return actionClass.isAssignableFrom(a.getClass()) && (id == null || id.equals(((AbstractBadgeAction) a).getId()));
return actionClass.isAssignableFrom(a.getClass()) && (id == null || id.equals(((AbstractAction) a).getId()));
}

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.jenkinsci.plugins.badge.dsl;

import com.jenkinsci.plugins.badge.action.AbstractAction;
import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
import com.jenkinsci.plugins.badge.action.BadgeSummaryAction;
import hudson.Extension;
Expand All @@ -39,7 +40,7 @@ public RemoveSummariesStep() {
}

@Override
protected Class<? extends AbstractBadgeAction> getActionClass() {
protected Class<? extends AbstractAction> getActionClass() {
return BadgeSummaryAction.class;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jenkinsci.plugins.badge.action;

import hudson.model.Action;
import hudson.model.BuildBadgeAction;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class ClassHierarchyTest {

@Test
public void badgeSummaryAction() {
assertTrue(Action.class.isAssignableFrom(BadgeSummaryAction.class));
assertTrue(AbstractAction.class.isAssignableFrom(BadgeSummaryAction.class));

assertFalse(BuildBadgeAction.class.isAssignableFrom(BadgeSummaryAction.class));
assertFalse(AbstractBadgeAction.class.isAssignableFrom(BadgeSummaryAction.class));
}

@Test
public void badgeAction() {
assertTrue(Action.class.isAssignableFrom(BadgeAction.class));
assertTrue(AbstractAction.class.isAssignableFrom(BadgeAction.class));

assertTrue(BuildBadgeAction.class.isAssignableFrom(BadgeAction.class));
assertTrue(BuildBadgeAction.class.isAssignableFrom(BadgeAction.class));
}

@Test
public void htmlBadgeAction() {
assertTrue(Action.class.isAssignableFrom(HtmlBadgeAction.class));
assertTrue(AbstractAction.class.isAssignableFrom(HtmlBadgeAction.class));

assertTrue(BuildBadgeAction.class.isAssignableFrom(HtmlBadgeAction.class));
assertTrue(BuildBadgeAction.class.isAssignableFrom(HtmlBadgeAction.class));
}

}

0 comments on commit 7df10d4

Please sign in to comment.