diff --git a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ManifestLoader.java b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ManifestLoader.java index 2b97b3328e11a27165f6a7e5b5a0960ab45bdc93..ddc9b047415f692f0f459fe7b5d915379acde161 100644 --- a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ManifestLoader.java +++ b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ManifestLoader.java @@ -19,13 +19,18 @@ * @author gregd */ public class ManifestLoader { + private static final String JAR_MANIFEST_REL_PATH = "META-INF/MANIFEST.MF"; public static Attributes loadInputStream(InputStream is) throws IOException { - Manifest manifest = new Manifest(is); + Manifest manifest = loadManifest(is); return manifest.getMainAttributes(); } + public static Manifest loadManifest(InputStream is) throws IOException { + return new Manifest(is); + } + public static Attributes loadFromJar(File jarFile) throws IOException { ZipFile zipFile = new ZipFile(jarFile); diff --git a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ModuleUpdates.java b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ModuleUpdates.java index d990167c96f2745a750397190e5d321bce686560..dcd69abba70316d236099315b8cd7a4886aa3237 100644 --- a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ModuleUpdates.java +++ b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/ModuleUpdates.java @@ -14,6 +14,7 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.jar.Attributes; +import java.util.jar.Manifest; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; @@ -45,6 +46,7 @@ public class ModuleUpdates { private static final Logger LOGGER = Logger.getLogger(ModuleUpdates.class.getName()); + static { LOGGER.addHandler(new StreamHandler(System.out, new SimpleFormatter())); } @@ -181,8 +183,9 @@ static void setVersions(File srcDir, Map<String, ModuleVersionNumbers> versNums) String moduleName = moduleNameDir.getKey(); File moduleDir = moduleNameDir.getValue(); ModuleVersionNumbers thisVersNums = versNums.get(moduleName); - + try { + LOGGER.log(Level.INFO, "Updating for module name: " + moduleName); updateProjXml(moduleDir, versNums); if (thisVersNums != null) { @@ -224,22 +227,29 @@ private static void updateManifest(File moduleDir, ModuleVersionNumbers thisVers return; } - Attributes attributes; + Manifest manifest; try (FileInputStream manifestIs = new FileInputStream(manifestFile)) { - attributes = ManifestLoader.loadInputStream(manifestIs); + manifest = ManifestLoader.loadManifest(manifestIs); } + Attributes attributes = manifest.getMainAttributes(); - updateAttr(attributes, IMPL_KEY, Integer.toString(thisVersNums.getImplementation()), true); - updateAttr(attributes, SPEC_KEY, thisVersNums.getSpec().getSemVerStr(), true); - updateAttr(attributes, RELEASE_KEY, thisVersNums.getRelease().getFullReleaseStr(), true); + boolean updated = updateAttr(attributes, IMPL_KEY, Integer.toString(thisVersNums.getImplementation()), true); + updated = updateAttr(attributes, SPEC_KEY, thisVersNums.getSpec().getSemVerStr(), true) || updated; + updated = updateAttr(attributes, RELEASE_KEY, thisVersNums.getRelease().getFullReleaseStr(), true) || updated; + if (updated) { + try (FileOutputStream manifestOut = new FileOutputStream(manifestFile)) { + manifest.write(manifestOut); + } + } } - private static void updateAttr(Attributes attributes, String key, String val, boolean updateOnlyIfPresent) { + private static boolean updateAttr(Attributes attributes, String key, String val, boolean updateOnlyIfPresent) { if (updateOnlyIfPresent && attributes.getValue(key) == null) { - return; + return false; } attributes.putValue(key, val); + return true; } private static void updateProjXml(File moduleDir, Map<String, ModuleVersionNumbers> versNums) @@ -282,7 +292,6 @@ private static void updateProjXml(File moduleDir, Map<String, ModuleVersionNumbe // pretty print XML //transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - DOMSource source = new DOMSource(projectXmlDoc); try (FileOutputStream xmlOut = new FileOutputStream(projXmlFile)) { StreamResult result = new StreamResult(xmlOut);