rzo1 commented on PR #652:
URL: https://github.com/apache/opennlp/pull/652#issuecomment-2357830215
@codyfearer I think
```bash
Index:
opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git
a/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
b/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
---
a/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
(revision 8d3b2dacc1da8d301734e9004b998b001f6619b0)
+++
b/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
(date 1726648019585)
@@ -63,8 +63,8 @@
private static final Logger logger =
LoggerFactory.getLogger(SimpleClassPathModelFinder.class);
private static final String FILE_PREFIX = "file";
- private static final Pattern CLASSPATH_SEPARATOR_PATTERN =
Pattern.compile("[;:]");
- // ; for Windows, : for Linux/OSX
+ private static final Pattern CLASSPATH_SEPARATOR_PATTERN_WINDOWS =
Pattern.compile(";");
+ private static final Pattern CLASSPATH_SEPARATOR_PATTERN_UNIX =
Pattern.compile(";");
/**
* By default, it scans for "opennlp-models-*.jar".
@@ -190,20 +190,26 @@
if (fromUcp != null && fromUcp.length > 0) {
return Arrays.asList(fromUcp);
} else {
- final String cp = System.getProperty("java.class.path", "");
- final String[] matches = CLASSPATH_SEPARATOR_PATTERN.split(cp);
- final List<URL> jarUrls = new ArrayList<>();
- for (String classPath: matches) {
- try {
- jarUrls.add(new URL(FILE_PREFIX, "", classPath));
- } catch (MalformedURLException ignored) {
- //if we cannot parse a URL from the system property, just
ignore it...
- //we couldn't load it anyway
- }
- }
- return jarUrls;
- }
- }
+ return getClassPathUrlsFromSystemProperty();
+ }
+ }
+ }
+
+ private List<URL> getClassPathUrlsFromSystemProperty() {
+ final String cp = System.getProperty("java.class.path", "");
+ final String[] matches = isWindows()
+ ? CLASSPATH_SEPARATOR_PATTERN_WINDOWS.split(cp)
+ : CLASSPATH_SEPARATOR_PATTERN_UNIX.split(cp);
+ final List<URL> jarUrls = new ArrayList<>();
+ for (String classPath: matches) {
+ try {
+ jarUrls.add(new URL(FILE_PREFIX, "", classPath));
+ } catch (MalformedURLException ignored) {
+ //if we cannot parse a URL from the system property, just ignore
it...
+ //we couldn't load it anyway
+ }
+ }
+ return jarUrls;
}
/*
```
should do the trick on Windows. The issue with the combined regex is, that
Windows cp elements start with "C:" for example and a split with "[;:]" will be
broken in that case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]