From 91916f899c14b1f23ec9d3e87cab7da8898456ff Mon Sep 17 00:00:00 2001 From: Oliver Granseier Date: Fri, 17 May 2024 10:10:45 +0200 Subject: [PATCH 1/2] Fixing problems with remote URL when using Maven Plugin --- .../java/org/jsonschema2pojo/util/URLUtil.java | 16 ++++++++++++++++ .../maven/Jsonschema2PojoMojo.java | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java index d9e19abd7..92e26e2f3 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java @@ -21,12 +21,28 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; import org.jsonschema2pojo.URLProtocol; public class URLUtil { + private static final Set LOCAL_PROTOCOL = Arrays.stream(new URLProtocol[]{URLProtocol.NO_PROTOCOL, URLProtocol.FILE}).collect(Collectors.toSet()); + + private URLUtil() { + } + + public static boolean isLocalUrl(String input) { + return LOCAL_PROTOCOL.contains(parseProtocol(input)); + } + + public static boolean isRemoteUrl(String input) { + return !isLocalUrl(input); + } + public static URLProtocol parseProtocol(String input) { return URLProtocol.fromString(StringUtils.substringBefore(input, ":")); } diff --git a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java index 5c3d4d279..3f24cde39 100644 --- a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java +++ b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java @@ -819,7 +819,8 @@ public void execute() throws MojoExecutionException { } else if (!isEmpty(sourcePaths)) { // verify individual source paths for (int i = 0; i < sourcePaths.length; i++) { - sourcePaths[i] = FilenameUtils.normalize(sourcePaths[i]); + sourcePaths[i] = URLUtil.isLocalUrl(sourcePaths[i]) ? + FilenameUtils.normalize(sourcePaths[i]) : sourcePaths[i]; try { URLUtil.parseURL(sourcePaths[i]); } catch (IllegalArgumentException e) { From a4c47df041f2f1dde705296e77a664baa1d64214 Mon Sep 17 00:00:00 2001 From: Oliver Granseier Date: Mon, 24 Jun 2024 08:47:42 +0200 Subject: [PATCH 2/2] Changing to EnumSet instead of Streaming API --- .../main/java/org/jsonschema2pojo/util/URLUtil.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java index 92e26e2f3..fd8b30b81 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java @@ -16,21 +16,21 @@ package org.jsonschema2pojo.util; +import org.apache.commons.lang.StringUtils; +import org.jsonschema2pojo.URLProtocol; + import java.io.File; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.commons.lang.StringUtils; -import org.jsonschema2pojo.URLProtocol; public class URLUtil { - private static final Set LOCAL_PROTOCOL = Arrays.stream(new URLProtocol[]{URLProtocol.NO_PROTOCOL, URLProtocol.FILE}).collect(Collectors.toSet()); + private static final Set LOCAL_PROTOCOL = Collections.unmodifiableSet(EnumSet.of(URLProtocol.NO_PROTOCOL, URLProtocol.FILE)); private URLUtil() { }