From 00e03e7520b0aad94c6fb8488e1389bd1e09d693 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro <gregd@basistech.com> Date: Tue, 29 Aug 2023 17:13:37 -0400 Subject: [PATCH] updates --- .../autopsy/apiupdate/CLIProcessor.java | 30 +++++----- .../org/sleuthkit/autopsy/apiupdate/Main.java | 58 +++++++++---------- .../autopsy/apiupdate/ModuleUpdates.java | 28 +++++---- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/CLIProcessor.java b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/CLIProcessor.java index 5295febd70..1b5597e235 100644 --- a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/CLIProcessor.java +++ b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/CLIProcessor.java @@ -57,8 +57,8 @@ public class CLIProcessor { .option("cv") .required(true) .build(); - - static Option SRC_LOC_OPT = Option.builder() + + static Option SRC_LOC_OPT = Option.builder() .argName("path") .desc("The path to the root of the autopsy repor") .hasArg(true) @@ -97,8 +97,7 @@ private static Options getCliOptions(List<Option> opts) { static Options HELP_OPTIONS = getCliOptions(Collections.singletonList(HELP_OPT)); private static CommandLineParser parser = new DefaultParser(); - - + private static HelpFormatter helpFormatter = new HelpFormatter(); static void printHelp(Exception ex) { @@ -133,15 +132,14 @@ static CLIArgs parseCli(String[] args) throws ParseException { if (!prevVersFile.isDirectory()) { throw new ParseException("No directory found at " + prevVersFile.getAbsolutePath()); } - - if (!srcPathFile.isDirectory()) { + + if (!srcPathFile.isDirectory()) { throw new ParseException("No directory found at " + srcPathFile.getAbsolutePath()); } return new CLIArgs(curVers, prevVers, curVersFile, prevVersFile, srcPathFile, false); } - public static class CLIArgs { private final String currentVersion; @@ -151,6 +149,15 @@ public static class CLIArgs { private final boolean isHelp; private final File srcPath; + public CLIArgs(String currentVersion, String previousVersion, File currentVersPath, File previousVersPath, File srcPath, boolean isHelp) { + this.currentVersion = currentVersion; + this.previousVersion = previousVersion; + this.currentVersPath = currentVersPath; + this.previousVersPath = previousVersPath; + this.srcPath = srcPath; + this.isHelp = isHelp; + } + public String getCurrentVersion() { return currentVersion; } @@ -171,13 +178,8 @@ public boolean isIsHelp() { return isHelp; } - public CLIArgs(String currentVersion, String previousVersion, File currentVersPath, File previousVersPath, File srcPath, boolean isHelp) { - this.currentVersion = currentVersion; - this.previousVersion = previousVersion; - this.currentVersPath = currentVersPath; - this.previousVersPath = previousVersPath; - this.srcPath = srcPath; - this.isHelp = isHelp; + public File getSrcPath() { + return srcPath; } } diff --git a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/Main.java b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/Main.java index 71e410cc99..77b91e61eb 100644 --- a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/Main.java +++ b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/Main.java @@ -3,31 +3,14 @@ */ package org.sleuthkit.autopsy.apiupdate; -import japicmp.cmp.JApiCmpArchive; -import japicmp.cmp.JarArchiveComparator; -import japicmp.cmp.JarArchiveComparatorOptions; -import japicmp.model.JApiClass; -import java.io.File; -import java.io.FileFilter; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.text.MessageFormat; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.jar.Attributes; -import java.util.jar.Manifest; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; import org.apache.commons.cli.ParseException; import org.sleuthkit.autopsy.apiupdate.CLIProcessor.CLIArgs; import org.sleuthkit.autopsy.apiupdate.ModuleUpdates.ModuleVersionNumbers; +import org.sleuthkit.autopsy.apiupdate.ModuleUpdates.ReleaseVal; /** * @@ -49,17 +32,32 @@ public static void main(String[] args) { System.exit(-1); return; } + + Map<String, ModuleVersionNumbers> versNums = Stream.of( + new ModuleVersionNumbers( + "org.sleuthkit.autopsy.core", + new ModuleUpdates.SemVer(1,2,3), + 4, + new ReleaseVal("org.sleuthkit.autopsy.core", 5)), + new ModuleVersionNumbers( + "org.sleuthkit.autopsy.corelibs", + new ModuleUpdates.SemVer(6,7,8), + 9, + new ReleaseVal("org.sleuthkit.autopsy.corelibs", 10))) + .collect(Collectors.toMap(v -> v.getModuleName(), v -> v, (v1, v2) -> v1)); + + ModuleUpdates.setVersions(cliArgs.getSrcPath(), versNums); - for (String commonJarFileName : APIDiff.getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) { - try { - ModuleVersionNumbers m = ModuleUpdates.getVersionsFromJar(cliArgs.getPreviousVersPath().toPath().resolve(commonJarFileName).toFile()); - System.out.println(MessageFormat.format("release: {0}, spec: {1}, implementation: {2}", m.getRelease().getFullReleaseStr(), m.getSpec().getSemVerStr(), m.getImplementation())); - - } catch (IOException ex) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); - } - - } +// for (String commonJarFileName : APIDiff.getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) { +// try { +// ModuleVersionNumbers m = ModuleUpdates.getVersionsFromJar(cliArgs.getPreviousVersPath().toPath().resolve(commonJarFileName).toFile()); +// System.out.println(MessageFormat.format("release: {0}, spec: {1}, implementation: {2}", m.getRelease().getFullReleaseStr(), m.getSpec().getSemVerStr(), m.getImplementation())); +// +// } catch (IOException ex) { +// Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); +// } +// +// } 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 ec50af24d7..d990167c96 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 @@ -16,12 +16,13 @@ import java.util.jar.Attributes; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; +import java.util.logging.StreamHandler; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; @@ -44,6 +45,9 @@ public class ModuleUpdates { private static final Logger LOGGER = Logger.getLogger(ModuleUpdates.class.getName()); + static { + LOGGER.addHandler(new StreamHandler(System.out, new SimpleFormatter())); + } private static final Pattern SPEC_REGEX = Pattern.compile("^\\s*((?<major>\\d*)\\.)?(?<minor>\\d*)(\\.(?<patch>\\d*))?\\s*$"); private static final String SPEC_KEY = "OpenIDE-Module-Specification-Version"; @@ -60,7 +64,7 @@ public class ModuleUpdates { private static final String PROJ_XML_REL_PATH = "nbproject/project.xml"; private static final String MANIFEST_FILE_NAME = "manifest.mf"; - private static final String PROJ_XML_FMT_STR = "//project/configuration/data/module-dependencies/dependency[code-name-base[contains(text(), '{0}')]]/run-dependency"; + private static final String PROJ_XML_FMT_STR = "//project/configuration/data/module-dependencies/dependency[code-name-base[contains(text(), ''{0}'')]]/run-dependency"; private static final String PROJ_XML_RELEASE_VERS_EL = "release-version"; private static final String PROJ_XML_SPEC_VERS_EL = "specification-version"; private static final String PROJ_XML_IMPL_VERS_EL = "implementation-version"; @@ -225,17 +229,17 @@ private static void updateManifest(File moduleDir, ModuleVersionNumbers thisVers attributes = ManifestLoader.loadInputStream(manifestIs); } - updateAttr(attributes, IMPL_KEY, thisVersNums.getImplementation(), true); + 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); } - private static void updateAttr(Attributes attributes, String key, Object val, boolean updateOnlyIfPresent) { + private static void updateAttr(Attributes attributes, String key, String val, boolean updateOnlyIfPresent) { if (updateOnlyIfPresent && attributes.getValue(key) == null) { return; } - attributes.put(key, val); + attributes.putValue(key, val); } private static void updateProjXml(File moduleDir, Map<String, ModuleVersionNumbers> versNums) @@ -277,7 +281,7 @@ private static void updateProjXml(File moduleDir, Map<String, ModuleVersionNumbe Transformer transformer = transformerFactory.newTransformer(); // pretty print XML - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + //transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(projectXmlDoc); try (FileOutputStream xmlOut = new FileOutputStream(projXmlFile)) { @@ -298,7 +302,7 @@ private static boolean updateXmlChildrenIfPresent(Node parentNode, Map<String, S String newChildNodeText = childElText.get(childNodeEl); if (newChildNodeText != null && StringUtils.isNotBlank(childNodeText)) { - childNode.setPrefix(newChildNodeText); + childNode.setTextContent(newChildNodeText); changed = true; } } @@ -381,20 +385,20 @@ public String getSemVerStr() { public static class ModuleVersionNumbers { - private final String jarName; + private final String moduleName; private final SemVer spec; private final int implementation; private final ReleaseVal release; - public ModuleVersionNumbers(String jarName, SemVer spec, int implementation, ReleaseVal release) { - this.jarName = jarName; + public ModuleVersionNumbers(String moduleName, SemVer spec, int implementation, ReleaseVal release) { + this.moduleName = moduleName; this.spec = spec; this.implementation = implementation; this.release = release; } - public String getJarName() { - return jarName; + public String getModuleName() { + return moduleName; } public SemVer getSpec() { -- GitLab