quality work inside NpmPackage loader

This commit is contained in:
Grahame Grieve 2020-02-20 09:20:11 +11:00
parent fe1afa7b4c
commit 3f10fc3430
2 changed files with 29 additions and 3 deletions

View File

@ -161,11 +161,21 @@ public class NpmPackage {
return name + " ("+ (folder == null ? "null" : folder.toString())+") | "+Boolean.toString(index != null)+" | "+content.size()+" | "+types.size(); return name + " ("+ (folder == null ? "null" : folder.toString())+") | "+Boolean.toString(index != null)+" | "+content.size()+" | "+types.size();
} }
public void removeFile(String n) throws IOException {
if (folder != null) {
new File(Utilities.path(folder.getAbsolutePath(), n)).delete();
} else {
content.remove(n);
}
changedByLoader = true;
}
} }
private String path; private String path;
private JsonObject npm; private JsonObject npm;
private Map<String, NpmPackageFolder> folders = new HashMap<>(); private Map<String, NpmPackageFolder> folders = new HashMap<>();
private boolean changedByLoader; // internal qa only!
private NpmPackage() { private NpmPackage() {
@ -333,11 +343,17 @@ public class NpmPackage {
private void checkIndexed(String desc) throws IOException { private void checkIndexed(String desc) throws IOException {
for (NpmPackageFolder folder : folders.values()) { for (NpmPackageFolder folder : folders.values()) {
List<String> remove = new ArrayList<>();
if (folder.index == null) { if (folder.index == null) {
NpmPackageIndexBuilder indexer = new NpmPackageIndexBuilder(); NpmPackageIndexBuilder indexer = new NpmPackageIndexBuilder();
indexer.start(); indexer.start();
for (String n : folder.listFiles()) { for (String n : folder.listFiles()) {
indexer.seeFile(n, folder.fetchFile(n)); if (!indexer.seeFile(n, folder.fetchFile(n))) {
remove.add(n);
}
}
for (String n : remove) {
folder.removeFile(n);
} }
String json = indexer.build(); String json = indexer.build();
try { try {
@ -818,5 +834,11 @@ public class NpmPackage {
} }
} }
} }
public boolean isChangedByLoader() {
return changedByLoader;
}
} }

View File

@ -34,7 +34,7 @@ public class NpmPackageIndexBuilder {
index.add("files", files); index.add("files", files);
} }
public void seeFile(String name, byte[] content) { public boolean seeFile(String name, byte[] content) {
if (name.endsWith(".json")) { if (name.endsWith(".json")) {
try { try {
JsonObject json = JsonTrackingParser.parseJson(content); JsonObject json = JsonTrackingParser.parseJson(content);
@ -57,8 +57,12 @@ public class NpmPackageIndexBuilder {
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error parsing "+name+": "+e.getMessage()); System.out.println("Error parsing "+name+": "+e.getMessage());
if (name.contains("openapi")) {
return false;
}
} }
} }
return true;
} }
public String build() { public String build() {