Skip to content

Commit

Permalink
Scanning only packages specify in env. #168
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver committed Jun 27, 2018
1 parent 44631f6 commit 61480dd
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/com/thoughtworks/gauge/scan/ClasspathScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

package com.thoughtworks.gauge.scan;

import java.io.File;
import java.net.URL;
import java.util.jar.JarFile;

import com.thoughtworks.gauge.ClasspathHelper;
import org.reflections.Configuration;
import org.reflections.Reflections;
Expand All @@ -30,6 +26,12 @@
import org.reflections.vfs.Vfs;
import org.reflections.vfs.ZipDir;

import java.io.File;
import java.net.URL;
import java.util.jar.JarFile;

import static com.thoughtworks.gauge.GaugeConstant.PACKAGE_TO_SCAN;

/**
* Scans the current Classpath and passes to all the scanners passed.
*/
Expand Down Expand Up @@ -59,9 +61,23 @@ public Vfs.Dir createDir(URL url) throws Exception {
Configuration config = new ConfigurationBuilder()
.setScanners(new MethodAnnotationsScanner(), new SubTypesScanner())
.addUrls(ClasspathHelper.getUrls())
.filterInputsBy(new FilterBuilder().include(".+\\.class"));
.filterInputsBy(this::shouldScan);

return new Reflections(config);
}

private boolean shouldScan(String s) {
final String packagesToScan = System.getenv(PACKAGE_TO_SCAN);
if (packagesToScan == null || packagesToScan.isEmpty()) {
return new FilterBuilder().include(".+\\.class").apply(s);
}
final String[] packages = packagesToScan.split(",");
for (String packageToScan : packages) {
String regex = String.format(".?\\.??%s.+\\.class", packageToScan);
if (new FilterBuilder().include(regex).apply(s)) {
return true;
}
}
return false;
}
}

0 comments on commit 61480dd

Please sign in to comment.