JBehave
  1. JBehave
  2. JBEHAVE-763

LoadFromRelativeFile break on windows when using maven traversal

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.6.1
    • Fix Version/s: 3.6.3, 3.7
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Windows Vista
    • Number of attachments :
      0

      Description

      When invoking LoadFromRelativeFile and passing in a traversal substitution stories are not found because the substitution is not applied. This is due to the difference in the StoryFilePath which forces path separators to be '/'. When the LoadFromRelativeFile code gets the absolute path of location file separators are converted to '\'. This keeps the locationPath.replace code from working

      Im invoking the code as..

      public Configuration configuration() {
      return new MostUsefulConfiguration() // where to find the stories
      .useStoryLoader(new LoadFromRelativeFile(CodeLocations.codeLocationFromClass(getClass()), LoadFromRelativeFile.mavenModuleTestStoryFilePath("src/test/resources/jbehave/")))
      .useStoryReporterBuilder(
      new StoryReporterBuilder().withDefaultFormats()
      .withFormats(Format.CONSOLE, Format.TXT));

      The code that breaks in LoadFromRelativeFile that break is

      String locationPath = new File(CodeLocations.getPathFromURL(location)).getAbsolutePath();
      for (StoryFilePath traversal : traversals)

      { String filePath = locationPath.replace(traversal.toRemove, traversal.relativePath) + "/" + resourcePath; locationPath would have all '/' converted to '\' by getAbsolutePath on windows machines. Maybe the following line should be inserted after the definition of locationPath locationPath = locationPath.replace("\\","/"); }

        Activity

        Hide
        Ricardo Lopez added a comment -

        With wiki markup..

        Im invoking the code as..

         public Configuration configuration() {
           return new MostUsefulConfiguration() // where to find the stories
         .useStoryLoader(new LoadFromRelativeFile(CodeLocations.codeLocationFromClass(getClass()), 
        LoadFromRelativeFile.mavenModuleTestStoryFilePath("src/test/resources/jbehave/")))
         .useStoryReporterBuilder(
         new StoryReporterBuilder().withDefaultFormats()
         .withFormats(Format.CONSOLE, Format.TXT));
        
        

        The code that breaks in LoadFromRelativeFile that break is

        LoadFromRelativeFile.java
         String locationPath = new File(CodeLocations.getPathFromURL(location)).getAbsolutePath();
         for (StoryFilePath traversal : traversals) { 
                String filePath = locationPath.replace(traversal.toRemove, traversal.relativePath) + "/" + resourcePath; 
        
        

        locationPath would have all '/' converted to '\' by getAbsolutePath on windows machines. Maybe the following line should be inserted after the definition of locationPath

         locationPath = locationPath.replace("\\","/");  
        Show
        Ricardo Lopez added a comment - With wiki markup.. Im invoking the code as.. public Configuration configuration() { return new MostUsefulConfiguration() // where to find the stories .useStoryLoader( new LoadFromRelativeFile(CodeLocations.codeLocationFromClass(getClass()), LoadFromRelativeFile.mavenModuleTestStoryFilePath( "src/test/resources/jbehave/" ))) .useStoryReporterBuilder( new StoryReporterBuilder().withDefaultFormats() .withFormats(Format.CONSOLE, Format.TXT)); The code that breaks in LoadFromRelativeFile that break is LoadFromRelativeFile.java String locationPath = new File(CodeLocations.getPathFromURL(location)).getAbsolutePath(); for (StoryFilePath traversal : traversals) { String filePath = locationPath.replace(traversal.toRemove, traversal.relativePath) + "/" + resourcePath; locationPath would have all '/' converted to '\' by getAbsolutePath on windows machines. Maybe the following line should be inserted after the definition of locationPath locationPath = locationPath.replace( "\\" , "/" );
        Mauro Talevi made changes -
        Field Original Value New Value
        Fix Version/s 3.6.3 [ 18417 ]
        Hide
        Mauro Talevi added a comment -

        Normalised all paths to use '/'.

        Show
        Mauro Talevi added a comment - Normalised all paths to use '/'.
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Alexander Lehmann added a comment -

        I assume that should be implemented with File objects instead of String, this way the os specific path separator isn't necessary

        I don't know how much changes are necessary around the source to do this.

        Show
        Alexander Lehmann added a comment - I assume that should be implemented with File objects instead of String, this way the os specific path separator isn't necessary I don't know how much changes are necessary around the source to do this.
        Mauro Talevi made changes -
        Fix Version/s 3.7 [ 18390 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Ricardo Lopez
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: