Skip to content

Commit 2940b8a

Browse files
committed
Initial Commit
0 parents  commit 2940b8a

File tree

13 files changed

+1093
-0
lines changed

13 files changed

+1093
-0
lines changed

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Maven build files
2+
target/
3+
4+
# Jenkins plugin development
5+
work/
6+
7+
# IntelliJ project files
8+
*.iml
9+
*.ipr
10+
*.iws
11+
.idea/
12+
13+
# Eclipse project files
14+
.settings/
15+
.classpath
16+
.project
17+
.metadata
18+
.loadpath

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 CloudBees, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

pom.xml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ The MIT License
4+
~
5+
~ Copyright (c) 2016, CloudBees, Inc.
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in
15+
~ all copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
~ THE SOFTWARE.
24+
-->
25+
26+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<groupId>org.jenkins-ci.plugins</groupId>
31+
<artifactId>plugin</artifactId>
32+
<version>2.11</version>
33+
</parent>
34+
35+
<artifactId>pipeline-maven</artifactId>
36+
<version>0.1</version>
37+
<packaging>hpi</packaging>
38+
39+
<name>Pipeline Maven Integration Plugin</name>
40+
<description>
41+
This plugin provides integration with Pipeline, configures maven environment to use within a pipeline job by calling sh mvn or bat mvn.
42+
The selected maven installation will be configured and prepended to the path.
43+
</description>
44+
<url></url>
45+
<licenses>
46+
<license>
47+
<name>The MIT license</name>
48+
<url>http://www.opensource.org/licenses/mit-license.php</url>
49+
<distribution>repo</distribution>
50+
</license>
51+
</licenses>
52+
53+
<developers>
54+
<developer>
55+
<id>alvarolobato</id>
56+
<name>Alvaro Lobato</name>
57+
<email>[email protected]</email>
58+
</developer>
59+
</developers>
60+
61+
<scm>
62+
<connection>scm:git:git://github.com/jenkinsci/pipeline-maven-plugin.git</connection>
63+
<developerConnection>scm:git:[email protected]:jenkinsci/pipeline-maven-plugin.git</developerConnection>
64+
<url>https://github.com/jenkinsci/pipeline-maven-plugin</url>
65+
</scm>
66+
67+
<properties>
68+
<jenkins.version>1.642.4</jenkins.version>
69+
</properties>
70+
71+
<repositories>
72+
<repository>
73+
<id>repo.jenkins-ci.org</id>
74+
<url>https://repo.jenkins-ci.org/public/</url>
75+
</repository>
76+
</repositories>
77+
78+
<pluginRepositories>
79+
<pluginRepository>
80+
<id>repo.jenkins-ci.org</id>
81+
<url>https://repo.jenkins-ci.org/public/</url>
82+
</pluginRepository>
83+
</pluginRepositories>
84+
85+
<dependencies>
86+
<dependency>
87+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
88+
<artifactId>workflow-step-api</artifactId>
89+
<version>2.2</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.jenkins-ci.plugins</groupId>
93+
<artifactId>config-file-provider</artifactId>
94+
<version>2.11</version>
95+
</dependency>
96+
</dependencies>
97+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2016, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package org.jenkinsci.plugins.pipeline.maven;
26+
27+
import org.jenkinsci.lib.configprovider.ConfigProvider;
28+
import org.jenkinsci.lib.configprovider.model.Config;
29+
import org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig.MavenSettingsConfigProvider;
30+
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
31+
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
32+
import org.kohsuke.stapler.DataBoundConstructor;
33+
import org.kohsuke.stapler.DataBoundSetter;
34+
35+
import hudson.Extension;
36+
import hudson.ExtensionList;
37+
import hudson.model.JDK;
38+
import hudson.tasks.Maven;
39+
import hudson.tasks.Maven.MavenInstallation;
40+
import hudson.util.ListBoxModel;
41+
import jenkins.model.Jenkins;
42+
import jenkins.mvn.GlobalMavenConfig;
43+
import jenkins.mvn.SettingsProvider;
44+
45+
/**
46+
* Configures maven environment to use within a pipeline job by calling <tt>sh mvn</tt> or <tt>bat mvn</tt>.
47+
* The selected maven installation will be configured and prepended to the path.
48+
*
49+
*/
50+
public class WithMavenStep extends AbstractStepImpl {
51+
52+
53+
private String mavenSettingsConfig;
54+
private String mavenSettingsFilePath;
55+
private String mavenInstallation;
56+
private String mavenOpts;
57+
private String jdk;
58+
private String mavenLocalRepo;
59+
60+
@DataBoundConstructor
61+
public WithMavenStep() {
62+
}
63+
64+
65+
public String getMavenSettingsConfig() {
66+
return mavenSettingsConfig;
67+
}
68+
69+
@DataBoundSetter
70+
public void setMavenSettingsConfig(String mavenSettingsConfig) {
71+
this.mavenSettingsConfig = mavenSettingsConfig;
72+
}
73+
74+
public String getMavenSettingsFilePath() {
75+
return mavenSettingsFilePath;
76+
}
77+
78+
@DataBoundSetter
79+
public void setMavenSettingsFilePath(String mavenSettingsFilePath) {
80+
this.mavenSettingsFilePath = mavenSettingsFilePath;
81+
}
82+
83+
public String getMavenInstallation() {
84+
return mavenInstallation;
85+
}
86+
87+
@DataBoundSetter
88+
public void setMavenInstallation(String mavenInstallation) {
89+
this.mavenInstallation = mavenInstallation;
90+
}
91+
92+
public String getMavenOpts() {
93+
return mavenOpts;
94+
}
95+
96+
@DataBoundSetter
97+
public void setMavenOpts(String mavenOpts) {
98+
this.mavenOpts = mavenOpts;
99+
}
100+
101+
public String getJdk() {
102+
return jdk;
103+
}
104+
105+
@DataBoundSetter
106+
public void setJdk(String jdk) {
107+
this.jdk = jdk;
108+
}
109+
110+
public String getMavenLocalRepo() {
111+
return mavenLocalRepo;
112+
}
113+
114+
@DataBoundSetter
115+
public void setMavenLocalRepo(String mavenLocalRepo) {
116+
this.mavenLocalRepo = mavenLocalRepo;
117+
}
118+
119+
@Extension
120+
public static class DescriptorImpl extends AbstractStepDescriptorImpl {
121+
122+
public DescriptorImpl() {
123+
super(WithMavenStepExecution.class);
124+
}
125+
126+
@Override
127+
public String getFunctionName() {
128+
return "withMaven";
129+
}
130+
131+
@Override
132+
public String getDisplayName() {
133+
return "Provide Maven environment";
134+
}
135+
136+
@Override
137+
public boolean takesImplicitBlockArgument() {
138+
return true;
139+
}
140+
141+
public SettingsProvider getDefaultSettingsProvider() {
142+
return GlobalMavenConfig.get().getSettingsProvider();
143+
}
144+
145+
private Maven.DescriptorImpl getMavenDescriptor() {
146+
return Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class);
147+
}
148+
149+
public ListBoxModel doFillMavenInstallationItems() {
150+
ListBoxModel r = new ListBoxModel();
151+
r.add("--- Use system default Maven ---",null);
152+
for (MavenInstallation installation : getMavenDescriptor().getInstallations()) {
153+
r.add(installation.getName());
154+
}
155+
return r;
156+
}
157+
158+
private JDK.DescriptorImpl getJDKDescriptor() {
159+
return Jenkins.getInstance().getDescriptorByType(JDK.DescriptorImpl.class);
160+
}
161+
162+
public ListBoxModel doFillJdkItems() {
163+
ListBoxModel r = new ListBoxModel();
164+
r.add("--- Use system default JDK ---",null);
165+
for (JDK installation : getJDKDescriptor().getInstallations()) {
166+
r.add(installation.getName());
167+
}
168+
return r;
169+
}
170+
171+
public ListBoxModel doFillMavenSettingsConfigItems() {
172+
ExtensionList<MavenSettingsConfigProvider> providers = Jenkins.getInstance().getExtensionList(MavenSettingsConfigProvider.class);
173+
ListBoxModel r = new ListBoxModel();
174+
r.add("--- Use system default settings or file path ---",null);
175+
for (ConfigProvider provider : providers) {
176+
for(Config config:provider.getAllConfigs()){
177+
r.add(config.name, config.id);
178+
}
179+
}
180+
return r;
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)