Skip to content
This repository was archived by the owner on Aug 3, 2019. It is now read-only.

Commit c18e52b

Browse files
authored
Merge pull request #7 from casz/jcasc
[JENKINS-57886] Modernize and add JCasC
2 parents 991daf7 + 8ac811d commit c18e52b

File tree

15 files changed

+252
-107
lines changed

15 files changed

+252
-107
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.mvn/checkstyle.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
3+
<module name="Checker">
4+
<module name="FileTabCharacter" />
5+
<module name="NewlineAtEndOfFile">
6+
<property name="lineSeparator" value="lf" />
7+
</module>
8+
<module name="RegexpSingleline">
9+
<property name="format" value="\s+$"/>
10+
<property name="message" value="Trailing spaces are not allowed."/>
11+
</module>
12+
<module name="TreeWalker">
13+
<module name="ImportOrder">
14+
<property name="separatedStaticGroups" value="true" />
15+
<property name="option" value="bottom" />
16+
</module>
17+
<module name="UnusedImports" />
18+
<module name="AvoidStarImport" />
19+
</module>
20+
</module>

.mvn/extensions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
2+
<extension>
3+
<groupId>io.jenkins.tools.incrementals</groupId>
4+
<artifactId>git-changelist-maven-extension</artifactId>
5+
<version>1.0-beta-7</version>
6+
</extension>
7+
</extensions>

.mvn/maven.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-Pconsume-incrementals
2+
-Pmight-produce-incrementals

.travis.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
language: java
2+
3+
dist: xenial
4+
5+
before_cache:
6+
- rm -rf $HOME/.m2/repository/io/jenkins/plugins/gitlab-branch-source*
7+
8+
cache:
9+
directories:
10+
- $HOME/.m2
11+
12+
env:
13+
global:
14+
- JAVA_LEVEL=8
15+
16+
matrix:
17+
include:
18+
- jdk: openjdk11
19+
env:
20+
- MVN_FLAG='-Djenkins.version=2.164.1 -Daccess-modifier-checker.failOnError=true'
21+
- jdk: openjdk8
22+
env:
23+
- MVN_FLAG='-Djenkins.version=2.164.1 -Daccess-modifier-checker.failOnError=true'
24+
- jdk: openjdk8
25+
26+
install:
27+
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V $MVN_FLAG -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
28+
29+
script:
30+
- |
31+
mvn clean install -B \
32+
-Djava.level=$JAVA_LEVEL \
33+
$MVN_FLAG -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
34+
35+
notifications:
36+
email: false

Jenkinsfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!groovy
2+
3+
// Use recommended configuration
4+
buildPlugin(configurations: buildPlugin.recommendedConfigurations())

pom.xml

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>3.4</version>
7+
<version>3.43</version>
88
<relativePath />
99
</parent>
1010
<groupId>io.jenkins.plugins</groupId>
1111
<artifactId>gitlab-branch-source</artifactId>
12-
<version>0.0.1.-SNAPSHOT</version>
12+
<version>${revision}${changelist}</version>
1313
<packaging>hpi</packaging>
1414
<properties>
15+
<revision>0.0.1.</revision>
16+
<changelist>-SNAPSHOT</changelist>
1517
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
16-
<jenkins.version>2.60.3</jenkins.version>
18+
<jenkins.version>2.138.4</jenkins.version>
1719
<java.level>8</java.level>
1820
<!-- Other properties you may want to use:
1921
~ jenkins-test-harness.version: Jenkins Test Harness version you use to test the plugin. For Jenkins version >= 1.580.1 use JTH 2.0 or higher.
2022
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
2123
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
2224
-->
25+
<jcasc.version>1.19</jcasc.version>
2326
</properties>
2427
<name>GitLab Branch Source Plugin</name>
2528
<description>GitLab Provides branch source and folder organisation functionality for GitLab Repositories in Jenkins Source Plugin</description>
@@ -44,7 +47,7 @@
4447
<dependency>
4548
<groupId>org.jenkins-ci.plugins</groupId>
4649
<artifactId>credentials</artifactId>
47-
<version>2.1.18</version>
50+
<version>2.2.0</version>
4851
</dependency>
4952
<dependency>
5053
<groupId>org.jenkins-ci.plugins</groupId>
@@ -75,6 +78,19 @@
7578
</exclusion>
7679
</exclusions>
7780
</dependency>
81+
<dependency>
82+
<groupId>io.jenkins</groupId>
83+
<artifactId>configuration-as-code</artifactId>
84+
<version>${jcasc.version}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>io.jenkins</groupId>
89+
<artifactId>configuration-as-code</artifactId>
90+
<version>${jcasc.version}</version>
91+
<classifier>tests</classifier>
92+
<scope>test</scope>
93+
</dependency>
7894
</dependencies>
7995

8096
<developers>
@@ -121,63 +137,44 @@
121137
</scm>
122138

123139
<build>
140+
<pluginManagement>
141+
<plugins>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-checkstyle-plugin</artifactId>
145+
<version>3.0.0</version>
146+
<dependencies>
147+
<dependency>
148+
<groupId>com.puppycrawl.tools</groupId>
149+
<artifactId>checkstyle</artifactId>
150+
<version>8.17</version>
151+
</dependency>
152+
</dependencies>
153+
</plugin>
154+
</plugins>
155+
</pluginManagement>
124156
<plugins>
125157
<plugin>
126-
<groupId>org.apache.maven.plugins</groupId>
127-
<artifactId>maven-enforcer-plugin</artifactId>
128-
<version>3.0.0-M1</version>
129-
<executions>
130-
<execution>
131-
<id>enforce-bytecode-version</id>
132-
<goals>
133-
<goal>enforce</goal>
134-
</goals>
135-
<configuration>
136-
<rules>
137-
<enforceBytecodeVersion>
138-
<maxJdkVersion>1.8</maxJdkVersion>
139-
<ignoreClasses>
140-
<ignoreClass>module-info</ignoreClass>
141-
</ignoreClasses>
142-
</enforceBytecodeVersion>
143-
</rules>
144-
</configuration>
145-
</execution>
146-
</executions>
147-
<dependencies>
148-
<dependency>
149-
<groupId>org.codehaus.mojo</groupId>
150-
<artifactId>extra-enforcer-rules</artifactId>
151-
<version>1.0-beta-9</version>
152-
</dependency>
153-
</dependencies>
154-
</plugin>
155-
<plugin>
156-
<groupId>org.apache.maven.plugins</groupId>
157-
<artifactId>maven-source-plugin</artifactId>
158-
<version>3.0.1</version>
158+
<artifactId>maven-checkstyle-plugin</artifactId>
159+
<configuration>
160+
<configLocation>${project.basedir}/.mvn/checkstyle.xml</configLocation>
161+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
162+
<sourceDirectories>
163+
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
164+
</sourceDirectories>
165+
<testSourceDirectories>
166+
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
167+
</testSourceDirectories>
168+
</configuration>
159169
<executions>
160170
<execution>
161-
<id>attach-sources</id>
162-
<phase>package</phase>
163171
<goals>
164-
<goal>jar-no-fork</goal>
172+
<goal>check</goal>
165173
</goals>
166174
</execution>
167175
</executions>
168176
</plugin>
169177
</plugins>
170-
171-
<pluginManagement>
172-
<plugins>
173-
<plugin>
174-
<groupId>org.codehaus.mojo</groupId>
175-
<artifactId>animal-sniffer-maven-plugin</artifactId>
176-
<version>1.17</version>
177-
</plugin>
178-
</plugins>
179-
</pluginManagement>
180-
181178
</build>
182179
<repositories>
183180
<repository>

src/main/java/io/jenkins/plugins/gitlabserver/credentials/PersonalAccessTokenImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import hudson.util.Secret;
1212
import jenkins.model.Jenkins;
1313
import org.apache.commons.lang.StringUtils;
14+
import org.jenkinsci.Symbol;
1415
import org.kohsuke.accmod.Restricted;
1516
import org.kohsuke.accmod.restrictions.NoExternalUse;
1617
import org.kohsuke.stapler.DataBoundConstructor;
@@ -60,9 +61,10 @@ public Secret getToken() {
6061
* Our descriptor.
6162
*/
6263
@Extension
64+
@Symbol("gitlabPersonalAccessToken")
6365
public static class DescriptorImpl extends CredentialsDescriptor {
6466

65-
private int GITLAB_ACCESS_TOKEN_LENGTH = 20;
67+
private static final int GITLAB_ACCESS_TOKEN_LENGTH = 20;
6668

6769
/**
6870
* {@inheritDoc}

src/main/java/io/jenkins/plugins/gitlabserver/servers/GitLabServer.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import hudson.util.FormValidation;
1616
import hudson.util.ListBoxModel;
1717
import io.jenkins.plugins.gitlabserver.credentials.PersonalAccessToken;
18+
import java.net.MalformedURLException;
19+
import java.net.URL;
1820
import jenkins.model.Jenkins;
1921
import jenkins.scm.api.SCMName;
2022
import org.apache.commons.lang.RandomStringUtils;
@@ -32,10 +34,6 @@
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
3436

35-
import javax.annotation.Nonnull;
36-
import java.net.MalformedURLException;
37-
import java.net.URL;
38-
3937
import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
4038
import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
4139
import static org.apache.commons.lang.StringUtils.defaultIfBlank;
@@ -76,13 +74,13 @@ public class GitLabServer extends AbstractDescribableImpl<GitLabServer> {
7674
/**
7775
* A unique name used to identify the endpoint.
7876
*/
79-
@Nonnull
77+
@NonNull
8078
private String name;
8179

8280
/**
8381
* The URL of this GitLab Server.
8482
*/
85-
@Nonnull
83+
@NonNull
8684
private final String serverUrl;
8785

8886
/**
@@ -109,7 +107,7 @@ private String getRandomName() {
109107
/**
110108
* {@inheritDoc}
111109
*/
112-
@Nonnull
110+
@NonNull
113111
public String getName() {
114112
return name;
115113
}
@@ -146,20 +144,13 @@ public String getCredentialsId() {
146144
/**
147145
* Data Bound Constructor for only mandatory parameter serverUrl
148146
*
149-
* @param serverUrl The URL of this GitLab Server
147+
* @param serverUrl The URL of this GitLab Server
148+
* @param name A unique name to use to describe the end-point, if empty replaced with a random
149+
* name
150150
*/
151151
@DataBoundConstructor
152-
public GitLabServer(@NonNull String serverUrl) {
152+
public GitLabServer(@NonNull String serverUrl, @NonNull String name) {
153153
this.serverUrl = defaultIfBlank(serverUrl, GITLAB_SERVER_URL);
154-
}
155-
156-
/**
157-
* Data Bound Setter for Server Name
158-
*
159-
* @param name A unique name to use to describe the end-point, if empty replaced with a random name
160-
*/
161-
@DataBoundSetter
162-
public void setName(@Nonnull String name) {
163154
this.name = StringUtils.isBlank(name)
164155
? getRandomName()
165156
: name;
@@ -197,7 +188,7 @@ public UsernamePasswordCredentials credentials() {
197188
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull(
198189
lookupCredentials(
199190
UsernamePasswordCredentials.class,
200-
Jenkins.getActiveInstance(),
191+
Jenkins.get(),
201192
ACL.SYSTEM,
202193
fromUri(serverUrl).build()),
203194
CredentialsMatchers.withId(credentialsId)
@@ -225,7 +216,7 @@ public static class DescriptorImpl extends Descriptor<GitLabServer> {
225216
* @return the validation results.
226217
*/
227218
public static FormValidation doCheckServerUrl(@QueryParameter String value) {
228-
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
219+
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
229220
try {
230221
new URL(value);
231222
} catch (MalformedURLException e) {
@@ -281,25 +272,28 @@ public FormValidation doTestConnection(@QueryParameter String serverUrl,
281272
@SuppressWarnings("unused")
282273
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl,
283274
@QueryParameter String credentialsId) {
284-
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
275+
Jenkins jenkins = Jenkins.get();
276+
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
285277
return new StandardListBoxModel().includeCurrentValue(credentialsId);
286278
}
287279
return new StandardListBoxModel()
288280
.includeEmptyValue()
289281
.includeMatchingAs(ACL.SYSTEM,
290-
Jenkins.getInstance(),
282+
jenkins,
291283
StandardCredentials.class,
292284
fromUri(serverUrl).build(),
293285
credentials -> credentials instanceof PersonalAccessToken);
294286
}
295287

296288
private static String getToken(String serverUrl, String credentialsId) {
297289
String privateToken = UNKNOWN_TOKEN;
298-
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
290+
Jenkins jenkins = Jenkins.get();
291+
jenkins.checkPermission(Jenkins.ADMINISTER);
292+
299293
PersonalAccessToken credentials = CredentialsMatchers.firstOrNull(
300294
lookupCredentials(
301295
PersonalAccessToken.class,
302-
Jenkins.getActiveInstance(),
296+
jenkins,
303297
ACL.SYSTEM,
304298
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()),
305299
CredentialsMatchers.withId(credentialsId)

0 commit comments

Comments
 (0)