Skip to content

Commit a21b403

Browse files
committed
#121 - Introduce Jenkins.
1 parent 0d5f508 commit a21b403

File tree

8 files changed

+717
-0
lines changed

8 files changed

+717
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
import java.net.*;
21+
import java.io.*;
22+
import java.nio.channels.*;
23+
import java.util.Properties;
24+
25+
public class MavenWrapperDownloader {
26+
27+
/**
28+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
29+
*/
30+
private static final String DEFAULT_DOWNLOAD_URL =
31+
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
32+
33+
/**
34+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
35+
* use instead of the default one.
36+
*/
37+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
38+
".mvn/wrapper/maven-wrapper.properties";
39+
40+
/**
41+
* Path where the maven-wrapper.jar will be saved to.
42+
*/
43+
private static final String MAVEN_WRAPPER_JAR_PATH =
44+
".mvn/wrapper/maven-wrapper.jar";
45+
46+
/**
47+
* Name of the property which should be used to override the default download url for the wrapper.
48+
*/
49+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
50+
51+
public static void main(String args[]) {
52+
System.out.println("- Downloader started");
53+
File baseDirectory = new File(args[0]);
54+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
55+
56+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
57+
// wrapperUrl parameter.
58+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
59+
String url = DEFAULT_DOWNLOAD_URL;
60+
if(mavenWrapperPropertyFile.exists()) {
61+
FileInputStream mavenWrapperPropertyFileInputStream = null;
62+
try {
63+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64+
Properties mavenWrapperProperties = new Properties();
65+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
67+
} catch (IOException e) {
68+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69+
} finally {
70+
try {
71+
if(mavenWrapperPropertyFileInputStream != null) {
72+
mavenWrapperPropertyFileInputStream.close();
73+
}
74+
} catch (IOException e) {
75+
// Ignore ...
76+
}
77+
}
78+
}
79+
System.out.println("- Downloading from: : " + url);
80+
81+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
82+
if(!outputFile.getParentFile().exists()) {
83+
if(!outputFile.getParentFile().mkdirs()) {
84+
System.out.println(
85+
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
86+
}
87+
}
88+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
89+
try {
90+
downloadFileFromURL(url, outputFile);
91+
System.out.println("Done");
92+
System.exit(0);
93+
} catch (Throwable e) {
94+
System.out.println("- Error downloading");
95+
e.printStackTrace();
96+
System.exit(1);
97+
}
98+
}
99+
100+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
101+
URL website = new URL(urlString);
102+
ReadableByteChannel rbc;
103+
rbc = Channels.newChannel(website.openStream());
104+
FileOutputStream fos = new FileOutputStream(destination);
105+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
106+
fos.close();
107+
rbc.close();
108+
}
109+
110+
}

.mvn/wrapper/maven-wrapper.jar

47.2 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip

Jenkinsfile

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
pipeline {
2+
agent none
3+
4+
triggers {
5+
pollSCM 'H/10 * * * *'
6+
upstream(upstreamProjects: "spring-data-commons/master", threshold: hudson.model.Result.SUCCESS)
7+
}
8+
9+
options {
10+
disableConcurrentBuilds()
11+
}
12+
13+
stages {
14+
stage("Test") {
15+
parallel {
16+
stage("test: baseline") {
17+
agent {
18+
docker {
19+
image 'adoptopenjdk/openjdk8:latest'
20+
args '-u root -v /var/run/docker.sock:/var/run/docker.sock' // root but with no maven caching
21+
}
22+
}
23+
steps {
24+
sh "./mvnw -Pci,all-dbs clean dependency:list test -Dsort -Dbundlor.enabled=false -B"
25+
sh "chown -R 1001:1001 target"
26+
}
27+
}
28+
}
29+
}
30+
31+
stage('Release to artifactory') {
32+
when {
33+
branch 'issue/*'
34+
}
35+
agent {
36+
docker {
37+
label 'data'
38+
image 'adoptopenjdk/openjdk8:latest'
39+
args '-v $HOME/.m2:/root/.m2'
40+
}
41+
}
42+
43+
environment {
44+
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
45+
}
46+
47+
steps {
48+
sh "./mvnw -Pci,snapshot deploy -Dmaven.test.skip=true -B"
49+
}
50+
}
51+
52+
stage('Release to artifactory with docs') {
53+
when {
54+
branch 'master'
55+
}
56+
agent {
57+
docker {
58+
label 'data'
59+
image 'adoptopenjdk/openjdk8:latest'
60+
args '-v $HOME/.m2:/root/.m2'
61+
}
62+
}
63+
64+
environment {
65+
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
66+
}
67+
68+
steps {
69+
sh "./mvnw -Pci,snapshot deploy -Dmaven.test.skip=true -B"
70+
}
71+
}
72+
}
73+
74+
post {
75+
changed {
76+
script {
77+
slackSend(
78+
color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger',
79+
channel: '#spring-data-dev',
80+
message: "${currentBuild.fullDisplayName} - `${currentBuild.currentResult}`\n${env.BUILD_URL}")
81+
emailext(
82+
subject: "[${currentBuild.fullDisplayName}] ${currentBuild.currentResult}",
83+
mimeType: 'text/html',
84+
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']],
85+
body: "<a href=\"${env.BUILD_URL}\">${currentBuild.fullDisplayName} is reported as ${currentBuild.currentResult}</a>")
86+
}
87+
}
88+
}
89+
}

README.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
image:https://spring.io/badges/spring-data-r2dbc/snapshot.svg["Spring Data R2DBC", link="https://spring.io/projects/spring-data-r2dbc#learn"]
2+
3+
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-r2dbc%2Fmaster&subject=master["Spring Data R2DBC", link="https://jenkins.spring.io/view/SpringData/job/spring-data-r2dbc/"]
4+
15
= Spring Data R2DBC
26

37
The primary goal of the https://projects.spring.io/spring-data[Spring Data] project is to make it easier to build Spring-powered applications that use data access technologies. *Spring Data R2DBC* offers the popular Repository abstraction based on https://r2dbc.io[R2DBC].
@@ -184,6 +188,32 @@ If you want to build with the regular `mvn` command, you will need https://maven
184188

185189
_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests, and in particular please fill out the https://cla.pivotal.io/[Contributor's Agreement] before your first change._
186190

191+
== Running CI tasks locally
192+
193+
Since this pipeline is purely Docker-based, it's easy to:
194+
195+
* Debug what went wrong on your local machine.
196+
* Test out a a tweak to your `test.sh` script before sending it out.
197+
* Experiment against a new image before submitting your pull request.
198+
199+
All of these use cases are great reasons to essentially run what the CI server does on your local machine.
200+
201+
IMPORTANT: To do this you must have Docker installed on your machine.
202+
203+
1. `docker run -it --mount type=bind,source="$(pwd)",target=/spring-data-r2dbc-github -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock adoptopenjdk/openjdk8:latest /bin/bash`
204+
+
205+
This will launch the Docker image and mount your source code at `spring-data-r2dbc-github`.
206+
+
207+
2. `cd spring-data-r2dbc-github`
208+
+
209+
Next, test everything from inside the container:
210+
+
211+
3. `./mvnw -Pci,all-dbs clean dependency:list test -Dsort -B` (or whatever test configuration you must use)
212+
213+
Since the container is binding to your source, you can make edits from your IDE and continue to run build jobs.
214+
215+
NOTE: Docker containers can eat up disk space fast! From time to time, run `docker system prune` to clean out old images.
216+
187217
== Contributing to Spring Data R2DBC
188218

189219
Here are some ways for you to get involved in the community:

0 commit comments

Comments
 (0)