Skip to content
Permalink
Browse files

[JENKINS-34287,JENKINS-23232] Update the component towards 1.34 (#7)

* Update to the latest Parent POM and Java 7

* FindBugs: Propagate issues with file deletion

* Pick parent POM 1.37 with Java 7 support

* FindBugs: Fix resource leak when exception happens during the dependency list read

* Downgrade the code to Java 6

* Downgrade back to Java 1.3

* Address comment from @rsandell. Just in case
  • Loading branch information...
oleg-nenashev committed Sep 25, 2016
1 parent 5a5f013 commit b12662aed40ee06a75c03a51a6fc87a75c642179
Showing with 45 additions and 28 deletions.
  1. +6 −14 pom.xml
  2. +39 −14 src/main/java/Main.java
20 pom.xml
@@ -2,26 +2,18 @@
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.18</version>
<version>1.37</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.jenkins-ci</groupId>
<artifactId>executable-war</artifactId>
<name>Executable War 'header'</name>
<version>1.34-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- to report user friendly error with older JVMs, this module should be compiled with 1.3 -->
<source>1.3</source>
<target>1.3</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<java.level>3</java.level>
</properties>

<scm>
<connection>scm:git:git://github.com/jenkinsci/extras-executable-war.git</connection>
@@ -33,7 +25,7 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

@@ -39,6 +39,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@@ -49,6 +50,8 @@
import java.util.UUID;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipFile;

/**
@@ -58,18 +61,36 @@
* @author Kohsuke Kawaguchi
*/
public class Main {

private static final String DEPENDENCIES_LIST = "WEB-INF/classes/dependencies.txt";

private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

/**
* Reads <tt>WEB-INF/classes/dependencies.txt and builds "groupId:artifactId" -> "version" map.
*/
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")));
String line;
while ((line=in.readLine())!=null) {
line = line.trim();
String[] tokens = line.split(":");
if (tokens.length!=5) continue; // there should be 5 tuples group:artifact:type:version:scope
r.put(tokens[0]+":"+tokens[1],tokens[3]);

final InputStream dependenciesInputStream = Main.class.getResourceAsStream(DEPENDENCIES_LIST);
if (dependenciesInputStream == null) {
throw new IOException("Cannot find resource " + DEPENDENCIES_LIST);
}
final Map/*<String,String>*/ r = new HashMap/*<String,String>*/();
try {
final BufferedReader in = new BufferedReader(new InputStreamReader(dependenciesInputStream));
try {
String line;
while ((line=in.readLine())!=null) {
line = line.trim();
String[] tokens = line.split(":");
if (tokens.length!=5) continue; // there should be 5 tuples group:artifact:type:version:scope
r.put(tokens[0]+":"+tokens[1],tokens[3]);
}
} finally {
in.close();
}
} finally {
dependenciesInputStream.close();
}
return r;
}
@@ -193,9 +214,11 @@ private static void _main(String[] args) throws Exception {
// 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();

deleteWinstoneTempContents(new File(tempFile.getParent(), "winstone/" + me.getName()));
if (!tempFile.delete()) {
LOGGER.log(Level.WARNING, "Failed to delete the temporary file {0}", tempFile);
}

// locate the Winstone launcher
ClassLoader cl = new URLClassLoader(new URL[]{tmpJar.toURI().toURL()});
Class launcher = cl.loadClass("winstone.Launcher");
@@ -361,15 +384,17 @@ private static File extractFromJar(String resource, String fileName, String suff
return tmp;
}

private static void deleteContents(File file) throws IOException {
private static void deleteWinstoneTempContents(File file) throws IOException {
if(file.isDirectory()) {
File[] files = file.listFiles();
if(files!=null) {// be defensive
for (int i = 0; i < files.length; i++)
deleteContents(files[i]);
deleteWinstoneTempContents(files[i]);
}
}
file.delete();
if (!file.delete()) {
LOGGER.log(Level.WARNING, "Failed to delete the temporary Winstone file {0}", file);
}
}

/** Add some metadata to a File, allowing to trace setup issues */

0 comments on commit b12662a

Please sign in to comment.
You can’t perform that action at this time.