mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
javadoc updates
This commit is contained in:
parent
da37197a03
commit
fb7d735655
@ -55,14 +55,22 @@ import javassist.CtMember;
|
|||||||
import javassist.Modifier;
|
import javassist.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Handles diffing the public API between two jar files.
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public class APIDiff {
|
public class APIDiff {
|
||||||
|
|
||||||
|
// filters to a jar or nbm file
|
||||||
private static final FileFilter JAR_FILTER
|
private static final FileFilter JAR_FILTER
|
||||||
= (File f) -> f.isFile() && (f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".nbm"));
|
= (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<String> getCommonJars(File prevDir, File currDir) {
|
static List<String> getCommonJars(File prevDir, File currDir) {
|
||||||
Set<String> prevJars = getJars(prevDir);
|
Set<String> prevJars = getJars(prevDir);
|
||||||
Set<String> currJars = getJars(currDir);
|
Set<String> currJars = getJars(currDir);
|
||||||
@ -74,12 +82,27 @@ public class APIDiff {
|
|||||||
return commonJars.stream().sorted().collect(Collectors.toList());
|
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<String> getJars(File dir) {
|
private static Set<String> getJars(File dir) {
|
||||||
return Stream.of(dir.listFiles(JAR_FILTER))
|
return Stream.of(dir.listFiles(JAR_FILTER))
|
||||||
.map(f -> f.getName())
|
.map(f -> f.getName())
|
||||||
.collect(Collectors.toSet());
|
.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<String> getPublicPackages(File jarFile) throws IOException, IllegalStateException {
|
private static Set<String> getPublicPackages(File jarFile) throws IOException, IllegalStateException {
|
||||||
String publicPackageStr = ManifestLoader.loadFromJar(jarFile).getValue("OpenIDE-Module-Public-Packages");
|
String publicPackageStr = ManifestLoader.loadFromJar(jarFile).getValue("OpenIDE-Module-Public-Packages");
|
||||||
if (publicPackageStr == null) {
|
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) {
|
static boolean excludeMember(CtMember member) {
|
||||||
return !Modifier.isPublic(member.getModifiers()) && !Modifier.isProtected(member.getModifiers());
|
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 {
|
static ComparisonRecord getComparison(String prevVersion, String curVersion, File prevJar, File curJar) throws IOException {
|
||||||
// scope only to previous or current public packages
|
// scope only to previous or current public packages
|
||||||
Set<String> prevPublicApiPackages = getPublicPackages(prevJar);
|
Set<String> prevPublicApiPackages = getPublicPackages(prevJar);
|
||||||
@ -120,7 +158,7 @@ public class APIDiff {
|
|||||||
commonApiPackages.add(apiPackage);
|
commonApiPackages.add(apiPackage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JarArchiveComparatorOptions comparatorOptions = new JarArchiveComparatorOptions();
|
JarArchiveComparatorOptions comparatorOptions = new JarArchiveComparatorOptions();
|
||||||
// only classes in prev or current public api
|
// only classes in prev or current public api
|
||||||
comparatorOptions.getFilters().getExcludes().add((ClassFilter) (CtClass ctClass) -> !allPublicApiPackages.contains(ctClass.getPackageName()));
|
comparatorOptions.getFilters().getExcludes().add((ClassFilter) (CtClass ctClass) -> !allPublicApiPackages.contains(ctClass.getPackageName()));
|
||||||
@ -139,7 +177,7 @@ public class APIDiff {
|
|||||||
);
|
);
|
||||||
|
|
||||||
PublicApiChangeType changeType = getChangeType(jApiClasses);
|
PublicApiChangeType changeType = getChangeType(jApiClasses);
|
||||||
|
|
||||||
Options options = Options.newDefault();
|
Options options = Options.newDefault();
|
||||||
options.setOldArchives(Arrays.asList(new JApiCmpArchive(prevJar, prevVersion)));
|
options.setOldArchives(Arrays.asList(new JApiCmpArchive(prevJar, prevVersion)));
|
||||||
options.setNewArchives(Arrays.asList(new JApiCmpArchive(curJar, curVersion)));
|
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);
|
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<PublicApiChangeType> apiChangeRef, JApiHasChangeStatus tp) {
|
private static void updateToMax(AtomicReference<PublicApiChangeType> apiChangeRef, JApiHasChangeStatus tp) {
|
||||||
PublicApiChangeType apiChangeType;
|
PublicApiChangeType apiChangeType;
|
||||||
switch (tp.getChangeStatus()) {
|
switch (tp.getChangeStatus()) {
|
||||||
@ -164,14 +209,20 @@ public class APIDiff {
|
|||||||
default:
|
default:
|
||||||
apiChangeType = PublicApiChangeType.INCOMPATIBLE_CHANGE;
|
apiChangeType = PublicApiChangeType.INCOMPATIBLE_CHANGE;
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
|
|
||||||
final PublicApiChangeType finalApiChangeType = apiChangeType;
|
final PublicApiChangeType finalApiChangeType = apiChangeType;
|
||||||
apiChangeRef.updateAndGet((refType) -> Comparators.max(refType, finalApiChangeType));
|
apiChangeRef.updateAndGet((refType) -> Comparators.max(refType, finalApiChangeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PublicApiChangeType getChangeType(List<JApiClass> jApiClasses) {
|
/**
|
||||||
AtomicReference<PublicApiChangeType> apiChange = new AtomicReference<PublicApiChangeType>(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<JApiClass> jApiClasses) {
|
||||||
|
AtomicReference<PublicApiChangeType> apiChange = new AtomicReference<>(PublicApiChangeType.NONE);
|
||||||
|
|
||||||
Filter.filter(jApiClasses, new Filter.FilterVisitor() {
|
Filter.filter(jApiClasses, new Filter.FilterVisitor() {
|
||||||
@Override
|
@Override
|
||||||
@ -213,6 +264,10 @@ public class APIDiff {
|
|||||||
return apiChange.get();
|
return apiChange.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A record describing the public API comparison of a previous and current
|
||||||
|
* version.
|
||||||
|
*/
|
||||||
public static class ComparisonRecord {
|
public static class ComparisonRecord {
|
||||||
|
|
||||||
private final String prevVersion;
|
private final String prevVersion;
|
||||||
@ -237,43 +292,70 @@ public class APIDiff {
|
|||||||
this.commonApiPackages = commonApiPackages;
|
this.commonApiPackages = commonApiPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The previous version name.
|
||||||
|
*/
|
||||||
public String getPrevVersion() {
|
public String getPrevVersion() {
|
||||||
return prevVersion;
|
return prevVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The current version name.
|
||||||
|
*/
|
||||||
public String getCurVersion() {
|
public String getCurVersion() {
|
||||||
return curVersion;
|
return curVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The previous version jar file.
|
||||||
|
*/
|
||||||
public File getPrevJar() {
|
public File getPrevJar() {
|
||||||
return prevJar;
|
return prevJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The current version jar file.
|
||||||
|
*/
|
||||||
public File getCurJar() {
|
public File getCurJar() {
|
||||||
return curJar;
|
return curJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The human readable output describing the api changes.
|
||||||
|
*/
|
||||||
public String getHumanReadableApiChange() {
|
public String getHumanReadableApiChange() {
|
||||||
return humanReadableApiChange;
|
return humanReadableApiChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The public api change type.
|
||||||
|
*/
|
||||||
public PublicApiChangeType getChangeType() {
|
public PublicApiChangeType getChangeType() {
|
||||||
return changeType;
|
return changeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Names of packages only in previous public API.
|
||||||
|
*/
|
||||||
public Set<String> getOnlyPrevApiPackages() {
|
public Set<String> getOnlyPrevApiPackages() {
|
||||||
return onlyPrevApiPackages;
|
return onlyPrevApiPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Names of packages only in current public API.
|
||||||
|
*/
|
||||||
public Set<String> getOnlyCurrApiPackages() {
|
public Set<String> getOnlyCurrApiPackages() {
|
||||||
return onlyCurrApiPackages;
|
return onlyCurrApiPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Names of packages in common between previous and current
|
||||||
|
* public API.
|
||||||
|
*/
|
||||||
public Set<String> getCommonApiPackages() {
|
public Set<String> getCommonApiPackages() {
|
||||||
return commonApiPackages;
|
return commonApiPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,11 @@ import org.apache.commons.cli.Options;
|
|||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Processes CLI options.
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public class CLIProcessor {
|
public class CLIProcessor {
|
||||||
|
|
||||||
static Option PREV_VERS_PATH_OPT = Option.builder()
|
private static final Option PREV_VERS_PATH_OPT = Option.builder()
|
||||||
.argName("path")
|
.argName("path")
|
||||||
.desc("The path to the previous version jar files")
|
.desc("The path to the previous version jar files")
|
||||||
.hasArg(true)
|
.hasArg(true)
|
||||||
@ -46,7 +45,7 @@ public class CLIProcessor {
|
|||||||
.required(true)
|
.required(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Option CUR_VERS_PATH_OPT = Option.builder()
|
private static final Option CUR_VERS_PATH_OPT = Option.builder()
|
||||||
.argName("path")
|
.argName("path")
|
||||||
.desc("The path to the current version jar files")
|
.desc("The path to the current version jar files")
|
||||||
.hasArg(true)
|
.hasArg(true)
|
||||||
@ -55,7 +54,7 @@ public class CLIProcessor {
|
|||||||
.required(false)
|
.required(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Option PREV_VERS_OPT = Option.builder()
|
private static final Option PREV_VERS_OPT = Option.builder()
|
||||||
.argName("version")
|
.argName("version")
|
||||||
.desc("The previous version number")
|
.desc("The previous version number")
|
||||||
.hasArg(true)
|
.hasArg(true)
|
||||||
@ -64,7 +63,7 @@ public class CLIProcessor {
|
|||||||
.required(false)
|
.required(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Option CUR_VERS_OPT = Option.builder()
|
private static final Option CUR_VERS_OPT = Option.builder()
|
||||||
.argName("version")
|
.argName("version")
|
||||||
.desc("The current version number")
|
.desc("The current version number")
|
||||||
.hasArg(true)
|
.hasArg(true)
|
||||||
@ -73,7 +72,7 @@ public class CLIProcessor {
|
|||||||
.required(false)
|
.required(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Option SRC_LOC_OPT = Option.builder()
|
private static final Option SRC_LOC_OPT = Option.builder()
|
||||||
.argName("path")
|
.argName("path")
|
||||||
.desc("The path to the root of the autopsy repor")
|
.desc("The path to the root of the autopsy repor")
|
||||||
.hasArg(true)
|
.hasArg(true)
|
||||||
@ -82,7 +81,7 @@ public class CLIProcessor {
|
|||||||
.required(true)
|
.required(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Option UPDATE_OPT = Option.builder()
|
private static final Option UPDATE_OPT = Option.builder()
|
||||||
.desc("Update source code versions")
|
.desc("Update source code versions")
|
||||||
.hasArg(false)
|
.hasArg(false)
|
||||||
.longOpt("update")
|
.longOpt("update")
|
||||||
@ -90,7 +89,7 @@ public class CLIProcessor {
|
|||||||
.required(false)
|
.required(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static List<Option> ALL_OPTIONS = Arrays.asList(
|
private static final List<Option> ALL_OPTIONS = Arrays.asList(
|
||||||
PREV_VERS_PATH_OPT,
|
PREV_VERS_PATH_OPT,
|
||||||
CUR_VERS_PATH_OPT,
|
CUR_VERS_PATH_OPT,
|
||||||
PREV_VERS_OPT,
|
PREV_VERS_OPT,
|
||||||
@ -99,11 +98,16 @@ public class CLIProcessor {
|
|||||||
UPDATE_OPT
|
UPDATE_OPT
|
||||||
);
|
);
|
||||||
|
|
||||||
static Options CLI_OPTIONS = getCliOptions(ALL_OPTIONS);
|
private static final Options CLI_OPTIONS = getCliOptions(ALL_OPTIONS);
|
||||||
private static final String DEFAULT_CURR_VERSION = "Current Version";
|
private static final String DEFAULT_CURR_VERSION = "Current Version";
|
||||||
private static final String DEFAULT_PREV_VERSION = "Previous Version";
|
private static final String DEFAULT_PREV_VERSION = "Previous Version";
|
||||||
private static final String BUILD_REL_PATH = "build/cluster/modules";
|
private static final String BUILD_REL_PATH = "build/cluster/modules";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an Options object from a list of options.
|
||||||
|
* @param opts The list of options.
|
||||||
|
* @return The options object.
|
||||||
|
*/
|
||||||
private static Options getCliOptions(List<Option> opts) {
|
private static Options getCliOptions(List<Option> opts) {
|
||||||
Options toRet = new Options();
|
Options toRet = new Options();
|
||||||
for (Option opt : opts) {
|
for (Option opt : opts) {
|
||||||
@ -113,7 +117,7 @@ public class CLIProcessor {
|
|||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Option HELP_OPT = Option.builder()
|
private static final Option HELP_OPT = Option.builder()
|
||||||
.desc("Print help message")
|
.desc("Print help message")
|
||||||
.hasArg(false)
|
.hasArg(false)
|
||||||
.longOpt("help")
|
.longOpt("help")
|
||||||
@ -121,12 +125,16 @@ public class CLIProcessor {
|
|||||||
.required(false)
|
.required(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
static Options HELP_OPTIONS = getCliOptions(Collections.singletonList(HELP_OPT));
|
private static final Options HELP_OPTIONS = getCliOptions(Collections.singletonList(HELP_OPT));
|
||||||
|
|
||||||
private static CommandLineParser parser = new DefaultParser();
|
private static final CommandLineParser parser = new DefaultParser();
|
||||||
|
|
||||||
private static HelpFormatter helpFormatter = new HelpFormatter();
|
private static final HelpFormatter helpFormatter = new HelpFormatter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints help message.
|
||||||
|
* @param ex The exception or null if no exception.
|
||||||
|
*/
|
||||||
static void printHelp(Exception ex) {
|
static void printHelp(Exception ex) {
|
||||||
if (ex != null && ex.getMessage() != null && !ex.getMessage().isBlank()) {
|
if (ex != null && ex.getMessage() != null && !ex.getMessage().isBlank()) {
|
||||||
System.out.println(ex.getMessage());
|
System.out.println(ex.getMessage());
|
||||||
@ -135,6 +143,12 @@ public class CLIProcessor {
|
|||||||
helpFormatter.printHelp("APIUpdate", CLI_OPTIONS);
|
helpFormatter.printHelp("APIUpdate", CLI_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the CLI args.
|
||||||
|
* @param args The arguments.
|
||||||
|
* @return The CLIArgs object.
|
||||||
|
* @throws ParseException
|
||||||
|
*/
|
||||||
static CLIArgs parseCli(String[] args) throws ParseException {
|
static CLIArgs parseCli(String[] args) throws ParseException {
|
||||||
CommandLine helpCmd = parser.parse(HELP_OPTIONS, args, true);
|
CommandLine helpCmd = parser.parse(HELP_OPTIONS, args, true);
|
||||||
boolean isHelp = helpCmd.hasOption(HELP_OPT);
|
boolean isHelp = helpCmd.hasOption(HELP_OPT);
|
||||||
@ -171,6 +185,9 @@ public class CLIProcessor {
|
|||||||
return new CLIArgs(curVers, prevVers, curVersFile, prevVersFile, srcPathFile, makeUpdate, false);
|
return new CLIArgs(curVers, prevVers, curVersFile, prevVersFile, srcPathFile, makeUpdate, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CLI args object.
|
||||||
|
*/
|
||||||
public static class CLIArgs {
|
public static class CLIArgs {
|
||||||
|
|
||||||
private final String currentVersion;
|
private final String currentVersion;
|
||||||
@ -191,30 +208,52 @@ public class CLIProcessor {
|
|||||||
this.makeUpdate = makeUpdate;
|
this.makeUpdate = makeUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The current version name.
|
||||||
|
*/
|
||||||
public String getCurrentVersion() {
|
public String getCurrentVersion() {
|
||||||
return currentVersion;
|
return currentVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The previous version name.
|
||||||
|
*/
|
||||||
public String getPreviousVersion() {
|
public String getPreviousVersion() {
|
||||||
return previousVersion;
|
return previousVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The path to the directory containing the jars for current version.
|
||||||
|
*/
|
||||||
public File getCurrentVersPath() {
|
public File getCurrentVersPath() {
|
||||||
return currentVersPath;
|
return currentVersPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The path to the directory containing the jars for previous version.
|
||||||
|
*/
|
||||||
public File getPreviousVersPath() {
|
public File getPreviousVersPath() {
|
||||||
return previousVersPath;
|
return previousVersPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIsHelp() {
|
/**
|
||||||
|
* @return True if only print help message.
|
||||||
|
*/
|
||||||
|
public boolean isHelp() {
|
||||||
return isHelp;
|
return isHelp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if module versions should be updated.
|
||||||
|
*/
|
||||||
public boolean isMakeUpdate() {
|
public boolean isMakeUpdate() {
|
||||||
return makeUpdate;
|
return makeUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The path to the source directory root for autopsy.
|
||||||
|
*/
|
||||||
public File getSrcPath() {
|
public File getSrcPath() {
|
||||||
return srcPath;
|
return srcPath;
|
||||||
}
|
}
|
||||||
|
@ -30,19 +30,17 @@ import org.sleuthkit.autopsy.apiupdate.CLIProcessor.CLIArgs;
|
|||||||
import org.sleuthkit.autopsy.apiupdate.ModuleUpdates.ModuleVersionNumbers;
|
import org.sleuthkit.autopsy.apiupdate.ModuleUpdates.ModuleVersionNumbers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Main class.
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
args = "-p C:\\Users\\gregd\\Desktop\\apidiff\\old -s C:\\Users\\gregd\\Documents\\Source\\autopsy".split(" ");
|
|
||||||
CLIArgs cliArgs;
|
CLIArgs cliArgs;
|
||||||
try {
|
try {
|
||||||
cliArgs = CLIProcessor.parseCli(args);
|
cliArgs = CLIProcessor.parseCli(args);
|
||||||
if (cliArgs.isIsHelp()) {
|
if (cliArgs.isHelp()) {
|
||||||
CLIProcessor.printHelp(null);
|
CLIProcessor.printHelp(null);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -53,7 +51,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, ModuleVersionNumbers> newVersionNumMapping = new HashMap<>();
|
Map<String, ModuleVersionNumbers> newVersionNumMapping = new HashMap<>();
|
||||||
|
|
||||||
for (String commonJarFileName : APIDiff.getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) {
|
for (String commonJarFileName : APIDiff.getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) {
|
||||||
try {
|
try {
|
||||||
ModuleVersionNumbers prevVersionNums = ModuleUpdates.getVersionsFromJar(cliArgs.getPreviousVersPath().toPath().resolve(commonJarFileName).toFile());
|
ModuleVersionNumbers prevVersionNums = ModuleUpdates.getVersionsFromJar(cliArgs.getPreviousVersPath().toPath().resolve(commonJarFileName).toFile());
|
||||||
@ -81,28 +79,40 @@ public class Main {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs the difference between previous and current version public API.
|
||||||
|
*
|
||||||
|
* @param commonJarFileName The common jar file name.
|
||||||
|
* @param record The comparison record.
|
||||||
|
* @param prevVersionNums The version numbers in previous version.
|
||||||
|
* @param projectedVersionNums The calculated version numbers for current
|
||||||
|
* version.
|
||||||
|
*/
|
||||||
private static void outputDiff(
|
private static void outputDiff(
|
||||||
String commonJarFileName,
|
String commonJarFileName,
|
||||||
ComparisonRecord record,
|
ComparisonRecord record,
|
||||||
ModuleVersionNumbers prevVersionNums,
|
ModuleVersionNumbers prevVersionNums,
|
||||||
ModuleVersionNumbers projectedVersionNums
|
ModuleVersionNumbers projectedVersionNums
|
||||||
) {
|
) {
|
||||||
LOGGER.log(Level.INFO, MessageFormat.format("\n"
|
LOGGER.log(Level.INFO, MessageFormat.format("""
|
||||||
+ "====================================\n"
|
|
||||||
+ "DIFF FOR: {0}\n"
|
====================================
|
||||||
+ "Public API Change Type: {1}\n"
|
DIFF FOR: {0}
|
||||||
+ "Previous Version Numbers:\n"
|
Public API Change Type: {1}
|
||||||
+ " - release: {2}\n"
|
Previous Version Numbers:
|
||||||
+ " - specification: {3}\n"
|
- release: {2}
|
||||||
+ " - implementation: {4}\n"
|
- specification: {3}
|
||||||
+ "Current Version Numbers:\n"
|
- implementation: {4}
|
||||||
+ " - release: {5}\n"
|
Current Version Numbers:
|
||||||
+ " - specification: {6}\n"
|
- release: {5}
|
||||||
+ " - implementation: {7}\n"
|
- specification: {6}
|
||||||
+ "====================================\n"
|
- implementation: {7}
|
||||||
+ "Public API packages only in previous: {8}\n"
|
====================================
|
||||||
+ "Public API packages only in current: {9}\n"
|
Public API packages only in previous: {8}
|
||||||
+ "{10}\n\n",
|
Public API packages only in current: {9}
|
||||||
|
{10}
|
||||||
|
|
||||||
|
""",
|
||||||
commonJarFileName,
|
commonJarFileName,
|
||||||
record.getChangeType(),
|
record.getChangeType(),
|
||||||
prevVersionNums.getRelease().getFullReleaseStr(),
|
prevVersionNums.getRelease().getFullReleaseStr(),
|
||||||
|
@ -29,22 +29,39 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Loads manifest.mf files.
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public class ManifestLoader {
|
public class ManifestLoader {
|
||||||
|
|
||||||
private static final String JAR_MANIFEST_REL_PATH = "META-INF/MANIFEST.MF";
|
private static final String JAR_MANIFEST_REL_PATH = "META-INF/MANIFEST.MF";
|
||||||
|
|
||||||
public static Attributes loadInputStream(InputStream is) throws IOException {
|
/**
|
||||||
|
* Loads the manifest attributes from an input stream.
|
||||||
|
* @param is The input stream.
|
||||||
|
* @return The manifest attributes.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Attributes loadManifestAttributes(InputStream is) throws IOException {
|
||||||
Manifest manifest = loadManifest(is);
|
Manifest manifest = loadManifest(is);
|
||||||
return manifest.getMainAttributes();
|
return manifest.getMainAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the manifest from an input stream.
|
||||||
|
* @param is The input stream.
|
||||||
|
* @return The manifest.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public static Manifest loadManifest(InputStream is) throws IOException {
|
public static Manifest loadManifest(InputStream is) throws IOException {
|
||||||
return new Manifest(is);
|
return new Manifest(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads manifest attributes from a jar file.
|
||||||
|
* @param jarFile The jar file.
|
||||||
|
* @return The manifest attributes.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public static Attributes loadFromJar(File jarFile) throws IOException {
|
public static Attributes loadFromJar(File jarFile) throws IOException {
|
||||||
ZipFile zipFile = new ZipFile(jarFile);
|
ZipFile zipFile = new ZipFile(jarFile);
|
||||||
|
|
||||||
@ -53,7 +70,7 @@ public class ManifestLoader {
|
|||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
ZipEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
if (JAR_MANIFEST_REL_PATH.equalsIgnoreCase(entry.getName())) {
|
if (JAR_MANIFEST_REL_PATH.equalsIgnoreCase(entry.getName())) {
|
||||||
return loadInputStream(zipFile.getInputStream(entry));
|
return loadManifestAttributes(zipFile.getInputStream(entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,6 @@ import java.util.Set;
|
|||||||
import java.util.jar.Attributes;
|
import java.util.jar.Attributes;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.SimpleFormatter;
|
|
||||||
import java.util.logging.StreamHandler;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@ -215,7 +213,7 @@ public class ModuleUpdates {
|
|||||||
File manifestFile = dir.toPath().resolve(MANIFEST_FILE_NAME).toFile();
|
File manifestFile = dir.toPath().resolve(MANIFEST_FILE_NAME).toFile();
|
||||||
if (manifestFile.isFile()) {
|
if (manifestFile.isFile()) {
|
||||||
try (FileInputStream manifestIs = new FileInputStream(manifestFile)) {
|
try (FileInputStream manifestIs = new FileInputStream(manifestFile)) {
|
||||||
Attributes manifestAttrs = ManifestLoader.loadInputStream(manifestIs);
|
Attributes manifestAttrs = ManifestLoader.loadManifestAttributes(manifestIs);
|
||||||
ReleaseVal releaseVal = parseReleaseVers(manifestAttrs.getValue(MANIFEST_RELEASE_KEY), manifestFile.getAbsolutePath());
|
ReleaseVal releaseVal = parseReleaseVers(manifestAttrs.getValue(MANIFEST_RELEASE_KEY), manifestFile.getAbsolutePath());
|
||||||
moduleDirMapping.put(releaseVal.getModuleName(), dir);
|
moduleDirMapping.put(releaseVal.getModuleName(), dir);
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,27 @@ import java.util.Comparator;
|
|||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A public API change type (no change, compatible change, incompatible change).
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public enum PublicApiChangeType implements Comparator<PublicApiChangeType> {
|
public enum PublicApiChangeType implements Comparator<PublicApiChangeType> {
|
||||||
NONE(0), COMPATIBLE_CHANGE(1), INCOMPATIBLE_CHANGE(2);
|
NONE(0), COMPATIBLE_CHANGE(1), INCOMPATIBLE_CHANGE(2);
|
||||||
|
|
||||||
private int level;
|
private int level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* COnstructor.
|
||||||
|
*
|
||||||
|
* @param level The level for the api change (none is min, incompatible is
|
||||||
|
* max).
|
||||||
|
*/
|
||||||
PublicApiChangeType(int level) {
|
PublicApiChangeType(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return The level for the api change (none is min, incompatible is max).
|
||||||
|
*/
|
||||||
public int getLevel() {
|
public int getLevel() {
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user