Skip to content

Normalize file path when generating package name#3

Merged
wesleyegberto merged 1 commit into
wesleyegberto:masterfrom
baincd:fix-package-name-on-windows
Jul 9, 2021
Merged

Normalize file path when generating package name#3
wesleyegberto merged 1 commit into
wesleyegberto:masterfrom
baincd:fix-package-name-on-windows

Conversation

@baincd
Copy link
Copy Markdown
Contributor

@baincd baincd commented Jul 3, 2021

I found an issue on Windows with the package name generated for test classes.

Steps to recreate

  1. Open Java class located at C:\chris\wc\sample-multi-module\library\src\main\java\com\example\multimodule\service\MyService.java
  2. Run command "Command: Java: Create/Open Test Class"
  3. Test Class is generated with the package declaration package mple-multi-module\library\src\test\java\com\example\multimodule\service;

Root Cause

In a nutshell, the code uses uri.fsPath for the path and assumes the path separator is /, however on Windows the path separator (frustratingly) is \

Proposed Fix

This proposed fix normalizes the path by converting all \ to / in the file path once, and for consistency uses that normalized path for all package name generation functionality.

I tested generating a test class on both Windows and Linux, and this fix generated the correct package name in both!

Convert Windows path separators \ to /
@wesleyegberto wesleyegberto merged commit d41da48 into wesleyegberto:master Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants