Skip to content

Commit 29faef3

Browse files
committed
[refactor] Refactored Java and Scala parts into seperate Maven Modules to avoid Scala compilation clash with Jenkins approach to resource package naming for Jelly resources
1 parent 046936f commit 29faef3

File tree

29 files changed

+401
-233
lines changed

29 files changed

+401
-233
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
*.class
2-
*.log
3-
41
# sbt specific
52
dist/*
63
target/

jenkins-scala-plugin-executer/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2013, Adam Retter <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
Redistributions in binary form must reproduce the above copyright notice, this
11+
list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
14+
Neither the name of the {organization} nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

jenkins-scala-plugin-executer/pom.xml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.jenkins-ci.plugins</groupId>
9+
<artifactId>jenkins-scala-plugin-parent</artifactId>
10+
<version>1.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>jenkins-scala-plugin-executer</artifactId>
14+
<version>1.1-SNAPSHOT</version>
15+
<packaging>jar</packaging>
16+
<name>Jenkins Scala Plugin Executers</name>
17+
18+
<scm>
19+
<connection>scm:git:https://github.com/adamretter/jenkins-scala-plugin.git</connection>
20+
<developerConnection>scm:git:https://[email protected]/adamretter/jenkins-scala-plugin.git</developerConnection>
21+
<url>https://github.com/adamretter/ijenkins-scala-plugin</url>
22+
</scm>
23+
24+
<build>
25+
26+
<plugins>
27+
<plugin>
28+
<groupId>net.alchim31.maven</groupId>
29+
<artifactId>scala-maven-plugin</artifactId>
30+
<configuration>
31+
<recompileMode>incremental</recompileMode> <!-- NOTE: incremental compilation although faster requires passing to MAVEN_OPTS="-XX:MaxPermSize=128m" -->
32+
<useZincServer>true</useZincServer> <!-- NOTE: if you have Zinc server installed and running, you can get faster compilation by enabling this -->
33+
<!-- addScalacArgs>-feature</addScalacArgs -->
34+
<args>
35+
<arg>-Yresolve-term-conflict:object</arg> <!-- required for package/object name conflict in Jenkins jar -->
36+
</args>
37+
<javacArgs>
38+
<javacArg>-Xlint:unchecked</javacArg>
39+
<javacArg>-Xlint:deprecation</javacArg>
40+
</javacArgs>
41+
</configuration>
42+
<executions>
43+
<execution>
44+
<id>scala-compile-first</id>
45+
<phase>process-resources</phase>
46+
<goals>
47+
<goal>add-source</goal>
48+
<goal>compile</goal>
49+
</goals>
50+
</execution>
51+
<execution>
52+
<id>scala-test-compile</id>
53+
<phase>process-test-resources</phase>
54+
<goals>
55+
<goal>testCompile</goal>
56+
</goals>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<configuration>
64+
<source>${project.build.source.version}</source>
65+
<target>${project.build.target.version}</target>
66+
<encoding>${project.build.source.encoding}</encoding>
67+
</configuration>
68+
<executions>
69+
<execution>
70+
<phase>compile</phase>
71+
<goals>
72+
<goal>compile</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<groupId>com.mmakowski</groupId>
79+
<artifactId>maven-specs2-plugin</artifactId>
80+
<executions>
81+
<execution>
82+
<id>verify</id>
83+
<phase>verify</phase>
84+
<goals>
85+
<goal>run-specs</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
<dependencies>
94+
<dependency>
95+
<groupId>org.scala-lang</groupId>
96+
<artifactId>scala-library</artifactId>
97+
</dependency>
98+
99+
<dependency>
100+
<groupId>org.scala-lang</groupId>
101+
<artifactId>scala-compiler</artifactId>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>com.github.scala-incubator.io</groupId>
106+
<artifactId>scala-io-file_2.10</artifactId>
107+
<version>0.4.2</version>
108+
</dependency>
109+
110+
<dependency>
111+
<groupId>org.specs2</groupId>
112+
<artifactId>specs2_2.10</artifactId>
113+
<version>1.14</version>
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
117+
118+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) 2013, Adam Retter <[email protected]>
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice, this
12+
* list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* Neither the name of the {organization} nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package hudson.plugins.scala.executer
31+
32+
import hudson.model.{BuildListener, AbstractBuild}
33+
import hudson.{EnvVars, FilePath, Launcher}
34+
35+
class ForkedScalaExecutor {
36+
37+
def execute(build: AbstractBuild[_, _], launcher: Launcher, listener: BuildListener, scalaHome: String, scalaExecutable: String, script: FilePath, scalaParameters: String, classpath: String, scriptParameters: String, debug: Boolean, suspend: Boolean, jdwpPort: Integer) : Boolean = {
38+
39+
/**
40+
* Strings that come in from java may be null or empty
41+
* but to us the effect is the same, we are only interested
42+
* in strings with content
43+
*/
44+
def nonEmptyString(javaString: String) : Option[String] = {
45+
if(javaString == null || javaString.isEmpty) {
46+
None
47+
} else {
48+
Some(javaString)
49+
}
50+
}
51+
52+
//TODO add checkbox options for "-nocompdaemon" and "-savecompiled" make nocompdaemon on by default
53+
def scalaCmdParameters : Option[String] = Some(("-nocompdaemon" :: nonEmptyString(scalaParameters).toList).mkString(" ").trim())
54+
55+
def javaDebugParameters : Option[String] = {
56+
def booleanToChar(boolean: Boolean) = if(boolean) 'y' else 'n'
57+
debug match {
58+
case true => Some(s"-J-debug -J-Xrunjdwp:transport=dt_socket,server=y,suspend=${booleanToChar(suspend)},address=$jdwpPort")
59+
case false => None
60+
}
61+
}
62+
63+
def scalaClassPathParameter : Option[String] = nonEmptyString(classpath).map(cl => "-cp " + cl)
64+
65+
def execCommand(script: FilePath) : String = {
66+
val cmdParts: List[Option[String]] = List(nonEmptyString(scalaExecutable), scalaCmdParameters, javaDebugParameters, scalaClassPathParameter, nonEmptyString(script.getRemote), nonEmptyString(scriptParameters))
67+
cmdParts.flatten.mkString(" ")
68+
}
69+
70+
def executeScript(env: EnvVars, workspace: FilePath, script: FilePath) : Boolean = {
71+
val cmd = execCommand(script)
72+
//val shell = new Shell(scala_launch_cmd)
73+
listener.getLogger().println("Scala command is: " + cmd)
74+
75+
val result = launcher.launch().cmdAsSingleString(cmd).envs(env).stdout(listener).pwd(workspace).join()
76+
//val result = launcher.launch().cmds(cmd).envs(env).stdout(listener).pwd(workspace).join()
77+
//shell.perform(build, launcher, listener);
78+
result == 0
79+
}
80+
81+
val env = build.getEnvironment(listener)
82+
nonEmptyString(scalaHome) match {
83+
case Some(scalaHome) => {
84+
env.put("SCALA_HOME", scalaHome)
85+
listener.getLogger.println(s"Set SCALA_HOME=$scalaHome")
86+
}
87+
case None =>
88+
}
89+
90+
val workspace = build.getWorkspace()
91+
Option(script) match {
92+
case Some(script) => {
93+
executeScript(env, workspace, script)
94+
}
95+
case None => {
96+
listener.fatalError("Could not process Scala Script")
97+
false
98+
}
99+
}
100+
}
101+
}

jenkins-scala-plugin/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.class
2+
*.log
3+
4+
# sbt specific
5+
dist/*
6+
target/
7+
lib_managed/
8+
src_managed/
9+
project/boot/
10+
project/plugins/project/
11+
12+
# Scala-IDE specific
13+
.scala_dependencies
14+
.idea/*

jenkins-scala-plugin/LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2013, Adam Retter <[email protected]>
2+
All rights reserved.
3+
4+
This software includes code from: groovy-plugin https://github.com/jenkinsci/groovy-plugin,
5+
Copyright (c) <2007> <Red Hat, Inc.>.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
Redistributions in binary form must reproduce the above copyright notice, this
14+
list of conditions and the following disclaimer in the documentation and/or
15+
other materials provided with the distribution.
16+
17+
Neither the name of the {organization} nor the names of its
18+
contributors may be used to endorse or promote products derived from
19+
this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

jenkins-scala-plugin/pom.xml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.jenkins-ci.plugins</groupId>
9+
<artifactId>jenkins-scala-plugin-parent</artifactId>
10+
<version>1.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>jenkins-scala-plugin</artifactId>
14+
<packaging>hpi</packaging>
15+
<name>Jenkins Scala Plugin</name>
16+
17+
<scm>
18+
<connection>scm:git:https://github.com/adamretter/jenkins-scala-plugin.git</connection>
19+
<developerConnection>scm:git:https://[email protected]/adamretter/jenkins-scala-plugin.git</developerConnection>
20+
<url>https://github.com/adamretter/ijenkins-scala-plugin</url>
21+
</scm>
22+
23+
<build>
24+
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<configuration>
30+
<source>${project.build.source.version}</source>
31+
<target>${project.build.target.version}</target>
32+
<encoding>${project.build.source.encoding}</encoding>
33+
</configuration>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>${project.groupId}</groupId>
41+
<artifactId>jenkins-scala-plugin-executer</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
</dependencies>
45+
</project>

0 commit comments

Comments
 (0)