You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Marcus Berndt (JIRA)" <ji...@apache.org> on 2015/06/16 13:17:00 UTC

[jira] [Commented] (GROOVY-7018) GroovyClassLoader addClasspath RegexPattern issue

    [ https://issues.apache.org/jira/browse/GROOVY-7018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14587887#comment-14587887 ] 

Marcus Berndt commented on GROOVY-7018:
---------------------------------------

We have got the same problem as mentioned by Oliver Croquette with Symptom 1. So I tried to create a small fix in the 2 above mentioned Groovy classes GroovyMain and GroovyClassLoader.

It looks like the following:
{code:title=GroovyMain#getScriptSource|borderStyle=solid}

protected GroovyCodeSource getScriptSource(boolean isScriptFile, String script) throws IOException, URISyntaxException {
  //check the script is currently valid before starting a server against the script
  if (isScriptFile) {
     // search for the file and if it exists don't try to use URIs ...
     File scriptFile = huntForTheScriptFile(script);
     if (!scriptFile.exists() && uriPattern.matcher(script).matches()) {
        return new GroovyCodeSource(new URI(script));
     }
        return new GroovyCodeSource(scriptFile);
  }
  return new GroovyCodeSource(script, "script_from_command_line", GroovyShell.DEFAULT_CODE_BASE);
}
{code}

{code:title=GroovyClassloader#addClasspath|borderStyle=solid}
final File file = new File(path);
// search for the file and if it exists don't try to use URIs ...
if (file.exists() && !URI_PATTERN.matcher(path).matches()) {
  newURI = file.toURI();
} else {
  newURI = new URI(path);
}
{code}

For our scripts this works for both cases Oliver mentioned above.

I'm not sure if this fits all problems, but if it does i would create a pull request.

> GroovyClassLoader addClasspath RegexPattern issue
> -------------------------------------------------
>
>                 Key: GROOVY-7018
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7018
>             Project: Groovy
>          Issue Type: Bug
>          Components: GroovyScriptEngine
>    Affects Versions: 2.3.6
>         Environment: JDK 1.7u51
>            Reporter: Stefan Leonhartsberger
>
> When adding Groovy Files from the file system to the GroovyClassLoader's classpath grabbed from a default java properties file ("/" instead of "\"))
> Then the addClasspath() method uses a simple URL instead of the File URL
> This is due to a simple mistake in this mentioned method:
> {code}
> public void addClasspath(final String path) {
> ....
>      if (!URI_PATTERN.matcher(path).matches()) {
>           newURI = new File(path).toURI();
>      } else {
>           newURI = new URI(path);
>      }
> }
> private static final Pattern URI_PATTERN = Pattern.compile("\\p{Alpha}[-+.\\p{Alnum}]*:[^\\\\]*");
> {code}
> The URI_PATTERN which should match "URIs but not Windows filenames" doesn't work as expected.
> It matches i.e. C:/xxx/file.ext 
> This is related to using forward instead of backslashes - which souldn't matter.
> This was i.e. NOT the case for Groovy 2.1.3



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)