Skip to content
Permalink
Browse files
[FIXED JENKINS-44884] Add @symbol annotations
  • Loading branch information
stephenc committed Jun 14, 2017
1 parent cec5622 commit d16e1eb8afcb159881fdc1a797e7d2d44e595bd4
@@ -84,6 +84,12 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.8-20170614.081136-1</version> <!-- TODO remove SNAPSHOT before release -->
<!-- require at least 1.8 as existing implementations that add support for traits will need JENKINS-44864 -->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -34,6 +34,7 @@
import java.util.List;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceObserver;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -77,6 +78,7 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
projectObserver.complete();
}

@Symbol("fromSource")
@Extension
public static class DescriptorImpl extends SCMNavigatorDescriptor {

@@ -44,6 +44,7 @@
import jenkins.scm.api.SCMSourceCriteria;
import jenkins.scm.api.SCMSourceDescriptor;
import jenkins.scm.api.SCMSourceOwner;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;

@@ -172,6 +173,7 @@ public int hashCode() {
/**
* Our descriptor.
*/
@Symbol("fromScm")
@Extension
@SuppressWarnings("unused") // instantiated by Jenkins
public static class DescriptorImpl extends SCMSourceDescriptor {
@@ -36,6 +36,7 @@
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -111,6 +112,7 @@ public boolean isExcluded(@NonNull SCMSource source, @NonNull SCMHead head) {
/**
* Our descriptor.
*/
@Symbol("headRegexFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
@@ -35,6 +35,7 @@
import jenkins.scm.api.trait.SCMNavigatorTrait;
import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor;
import jenkins.scm.api.trait.SCMSourcePrefilter;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -110,6 +111,7 @@ public boolean isExcluded(@NonNull SCMNavigator source, @NonNull String projectN
/**
* Our descriptor.
*/
@Symbol("sourceRegexFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMNavigatorTraitDescriptor {
@@ -35,6 +35,7 @@
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

/**
@@ -129,6 +130,7 @@ private String getPattern(String branches) {
/**
* Our descriptor.
*/
@Symbol("headsWildcardFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
@@ -33,6 +33,7 @@
import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor;
import jenkins.scm.api.trait.SCMSourcePrefilter;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

/**
@@ -127,6 +128,7 @@ private String getPattern(String branches) {
/**
* Our descriptor.
*/
@Symbol("sourceWildcardFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMNavigatorTraitDescriptor {
@@ -0,0 +1,166 @@
/*
* The MIT License
*
* Copyright (c) 2017 CloudBees, Inc.
*
* 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 jenkins.scm.impl;

import java.util.Arrays;
import java.util.Collections;
import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.mock.MockSCM;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMDiscoverChangeRequests;
import jenkins.scm.impl.mock.MockSCMDiscoverTags;
import jenkins.scm.impl.mock.MockSCMHead;
import jenkins.scm.impl.mock.MockSCMNavigator;
import jenkins.scm.impl.mock.MockSCMRevision;
import jenkins.scm.impl.mock.MockSCMSource;
import jenkins.scm.impl.trait.RegexSCMHeadFilterTrait;
import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait;
import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
import jenkins.scm.impl.trait.WildcardSCMSourceFilterTrait;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;

public class SymbolAnnotationsTest {
@ClassRule
public static JenkinsRule r = new JenkinsRule();

@Test
public void given__mockScm__when__uninstantiating__then__noRaw$class() throws Exception {
MockSCMController c = MockSCMController.create();
try {
c.createRepository("test");
MockSCM instance = new MockSCM(c, "test", new MockSCMHead("master"), new MockSCMRevision(
new MockSCMHead("master"), c.getRevision("test", "master")));
assertThat(DescribableModel.uninstantiate2_(instance).toString(), allOf(
startsWith("@"),
not(containsString(", $")),
not(containsString("=$")),
not(containsString("[$")),
not(containsString("{$"))
));
} finally {
c.close();
}
}

@Test
public void given__mockScmSource__when__uninstantiating__then__noRaw$class() throws Exception {
MockSCMController c = MockSCMController.create();
try {
c.createRepository("test");
MockSCMSource instance = new MockSCMSource(null, c, "test", new MockSCMDiscoverBranches(),
new MockSCMDiscoverChangeRequests(), new MockSCMDiscoverTags(),
new WildcardSCMHeadFilterTrait("*", "ignore"), new RegexSCMHeadFilterTrait("i.*"));
assertThat(DescribableModel.uninstantiate2_(instance).toString(), allOf(
startsWith("@"),
not(containsString(", $")),
not(containsString("=$")),
not(containsString("[$")),
not(containsString("{$"))
));
} finally {
c.close();
}
}

@Test
public void given__mockScmNavigator__when__uninstantiating__then__noRaw$class() throws Exception {
MockSCMController c = MockSCMController.create();
try {
c.createRepository("test");
MockSCMNavigator instance = new MockSCMNavigator(c,
new MockSCMDiscoverBranches(),
new MockSCMDiscoverChangeRequests(),
new MockSCMDiscoverTags(),
new WildcardSCMHeadFilterTrait("*", "ignore"),
new RegexSCMHeadFilterTrait("i.*"),
new WildcardSCMSourceFilterTrait("i*", "ignored"),
new RegexSCMSourceFilterTrait("ig.*")
);
assertThat(DescribableModel.uninstantiate2_(instance).toString(), allOf(
startsWith("@"),
not(containsString(", $")),
not(containsString("=$")),
not(containsString("[$")),
not(containsString("{$"))
));
} finally {
c.close();
}
}

@Test
public void given__singleScmNavigator__when__uninstantiating__then__noRaw$class() throws Exception {
MockSCMController c = MockSCMController.create();
try {
c.createRepository("test");
SingleSCMNavigator instance = new SingleSCMNavigator("foo",
Collections.<SCMSource>singletonList(new MockSCMSource(null, c, "test"))
);
assertThat(DescribableModel.uninstantiate2_(instance).toString(), allOf(
startsWith("@"),
not(containsString(", $")),
not(containsString("=$")),
not(containsString("[$")),
not(containsString("{$"))
));
} finally {
c.close();
}
}

@Test
public void given__singleScmSource__when__uninstantiating__then__noRaw$class() throws Exception {
MockSCMController c = MockSCMController.create();
try {
c.createRepository("test");
SingleSCMSource instance = new SingleSCMSource("foo", "foo", new MockSCM(c, "test",
new MockSCMHead("master"), new MockSCMRevision(
new MockSCMHead("master"), c.getRevision("test", "master")))
);
assertThat(DescribableModel.uninstantiate2_(instance).toString(), allOf(
startsWith("@"),
not(containsString(", $")),
not(containsString("=$")),
not(containsString("[$")),
not(containsString("{$"))
));
} finally {
c.close();
}
}

}
@@ -59,6 +59,7 @@
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.util.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.xml.sax.SAXException;
@@ -283,6 +284,7 @@ public MockSCMRevision getRevision() {
}
}

@Symbol("mockScm")
@Extension
public static class DescriptorImpl extends SCMDescriptor<MockSCM> {

@@ -31,6 +31,7 @@
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MockSCMDiscoverBranches extends SCMSourceTrait {
@@ -49,6 +50,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category.isUncategorized();
}

@Symbol("discoverBranches")
@Extension
public static final class DescriptorImpl extends SCMSourceTraitDescriptor {

@@ -38,6 +38,7 @@
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import jenkins.scm.impl.ChangeRequestSCMHeadCategory;
import org.codehaus.plexus.util.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MockSCMDiscoverChangeRequests extends SCMSourceTrait {
@@ -91,6 +92,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category instanceof ChangeRequestSCMHeadCategory;
}

@Symbol("discoverChangeRequests")
@Extension
public static final class DescriptorImpl extends SCMSourceTraitDescriptor {

@@ -32,6 +32,7 @@
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import jenkins.scm.impl.TagSCMHeadCategory;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MockSCMDiscoverTags extends SCMSourceTrait {
@@ -50,6 +51,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category instanceof TagSCMHeadCategory;
}

@Symbol("discoverTags")
@Extension
public static final class DescriptorImpl extends SCMSourceTraitDescriptor {

@@ -49,6 +49,7 @@
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMTrait;
import jenkins.scm.api.trait.SCMTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class MockSCMNavigator extends SCMNavigator {
@@ -150,6 +151,7 @@ public SCMSource create(@NonNull String name) {
return result;
}

@Symbol("mockScm")
@Extension
public static class DescriptorImpl extends SCMNavigatorDescriptor {

@@ -62,6 +62,7 @@
import jenkins.scm.impl.TagSCMHeadCategory;
import jenkins.scm.impl.UncategorizedSCMHeadCategory;
import org.apache.commons.io.IOUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

@@ -315,6 +316,7 @@ protected boolean isCategoryEnabled(@NonNull SCMHeadCategory category) {
return false;
}

@Symbol("mockScm")
@Extension
public static class DescriptorImpl extends SCMSourceDescriptor {
@Nonnull

0 comments on commit d16e1eb

Please sign in to comment.