Skip to content
Snippets Groups Projects
Commit a0963e49 authored by Greg DiCristofaro's avatar Greg DiCristofaro
Browse files

work towards module updates

parent 9906d5dc
Branches
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <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> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<mainClass>org.sleuthkit.autopsy.apiupdate.Main</mainClass> <mainClass>${exec.mainClass}</mainClass>
</manifest> </manifest>
</archive> </archive>
<descriptorRefs> <descriptorRefs>
......
...@@ -27,7 +27,7 @@ public class APIDiff { ...@@ -27,7 +27,7 @@ public class APIDiff {
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"));
private 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);
...@@ -44,7 +44,7 @@ private static Set<String> getJars(File dir) { ...@@ -44,7 +44,7 @@ private static Set<String> getJars(File dir) {
.collect(Collectors.toSet()); .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"); String publicPackageStr = ManifestLoader.loadFromJar(jarFile).getValue("OpenIDE-Module-Public-Packages");
if (publicPackageStr == null) { if (publicPackageStr == null) {
throw new IllegalStateException(MessageFormat.format("Manifest for {0} does not have key of 'OpenIDE-Module-Public-Packages'", jarFile.getAbsolutePath())); throw new IllegalStateException(MessageFormat.format("Manifest for {0} does not have key of 'OpenIDE-Module-Public-Packages'", jarFile.getAbsolutePath()));
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.sleuthkit.autopsy.apiupdate.CLIProcessor.CLIArgs; import org.sleuthkit.autopsy.apiupdate.CLIProcessor.CLIArgs;
import org.sleuthkit.autopsy.apiupdate.ModuleUpdates.ModuleVersionNumbers;
/** /**
* *
...@@ -35,7 +36,7 @@ ...@@ -35,7 +36,7 @@
public class Main { public class Main {
public static void main(String[] args) { 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; CLIArgs cliArgs;
try { try {
cliArgs = CLIProcessor.parseCli(args); cliArgs = CLIProcessor.parseCli(args);
...@@ -49,6 +50,19 @@ public static void main(String[] args) { ...@@ -49,6 +50,19 @@ public static void main(String[] args) {
return; 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())) { // for (String commonJarFileName : getCommonJars(cliArgs.getPreviousVersPath(), cliArgs.getCurrentVersPath())) {
//// getComparison( //// getComparison(
//// cliArgs.getPreviousVersion(), //// cliArgs.getPreviousVersion(),
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.ParseException; import java.util.Map;
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.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
/** /**
...@@ -22,79 +24,64 @@ ...@@ -22,79 +24,64 @@
public class ModuleUpdates { public class ModuleUpdates {
private static final Logger LOGGER = Logger.getLogger(ModuleUpdates.class.getName()); 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 SPEC_KEY = "OpenIDE-Module-Specification-Version";
private static final String IMPL_KEY = "OpenIDE-Module-Implementation-Version"; private static final String IMPL_KEY = "OpenIDE-Module-Implementation-Version";
private static final String RELEASE_KEY = "OpenIDE-Module"; private static final String RELEASE_KEY = "OpenIDE-Module";
private static final Pattern RELEASE_REGEX = Pattern.compile("^\\s*(?<releaseName>.+?)(/(?<releaseNum>\\d*))?\\s*$"); 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 SemVer DEFAULT_SEMVER = new SemVer(1, 0, null);
private static final int DEFAULT_VERS_VAL = 1; 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) { private static SemVer parseSemVer(String semVerStr, SemVer defaultSemVer, String resourceForLogging) {
if (StringUtils.isBlank(semVerStr)) { if (StringUtils.isBlank(semVerStr)) {
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver for empty string in {0}", resourceForLogging));
return defaultSemVer; return defaultSemVer;
} }
Matcher m = SPEC_REGEX.matcher(semVerStr); Matcher m = SPEC_REGEX.matcher(semVerStr);
if (m.find()) { if (m.find()) {
try { 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")); int minor = Integer.parseInt(m.group("minor"));
String patchStr = m.group("patch"); String patchStr = m.group("patch");
Integer patch = StringUtils.isBlank(patchStr) ? null : Integer.parseInt(patchStr); Integer patch = StringUtils.isBlank(patchStr) ? null : Integer.parseInt(patchStr);
return new SemVer(major, minor, patch); return new SemVer(major, minor, patch);
} catch (NullPointerException | NumberFormatException ex) { } catch (NullPointerException | NumberFormatException ex) {
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", semVerStr, resourceForLogging), ex); LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", semVerStr, resourceForLogging), ex);
return defaultSemVer;
} }
} else { } else {
return defaultSemVer; LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", semVerStr, resourceForLogging));
} }
}
private static ReleaseVal parseReleaseVers(String releaseStr, ReleaseVal defaultVal, String resourceForLogging) { return defaultSemVer;
if (StringUtils.isBlank(releaseStr)) { }
return defaultVal;
}
Matcher m = RELEASE_REGEX.matcher(releaseStr); private static ReleaseVal parseReleaseVers(String releaseStr, String resourceForLogging) {
if (m.find()) { Matcher m = RELEASE_REGEX.matcher(StringUtils.defaultString(releaseStr));
if (StringUtils.isNotBlank(releaseStr) && m.find()) {
String releaseName = m.group("releaseName");
Integer releaseNum = null;
try { try {
int major = Integer.parseInt(m.group("major")); String releaseNumStr = m.group("releaseNum");
int minor = Integer.parseInt(m.group("minor")); releaseNum = StringUtils.isBlank(releaseNumStr) ? null : Integer.parseInt(releaseNumStr);
String patchStr = m.group("patch");
Integer patch = StringUtils.isBlank(patchStr) ? null : Integer.parseInt(patchStr);
return new SemVer(major, minor, patch);
} catch (NullPointerException | NumberFormatException ex) { } catch (NullPointerException | NumberFormatException ex) {
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse semver string {0} for {1}", releaseStr, resourceForLogging), ex); LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to parse release version string {0} for {1}", releaseStr, resourceForLogging), ex);
return defaultSemVer;
} }
return new ReleaseVal(releaseName, releaseNum);
} else { } 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) { private static int tryParse(String str, int defaultVal, String resourceForLogging) {
try { try {
...@@ -105,7 +92,7 @@ private static int tryParse(String str, int defaultVal, String resourceForLoggin ...@@ -105,7 +92,7 @@ private static int tryParse(String str, int defaultVal, String resourceForLoggin
} }
} }
public static SemVer getPrevVersions(File jarFile) throws IOException { public static ModuleVersionNumbers getVersionsFromJar(File jarFile) throws IOException {
Attributes manifest = ManifestLoader.loadFromJar(jarFile); Attributes manifest = ManifestLoader.loadFromJar(jarFile);
String spec = manifest.getValue(SPEC_KEY); String spec = manifest.getValue(SPEC_KEY);
SemVer specSemVer = parseSemVer(spec, DEFAULT_SEMVER, SemVer specSemVer = parseSemVer(spec, DEFAULT_SEMVER,
...@@ -114,7 +101,32 @@ public static SemVer getPrevVersions(File jarFile) throws IOException { ...@@ -114,7 +101,32 @@ public static SemVer getPrevVersions(File jarFile) throws IOException {
int implementation = tryParse(manifest.getValue(IMPL_KEY), DEFAULT_VERS_VAL, int implementation = tryParse(manifest.getValue(IMPL_KEY), DEFAULT_VERS_VAL,
MessageFormat.format("{0} in manifest for {1}", IMPL_KEY, jarFile)); MessageFormat.format("{0} in manifest for {1}", IMPL_KEY, jarFile));
// // Spec 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() {
// [specification major/minor/patch, implementation, release]
// assumed defaults???
// NON_COMPATIBLE:
// specification.major += 1
// implementation += 1
// release += 1
// COMPATIBLE:
// specification.minor += 1
// 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 // // project.properties
// // spec.version.base // // spec.version.base
// // manifest // // manifest
...@@ -133,21 +145,6 @@ public static SemVer getPrevVersions(File jarFile) throws IOException { ...@@ -133,21 +145,6 @@ public static SemVer getPrevVersions(File jarFile) throws IOException {
// // release-version // // release-version
} }
private static void updateVersions() {
// [specification major/minor/patch, implementation, release]
// assumed defaults???
// NON_COMPATIBLE:
// specification.major += 1
// implementation += 1
// release += 1
// COMPATIBLE:
// specification.minor += 1
// implementation += 1
// NO_CHANGES:
// implementation += 1
}
public static class ReleaseVal { public static class ReleaseVal {
private final String moduleName; private final String moduleName;
...@@ -206,16 +203,22 @@ public String getSemVerStr() { ...@@ -206,16 +203,22 @@ public String getSemVerStr() {
public static class ModuleVersionNumbers { public static class ModuleVersionNumbers {
private final String jarName;
private final SemVer spec; private final SemVer spec;
private final int implementation; 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.spec = spec;
this.implementation = implementation; this.implementation = implementation;
this.release = release; this.release = release;
} }
public String getJarName() {
return jarName;
}
public SemVer getSpec() { public SemVer getSpec() {
return spec; return spec;
} }
...@@ -224,7 +227,7 @@ public int getImplementation() { ...@@ -224,7 +227,7 @@ public int getImplementation() {
return implementation; return implementation;
} }
public int getRelease() { public ReleaseVal getRelease() {
return release; return release;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment