[jenkins-executable-war] Work with exploded WAR
Michal Srb
msrb at fedoraproject.org
Sat Sep 27 18:47:03 UTC 2014
commit e70c4a99cea1605913886e93ace99fd907150505
Author: Michal Srb <msrb at redhat.com>
Date: Mon Sep 22 15:02:27 2014 +0200
Work with exploded WAR
0001-Work-with-exploded-WAR.patch | 123 +++++++++++++++++++++++++++++++++++++
jenkins-executable-war.spec | 9 +++-
2 files changed, 131 insertions(+), 1 deletions(-)
---
diff --git a/0001-Work-with-exploded-WAR.patch b/0001-Work-with-exploded-WAR.patch
new file mode 100644
index 0000000..fa03baa
--- /dev/null
+++ b/0001-Work-with-exploded-WAR.patch
@@ -0,0 +1,123 @@
+From 0a2883604711163c585318b8d0bdb54dc74d505a Mon Sep 17 00:00:00 2001
+From: Michal Srb <msrb at redhat.com>
+Date: Mon, 15 Sep 2014 13:31:02 +0200
+Subject: [PATCH] Work with exploded WAR
+
+---
+ src/main/java/Main.java | 37 ++++++++++++++++---------------------
+ 1 file changed, 16 insertions(+), 21 deletions(-)
+
+diff --git a/src/main/java/Main.java b/src/main/java/Main.java
+index 3b49cf3..45dcca6 100644
+--- a/src/main/java/Main.java
++++ b/src/main/java/Main.java
+@@ -25,7 +25,9 @@
+ import javax.naming.InitialContext;
+ import javax.naming.NamingException;
+ import javax.naming.Context;
++
+ import java.io.File;
++import java.io.FileInputStream;
+ import java.io.FileOutputStream;
+ import java.io.IOException;
+ import java.io.InputStream;
+@@ -58,6 +60,9 @@ import java.util.zip.ZipFile;
+ * @author Kohsuke Kawaguchi
+ */
+ public class Main {
++
++ private static File extractedFilesFolder;
++
+ private static boolean hasLogOption(String[] args) {
+ for (int i = 0; i < args.length; i++)
+ if(args[i].startsWith("--logfile="))
+@@ -70,7 +75,7 @@ public class Main {
+ */
+ private static Map/*<String,String>*/ parseDependencyVersions() throws IOException {
+ Map r = new HashMap();
+- BufferedReader in = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("WEB-INF/classes/dependencies.txt")));
++ BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(extractedFilesFolder + "/WEB-INF/classes/dependencies.txt")));
+ String line;
+ while ((line=in.readLine())!=null) {
+ line = line.trim();
+@@ -78,6 +83,7 @@ public class Main {
+ if (tokens.length!=5) continue; // there should be 5 tuples group:artifact:type:version:scope
+ r.put(tokens[0]+":"+tokens[1],tokens[3]);
+ }
++ in.close();
+ return r;
+ }
+
+@@ -104,7 +110,7 @@ public class Main {
+ }
+
+ private static void _main(String[] args) throws Exception {
+- File extractedFilesFolder = null;
++ extractedFilesFolder = null;
+ for (int i = 0; i < args.length; i++) {
+ if(args[i].startsWith("--extractedFilesFolder=")) {
+ extractedFilesFolder = new File(args[i].substring("--extractedFilesFolder=".length()));
+@@ -122,8 +128,8 @@ public class Main {
+
+ // load the daemonization code
+ ClassLoader cl = new URLClassLoader(new URL[]{
+- extractFromJar("WEB-INF/lib/jna-"+getVersion(revisions, "net.java.dev.jna", "jna") +".jar","jna","jar", extractedFilesFolder).toURI().toURL(),
+- extractFromJar("WEB-INF/lib/akuma-"+getVersion(revisions,"org.kohsuke","akuma")+".jar","akuma","jar", extractedFilesFolder).toURI().toURL(),
++ new File(extractedFilesFolder, "WEB-INF/lib/jna-"+getVersion(revisions, "net.java.dev.jna", "jna") +".jar").toURI().toURL(),
++ new File(extractedFilesFolder, "WEB-INF/lib/akuma-"+getVersion(revisions,"org.kohsuke","akuma")+".jar").toURI().toURL(),
+ });
+ Class $daemon = cl.loadClass("com.sun.akuma.Daemon");
+ Object daemon = $daemon.newInstance();
+@@ -165,14 +171,13 @@ public class Main {
+ if(System.getProperty("hudson.diyChunking")==null)
+ System.setProperty("hudson.diyChunking","true");
+
+- File me = whoAmI(extractedFilesFolder);
+- System.out.println("Running from: " + me);
+- System.setProperty("executable-war",me.getAbsolutePath()); // remember the location so that we can access it from within webapp
++ //File me = whoAmI(extractedFilesFolder);
++ //System.out.println("Running from: " + me);
++ //System.setProperty("executable-war",me.getAbsolutePath()); // remember the location so that we can access it from within webapp
+
+ // figure out the arguments
+ List arguments = new ArrayList(Arrays.asList(args));
+ trimOffOurOptions(arguments);
+- arguments.add(0,"--warfile="+ me.getAbsolutePath());
+ if(!hasWebRoot(arguments)) {
+ // defaults to ~/.jenkins/war since many users reported that cron job attempts to clean up
+ // the contents in the temporary directory.
+@@ -186,18 +191,10 @@ public class Main {
+ return;
+ }
+
+- // put winstone jar in a file system so that we can load jars from there
+- File tmpJar = extractFromJar("winstone.jar","winstone",".jar", extractedFilesFolder);
+-
+- // clean up any previously extracted copy, since
+- // winstone doesn't do so and that causes problems when newer version of Jenkins
+- // is deployed.
+- File tempFile = File.createTempFile("dummy", "dummy");
+- deleteContents(new File(tempFile.getParent(), "winstone/" + me.getName()));
+- tempFile.delete();
++ File winstoneJar = new File(extractedFilesFolder, "winstone.jar");
+
+ // locate the Winstone launcher
+- ClassLoader cl = new URLClassLoader(new URL[]{tmpJar.toURI().toURL()});
++ ClassLoader cl = new URLClassLoader(new URL[]{winstoneJar.toURI().toURL()});
+ Class launcher = cl.loadClass("winstone.Launcher");
+ Method mainMethod = launcher.getMethod("main", new Class[]{String[].class});
+
+@@ -383,9 +380,7 @@ public class Main {
+ * Extract a resource from jar, mark it for deletion upon exit, and return its location.
+ */
+ private static File extractFromJar(String resource, String fileName, String suffix, File directory) throws IOException {
+- URL res = Main.class.getResource(resource);
+- if (res==null)
+- throw new IOException("Unable to find the resource: "+resource);
++ URL res = new URL("file://" + resource);
+
+ // put this jar in a file system so that we can load jars from there
+ File tmp;
+--
+1.9.3
+
diff --git a/jenkins-executable-war.spec b/jenkins-executable-war.spec
index c5239bd..2ad68d8 100644
--- a/jenkins-executable-war.spec
+++ b/jenkins-executable-war.spec
@@ -3,7 +3,7 @@
Name: jenkins-executable-war
Version: 1.29
-Release: 2%{?dist}
+Release: 3%{?dist}
Summary: Jenkins Executable War
# License is specified in pom.xml
@@ -13,6 +13,8 @@ Source0: https://github.com/jenkinsci/%{mod_name}/archive/%{short_name}-%
# Text copied from http://www.opensource.org/licenses/mit-license.php
Source1: LICENSE.txt
+Patch0: 0001-Work-with-exploded-WAR.patch
+
BuildRequires: maven-local
BuildArch: noarch
@@ -29,6 +31,8 @@ This package contains the API documentation for %{name}.
%prep
%setup -q -n %{mod_name}-%{short_name}-%{version}
+%patch0 -p1
+
cp %{SOURCE1} .
# there is a licensing issue with parent POM
@@ -52,6 +56,9 @@ cp %{SOURCE1} .
%doc LICENSE.txt
%changelog
+* Mon Sep 22 2014 Michal Srb <msrb at redhat.com> - 1.29-3
+- Work with exploded WAR
+
* Sun Jun 08 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.29-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild
More information about the scm-commits
mailing list