Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problems with remote URL when using Maven Plugin #1614

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<URLProtocol> LOCAL_PROTOCOL = Arrays.stream(new URLProtocol[]{URLProtocol.NO_PROTOCOL, URLProtocol.FILE}).collect(Collectors.toSet());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be replaced by Set.of?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it can't since Set::of was introduced in Java 9 and current compiler configuration is:

jsonschema2pojo/pom.xml

Lines 213 to 223 in 34cc693

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
</configuration>
</plugin>

That being said it could be changed to = EnumSet.of(URLProtocol.NO_PROTOCOL, URLProtocol.FILE) with a small caveat - resulting set would be mutable (however that shouldn't be a problem since it's private and there are no methods returning it's reference.

Copy link
Author

@gr0l gr0l Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the corresponding line. I am now using an EnumSet wrapped in an unmodifiable set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelittlejohn: Can it be merged now?


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, ":"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down