mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
work towards module updates
This commit is contained in:
parent
9906d5dc47
commit
a0963e49a9
@ -9,7 +9,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<exec.mainClass>org.sleuthkit.autopsy.classpathsimplication.apiupdate.APIUpdate</exec.mainClass>
|
||||
<exec.mainClass>org.sleuthkit.autopsy.apiupdate.Main</exec.mainClass>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -40,7 +40,7 @@
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.sleuthkit.autopsy.apiupdate.Main</mainClass>
|
||||
<mainClass>${exec.mainClass}</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
|
@ -27,7 +27,7 @@ public class APIDiff {
|
||||
private static final FileFilter JAR_FILTER
|
||||
= (File f) -> f.isFile() && (f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".nbm"));
|
||||
|
||||
private static List<String> getCommonJars(File prevDir, File currDir) {
|
||||
static List<String> getCommonJars(File prevDir, File currDir) {
|
||||
Set<String> prevJars = getJars(prevDir);
|
||||
Set<String> currJars = getJars(currDir);
|
||||
|
||||
@ -44,7 +44,7 @@ public class APIDiff {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static Set<String> getPublicPackages(File jarFile) throws IOException, IllegalStateException {
|
||||
static Set<String> getPublicPackages(File jarFile) throws IOException, IllegalStateException {
|
||||
String publicPackageStr = ManifestLoader.loadFromJar(jarFile).getValue("OpenIDE-Module-Public-Packages");
|
||||
if (publicPackageStr == null) {
|
||||
throw new IllegalStateException(MessageFormat.format("Manifest for {0} does not have key of 'OpenIDE-Module-Public-Packages'", jarFile.getAbsolutePath()));
|
||||
|
@ -27,6 +27,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -35,7 +36,7 @@ import org.sleuthkit.autopsy.apiupdate.CLIProcessor.CLIArgs;
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
args = "-c C:\\Users\\gregd\\Documents\\Source\\autopsy\\build\\cluster\\modules -p C:\\Users\\gregd\\Desktop\\prevVers -cv 4.21.0 -pv 4.20.0".split(" ");
|
||||
args = "-c C:\\Users\\gregd\\Documents\\Source\\autopsy\\build\\cluster\\modules -p C:\\Users\\gregd\\Desktop\\prevVers -cv 4.21.0 -pv 4.20.0 -s C:\\Users\\gregd\\Documents\\Source\\autopsy".split(" ");
|
||||
CLIArgs cliArgs;
|
||||
try {
|
||||
cliArgs = CLIProcessor.parseCli(args);
|
||||
@ -49,6 +50,19 @@ public class Main {
|
||||
return;
|
||||
}
|
||||
|
||||
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 : getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) {
|
||||
//// getComparison(
|
||||
//// cliArgs.getPreviousVersion(),
|
||||
|
@ -7,12 +7,14 @@ package org.sleuthkit.autopsy.apiupdate;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
@ -22,79 +24,64 @@ import org.apache.commons.lang3.StringUtils;
|
||||
public class ModuleUpdates {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ModuleUpdates.class.getName());
|
||||
// // Spec
|
||||
// // project.properties
|
||||
// // spec.version.base
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Specification-Version
|
||||
// // Implementation
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Implementation-Version
|
||||
// // Release
|
||||
// // manifest
|
||||
// // OpenIDE-Module (/number)
|
||||
//
|
||||
// // Dependency specification
|
||||
// // project.xml
|
||||
// // project.configuration.data.module-dependencies.dependency.run-dependency:
|
||||
// // specification-version
|
||||
// // release-version
|
||||
|
||||
private static final Pattern SPEC_REGEX = Pattern.compile("^\\s*(?<major>\\d*)\\.(?<minor>\\d*)(\\.(?<patch>\\d*))?\\s*$");
|
||||
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";
|
||||
private static final String IMPL_KEY = "OpenIDE-Module-Implementation-Version";
|
||||
private static final String RELEASE_KEY = "OpenIDE-Module";
|
||||
|
||||
|
||||
private static final Pattern RELEASE_REGEX = Pattern.compile("^\\s*(?<releaseName>.+?)(/(?<releaseNum>\\d*))?\\s*$");
|
||||
|
||||
private static final SemVer DEFAULT_SEMVER = new SemVer(1, 0, null);
|
||||
private static final int DEFAULT_VERS_VAL = 1;
|
||||
|
||||
private static final String AUTOPSY_PREFIX = "org-sleuthkit-autopsy-";
|
||||
|
||||
private static SemVer parseSemVer(String semVerStr, SemVer defaultSemVer, String resourceForLogging) {
|
||||
if (StringUtils.isBlank(semVerStr)) {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver for empty string in {0}", resourceForLogging));
|
||||
return defaultSemVer;
|
||||
}
|
||||
|
||||
Matcher m = SPEC_REGEX.matcher(semVerStr);
|
||||
if (m.find()) {
|
||||
try {
|
||||
int major = Integer.parseInt(m.group("major"));
|
||||
String majorStr = m.group("major");
|
||||
int major = StringUtils.isBlank(majorStr) ? 1 : Integer.parseInt(majorStr);
|
||||
int minor = Integer.parseInt(m.group("minor"));
|
||||
String patchStr = m.group("patch");
|
||||
Integer patch = StringUtils.isBlank(patchStr) ? null : Integer.parseInt(patchStr);
|
||||
return new SemVer(major, minor, patch);
|
||||
} catch (NullPointerException | NumberFormatException ex) {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", semVerStr, resourceForLogging), ex);
|
||||
return defaultSemVer;
|
||||
}
|
||||
} else {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", semVerStr, resourceForLogging));
|
||||
}
|
||||
|
||||
return defaultSemVer;
|
||||
}
|
||||
}
|
||||
|
||||
private static ReleaseVal parseReleaseVers(String releaseStr, ReleaseVal defaultVal, String resourceForLogging) {
|
||||
if (StringUtils.isBlank(releaseStr)) {
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
Matcher m = RELEASE_REGEX.matcher(releaseStr);
|
||||
if (m.find()) {
|
||||
private static ReleaseVal parseReleaseVers(String releaseStr, String resourceForLogging) {
|
||||
Matcher m = RELEASE_REGEX.matcher(StringUtils.defaultString(releaseStr));
|
||||
if (StringUtils.isNotBlank(releaseStr) && m.find()) {
|
||||
String releaseName = m.group("releaseName");
|
||||
Integer releaseNum = null;
|
||||
try {
|
||||
int major = Integer.parseInt(m.group("major"));
|
||||
int minor = Integer.parseInt(m.group("minor"));
|
||||
String patchStr = m.group("patch");
|
||||
Integer patch = StringUtils.isBlank(patchStr) ? null : Integer.parseInt(patchStr);
|
||||
return new SemVer(major, minor, patch);
|
||||
String releaseNumStr = m.group("releaseNum");
|
||||
releaseNum = StringUtils.isBlank(releaseNumStr) ? null : Integer.parseInt(releaseNumStr);
|
||||
} catch (NullPointerException | NumberFormatException ex) {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", releaseStr, resourceForLogging), ex);
|
||||
return defaultSemVer;
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse release version string {0} for {1}", releaseStr, resourceForLogging), ex);
|
||||
}
|
||||
return new ReleaseVal(releaseName, releaseNum);
|
||||
} else {
|
||||
return defaultSemVer;
|
||||
}
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse release version string {0} for {1}", releaseStr, resourceForLogging));
|
||||
}
|
||||
|
||||
return new ReleaseVal("", null);
|
||||
|
||||
}
|
||||
|
||||
private static int tryParse(String str, int defaultVal, String resourceForLogging) {
|
||||
try {
|
||||
@ -105,7 +92,7 @@ public class ModuleUpdates {
|
||||
}
|
||||
}
|
||||
|
||||
public static SemVer getPrevVersions(File jarFile) throws IOException {
|
||||
public static ModuleVersionNumbers getVersionsFromJar(File jarFile) throws IOException {
|
||||
Attributes manifest = ManifestLoader.loadFromJar(jarFile);
|
||||
String spec = manifest.getValue(SPEC_KEY);
|
||||
SemVer specSemVer = parseSemVer(spec, DEFAULT_SEMVER,
|
||||
@ -114,23 +101,10 @@ public class ModuleUpdates {
|
||||
int implementation = tryParse(manifest.getValue(IMPL_KEY), DEFAULT_VERS_VAL,
|
||||
MessageFormat.format("{0} in manifest for {1}", IMPL_KEY, jarFile));
|
||||
|
||||
// // Spec
|
||||
// // project.properties
|
||||
// // spec.version.base
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Specification-Version
|
||||
// // Implementation
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Implementation-Version
|
||||
// // Release
|
||||
// // manifest
|
||||
// // OpenIDE-Module (/number)
|
||||
//
|
||||
// // Dependency specification
|
||||
// // project.xml
|
||||
// // project.configuration.data.module-dependencies.dependency.run-dependency:
|
||||
// // specification-version
|
||||
// // release-version
|
||||
ReleaseVal release = parseReleaseVers(manifest.getValue(RELEASE_KEY),
|
||||
MessageFormat.format("{0} in manifest for {1}", RELEASE_KEY, jarFile));
|
||||
|
||||
return new ModuleVersionNumbers(jarFile.getName(), specSemVer, implementation, release);
|
||||
}
|
||||
|
||||
private static void updateVersions() {
|
||||
@ -145,7 +119,30 @@ public class ModuleUpdates {
|
||||
// implementation += 1
|
||||
// NO_CHANGES:
|
||||
// implementation += 1
|
||||
}
|
||||
|
||||
private static void setVersions(File srcDir, Map<String, ModuleVersionNumbers> versNums) {
|
||||
// TODO parse from repo/DIR/manifest.mf release version
|
||||
Map<String, File> moduleDirs = Stream.of(srcDir.listFiles((File f) -> f.isDirectory()))
|
||||
.filter(f -> versNums.containsKey((AUTOPSY_PREFIX + f.getName()).toLowerCase()))
|
||||
.collect(Collectors.toMap(f -> (AUTOPSY_PREFIX + f.getName()).toLowerCase(), f -> f, (f1, f2) -> f1);
|
||||
// // Spec
|
||||
// // project.properties
|
||||
// // spec.version.base
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Specification-Version
|
||||
// // Implementation
|
||||
// // manifest
|
||||
// // OpenIDE-Module-Implementation-Version
|
||||
// // Release
|
||||
// // manifest
|
||||
// // OpenIDE-Module (/number)
|
||||
//
|
||||
// // Dependency specification
|
||||
// // project.xml
|
||||
// // project.configuration.data.module-dependencies.dependency.run-dependency:
|
||||
// // specification-version
|
||||
// // release-version
|
||||
}
|
||||
|
||||
public static class ReleaseVal {
|
||||
@ -206,16 +203,22 @@ public class ModuleUpdates {
|
||||
|
||||
public static class ModuleVersionNumbers {
|
||||
|
||||
private final String jarName;
|
||||
private final SemVer spec;
|
||||
private final int implementation;
|
||||
private final int release;
|
||||
private final ReleaseVal release;
|
||||
|
||||
public ModuleVersionNumbers(SemVer spec, int implementation, int release) {
|
||||
public ModuleVersionNumbers(String jarName, SemVer spec, int implementation, ReleaseVal release) {
|
||||
this.jarName = jarName;
|
||||
this.spec = spec;
|
||||
this.implementation = implementation;
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
public String getJarName() {
|
||||
return jarName;
|
||||
}
|
||||
|
||||
public SemVer getSpec() {
|
||||
return spec;
|
||||
}
|
||||
@ -224,7 +227,7 @@ public class ModuleUpdates {
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public int getRelease() {
|
||||
public ReleaseVal getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user