Skip to content

Commit

Permalink
Allows multiple comma separated packages to scan - Fixes getgauge#161
Browse files Browse the repository at this point in the history
  • Loading branch information
haroon-sheikh committed Jun 3, 2018
1 parent c92a8c0 commit 1036935
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/thoughtworks/gauge/GaugeConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class GaugeConstant {
public static final String SCREENSHOT_ENABLED = "screenshot_on_failure";
public static final String STEP_ANNOTATION_QUALIFIER = "com.thoughtworks.gauge.Step";
public static final String GAUGE_DEBUG_OPTS_ENV = "GAUGE_DEBUG_OPTS";
public static final String PACKAGE_TO_SCAN = "package_to_scan";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thoughtworks.gauge.execution.parameters.parsers.base;

import com.thoughtworks.gauge.GaugeConstant;
import com.thoughtworks.gauge.execution.parameters.ParsingException;
import com.thoughtworks.gauge.execution.parameters.parsers.converters.TableConverter;
import com.thoughtworks.gauge.execution.parameters.parsers.types.EnumParameterParser;
Expand All @@ -16,6 +17,8 @@

import javax.annotation.Nullable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -68,9 +71,14 @@ public Object parse(Class<?> parameterType, Parameter parameter) throws ParsingE
}

private Collection<URL> getUrls() {
String packageToScan = System.getenv("package_to_scan");
if (packageToScan != null) {
return ClasspathHelper.forPackage(packageToScan);
final String packagesToScan = System.getenv(GaugeConstant.PACKAGE_TO_SCAN);
if (packagesToScan != null) {
Collection<URL> urls = new ArrayList<>();
final List<String> packages = Arrays.asList(packagesToScan.split(","));
for (String packageToScan : packages) {
urls.addAll(ClasspathHelper.forPackage(packageToScan));
}
return urls;
}
return ClasspathHelper.forJavaClassPath();
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/thoughtworks/gauge/scan/ClasspathScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.jar.JarFile;

import com.thoughtworks.gauge.GaugeConstant;
import org.reflections.Configuration;
import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
Expand Down Expand Up @@ -65,9 +69,14 @@ public Vfs.Dir createDir(URL url) throws Exception {
}

private Collection<URL> getUrls() {
String packageToScan = System.getenv("package_to_scan");
if (packageToScan != null) {
return ClasspathHelper.forPackage(packageToScan);
final String packagesToScan = System.getenv(GaugeConstant.PACKAGE_TO_SCAN);
if (packagesToScan != null) {
Collection<URL> urls = new ArrayList<>();
final List<String> packages = Arrays.asList(packagesToScan.split(","));
for (String packageToScan : packages) {
urls.addAll(ClasspathHelper.forPackage(packageToScan));
}
return urls;
}
return ClasspathHelper.forJavaClassPath();
}
Expand Down

0 comments on commit 1036935

Please sign in to comment.