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.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -204,6 +205,9 @@ public class NpmPackage {
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that parses a package from an extracted folder
|
||||
*/
|
||||
public static NpmPackage fromFolder(String path) throws IOException {
|
||||
NpmPackage res = new NpmPackage();
|
||||
loadFiles(res, path, new File(path));
|
||||
|
@ -211,6 +215,15 @@ public class NpmPackage {
|
|||
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() {
|
||||
return userData;
|
||||
}
|
||||
|
@ -787,7 +800,7 @@ public class NpmPackage {
|
|||
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"));
|
||||
}
|
||||
byte[] cnt = TextFile.stringToBytes(new GsonBuilder().setPrettyPrinting().create().toJson(npm), false);
|
||||
|
@ -825,7 +838,7 @@ public class NpmPackage {
|
|||
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");
|
||||
entry.setSize(cnt.length);
|
||||
tar.putArchiveEntry(entry);
|
||||
|
@ -942,6 +955,9 @@ public class NpmPackage {
|
|||
}
|
||||
|
||||
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);
|
||||
folder.content.put(name, cnt);
|
||||
if (!folder.types.containsKey(type))
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
package org.hl7.fhir.utilities.cache;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -63,9 +63,14 @@ public class PackageGenerator {
|
|||
throw new Error("Unknown Type");
|
||||
}
|
||||
}
|
||||
|
||||
private OutputStream stream;
|
||||
private JsonObject object;
|
||||
|
||||
public PackageGenerator() {
|
||||
object = new JsonObject();
|
||||
}
|
||||
|
||||
public PackageGenerator(OutputStream stream) {
|
||||
super();
|
||||
this.stream = stream;
|
||||
|
@ -79,7 +84,11 @@ public class PackageGenerator {
|
|||
object = parser.parse(TextFile.streamToString(template)).getAsJsonObject();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public JsonObject getRootJsonObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void commit() throws IOException {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json = gson.toJson(object);
|
||||
|
|
Loading…
Reference in New Issue