Skip to content
Permalink
Browse files

Merge pull request #174 from daspilker/JENKINS-45860

[JENKINS-45860] added a workaround for JENKINS-26535
  • Loading branch information
rsandell committed Apr 17, 2018
2 parents 66373c2 + 745dfbf commit 2aaa13771c05c784bfff060856ed6c4d055bf6f1
@@ -45,6 +45,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
@@ -317,9 +318,11 @@ public String getRepoOwner() {
*
* @param traits the new behavioural traits.
*/
@SuppressWarnings("unchecked")
@DataBoundSetter
public void setTraits(@CheckForNull List<SCMTrait<? extends SCMTrait<?>>> traits) {
this.traits = traits != null ? new ArrayList<>(traits) : new ArrayList<SCMTrait<? extends SCMTrait<?>>>();
public void setTraits(@CheckForNull List<SCMTrait> traits) {
// the reduced generics in the method signature are a workaround for JENKINS-26535
this.traits = traits != null ? new ArrayList<>((Collection) traits) : new ArrayList<SCMTrait<? extends SCMTrait<?>>>();
}

/**
@@ -1283,10 +1286,11 @@ public String getIconClassName() {
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public SCMNavigator newInstance(String name) {
GitHubSCMNavigator navigator = new GitHubSCMNavigator(name);
navigator.setTraits(getTraitsDefaults());
navigator.setTraits((List) getTraitsDefaults());
return navigator;
}

@@ -1632,14 +1632,14 @@ public void given__legacyCode__when__constructor_server__then__discoveryTraitDef
@Test
public void given__instance__when__setTraits_empty__then__traitsEmpty() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Collections.<SCMTrait<?>>emptyList());
instance.setTraits(Collections.<SCMTrait>emptyList());
assertThat(instance.getTraits(), is(Collections.<SCMTrait<?>>emptyList()));
}

@Test
public void given__instance__when__setTraits__then__traitsSet() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.<SCMTrait<?>>asList(new BranchDiscoveryTrait(1),
instance.setTraits(Arrays.<SCMTrait>asList(new BranchDiscoveryTrait(1),
new SSHCheckoutTrait(null)));
assertThat(instance.getTraits(),
containsInAnyOrder(
@@ -1701,7 +1701,7 @@ public void given__instance__when__setApiUri_cloudUrl__then__valueApplied() {
@Test
public void given__legacyCode__when__setPattern_default__then__patternSetAndTraitRemoved() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(true, false), new RegexSCMSourceFilterTrait("job.*"),
instance.setTraits(Arrays.<SCMTrait>asList(new BranchDiscoveryTrait(true, false), new RegexSCMSourceFilterTrait("job.*"),
new SSHCheckoutTrait("dummy")));
assertThat(instance.getPattern(), is("job.*"));
assertThat(instance.getTraits(), Matchers.<SCMTrait<?>>hasItem(instanceOf(RegexSCMSourceFilterTrait.class)));
@@ -1716,7 +1716,7 @@ public void given__legacyCode__when__setPattern_default__then__patternSetAndTrai
public void given__legacyCode__when__setPattern_custom__then__patternSetAndTraitAdded() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(
Arrays.<SCMTrait<?>>asList(new BranchDiscoveryTrait(true, false), new SSHCheckoutTrait("dummy")));
Arrays.<SCMTrait>asList(new BranchDiscoveryTrait(true, false), new SSHCheckoutTrait("dummy")));
assertThat(instance.getPattern(), is(".*"));
assertThat(instance.getTraits(),
not(Matchers.<SCMTrait<?>>hasItem(instanceOf(RegexSCMSourceFilterTrait.class))));
@@ -1730,7 +1730,7 @@ public void given__legacyCode__when__setPattern_custom__then__patternSetAndTrait
@Test
public void given__legacyCode__when__setPattern_custom__then__patternSetAndTraitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(true, false), new RegexSCMSourceFilterTrait("job.*"),
instance.setTraits(Arrays.<SCMTrait>asList(new BranchDiscoveryTrait(true, false), new RegexSCMSourceFilterTrait("job.*"),
new SSHCheckoutTrait("dummy")));
assertThat(instance.getPattern(), is("job.*"));
assertThat(instance.getTraits(), Matchers.<SCMTrait<?>>hasItem(instanceOf(RegexSCMSourceFilterTrait.class)));
@@ -1784,7 +1784,7 @@ public void given__legacyCode__when__checkoutCredentials_ANONYMOUS__then__traitA
@Test
public void given__legacyCode_withoutExcludes__when__setIncludes_default__then__traitRemoved() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "")
@@ -1807,7 +1807,7 @@ public void given__legacyCode_withoutExcludes__when__setIncludes_default__then__
@Test
public void given__legacyCode_withoutExcludes__when__setIncludes_value__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "")
@@ -1832,7 +1832,7 @@ public void given__legacyCode_withoutExcludes__when__setIncludes_value__then__tr
@Test
public void given__legacyCode_withoutTrait__when__setIncludes_value__then__traitAdded() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*")
));
@@ -1854,7 +1854,7 @@ public void given__legacyCode_withoutTrait__when__setIncludes_value__then__trait
@Test
public void given__legacyCode_withExcludes__when__setIncludes_default__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "feature/ignore")
@@ -1879,7 +1879,7 @@ public void given__legacyCode_withExcludes__when__setIncludes_default__then__tra
@Test
public void given__legacyCode_withExcludes__when__setIncludes_value__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "feature/ignore")
@@ -1904,7 +1904,7 @@ public void given__legacyCode_withExcludes__when__setIncludes_value__then__trait
@Test
public void given__legacyCode_withoutIncludes__when__setExcludes_default__then__traitRemoved() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("*", "feature/ignore")
@@ -1927,7 +1927,7 @@ public void given__legacyCode_withoutIncludes__when__setExcludes_default__then__
@Test
public void given__legacyCode_withoutIncludes__when__setExcludes_value__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("*", "feature/ignore")
@@ -1952,7 +1952,7 @@ public void given__legacyCode_withoutIncludes__when__setExcludes_value__then__tr
@Test
public void given__legacyCode_withoutTrait__when__setExcludes_value__then__traitAdded() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*")
));
@@ -1974,7 +1974,7 @@ public void given__legacyCode_withoutTrait__when__setExcludes_value__then__trait
@Test
public void given__legacyCode_withIncludes__when__setExcludes_default__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "feature/ignore")
@@ -1999,7 +1999,7 @@ public void given__legacyCode_withIncludes__when__setExcludes_default__then__tra
@Test
public void given__legacyCode_withIncludes__when__setExcludes_value__then__traitUpdated() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(
instance.setTraits(Arrays.<SCMTrait>asList(
new BranchDiscoveryTrait(true, false),
new RegexSCMSourceFilterTrait("job.*"),
new WildcardSCMHeadFilterTrait("feature/*", "")
@@ -2024,7 +2024,7 @@ public void given__legacyCode_withIncludes__when__setExcludes_value__then__trait
@Test
public void given__legacyCode__when__setBuildOriginBranch__then__traitsMaintained() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Collections.<SCMTrait<?>>emptyList());
instance.setTraits(Collections.<SCMTrait>emptyList());
assertThat(instance.getTraits(), is(Collections.<SCMTrait<?>>emptyList()));
instance.setBuildOriginBranch(true);
assertThat(instance.getTraits(), contains(instanceOf(BranchDiscoveryTrait.class)));

0 comments on commit 2aaa137

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