From 70b94edca8bb156ce8ce0c294ec49b2d73837fa9 Mon Sep 17 00:00:00 2001 From: Pavel Vlasov Date: Mon, 30 Dec 2024 11:35:14 -0500 Subject: [PATCH] 2024.12.0 --- capability-tests/pom.xml | 2 +- capability/pom.xml | 4 +- cli/pom.xml | 6 +- .../java/org/nasdanika/cli/DrawioCommand.java | 133 +++++++++++++++++- .../org/nasdanika/cli/PropertiesMixIn.java | 2 +- common/pom.xml | 10 +- diagram/pom.xml | 2 +- drawio.model/pom.xml | 2 +- drawio/pom.xml | 2 +- emf/pom.xml | 4 +- exec.gen/pom.xml | 2 +- exec/pom.xml | 2 +- graph.model/pom.xml | 2 +- graph/pom.xml | 6 +- groovy/pom.xml | 4 +- http/pom.xml | 4 +- mapping/pom.xml | 2 +- maven/pom.xml | 2 +- ncore.gen/pom.xml | 2 +- ncore/pom.xml | 2 +- persistence/pom.xml | 2 +- pom.xml | 18 +-- resources/pom.xml | 2 +- 23 files changed, 169 insertions(+), 48 deletions(-) diff --git a/capability-tests/pom.xml b/capability-tests/pom.xml index db55f004..f7e3d052 100644 --- a/capability-tests/pom.xml +++ b/capability-tests/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. capability-tests diff --git a/capability/pom.xml b/capability/pom.xml index b4bef5bb..5cedd5bf 100644 --- a/capability/pom.xml +++ b/capability/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. capability @@ -20,7 +20,7 @@ io.projectreactor reactor-core - 3.6.10 + 3.7.1 \ No newline at end of file diff --git a/cli/pom.xml b/cli/pom.xml index f6f610bd..0caba2a3 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. cli @@ -39,7 +39,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.5.0 + 3.5.2 @@ -70,7 +70,7 @@ org.jline jline - 3.26.3 + 3.28.0 \ No newline at end of file diff --git a/cli/src/main/java/org/nasdanika/cli/DrawioCommand.java b/cli/src/main/java/org/nasdanika/cli/DrawioCommand.java index b78af883..8c8f5e01 100644 --- a/cli/src/main/java/org/nasdanika/cli/DrawioCommand.java +++ b/cli/src/main/java/org/nasdanika/cli/DrawioCommand.java @@ -3,19 +3,31 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; import java.util.function.Function; import javax.xml.parsers.ParserConfigurationException; import org.eclipse.emf.common.util.URI; +import org.json.JSONObject; +import org.json.JSONTokener; import org.nasdanika.capability.CapabilityLoader; import org.nasdanika.common.DefaultConverter; import org.nasdanika.common.NasdanikaException; import org.nasdanika.common.ProgressMonitor; import org.nasdanika.drawio.Document; import org.xml.sax.SAXException; +import org.yaml.snakeyaml.Yaml; +import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; import picocli.CommandLine.Option; @@ -55,6 +67,42 @@ protected DrawioCommand(CapabilityLoader capabilityLoader) { @Mixin PropertiesMixIn propertiesMixIn; + + @Option( + names = {"-u", "--uri"}, + description = { + "URI to URL mapping", + "Target URLs are resolved", + "relative to the document URL"}) + private Map uris = new LinkedHashMap<>(); + + @Option( + names = {"-U", "--uris"}, + paramLabel = "URL of URI to URL mapping resource", + description = { + "URI map resource URL relative to the document file", + "YAML, JSON, or properties", + "Type is inferred from the content type header, if it is present, ", + "or extension" + }) + private List uriMapSources = new ArrayList<>(); + + protected Map loadJson(InputStream in) throws IOException { + JSONObject jo = new JSONObject(new JSONTokener(in)); + return jo.toMap(); + } + + protected Map loadYaml(InputStream in) throws IOException { + Yaml yaml = new Yaml(); + return yaml.load(in); + } + + protected Properties loadProperties(InputStream in) throws IOException { + Properties props = new Properties(); + props.load(in); + return props; + } + @Override public Document getDocument(ProgressMonitor progressMonitor) { File currentDir = new File("."); @@ -64,7 +112,7 @@ public Document getDocument(ProgressMonitor progressMonitor) { if (isFile) { File documentFile = new File(document); try { - return Document.load(documentFile, getUriHandler(progressMonitor), getPropertySource(progressMonitor)); + return Document.load(documentFile, getUriHandler(URI.createFileURI(documentFile.toString()), progressMonitor), getPropertySource(progressMonitor)); } catch (IOException | ParserConfigurationException | SAXException e) { throw new NasdanikaException("Error loading document from '" + documentFile.getAbsolutePath() + "': " + e, e); } @@ -73,17 +121,90 @@ public Document getDocument(ProgressMonitor progressMonitor) { URI baseURI = URI.createFileURI(currentDir.getAbsolutePath()).appendSegment(""); URI documentURI = URI.createURI(document).resolve(baseURI); try { - return Document.load(documentURI, getUriHandler(progressMonitor), getPropertySource(progressMonitor)); + return Document.load(documentURI, getUriHandler(documentURI, progressMonitor), getPropertySource(progressMonitor)); } catch (IOException | ParserConfigurationException | SAXException e) { throw new NasdanikaException("Error loading document from '" + documentURI.toString() + "': " + e, e); } } - protected Function getUriHandler(ProgressMonitor progressMonitor) { - // TODO - return null; - } + protected Function getUriHandler(URI baseURI, ProgressMonitor progressMonitor) { + Map data = new LinkedHashMap<>(uris); + File currentDir = new File("."); + for (String location: uriMapSources) { + try { + URL url = currentDir.toURI().resolve(location).toURL(); + URLConnection connection = url.openConnection(); + + if (location.endsWith(".json")) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadJson(in)); + } + } else if (location.endsWith(".yml") || location.endsWith(".yaml")) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadYaml(in)); + } + } else if (location.endsWith(".properties")) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadProperties(in)); + } + } else { + // Can't deduce content type from extension, attempting to use Content-Type header + if (connection instanceof HttpURLConnection && ((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_OK) { + String contentType = ((HttpURLConnection) connection).getHeaderField("Content-Type"); + if ("application/json".equals(contentType)) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadJson(in)); + } + } else if ("application/x-yaml".equals(contentType)) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadYaml(in)); + } + } else if ("text/x-java-properties".equals(contentType)) { + try (InputStream in = connection.getInputStream()) { + data.putAll(loadProperties(in)); + } + } else { + throw new CommandLine.ParameterException(spec.commandLine(), "Unsupported content type '" + contentType + "' for " + url); + } + } else { + throw new CommandLine.ParameterException(spec.commandLine(), "Unknown resource type " + url); + } + } + } catch (IOException e) { + throw new CommandLine.ParameterException(spec.commandLine(), "Cannot load properties from " + location + ": " + e, e); + } + } + if (data.isEmpty()) { + return null; + } + + return uri -> { + for (Entry dataEntry: data.entrySet()) { + String keyStr = dataEntry.getKey().toString(); + URI keyURI = URI.createURI(keyStr); + URI valueURI = URI.createURI(dataEntry.getValue().toString()); + if (valueURI.isRelative() && baseURI != null) { + valueURI = valueURI.resolve(baseURI); + } + if (keyURI.equals(uri)) { + uri = valueURI; + break; + } + if (uri.toString().startsWith(keyStr)) { + URI relative = uri.deresolve(keyURI, true, true, true); + uri = relative.resolve(valueURI); + break; + } + } + + try { + return new URL(uri.toString()).openStream(); + } catch (IOException e) { + throw new NasdanikaException("Error opening stream from " + uri + ": " + e, e); + } + }; + } protected Function getPropertySource(ProgressMonitor progressMonitor) { Map properties = propertiesMixIn.getProperties(); diff --git a/cli/src/main/java/org/nasdanika/cli/PropertiesMixIn.java b/cli/src/main/java/org/nasdanika/cli/PropertiesMixIn.java index 8477a8eb..3ea7f870 100644 --- a/cli/src/main/java/org/nasdanika/cli/PropertiesMixIn.java +++ b/cli/src/main/java/org/nasdanika/cli/PropertiesMixIn.java @@ -33,7 +33,7 @@ public class PropertiesMixIn { @Option( names = {"-p", "--property"}, - description = { "Properties" }) + description = { "Property" }) private Map properties = new LinkedHashMap<>(); @Option( diff --git a/common/pom.xml b/common/pom.xml index beb2ffe0..3fa01bc3 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. common @@ -16,7 +16,7 @@ org.eclipse.emf org.eclipse.emf.ecore - 2.37.0 + 2.38.0 org.eclipse.emf @@ -37,7 +37,7 @@ org.jsoup jsoup - 1.18.1 + 1.18.3 @@ -55,7 +55,7 @@ org.apache.commons commons-text - 1.12.0 + 1.13.0 @@ -67,7 +67,7 @@ org.springframework spring-expression - 6.1.14 + 6.2.1 diff --git a/diagram/pom.xml b/diagram/pom.xml index e09de52b..4f8816de 100644 --- a/diagram/pom.xml +++ b/diagram/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. diagram diff --git a/drawio.model/pom.xml b/drawio.model/pom.xml index 36bbc715..0b68a9ac 100644 --- a/drawio.model/pom.xml +++ b/drawio.model/pom.xml @@ -5,7 +5,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. drawio-model diff --git a/drawio/pom.xml b/drawio/pom.xml index e39e0603..fe766e39 100644 --- a/drawio/pom.xml +++ b/drawio/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. drawio diff --git a/emf/pom.xml b/emf/pom.xml index 294e702d..d133f6d1 100644 --- a/emf/pom.xml +++ b/emf/pom.xml @@ -3,7 +3,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. emf @@ -24,7 +24,7 @@ org.eclipse.jgit org.eclipse.jgit - 7.0.0.202409031743-r + 7.1.0.202411261347-r org.apache.poi diff --git a/exec.gen/pom.xml b/exec.gen/pom.xml index a64fa0fc..38537504 100644 --- a/exec.gen/pom.xml +++ b/exec.gen/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. exec-gen diff --git a/exec/pom.xml b/exec/pom.xml index 9f89a4e5..2d7ea34f 100644 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -5,7 +5,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. exec diff --git a/graph.model/pom.xml b/graph.model/pom.xml index 5990cf03..84caa3ec 100644 --- a/graph.model/pom.xml +++ b/graph.model/pom.xml @@ -5,7 +5,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. graph-model diff --git a/graph/pom.xml b/graph/pom.xml index 19451aa8..507e5528 100644 --- a/graph/pom.xml +++ b/graph/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. graph @@ -28,9 +28,9 @@ 1.5.2 - org.nasdanika.core + ${project.groupId} common - 2024.11.1 + ${project.version} \ No newline at end of file diff --git a/groovy/pom.xml b/groovy/pom.xml index 347629ce..018bbd9f 100644 --- a/groovy/pom.xml +++ b/groovy/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. groovy @@ -21,7 +21,7 @@ org.apache.groovy groovy-groovysh - 4.0.23 + 4.0.24 \ No newline at end of file diff --git a/http/pom.xml b/http/pom.xml index c4b4ab8b..c6fdf6d1 100644 --- a/http/pom.xml +++ b/http/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. http @@ -21,7 +21,7 @@ io.projectreactor.netty reactor-netty-http - 1.1.22 + 1.2.1 \ No newline at end of file diff --git a/mapping/pom.xml b/mapping/pom.xml index a5f6b670..84d1d46d 100644 --- a/mapping/pom.xml +++ b/mapping/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. mapping diff --git a/maven/pom.xml b/maven/pom.xml index 1f7b72bb..bd162fbc 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. diff --git a/ncore.gen/pom.xml b/ncore.gen/pom.xml index 8d397976..e62947e5 100644 --- a/ncore.gen/pom.xml +++ b/ncore.gen/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. ncore-gen diff --git a/ncore/pom.xml b/ncore/pom.xml index 69b5a134..9a5b2e90 100644 --- a/ncore/pom.xml +++ b/ncore/pom.xml @@ -5,7 +5,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. ncore diff --git a/persistence/pom.xml b/persistence/pom.xml index 853ef0b9..8da86b49 100644 --- a/persistence/pom.xml +++ b/persistence/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. persistence diff --git a/pom.xml b/pom.xml index ea79265b..67659191 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.nasdanika.core - 2024.11.1 + 2024.12.0 parent pom Nasdanika Core Parent @@ -69,7 +69,7 @@ org.apache.maven.plugins maven-site-plugin - 3.20.0 + 3.21.0 org.apache.maven.plugins @@ -87,19 +87,19 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.0 + 3.5.2 org.junit.jupiter junit-jupiter-engine - 5.11.0 + 5.11.4 org.apache.maven.plugins maven-javadoc-plugin - 3.10.0 + 3.11.2 @@ -159,20 +159,20 @@ org.junit.jupiter junit-jupiter-api - 5.11.0 + 5.11.4 test org.junit.jupiter junit-jupiter-engine - 5.11.0 + 5.11.4 test org.assertj assertj-core - 3.26.3 + 3.27.0 test @@ -231,7 +231,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.6 + 3.2.7 sign-artifacts diff --git a/resources/pom.xml b/resources/pom.xml index e97b2d12..2ef69b61 100644 --- a/resources/pom.xml +++ b/resources/pom.xml @@ -4,7 +4,7 @@ parent org.nasdanika.core - 2024.11.1 + 2024.12.0 .. resources