Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-12753] Added PluginStrategy.getShortName to avoid actu…
…ally trying to unpack a plugin before throwing RestartRequiredException.
- Loading branch information
Showing
6 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
import java.util.List; | ||
import java.util.Vector; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.JarFile; | ||
import java.util.jar.Manifest; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
@@ -92,15 +93,26 @@ public ClassicPluginStrategy(PluginManager pluginManager) { | |
this.pluginManager = pluginManager; | ||
} | ||
|
||
public PluginWrapper createPluginWrapper(File archive) throws IOException { | ||
final Manifest manifest; | ||
URL baseResourceURL; | ||
@Override public String getShortName(File archive) throws IOException { | ||
Manifest manifest; | ||
if (isLinked(archive)) { | ||
manifest = loadLinkedManifest(archive); | ||
} else { | ||
JarFile jf = new JarFile(archive, false); | ||
try { | ||
manifest = jf.getManifest(); | ||
} finally { | ||
jf.close(); | ||
} | ||
} | ||
return PluginWrapper.computeShortName(manifest, archive); | ||
} | ||
|
||
File expandDir = null; | ||
// if .hpi, this is the directory where war is expanded | ||
private static boolean isLinked(File archive) { | ||
return archive.getName().endsWith(".hpl") || archive.getName().endsWith(".jpl"); | ||
} | ||
|
||
boolean isLinked = archive.getName().endsWith(".hpl") || archive.getName().endsWith(".jpl"); | ||
if (isLinked) { | ||
private static Manifest loadLinkedManifest(File archive) throws IOException { | ||
// resolve the .hpl file to the location of the manifest file | ||
final String firstLine = IOUtils.readFirstLine(new FileInputStream(archive), "UTF-8"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (firstLine.startsWith("Manifest-Version:")) { | ||
This comment has been minimized.
Sorry, something went wrong.
oleg-nenashev
Member
|
||
|
@@ -112,12 +124,24 @@ public PluginWrapper createPluginWrapper(File archive) throws IOException { | |
// then parse manifest | ||
FileInputStream in = new FileInputStream(archive); | ||
try { | ||
manifest = new Manifest(in); | ||
return new Manifest(in); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to load " + archive, e); | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
|
||
@Override public PluginWrapper createPluginWrapper(File archive) throws IOException { | ||
final Manifest manifest; | ||
URL baseResourceURL; | ||
|
||
File expandDir = null; | ||
// if .hpi, this is the directory where war is expanded | ||
|
||
boolean isLinked = isLinked(archive); | ||
if (isLinked) { | ||
manifest = loadLinkedManifest(archive); | ||
} else { | ||
if (archive.isDirectory()) {// already expanded | ||
expandDir = archive; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There're complains from Coverity (not related to the commit):
CID 1219446 (#1 of 1): Resource leak (RESOURCE_LEAK)3. leaked_resource: Failing to save or close resource created by new java.io.FileInputStream(archive) leaks it