gauge-java icon indicating copy to clipboard operation
gauge-java copied to clipboard

can specify the path to scan the step implement ?

Open guolongxu opened this issue 7 years ago • 9 comments

now ,getgauge scan the step implement by system property "java.class.path" ,it will scan all the file in the "java.class.path" , there is two problem : 1)It will scan many meaningless files, which will be less efficient

2)There is not check for file suffix ,, and all files are loaded as class, so if a properties file is included in the jar package, an exception is thrown

I suggest getgauge can specify the package to scan ,just like spring , others ,It shoud check the file suffix ,only deal the suffix of ".class"

guolongxu avatar Dec 04 '17 13:12 guolongxu

If you have compiled jars, then you can use gauge_custom_build_path and gauge will only scan jars in that location.

sriv avatar Dec 04 '17 13:12 sriv

the property "gauge_custom_build_path " is not the out directory for build class ?

In fact , In most cases ,jars are only dependencies ,they are not contain the step implement , and the step implement would specify package ,not all package or classpath.

can you give me a reason for not support specify the package for scan ?

guolongxu avatar Dec 04 '17 13:12 guolongxu

the property "gauge_custom_build_path " is not the out directory for build class ?

No, by default gauge-java attempts to build the test project before execution. Setting gauge_custom_build_path indicates that the project is part of another build system which would compile the project, so that gauge-java does not have to again.

can you give me a reason for not support specify the package for scan ?

Well, honestly, no one has asked for it, and this is the first time this has been raised, AFAIK. My theory is that people would like to have the spec implementations organized across packages and not just in one. I could be wrong though.

There was a feature implemented a while ago, which adds support for IoC containers with gauge, so perhaps you can take some hints from the discussions there. Summary is - you can have your own scanning mechanism by implementing the ClassInitializer

sriv avatar Dec 05 '17 02:12 sriv

It like this ? where "D:/workspace/enterprise/work/nginf2.0/target/" is my project build directory

#IntelliJ and Eclipse out directory will be usually autodetected #Use the below property if you need to override the build path gauge_custom_build_path =D:/workspace/enterprise/work/nginf2.0/target/

can you give a example ?

guolongxu avatar Dec 05 '17 03:12 guolongxu

Gauge project like this

├── libs └── src └── test └── java └── gauge └── example └── StepImplementation.java ├── env └── default └── java.properties

if I just want to scan the package of "gauge.example" ,how can I config?

guolongxu avatar Dec 05 '17 03:12 guolongxu

my problem

15:32:09.118 [main] DEBUG org.reflections.Reflections - could not scan file ch/qos/logback/classic/db/script/postgresql.sql in url file:/D:/install/apache-maven-3.3.9/data/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar with scanner MethodAnnotationsScanner org.reflections.ReflectionsException: could not create class object from file ch/qos/logback/classic/db/script/postgresql.sql at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:32) at org.reflections.Reflections.scan(Reflections.java:253) at org.reflections.Reflections.scan(Reflections.java:202) at org.reflections.Reflections.(Reflections.java:123) at com.thoughtworks.gauge.scan.ClasspathScanner.createReflections(ClasspathScanner.java:59) at com.thoughtworks.gauge.scan.ClasspathScanner.scan(ClasspathScanner.java:37) at com.thoughtworks.gauge.GaugeRuntime.connectSynchronously(GaugeRuntime.java:82) at com.thoughtworks.gauge.GaugeRuntime.main(GaugeRuntime.java:54)

guolongxu avatar Dec 05 '17 07:12 guolongxu

This is really strange, is there a sample project that you can share?

Aside : There is no way to tell gauge to scan only a package. You may want to implement a custom scanner if you think that is necessary.

sriv avatar Dec 05 '17 07:12 sriv

You can add spring boot dependency to test

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

You may want to implement a custom scanner if you think that is necessary.

How can I specify the custom Scanner ?

guolongxu avatar Dec 05 '17 09:12 guolongxu

I mentioned earlier : you can have your own scanning mechanism by implementing the ClassInitializer

sriv avatar Dec 05 '17 09:12 sriv