Search in sources :

Example 26 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackage method fromFolder.

public static NpmPackage fromFolder(String folder, PackageType defType, String... exemptions) throws IOException {
    NpmPackage res = new NpmPackage();
    res.loadFiles(folder, new File(folder), exemptions);
    if (!res.folders.containsKey("package")) {
        res.folders.put("package", res.new NpmPackageFolder("package"));
    }
    if (!res.folders.get("package").hasFile("package.json") && defType != null) {
        TextFile.stringToFile("{ \"type\" : \"" + defType.getCode() + "\"}", Utilities.path(res.folders.get("package").folder.getAbsolutePath(), "package.json"));
    }
    res.npm = (JsonObject) new com.google.gson.JsonParser().parse(new String(res.folders.get("package").fetchFile("package.json")));
    return res;
}
Also used : File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 27 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackage method fromUrl.

public static NpmPackage fromUrl(String source) throws IOException {
    SimpleHTTPClient fetcher = new SimpleHTTPClient();
    HTTPResult res = fetcher.get(source + "?nocache=" + System.currentTimeMillis());
    res.checkThrowException();
    return fromPackage(new ByteArrayInputStream(res.getContent()));
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 28 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class CorePackageTools method buildPackage.

private void buildPackage(String path, String output) throws IOException {
    NpmPackage npm = NpmPackage.fromFolder(path);
    npm.loadAllFiles();
    npm.save(new FileOutputStream(output));
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) FileOutputStream(java.io.FileOutputStream)

Example 29 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackageTests method testOldTgz.

@Test
public void testOldTgz() throws IOException {
    NpmPackage npm = NpmPackage.fromPackage(TestingUtilities.loadTestResourceStream("npm", "test.format.old.tgz"));
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) Test(org.junit.jupiter.api.Test)

Example 30 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackageTests method testNewFolder.

@Test
public void testNewFolder() throws IOException {
    // extract the test
    String dst = Utilities.path("[tmp]", "npm", "test.format.new");
    Utilities.clearDirectory(dst);
    unzip(TestingUtilities.loadTestResourceStream("npm", "test.format.new.zip"), new File(dst));
    dst = Utilities.path(dst, "test.format.new");
    NpmPackage npm = NpmPackage.fromFolder(dst);
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)34 File (java.io.File)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)13 IOException (java.io.IOException)11 Test (org.junit.jupiter.api.Test)11 FileNotFoundException (java.io.FileNotFoundException)9 TextFile (org.hl7.fhir.utilities.TextFile)8 FileOutputStream (java.io.FileOutputStream)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)6 SimpleWorkerContext (org.hl7.fhir.r5.context.SimpleWorkerContext)4 IniFile (org.hl7.fhir.utilities.IniFile)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)3