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

Ken Hu commented on TINKERPOP-2744:
-----------------------------------

I've been trying to reproduce this issue locally on Windows but haven't seen 
the issue so far. Following the steps from the Building and Testing section of 
the developer guide ([Building and 
Testing|https://github.com/apache/tinkerpop/blob/3.5-dev/docs/src/dev/developer/development-environment.asciidoc#building-and-testing]),
 I have tried both testing through Maven as well as the IntelliJ JUnit runner. 
Both were able to successfully run tests that called the generateTempFile() 
method.

My test runs using Maven seem to avoid that path computation code that you are 
mentioning is broken and instead gets the path from a _build.dir_ variable. If 
you are attempting to extend the tests from gremlin-test then you should follow 
the tip from the provider guide ([Validating with 
Gremlin-Test|https://github.com/apache/tinkerpop/blob/3.5-dev/docs/src/dev/provider/index.asciidoc#validating-with-gremlin-test])
 and set a _build.dir_ variable from the SureFire plugin with something like 
{_}${project.build.directory}{_}. See the link above for more information.

> TestSupport:::getRootOfBuildDirectory is broken on Windows
> ----------------------------------------------------------
>
>                 Key: TINKERPOP-2744
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2744
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: test-suite
>    Affects Versions: 3.5.0, 3.5.1, 3.6.0, 3.5.2, 3.5.3
>         Environment: Windows 10
>            Reporter: Jiading Guo
>            Priority: Blocker
>
> Inital discussion is in mailing list [1], I propose the solution but only 
> reply to Simon accidentally. I'll post it here since Jira seems to be the 
> palce for bug and fix.
>  
> When calling `TestSupport:::generateTempFile`, the code goes to 
> `TestSupport.java:L122`:
>  
> ```
> final String clsUri = clazz.getName().replace(".", "/") + ".class";
> final URL url = clazz.getClassLoader().getResource(clsUri);
> final String clsPath = url.getPath();
> final String computePath = clsPath.substring(0, clsPath.length() - 
> clsUri.length());
> ```
>  
> on Windows the `clsPath` is something like:
>  
> `file:/C:/Users/user/.m2/repository/org/apache/tinkerpop/gremlin-test/3.5.4-SNAPSHOT/gremlin-test-3.5.4-SNAPSHOT.jar!/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteTest.class`
>  
> and it then failed on `File.createTempFile(fileName, fileNameSuffix, path)` 
> with
>  
> `java.io.IOException: The filename, directory name, or volume label syntax is 
> incorrect`
>  
> In Linux this works fine as `clsPath` is resolved to:
>  
> `file:/home/user/.m2/repository/org/apache/tinkerpop/gremlin-test/3.5.4-SNAPSHOT/gremlin-test-3.5.4-SNAPSHOT.jar!/org/apache/tinkerpop/gremlin/process/traversal/step/map/WriteTest.class`
>  
> After some searching[2], maybe we could use URI or use substring like this?
> ```
> // getRootOfBuildDirectory
> final String clsUri = clazz.getName().replace(".", "/") + ".class";
> final URL url = clazz.getClassLoader().getResource(clsUri);
> final String FILE_PREFIX = "file:";
> final String clsPath = url.getPath().substring(FILE_PREFIX.length());
> final String computePath = clsPath.substring(0, clsPath.length() -
> clsUri.length());
> ```
> The code worked on both Linux and Windows in my test. If needed I
> could submit a PR.
>  
> [1] [https://lists.apache.org/thread/lny64h5yjfoongwm1gtsydwc9pcvk6xj]
> [2] 
> [https://stackoverflow.com/questions/45782535/classloader-getresource-returns-odd-path-maybe]



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to