|
14 | 14 | import java.security.NoSuchAlgorithmException;
|
15 | 15 | import java.util.List;
|
16 | 16 | import java.util.Map;
|
| 17 | +import java.util.jar.JarFile; |
| 18 | +import java.util.jar.Manifest; |
| 19 | +import java.util.zip.ZipEntry; |
| 20 | +import java.util.zip.ZipInputStream; |
17 | 21 |
|
18 | 22 | import oracle.weblogic.deploy.exception.ExceptionHelper;
|
19 | 23 | import oracle.weblogic.deploy.logging.PlatformLogger;
|
@@ -1083,6 +1087,48 @@ public String addNodeManagerKeyStoreFile(File keystoreFile) throws WLSDeployArch
|
1083 | 1087 | return newName;
|
1084 | 1088 | }
|
1085 | 1089 |
|
| 1090 | + /** |
| 1091 | + * Return the manifest for the specified path in the archive, if present. |
| 1092 | + * The path may refer to a packaged EAR/JAR/WAR, or an exploded entry. |
| 1093 | + * @param sourcePath the path to be checked |
| 1094 | + * @return the Manifest object, or null |
| 1095 | + * @throws WLSDeployArchiveIOException if there is a problem reading the archive, or the manifest |
| 1096 | + */ |
| 1097 | + public Manifest getManifest(String sourcePath) throws WLSDeployArchiveIOException { |
| 1098 | + try { |
| 1099 | + if(containsFile(sourcePath)) { |
| 1100 | + // a jarred app or library in the archive. |
| 1101 | + try(ZipInputStream zipStream = new ZipInputStream(getZipFile().getZipEntry(sourcePath))) { |
| 1102 | + // JarInputStream.getManifest() has problems if MANIFEST.MF is not the first entry, |
| 1103 | + // so use ZipInputStream and search for the specific entry. |
| 1104 | + ZipEntry zipEntry; |
| 1105 | + while((zipEntry = zipStream.getNextEntry()) != null) { |
| 1106 | + if(JarFile.MANIFEST_NAME.equals(zipEntry.getName())) { |
| 1107 | + Manifest manifest = new Manifest(zipStream); |
| 1108 | + zipStream.closeEntry(); |
| 1109 | + return manifest; |
| 1110 | + } |
| 1111 | + zipStream.closeEntry(); |
| 1112 | + } |
| 1113 | + } |
| 1114 | + } else if(containsPath(sourcePath)) { |
| 1115 | + // an exploded app or library in the archive. |
| 1116 | + String manifestPath = sourcePath + "/" + JarFile.MANIFEST_NAME; |
| 1117 | + if (containsFile(manifestPath)) { |
| 1118 | + try (InputStream inStream = getZipFile().getZipEntry(manifestPath)) { |
| 1119 | + return new Manifest(inStream); |
| 1120 | + } |
| 1121 | + } |
| 1122 | + } |
| 1123 | + } catch(IOException e) { |
| 1124 | + WLSDeployArchiveIOException aioe = new WLSDeployArchiveIOException("WLSDPLY-01426", sourcePath, |
| 1125 | + getArchiveFileName(), e.getLocalizedMessage()); |
| 1126 | + LOGGER.throwing(aioe); |
| 1127 | + throw aioe; |
| 1128 | + } |
| 1129 | + return null; |
| 1130 | + } |
| 1131 | + |
1086 | 1132 | /**
|
1087 | 1133 | * This method removes all binaries from the archive. This method is intended to
|
1088 | 1134 | * be invoked by discovery to remove binaries from a previous run that might
|
|
0 commit comments