fix bug finding example resource

This commit is contained in:
Grahame Grieve 2019-12-05 07:44:53 +11:00
parent e5af619105
commit cc66ce9f34
2 changed files with 23 additions and 0 deletions

View File

@ -39,6 +39,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
@ -297,6 +298,14 @@ public class NPMPackageGenerator {
if (!path.startsWith("package/")) {
path = "package/" +path;
}
if (path.length() > 100) {
name = name.substring(0, name.indexOf("-"))+"-"+UUID.randomUUID().toString();
path = cat.getDirectory()+name;
if (!path.startsWith("package/")) {
path = "package/" +path;
}
}
if (created.contains(path)) {
System.out.println("Duplicate package file "+path);

View File

@ -575,6 +575,20 @@ public class NpmPackage {
return null;
}
public InputStream loadExampleResource(String type, String id) throws IOException {
NpmPackageFolder f = folders.get("example");
if (f != null) {
JsonArray files = f.index.getAsJsonArray("files");
for (JsonElement e : files) {
JsonObject i = (JsonObject) e;
if (type.equals(JSONUtil.str(i, "resourceType")) && id.equals(JSONUtil.str(i, "id"))) {
return load("example", JSONUtil.str(i, "filename"));
}
}
}
return null;
}
/** special case when playing around inside the package **/
public Map<String, NpmPackageFolder> getFolders() {
return folders;