source = Json.object(value);
+ if (!(source.get("uri") instanceof String) || !(source.get("revision") instanceof String)) return false;
+ URI uri = new URI((String) source.get("uri"));
+ if (!"file".equals(uri.getScheme()) || uri.getQuery() != null || uri.getFragment() != null
+ || uri.getUserInfo() != null) return false;
+ Path path = Paths.get(uri);
+ String revision = (String) source.get("revision");
+ if ("missing".equals(revision)) {
+ if (Files.exists(path)) return false;
+ } else {
+ if (!revision.matches("sha256:[0-9a-f]{64}") || !Files.isRegularFile(path)
+ || Files.size(path) > MAX_BYTES) return false;
+ byte[] bytes = Files.readAllBytes(path);
+ if (bytes.length > MAX_BYTES || !revision.equals("sha256:" + hex(MessageDigest.getInstance("SHA-256").digest(bytes)))) return false;
+ }
+ }
+ return true;
+ } catch (Exception error) { return false; }
+ }
+
+ static PluginError changed() {
+ return new PluginError("maven.configurationChanged", "Maven configuration changed while the project was read. Reload the project.");
+ }
+
+ private static String hex(byte[] bytes) {
+ StringBuilder result = new StringBuilder(bytes.length * 2);
+ for (byte value : bytes) result.append(String.format("%02x", value & 0xff));
+ return result.toString();
+ }
+}
diff --git a/backend/src/main/java/io/github/litheidea/maven/backend/Snapshots.java b/backend/src/main/java/io/github/litheidea/maven/backend/Snapshots.java
index b818be7..b378bbe 100644
--- a/backend/src/main/java/io/github/litheidea/maven/backend/Snapshots.java
+++ b/backend/src/main/java/io/github/litheidea/maven/backend/Snapshots.java
@@ -18,7 +18,7 @@
* fingerprint of the inputs it was computed from.
*
*
- * { "snapshotVersion": 1,
+ * { "snapshotVersion": 2,
* "roots": { "/abs/root": { "fingerprint", "savedAt", "model", "dependencies" } } }
*
*
@@ -28,7 +28,7 @@
*/
final class Snapshots {
static final String KEY = "maven-snapshot";
- static final int VERSION = 1;
+ static final int VERSION = 2;
/** Roots kept per workspace; the least recently saved go first. */
private static final int MAX_ROOTS = 32;
@@ -44,10 +44,12 @@ final class Snapshots {
synchronized MavenRuns.Loaded read(Path root, String fingerprint) {
Map entry = Json.object(roots(store.read(KEY, null)).get(root.toString()));
if (!fingerprint.equals(entry.get("fingerprint"))
- || !(entry.get("model") instanceof Map) || !(entry.get("dependencies") instanceof Map)) {
+ || !(entry.get("model") instanceof Map) || !(entry.get("dependencies") instanceof Map)
+ || !NativeSources.current(entry.get("nativeSources"))) {
return null;
}
- return new MavenRuns.Loaded(Json.object(entry.get("model")), Json.object(entry.get("dependencies")));
+ return new MavenRuns.Loaded(Json.object(entry.get("model")), Json.object(entry.get("dependencies")),
+ new ArrayList<>((List>) entry.get("nativeSources")));
}
synchronized void write(Path root, String fingerprint, MavenRuns.Loaded loaded) {
@@ -57,6 +59,7 @@ synchronized void write(Path root, String fingerprint, MavenRuns.Loaded loaded)
entry.put("savedAt", System.currentTimeMillis());
entry.put("model", loaded.model());
entry.put("dependencies", loaded.dependencies());
+ entry.put("nativeSources", loaded.nativeSources());
roots.remove(root.toString());
roots.put(root.toString(), entry);
prune(roots);
diff --git a/extension/pom.xml b/extension/pom.xml
index af91a24..06d45a9 100644
--- a/extension/pom.xml
+++ b/extension/pom.xml
@@ -41,6 +41,9 @@
1.7.29
provided