You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by "codyfearer (via GitHub)" <gi...@apache.org> on 2024/09/14 18:33:54 UTC

[PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

codyfearer opened a new pull request, #652:
URL: https://github.com/apache/opennlp/pull/652

   Updated SimpleClassPathModelFinder to return a list of paths instead of the delimiter
   
   <img width="1055" alt="After" src="https://github.com/user-attachments/assets/7414bab6-80c0-4192-a405-cd2e85b5951c">
   
   
   Thank you for contributing to Apache OpenNLP.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
   - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?
   
   ### For documentation related changes:
   
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions for build issues and submit an update to your PR as soon as possible.
   


-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on PR #652:
URL: https://github.com/apache/opennlp/pull/652#issuecomment-2352262682

   @codyfearer Thx for the PR. A screenshot is not a proof of correctness for the intended behavior. Could you therefore add a test case that demonstrates the difference in outcomes with your code change?


-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

Posted by "codyfearer (via GitHub)" <gi...@apache.org>.
codyfearer commented on PR #652:
URL: https://github.com/apache/opennlp/pull/652#issuecomment-2363646481

   Added the code for Windows paths. Was able to successfully build on a Windows 11 VM


-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on PR #652:
URL: https://github.com/apache/opennlp/pull/652#issuecomment-2352301857

   There is already a unit test but the branch isn't hit because of the surefire configuration. 
   
   @codyfearer Maybe just add an additional execution phase for surefire without the `--add-opens`, so the branch actually gets triggered. This will show, that the current impl is broken and your patch is a fix for it.


-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths (opennlp)

Posted by "jzonthemtn (via GitHub)" <gi...@apache.org>.
jzonthemtn merged PR #652:
URL: https://github.com/apache/opennlp/pull/652


-- 
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: dev-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org