Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 626ddba
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/main/java/hudson/maven/MavenEmbedderUtils.java
Expand Up @@ -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 );
Expand All @@ -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 );
}

Expand Down

0 comments on commit 626ddba

Please sign in to comment.