quality work inside NpmPackage loader
This commit is contained in:
parent
fe1afa7b4c
commit
3f10fc3430
|
@ -161,11 +161,21 @@ public class NpmPackage {
|
|||
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 JsonObject npm;
|
||||
private Map<String, NpmPackageFolder> folders = new HashMap<>();
|
||||
private boolean changedByLoader; // internal qa only!
|
||||
|
||||
private NpmPackage() {
|
||||
|
||||
|
@ -333,11 +343,17 @@ public class NpmPackage {
|
|||
|
||||
private void checkIndexed(String desc) throws IOException {
|
||||
for (NpmPackageFolder folder : folders.values()) {
|
||||
List<String> remove = new ArrayList<>();
|
||||
if (folder.index == null) {
|
||||
NpmPackageIndexBuilder indexer = new NpmPackageIndexBuilder();
|
||||
indexer.start();
|
||||
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();
|
||||
try {
|
||||
|
@ -818,5 +834,11 @@ public class NpmPackage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isChangedByLoader() {
|
||||
return changedByLoader;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class NpmPackageIndexBuilder {
|
|||
index.add("files", files);
|
||||
}
|
||||
|
||||
public void seeFile(String name, byte[] content) {
|
||||
public boolean seeFile(String name, byte[] content) {
|
||||
if (name.endsWith(".json")) {
|
||||
try {
|
||||
JsonObject json = JsonTrackingParser.parseJson(content);
|
||||
|
@ -57,9 +57,13 @@ public class NpmPackageIndexBuilder {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error parsing "+name+": "+e.getMessage());
|
||||
if (name.contains("openapi")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String build() {
|
||||
String res = new GsonBuilder().setPrettyPrinting().create().toJson(index);
|
||||
|
|
Loading…
Reference in New Issue