JBehave
  1. JBehave
  2. JBEHAVE-870

Find stories when running from jar with dependencies

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.7.5, 3.8
    • Component/s: Core
    • Labels:
      None
    • Environment:
      ETSY based project with a JFrame based UI + Maven Assembly plugin
    • Number of attachments :
      0

      Description

      Hello !

      I'm using a ETSY sample based project to run my JBehave stories with Selenium.

      I created a JFrame based user interface to have a standalone runnable for people who run JBehave + Selenium tests.

      My stories files are stored as following "project/src/main/resources/stories/*.story"

      To find the story files when running from Maven or Eclipse debug this line works fine :

      new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), asList("*/.story"), null).toArray(new String[0]);

      But when running from the JAR file that does not work : for "codeLocationFromClass(this.getClass()).getFile()" I get : "/C:/Documents%20and%20Settings/lbp0527/Bureau/project/build/project-1.0-SNAPSHOT-jar-with-dependencies.jar!"

      The JAR file contains at its root the "stories" folder with inside all my *.story files but I can't find a good way to retrieve this list from my UI.

      Do someone knows a way to find story files within the built JAR ?

      Maybe this is some "off topic" for the Jira, please tell me if and how to find my answer.

      Thanks !

        Activity

        Hide
        Mauro Talevi added a comment -

        Checkout this example:

        https://github.com/jbehave/jbehave-core/tree/master/examples/executable-jar

        You need to specify the paths individually, without using the * notation.

        Show
        Mauro Talevi added a comment - Checkout this example: https://github.com/jbehave/jbehave-core/tree/master/examples/executable-jar You need to specify the paths individually, without using the * notation.
        Hide
        Damien LG added a comment -

        Thanks for the answer !

        I was thinking there were a mechanism that could look for my "*/.story" pattern while executing from JAR and from Eclipse debug...

        Show
        Damien LG added a comment - Thanks for the answer ! I was thinking there were a mechanism that could look for my "* / .story" pattern while executing from JAR and from Eclipse debug...
        Hide
        Alexander Lehmann added a comment - - edited

        I think is almost impossible to search through classpath/jar files without resorting to plain zip operations, at least I have no idea how to get that done.

        (if anybody has a good idea ...)

        Show
        Alexander Lehmann added a comment - - edited I think is almost impossible to search through classpath/jar files without resorting to plain zip operations, at least I have no idea how to get that done. (if anybody has a good idea ...)
        Hide
        Alexander Lehmann added a comment - - edited

        I have implemented a first version of the jar file scanner for jbehave, if you want to give this a try:

        https://github.com/alexlehm/zipfile

        just include the JarFileScanner in your project and call it as mentioned in the readme

        if there is a sufficient interest, maybe we can include this in the jbehave StoryFinder class

        Show
        Alexander Lehmann added a comment - - edited I have implemented a first version of the jar file scanner for jbehave, if you want to give this a try: https://github.com/alexlehm/zipfile just include the JarFileScanner in your project and call it as mentioned in the readme if there is a sufficient interest, maybe we can include this in the jbehave StoryFinder class
        Hide
        Mauro Talevi added a comment -

        Excellent proposal. Can you please add the scan methods to the StoryFinder and provide a pull request from master branch (ie not 4.x, to which we'll merge afterwards)?

        Show
        Mauro Talevi added a comment - Excellent proposal. Can you please add the scan methods to the StoryFinder and provide a pull request from master branch (ie not 4.x, to which we'll merge afterwards)?
        Hide
        Alexander Lehmann added a comment -

        ok, will do.

        do you want the jar scan method to be included in the regular findPaths method or do you think we should have a specific method?

        Show
        Alexander Lehmann added a comment - ok, will do. do you want the jar scan method to be included in the regular findPaths method or do you think we should have a specific method?
        Hide
        Mauro Talevi added a comment -

        We could have a method

        findPathsFromJar(String jarPath, ... )
        

        which would use your scanner code, and perhaps allow seemless access to this method via the

        findPaths(URL codeLocation, ... )
        

        where we'd add a CodeLocations method to retrieve the jar path from the URL.

        WDYT?

        Show
        Mauro Talevi added a comment - We could have a method findPathsFromJar( String jarPath, ... ) which would use your scanner code, and perhaps allow seemless access to this method via the findPaths(URL codeLocation, ... ) where we'd add a CodeLocations method to retrieve the jar path from the URL. WDYT?
        Hide
        Alexander Lehmann added a comment -

        https://github.com/alexlehm/jbehave-core/tree/jbehave_870

        added methods to StoryFinder findPathsFromJar() to search inside a given jar
        file added check to remove trailing ! at the end of jar path (this was wrong
        since the fix for processing jar files, JBEHAVE-635, JBEHAVE-712 etc but
        previously the jar files were not opened directly)

        (this is not yet called from findPaths)

        Show
        Alexander Lehmann added a comment - https://github.com/alexlehm/jbehave-core/tree/jbehave_870 added methods to StoryFinder findPathsFromJar() to search inside a given jar file added check to remove trailing ! at the end of jar path (this was wrong since the fix for processing jar files, JBEHAVE-635 , JBEHAVE-712 etc but previously the jar files were not opened directly) (this is not yet called from findPaths)
        Mauro Talevi made changes -
        Field Original Value New Value
        Assignee Mauro Talevi [ maurotalevi ]
        Fix Version/s 3.7.5 [ 18997 ]
        Affects Version/s 4.x [ 18279 ]
        Hide
        Mauro Talevi added a comment -

        Pulled and refactored somewhat. First, removed the use of static in the JarFileScanner. Second, reuse the same facade of StoryFinder for both directory and jar sources.

        Have a look at latest master and let me know if you think anything more needs adding or changing.

        Show
        Mauro Talevi added a comment - Pulled and refactored somewhat. First, removed the use of static in the JarFileScanner. Second, reuse the same facade of StoryFinder for both directory and jar sources. Have a look at latest master and let me know if you think anything more needs adding or changing.
        Mauro Talevi made changes -
        Issue Type Wish [ 5 ] Improvement [ 4 ]
        Hide
        Alexander Lehmann added a comment -

        https://github.com/alexlehm/jbehave-core/tree/jbehave_870_2

        changed executable-jar example to use StoryFinder both for filesystem and jar.
        fixed jar search on Windows, changed include/exclude patterns to local
        path separator, otherwise the patterns do not work. This also failed in
        the unit test in Windows. The operation is a no-op on Unix so this didn't
        show up in Unix.
        added a note about creating jar files with Eclipse

        Show
        Alexander Lehmann added a comment - https://github.com/alexlehm/jbehave-core/tree/jbehave_870_2 changed executable-jar example to use StoryFinder both for filesystem and jar. fixed jar search on Windows, changed include/exclude patterns to local path separator, otherwise the patterns do not work. This also failed in the unit test in Windows. The operation is a no-op on Unix so this didn't show up in Unix. added a note about creating jar files with Eclipse
        Hide
        Mauro Talevi added a comment -

        Pulled with thanks.

        Show
        Mauro Talevi added a comment - Pulled with thanks.
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Mauro Talevi made changes -
        Fix Version/s 3.8 [ 19104 ]

          People

          • Assignee:
            Mauro Talevi
            Reporter:
            Damien LG
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: