A bit of package rework
This commit is contained in:
parent
0d8cab0b6e
commit
56d933199c
|
@ -40,6 +40,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -204,6 +205,9 @@ public class NpmPackage {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method that parses a package from an extracted folder
|
||||||
|
*/
|
||||||
public static NpmPackage fromFolder(String path) throws IOException {
|
public static NpmPackage fromFolder(String path) throws IOException {
|
||||||
NpmPackage res = new NpmPackage();
|
NpmPackage res = new NpmPackage();
|
||||||
loadFiles(res, path, new File(path));
|
loadFiles(res, path, new File(path));
|
||||||
|
@ -211,6 +215,15 @@ public class NpmPackage {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method that starts a new empty package using the given PackageGenerator to create the manifest
|
||||||
|
*/
|
||||||
|
public static NpmPackage empty(PackageGenerator thePackageGenerator) {
|
||||||
|
NpmPackage retVal = new NpmPackage();
|
||||||
|
retVal.npm = thePackageGenerator.getRootJsonObject();
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> getUserData() {
|
public Map<String, Object> getUserData() {
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
@ -787,7 +800,7 @@ public class NpmPackage {
|
||||||
TextFile.bytesToFile(b, Utilities.path(dir.getAbsolutePath(), n, s));
|
TextFile.bytesToFile(b, Utilities.path(dir.getAbsolutePath(), n, s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] cnt = indexer.build().getBytes(Charset.forName("UTF-8"));
|
byte[] cnt = indexer.build().getBytes(StandardCharsets.UTF_8);
|
||||||
TextFile.bytesToFile(cnt, Utilities.path(dir.getAbsolutePath(), n, ".index.json"));
|
TextFile.bytesToFile(cnt, Utilities.path(dir.getAbsolutePath(), n, ".index.json"));
|
||||||
}
|
}
|
||||||
byte[] cnt = TextFile.stringToBytes(new GsonBuilder().setPrettyPrinting().create().toJson(npm), false);
|
byte[] cnt = TextFile.stringToBytes(new GsonBuilder().setPrettyPrinting().create().toJson(npm), false);
|
||||||
|
@ -825,7 +838,7 @@ public class NpmPackage {
|
||||||
tar.closeArchiveEntry();
|
tar.closeArchiveEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] cnt = indexer.build().getBytes(Charset.forName("UTF-8"));
|
byte[] cnt = indexer.build().getBytes(StandardCharsets.UTF_8);
|
||||||
TarArchiveEntry entry = new TarArchiveEntry(n+"/.index.json");
|
TarArchiveEntry entry = new TarArchiveEntry(n+"/.index.json");
|
||||||
entry.setSize(cnt.length);
|
entry.setSize(cnt.length);
|
||||||
tar.putArchiveEntry(entry);
|
tar.putArchiveEntry(entry);
|
||||||
|
@ -942,6 +955,9 @@ public class NpmPackage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFile(String folderName, String name, byte[] cnt, String type) {
|
public void addFile(String folderName, String name, byte[] cnt, String type) {
|
||||||
|
if (!folders.containsKey(folderName)) {
|
||||||
|
folders.put(folderName, new NpmPackageFolder(folderName));
|
||||||
|
}
|
||||||
NpmPackageFolder folder = folders.get(folderName);
|
NpmPackageFolder folder = folders.get(folderName);
|
||||||
folder.content.put(name, cnt);
|
folder.content.put(name, cnt);
|
||||||
if (!folder.types.containsKey(type))
|
if (!folder.types.containsKey(type))
|
||||||
|
|
|
@ -63,9 +63,14 @@ public class PackageGenerator {
|
||||||
throw new Error("Unknown Type");
|
throw new Error("Unknown Type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutputStream stream;
|
private OutputStream stream;
|
||||||
private JsonObject object;
|
private JsonObject object;
|
||||||
|
|
||||||
|
public PackageGenerator() {
|
||||||
|
object = new JsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
public PackageGenerator(OutputStream stream) {
|
public PackageGenerator(OutputStream stream) {
|
||||||
super();
|
super();
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
@ -80,6 +85,10 @@ public class PackageGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonObject getRootJsonObject() {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
public void commit() throws IOException {
|
public void commit() throws IOException {
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
String json = gson.toJson(object);
|
String json = gson.toJson(object);
|
||||||
|
|
Loading…
Reference in New Issue