From 11cbd5ddb13f8d61bd6d0946234b5508f5d28709 Mon Sep 17 00:00:00 2001 From: Elliot Silver Date: Mon, 26 Jun 2023 02:26:13 -0700 Subject: [PATCH 1/3] Support private (non-HL7) publication of templates --- .../publisher/utils/TemplateReleaser.java | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java index 4264ece15..6a419dd73 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java @@ -123,6 +123,8 @@ public String summary() { private File xml; + private Boolean assumeValidDependencies; + // 3 parameters: source of package, package dest folder, and release note public static void main(String[] args) throws Exception { @@ -138,6 +140,7 @@ public static void main(String[] args) throws Exception { private void release(String source, String dest) throws Exception { SimpleDateFormat df = new SimpleDateFormat(RSS_DATE, new Locale("en", "US")); + assumeValidDependencies = ("YES".equals(System.getenv("PUB_ASSUME_VALID_DEPENDENCIES"))); checkDest(dest); Map currentPublishedVersions = scanForCurrentVersions(dest); System.out.println("Current Published Versions"); @@ -215,13 +218,21 @@ private void buildIndexPage(Map currentVersions, String path) th for (String id : Utilities.sorted(currentVersions.keySet())) { tr = tbl.tr(); PackageList pl = new PackageList(JsonParser.parseObject(new File(Utilities.path(path, id, "package-list.json")))); - tr.td().ah("http://fhir.org/templates/"+id).tx(pl.pid()); + tr.td().ah(pl.canonical()).tx(pl.pid()); tr.td().tx(pl.title()); - tr.td().ah("http://fhir.org/templates/"+id+"/"+pl.current().version()+"/package.tgz").tx(pl.current().version()); + tr.td().ah(pl.current().path() + "/package.tgz").tx(pl.current().version()); tr.td().tx(pl.current().date()); } - String s = INDEX_TEMPLATE.replace("{{index}}", new XhtmlComposer(false, false).compose(tbl)); - TextFile.stringToFile(s, Utilities.path(path, "index.html"), false); + + String templateName = System.getenv("PUB_INDEX_TEMPLATE_FILE"); + if (templateName != null) { + String s = TextFile.fileToString(templateName).replace("{{index}}", new XhtmlComposer(false, false).compose(tbl)); + TextFile.stringToFile(s, Utilities.path(path, "index.html"), false); + } + else { + String s = INDEX_TEMPLATE.replace("{{index}}", new XhtmlComposer(false, false).compose(tbl)); + TextFile.stringToFile(s, Utilities.path(path, "index.html"), false); + } } private void build(String source, VersionDecision vd, List versions) throws Exception { @@ -242,12 +253,23 @@ private void updateVersions(String source, VersionDecision vd, List deps = new ArrayList<>(); - for (JsonProperty e : d.getProperties()) { - deps.add(e.getName()); + if (assumeValidDependencies) { + for (JsonProperty e : d.getProperties()) { + if (assumeValidDependencies && "current".equals(e.getValue().asJsonString().getValue())) { + throw new Error("When skipping dependency checks, cannot use \"current\" for "+e.getName()+" in "+vd.getId()+"."); + } + } } - for (String s : deps) { - d.remove(s); - d.add(s, findVersion(versionsList, s).newVersion); + else { + for (JsonProperty e : d.getProperties()) { + deps.add(e.getName()); + } + if (!assumeValidDependencies) { + for (String s : deps) { + d.remove(s); + d.add(s, findVersion(versionsList, s).newVersion); + } + } } } String jcnt = JsonParser.compose(npm, true); @@ -255,6 +277,9 @@ private void updateVersions(String source, VersionDecision vd, List versionsList) throws FileNotFoundException, IOException { + if (assumeValidDependencies) { + return; + } JsonObject npm = JsonParser.parseObject(new FileInputStream(Utilities.path(source, vd.getId(), "package", "package.json"))); if (npm.has("dependencies")) { JsonObject d = npm.getJsonObject("dependencies"); @@ -282,7 +307,7 @@ private void updateDate(String source, VersionDecision vd, String dateFmt) throw } } if (!ok) { - throw new Error("unable to find version "+vd.getNewVersion()+" in pacjage list"); + throw new Error("unable to find version "+vd.getNewVersion()+" in package list"); } TextFile.stringToFile(pl.toJson(), Utilities.path(source, vd.getId(), "package-list.json")); } @@ -356,8 +381,8 @@ private String getNewVersion(VersionChangeType t, String v) { private void checkDependencies(String source, VersionDecision vd, List versions) throws Exception { vd.checked = false; - List dependendencies = listDependencies(source, vd.getId()); - for (String s : dependendencies) { + List dependencies = listDependencies(source, vd.getId()); + for (String s : dependencies) { VersionDecision v = findVersion(versions, s); if (v.checked == null) { checkDependencies(source, v, versions); @@ -395,7 +420,7 @@ private VersionDecision findVersion(List versions, String s) { private List listDependencies(String source, String id) throws Exception { JsonObject npm = JsonParser.parseObject(TextFile.fileToString(Utilities.path(source, id, "package", "package.json"))); List res = new ArrayList(); - if (npm.has("dependencies")) { + if (!assumeValidDependencies && npm.has("dependencies")) { for (JsonProperty s : npm.getJsonObject("dependencies").getProperties()) { // if (!"current".equals(s.getValue().getAsString())) { // throw new Exception("Dependency is not 'current'"); From 1b673fadd88cd8653cfb959ef30cc6c67443df58 Mon Sep 17 00:00:00 2001 From: Elliot Silver Date: Mon, 26 Jun 2023 21:43:37 -0700 Subject: [PATCH 2/3] Correct Template index page jekyll template --- .../java/org/hl7/fhir/igtools/publisher/Publisher.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 083b46a9c..217a62e42 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -1032,10 +1032,10 @@ private String makeTemplateIndexPage() { } private String makeTemplateJekyllIndexPage() { - String page = "---"+ - "layout: page"+ - "title: {{npm}}"+ - "---"+ + String page = "---\r\n"+ + "layout: page\r\n"+ + "title: {{npm}}\r\n"+ + "---\r\n"+ "

Template {{npm}}

\r\n"+ "

You can download the template, though you should not need to; just refer to the template as {{npm}} in your IG configuration.

\r\n"+ "

A full version history is published

\r\n"; From 98034adcbec2f7d6eaae91669f121e6ad4dc1332 Mon Sep 17 00:00:00 2001 From: Elliot Silver Date: Tue, 27 Jun 2023 18:48:58 -0700 Subject: [PATCH 3/3] Package located canonical + version, not declared path --- .../org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java index 6a419dd73..224449256 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/utils/TemplateReleaser.java @@ -220,7 +220,7 @@ private void buildIndexPage(Map currentVersions, String path) th PackageList pl = new PackageList(JsonParser.parseObject(new File(Utilities.path(path, id, "package-list.json")))); tr.td().ah(pl.canonical()).tx(pl.pid()); tr.td().tx(pl.title()); - tr.td().ah(pl.current().path() + "/package.tgz").tx(pl.current().version()); + tr.td().ah(pl.canonical() + "/" + pl.current().version() + "/package.tgz").tx(pl.current().version()); tr.td().tx(pl.current().date()); }