From fb7d7356551c4822af72094ab9ba927f07c48d87 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Fri, 1 Sep 2023 13:07:43 -0400 Subject: [PATCH] javadoc updates --- .../sleuthkit/autopsy/apiupdate/APIDiff.java | 102 ++++++++++++++++-- .../autopsy/apiupdate/CLIProcessor.java | 69 +++++++++--- .../org/sleuthkit/autopsy/apiupdate/Main.java | 52 +++++---- .../autopsy/apiupdate/ManifestLoader.java | 25 ++++- .../autopsy/apiupdate/ModuleUpdates.java | 4 +- .../apiupdate/PublicApiChangeType.java | 13 ++- 6 files changed, 210 insertions(+), 55 deletions(-) diff --git a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/APIDiff.java b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/APIDiff.java index b41cea00d6..3b59850ac9 100644 --- a/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/APIDiff.java +++ b/release_scripts/APIUpdate/src/main/java/org/sleuthkit/autopsy/apiupdate/APIDiff.java @@ -55,14 +55,22 @@ import javassist.CtMember; import javassist.Modifier; /** - * - * @author gregd + * Handles diffing the public API between two jar files. */ public class APIDiff { + // filters to a jar or nbm file private static final FileFilter JAR_FILTER = (File f) -> f.isFile() && (f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".nbm")); + /** + * Identifies common jar files between two directories. Only files listed in + * the directory are considered. This method does not recurse. + * + * @param prevDir The previous version directory. + * @param currDir The current version directory. + * @return The jar file names. + */ static List getCommonJars(File prevDir, File currDir) { Set prevJars = getJars(prevDir); Set currJars = getJars(currDir); @@ -74,12 +82,27 @@ public class APIDiff { return commonJars.stream().sorted().collect(Collectors.toList()); } + /** + * Returns all jar files listed in directory (does not recurse). + * + * @param dir The directory. + * @return The jar file names. + */ private static Set getJars(File dir) { return Stream.of(dir.listFiles(JAR_FILTER)) .map(f -> f.getName()) .collect(Collectors.toSet()); } + /** + * Uses manfest.mf specification of "OpenIDE-Module-Public-Packages" to + * determine public API packages. + * + * @param jarFile The jar file. + * @return The set of package names. + * @throws IOException + * @throws IllegalStateException + */ private static Set getPublicPackages(File jarFile) throws IOException, IllegalStateException { String publicPackageStr = ManifestLoader.loadFromJar(jarFile).getValue("OpenIDE-Module-Public-Packages"); if (publicPackageStr == null) { @@ -92,11 +115,26 @@ public class APIDiff { } } - // only fields, methods that are public or protected + /** + * Filter to identify non-public, non-protected members for exclusion. + * + * @param member The CtMember (field/method). + * @return True if should be excluded (private/package private). + */ static boolean excludeMember(CtMember member) { return !Modifier.isPublic(member.getModifiers()) && !Modifier.isProtected(member.getModifiers()); } + /** + * Compares two jar files. + * + * @param prevVersion The name of the previous version. + * @param curVersion The name of the current version. + * @param prevJar The previous version jar file. + * @param curJar The current version jar file. + * @return A record describing the comparison in public API. + * @throws IOException + */ static ComparisonRecord getComparison(String prevVersion, String curVersion, File prevJar, File curJar) throws IOException { // scope only to previous or current public packages Set prevPublicApiPackages = getPublicPackages(prevJar); @@ -120,7 +158,7 @@ public class APIDiff { commonApiPackages.add(apiPackage); } } - + JarArchiveComparatorOptions comparatorOptions = new JarArchiveComparatorOptions(); // only classes in prev or current public api comparatorOptions.getFilters().getExcludes().add((ClassFilter) (CtClass ctClass) -> !allPublicApiPackages.contains(ctClass.getPackageName())); @@ -139,7 +177,7 @@ public class APIDiff { ); PublicApiChangeType changeType = getChangeType(jApiClasses); - + Options options = Options.newDefault(); options.setOldArchives(Arrays.asList(new JApiCmpArchive(prevJar, prevVersion))); options.setNewArchives(Arrays.asList(new JApiCmpArchive(curJar, curVersion))); @@ -150,6 +188,13 @@ public class APIDiff { return new ComparisonRecord(prevVersion, curVersion, prevJar, curJar, humanReadableApiChange, changeType, onlyPrevApiPackages, onlyCurApiPackages, commonApiPackages); } + /** + * Updates an atomic ref to the public api change type to the maximum change + * (where no change is min and incompatible change is max). + * + * @param apiChangeRef The atomic ref to a public api change type. + * @param tp The possibly new change type. + */ private static void updateToMax(AtomicReference apiChangeRef, JApiHasChangeStatus tp) { PublicApiChangeType apiChangeType; switch (tp.getChangeStatus()) { @@ -164,14 +209,20 @@ public class APIDiff { default: apiChangeType = PublicApiChangeType.INCOMPATIBLE_CHANGE; break; - }; + } final PublicApiChangeType finalApiChangeType = apiChangeType; apiChangeRef.updateAndGet((refType) -> Comparators.max(refType, finalApiChangeType)); } - static PublicApiChangeType getChangeType(List jApiClasses) { - AtomicReference apiChange = new AtomicReference(PublicApiChangeType.NONE); + /** + * Determines the public api change type for the given classes. + * + * @param jApiClasses The classes. + * @return The public API change type. + */ + static PublicApiChangeType getChangeType(List jApiClasses) { + AtomicReference apiChange = new AtomicReference<>(PublicApiChangeType.NONE); Filter.filter(jApiClasses, new Filter.FilterVisitor() { @Override @@ -213,6 +264,10 @@ public class APIDiff { return apiChange.get(); } + /** + * A record describing the public API comparison of a previous and current + * version. + */ public static class ComparisonRecord { private final String prevVersion; @@ -237,43 +292,70 @@ public class APIDiff { this.commonApiPackages = commonApiPackages; } + /** + * @return The previous version name. + */ public String getPrevVersion() { return prevVersion; } + /** + * @return The current version name. + */ public String getCurVersion() { return curVersion; } + /** + * @return The previous version jar file. + */ public File getPrevJar() { return prevJar; } + /** + * @return The current version jar file. + */ public File getCurJar() { return curJar; } + /** + * @return The human readable output describing the api changes. + */ public String getHumanReadableApiChange() { return humanReadableApiChange; } + /** + * @return The public api change type. + */ public PublicApiChangeType getChangeType() { return changeType; } + /** + * @return Names of packages only in previous public API. + */ public Set getOnlyPrevApiPackages() { return onlyPrevApiPackages; } + /** + * @return Names of packages only in current public API. + */ public Set getOnlyCurrApiPackages() { return onlyCurrApiPackages; } + /** + * @return Names of packages in common between previous and current + * public API. + */ public Set getCommonApiPackages() { return commonApiPackages; } - - + } } 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 d45f9bd8b3..db00a54d7d 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 @@ -32,12 +32,11 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; /** - * - * @author gregd + * Processes CLI options. */ public class CLIProcessor { - static Option PREV_VERS_PATH_OPT = Option.builder() + private static final Option PREV_VERS_PATH_OPT = Option.builder() .argName("path") .desc("The path to the previous version jar files") .hasArg(true) @@ -46,7 +45,7 @@ public class CLIProcessor { .required(true) .build(); - static Option CUR_VERS_PATH_OPT = Option.builder() + private static final Option CUR_VERS_PATH_OPT = Option.builder() .argName("path") .desc("The path to the current version jar files") .hasArg(true) @@ -55,7 +54,7 @@ public class CLIProcessor { .required(false) .build(); - static Option PREV_VERS_OPT = Option.builder() + private static final Option PREV_VERS_OPT = Option.builder() .argName("version") .desc("The previous version number") .hasArg(true) @@ -64,7 +63,7 @@ public class CLIProcessor { .required(false) .build(); - static Option CUR_VERS_OPT = Option.builder() + private static final Option CUR_VERS_OPT = Option.builder() .argName("version") .desc("The current version number") .hasArg(true) @@ -73,7 +72,7 @@ public class CLIProcessor { .required(false) .build(); - static Option SRC_LOC_OPT = Option.builder() + private static final Option SRC_LOC_OPT = Option.builder() .argName("path") .desc("The path to the root of the autopsy repor") .hasArg(true) @@ -82,7 +81,7 @@ public class CLIProcessor { .required(true) .build(); - static Option UPDATE_OPT = Option.builder() + private static final Option UPDATE_OPT = Option.builder() .desc("Update source code versions") .hasArg(false) .longOpt("update") @@ -90,7 +89,7 @@ public class CLIProcessor { .required(false) .build(); - static List