Changes to support upgrades to IG publisher -go-publish process

This commit is contained in:
Grahame Grieve 2023-01-05 08:44:45 +11:00
parent 19f1171962
commit e794eca959
4 changed files with 117 additions and 2 deletions

View File

@ -0,0 +1,39 @@
package org.hl7.fhir.utilities;
public class FTPClient {
/**
* Connect to an FTP server
* @param server - the server to connect to (uusally just an IP address). It's up to the system to figure out access (VPN etc)
* @param path - the path on the FTP server to treat all the operations as relative to
* @param user - username for the FTP server
* @param password - password for the FTP server
*/
public FTPClient(String server, String path, String user, String password) {
}
/**
* Connect to the server, throw an exception if it fails
*/
public void connect() {
}
/**
* Delete a file on the FTP server
*
* @param path - relative to the path provided in the constructor
*/
public void delete(String path) {
}
/**
* Upload a file from the local system to the FTP Server
* @param source - absolute path on local system
* @param path - relative to the path provided in the constructor
*/
public void upload(String source, String path) {
}
}

View File

@ -1469,6 +1469,10 @@ public class Utilities {
return byteArrays;
}
public static void unzip(InputStream zip, String target) throws IOException {
unzip(zip, Path.of(target));
}
public static void unzip(InputStream zip, Path target) throws IOException {
try (ZipInputStream zis = new ZipInputStream(zip)) {
ZipEntry zipEntry = zis.getNextEntry();
@ -1494,7 +1498,7 @@ public class Utilities {
}
}
private static Path zipSlipProtect(ZipEntry zipEntry, Path targetDir)
public static Path zipSlipProtect(ZipEntry zipEntry, Path targetDir)
throws IOException {
// test zip slip vulnerability
@ -1815,4 +1819,47 @@ public class Utilities {
}
return baseText + "\r\n" + derivedText.substring(3);
}
public static void deleteEmptyFolders(File df) {
for (File f : df.listFiles()) {
if (f.isDirectory()) {
deleteEmptyFolders(f);
}
}
boolean empty = true;
for (File f : df.listFiles()) {
empty = false;
break;
}
if (empty) {
df.delete();
}
}
public static String getRelativePath(String root, String path) {
String res = path.substring(root.length());
if (res.startsWith(File.separator)) {
res = res.substring(1);
}
return res;
}
public static List<String> listAllFiles(String path, List<String> ignoreList) {
List<String> res = new ArrayList<>();
addAllFiles(res, path, new File(path), ignoreList);
return res;
}
private static void addAllFiles(List<String> res, String root, File dir, List<String> ignoreList) {
for (File f : dir.listFiles()) {
if (ignoreList == null || !ignoreList.contains(f.getAbsolutePath())) {
if (f.isDirectory()) {
addAllFiles(res, root, f, ignoreList);
} else {
res.add(getRelativePath(root, f.getAbsolutePath()));
}
}
}
}
}

View File

@ -181,7 +181,7 @@ public class JsonParser {
}
public static byte[] composeBytes(JsonElement element, boolean pretty) {
String s = compose(element);
String s = compose(element, pretty);
return s.getBytes(StandardCharsets.UTF_8);
}

View File

@ -2,6 +2,8 @@ package org.hl7.fhir.utilities.npm;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@ -45,6 +47,8 @@ public class PackageList {
}
public String fhirVersion() {
if (json.has("fhir-version")) // legacy
return json.asString("fhir-version");
return json.asString("fhirversion");
}
@ -114,6 +118,14 @@ public class PackageList {
json.set("changes", changes);
}
}
public JsonObject json() {
return json;
}
public Instant instant() throws ParseException {
return json.asInstant("date");
}
}
private String source;
@ -251,4 +263,21 @@ public class PackageList {
return null;
}
}
public String title() {
return json.asString("title");
}
public PackageListEntry current() {
for (PackageListEntry e : list) {
if (e.current() && !"ci-build".equals(e.status())) {
return e;
}
}
return null;
}
public String intro() {
return json.asString("introduction");
}
}