Skip to content
This repository was archived by the owner on Aug 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
20 changes: 20 additions & 0 deletions .mvn/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="FileTabCharacter" />
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf" />
</module>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="Trailing spaces are not allowed."/>
</module>
<module name="TreeWalker">
<module name="ImportOrder">
<property name="separatedStaticGroups" value="true" />
<property name="option" value="bottom" />
</module>
<module name="UnusedImports" />
<module name="AvoidStarImport" />
</module>
</module>
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
language: java

dist: xenial

before_cache:
- rm -rf $HOME/.m2/repository/io/jenkins/plugins/gitlab-branch-source*

cache:
directories:
- $HOME/.m2

env:
global:
- JAVA_LEVEL=8

matrix:
include:
- jdk: openjdk11
env:
- MVN_FLAG='-Djenkins.version=2.164.1 -Daccess-modifier-checker.failOnError=true'
- jdk: openjdk8
env:
- MVN_FLAG='-Djenkins.version=2.164.1 -Daccess-modifier-checker.failOnError=true'
- jdk: openjdk8

install:
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V $MVN_FLAG -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

script:
- |
mvn clean install -B \
-Djava.level=$JAVA_LEVEL \
$MVN_FLAG -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

notifications:
email: false
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!groovy

// Use recommended configuration
buildPlugin(configurations: buildPlugin.recommendedConfigurations())
99 changes: 48 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.4</version>
<version>3.43</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>gitlab-branch-source</artifactId>
<version>0.0.1.-SNAPSHOT</version>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>
<properties>
<revision>0.0.1.</revision>
<changelist>-SNAPSHOT</changelist>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.60.3</jenkins.version>
<jenkins.version>2.138.4</jenkins.version>
<java.level>8</java.level>
<!-- Other properties you may want to use:
~ 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.
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->
<jcasc.version>1.19</jcasc.version>
</properties>
<name>GitLab Branch Source Plugin</name>
<description>GitLab Provides branch source and folder organisation functionality for GitLab Repositories in Jenkins Source Plugin</description>
Expand All @@ -44,7 +47,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.1.18</version>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -75,6 +78,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${jcasc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${jcasc.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<developers>
Expand Down Expand Up @@ -121,63 +137,44 @@
</scm>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.17</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<ignoreClasses>
<ignoreClass>module-info</ignoreClass>
</ignoreClasses>
</enforceBytecodeVersion>
</rules>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.0-beta-9</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/.mvn/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
</sourceDirectories>
<testSourceDirectories>
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</testSourceDirectories>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
</plugin>
</plugins>
</pluginManagement>

</build>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -60,9 +61,10 @@ public Secret getToken() {
* Our descriptor.
*/
@Extension
@Symbol("gitlabPersonalAccessToken")
public static class DescriptorImpl extends CredentialsDescriptor {

private int GITLAB_ACCESS_TOKEN_LENGTH = 20;
private static final int GITLAB_ACCESS_TOKEN_LENGTH = 20;

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import io.jenkins.plugins.gitlabserver.credentials.PersonalAccessToken;
import java.net.MalformedURLException;
import java.net.URL;
import jenkins.model.Jenkins;
import jenkins.scm.api.SCMName;
import org.apache.commons.lang.RandomStringUtils;
Expand All @@ -32,10 +34,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.net.MalformedURLException;
import java.net.URL;

import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
import static com.cloudbees.plugins.credentials.domains.URIRequirementBuilder.fromUri;
import static org.apache.commons.lang.StringUtils.defaultIfBlank;
Expand Down Expand Up @@ -76,13 +74,13 @@ public class GitLabServer extends AbstractDescribableImpl<GitLabServer> {
/**
* A unique name used to identify the endpoint.
*/
@Nonnull
@NonNull
private String name;

/**
* The URL of this GitLab Server.
*/
@Nonnull
@NonNull
private final String serverUrl;

/**
Expand All @@ -109,7 +107,7 @@ private String getRandomName() {
/**
* {@inheritDoc}
*/
@Nonnull
@NonNull
public String getName() {
return name;
}
Expand Down Expand Up @@ -146,20 +144,13 @@ public String getCredentialsId() {
/**
* Data Bound Constructor for only mandatory parameter serverUrl
*
* @param serverUrl The URL of this GitLab Server
* @param serverUrl The URL of this GitLab Server
* @param name A unique name to use to describe the end-point, if empty replaced with a random
* name
*/
@DataBoundConstructor
public GitLabServer(@NonNull String serverUrl) {
public GitLabServer(@NonNull String serverUrl, @NonNull String name) {
this.serverUrl = defaultIfBlank(serverUrl, GITLAB_SERVER_URL);
}

/**
* Data Bound Setter for Server Name
*
* @param name A unique name to use to describe the end-point, if empty replaced with a random name
*/
@DataBoundSetter
public void setName(@Nonnull String name) {
this.name = StringUtils.isBlank(name)
? getRandomName()
: name;
Expand Down Expand Up @@ -197,7 +188,7 @@ public UsernamePasswordCredentials credentials() {
return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull(
lookupCredentials(
UsernamePasswordCredentials.class,
Jenkins.getActiveInstance(),
Jenkins.get(),
ACL.SYSTEM,
fromUri(serverUrl).build()),
CredentialsMatchers.withId(credentialsId)
Expand Down Expand Up @@ -225,7 +216,7 @@ public static class DescriptorImpl extends Descriptor<GitLabServer> {
* @return the validation results.
*/
public static FormValidation doCheckServerUrl(@QueryParameter String value) {
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
try {
new URL(value);
} catch (MalformedURLException e) {
Expand Down Expand Up @@ -281,25 +272,28 @@ public FormValidation doTestConnection(@QueryParameter String serverUrl,
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl,
@QueryParameter String credentialsId) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
Jenkins jenkins = Jenkins.get();
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
return new StandardListBoxModel()
.includeEmptyValue()
.includeMatchingAs(ACL.SYSTEM,
Jenkins.getInstance(),
jenkins,
StandardCredentials.class,
fromUri(serverUrl).build(),
credentials -> credentials instanceof PersonalAccessToken);
}

private static String getToken(String serverUrl, String credentialsId) {
String privateToken = UNKNOWN_TOKEN;
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);

PersonalAccessToken credentials = CredentialsMatchers.firstOrNull(
lookupCredentials(
PersonalAccessToken.class,
Jenkins.getActiveInstance(),
jenkins,
ACL.SYSTEM,
fromUri(defaultIfBlank(serverUrl, GITLAB_SERVER_URL)).build()),
CredentialsMatchers.withId(credentialsId)
Expand Down
Loading