Skip to content
Permalink
Browse files

[JENKINS-42549] - Prevent collision of files when reading them in par…

…allel
  • Loading branch information...
oleg-nenashev committed Jul 3, 2017
1 parent e579f8a commit 626ddba71616fd1b10a66e627140c754dd6be443
Showing with 11 additions and 23 deletions.
  1. +11 −23 src/main/java/hudson/maven/MavenEmbedderUtils.java
@@ -198,8 +198,6 @@ public static MavenInformation getMavenVersion(@Nonnull File mavenHome) throws M
debugMavenVersion(realm);
}
ClassLoader original = Thread.currentThread().getContextClassLoader();
InputStream inputStream = null;
JarFile jarFile = null;
MavenInformation information = null;
try {
Thread.currentThread().setContextClassLoader( realm );
@@ -210,31 +208,21 @@ public static MavenInformation getMavenVersion(@Nonnull File mavenHome) throws M
+ "'. Are you sure that this is a valid maven home?");
}
URLConnection uc = resource.openConnection();
if (uc instanceof JarURLConnection) {
final JarURLConnection connection = (JarURLConnection)uc;
final String entryName = connection.getEntryName();
try {
jarFile = connection.getJarFile();
final JarEntry entry = (entryName != null && jarFile != null) ? jarFile.getJarEntry(entryName) : null;
if (entry != null) {
inputStream = jarFile.getInputStream(entry);
if (preopertiesPreloadHook != null) {
preopertiesPreloadHook.call();
}
Properties properties = new Properties();
properties.load( inputStream );
information = new MavenInformation( properties.getProperty( "version" ) , resource.toExternalForm() );
}
} finally {
if (jarFile != null) {
jarFile.close();
}
uc.setUseCaches(false);
InputStream istream = uc.getInputStream();
try {
if (preopertiesPreloadHook != null) {
preopertiesPreloadHook.call();
}
}
Properties properties = new Properties();
properties.load( istream );
information = new MavenInformation( properties.getProperty( "version" ) , resource.toExternalForm() );
} finally {
istream.close();
}
} catch ( IOException e ) {
throw new MavenEmbedderException( e.getMessage(), e );
} finally {
IOUtil.close( inputStream );
Thread.currentThread().setContextClassLoader( original );
}

0 comments on commit 626ddba

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