Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-44884] Add @symbol annotations
  • Loading branch information
stephenc committed Jun 14, 2017
1 parent cec5622 commit d16e1eb
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jenkins/scm/impl/SingleSCMNavigator.java
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,7 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
projectObserver.complete();
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jenkins/scm/impl/SingleSCMSource.java
Expand Up @@ -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;

Expand Down Expand Up @@ -172,6 +173,7 @@ public int hashCode() {
/**
* Our descriptor.
*/
@Symbol("fromScm")
@Extension
@SuppressWarnings("unused") // instantiated by Jenkins
public static class DescriptorImpl extends SCMSourceDescriptor {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -129,6 +130,7 @@ private String getPattern(String branches) {
/**
* Our descriptor.
*/
@Symbol("headsWildcardFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -127,6 +128,7 @@ private String getPattern(String branches) {
/**
* Our descriptor.
*/
@Symbol("sourceWildcardFilter")
@Extension
@Selection
public static class DescriptorImpl extends SCMNavigatorTraitDescriptor {
Expand Down
166 changes: 166 additions & 0 deletions src/test/java/jenkins/scm/impl/SymbolAnnotationsTest.java
@@ -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();
}
}

}
2 changes: 2 additions & 0 deletions src/test/java/jenkins/scm/impl/mock/MockSCM.java
Expand Up @@ -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;
Expand Down Expand Up @@ -283,6 +284,7 @@ public MockSCMRevision getRevision() {
}
}

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

Expand Down
Expand Up @@ -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 {
Expand All @@ -49,6 +50,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category.isUncategorized();
}

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

Expand Down
Expand Up @@ -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 {
Expand Down Expand Up @@ -91,6 +92,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category instanceof ChangeRequestSCMHeadCategory;
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverTags.java
Expand Up @@ -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 {
Expand All @@ -50,6 +51,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
return category instanceof TagSCMHeadCategory;
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/jenkins/scm/impl/mock/MockSCMNavigator.java
Expand Up @@ -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 {
Expand Down Expand Up @@ -150,6 +151,7 @@ public List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner,
return result;
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/jenkins/scm/impl/mock/MockSCMSource.java
Expand Up @@ -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;

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

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

0 comments on commit d16e1eb

Please sign in to comment.