Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void main(String[] argv) {
* @return 0 if execution was successful, 1 if it was not (test failures)
*/
public static byte run(String[] argv, ClassLoader classLoader) {
log.warn("You are using deprecated Main class. Please use io.cucumber.core.cli.Main");
log.warn(() -> "You are using deprecated Main class. Please use io.cucumber.core.cli.Main");
return io.cucumber.core.cli.Main.run(argv, classLoader);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/io/cucumber/core/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static byte run(String[] argv, ClassLoader classLoader) {

final Runtime runtime = Runtime.builder()
.withRuntimeOptions(runtimeOptions)
.withClassLoader(classLoader)
.withClassLoader(() -> classLoader)
.build();

runtime.run();
Expand Down
21 changes: 18 additions & 3 deletions core/src/main/java/io/cucumber/core/feature/CucumberPickle.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ public String getName() {
* @return line in the feature file
*/
public int getLine() {
return pickle.getLocations().get(0).getLine();
return getPickleLocation().getLine();
}

public int getColumn() {
return getPickleLocation().getColumn();
}

private PickleLocation getPickleLocation() {
return pickle.getLocations().get(0);
}

/**
Expand All @@ -72,8 +80,16 @@ public int getLine() {
* @return line in the feature file
*/
public int getScenarioLine() {
return getScenarioLocation().getLine();
}

public int getScenarioColumn(){
return getScenarioLocation().getColumn();
}

private PickleLocation getScenarioLocation() {
List<PickleLocation> stepLocations = pickle.getLocations();
return stepLocations.get(stepLocations.size() - 1).getLine();
return stepLocations.get(stepLocations.size() - 1);
}

public List<CucumberStep> getSteps() {
Expand All @@ -88,5 +104,4 @@ public URI getUri() {
return uri;
}


}
12 changes: 8 additions & 4 deletions core/src/main/java/io/cucumber/core/feature/Encoding.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package io.cucumber.core.feature;

import io.cucumber.core.io.Resource;
import io.cucumber.core.resource.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.lang.System.lineSeparator;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Locale.ROOT;
import static java.util.stream.Collectors.joining;

/**
* Utilities for reading the encoding of a file.
Expand All @@ -35,8 +37,10 @@ static String readFile(Resource resource) throws RuntimeException, IOException {
}

private static String read(Resource resource, String encoding) throws IOException {
try(BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream(), encoding))){
return br.lines().collect(Collectors.joining(System.lineSeparator()));
try (InputStream is = resource.getInputStream()) {
InputStreamReader in = new InputStreamReader(is, encoding);
BufferedReader reader = new BufferedReader(in);
return reader.lines().collect(joining(lineSeparator()));
}
}

Expand Down
61 changes: 0 additions & 61 deletions core/src/main/java/io/cucumber/core/feature/FeatureBuilder.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.cucumber.core.feature;
import java.net.URI;
import java.nio.file.Path;

/**
* Identifies a single feature.
Expand Down Expand Up @@ -30,4 +31,7 @@ public static boolean isFeature(URI featureIdentifier) {
return featureIdentifier.getSchemeSpecificPart().endsWith(".feature");
}

public static boolean isFeature(Path path) {
return path.getFileName().toString().endsWith(".feature");
}
}
39 changes: 0 additions & 39 deletions core/src/main/java/io/cucumber/core/feature/FeatureLoader.java

This file was deleted.

12 changes: 6 additions & 6 deletions core/src/main/java/io/cucumber/core/feature/FeatureParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import gherkin.ast.GherkinDocument;
import gherkin.pickles.Compiler;
import io.cucumber.core.exception.CucumberException;
import io.cucumber.core.io.Resource;
import io.cucumber.core.resource.Resource;

import java.io.IOException;
import java.net.URI;
Expand All @@ -26,7 +26,7 @@ private FeatureParser() {

public static CucumberFeature parseResource(Resource resource) {
requireNonNull(resource);
URI path = resource.getPath();
URI uri = resource.getUri();
String source = read(resource);

try {
Expand All @@ -35,17 +35,17 @@ public static CucumberFeature parseResource(Resource resource) {
GherkinDocument gherkinDocument = parser.parse(source, matcher);
GherkinDialectProvider dialectProvider = new GherkinDialectProvider();
List<CucumberPickle> pickles = compilePickles(gherkinDocument, dialectProvider, resource);
return new CucumberFeature(gherkinDocument, path, source, pickles);
return new CucumberFeature(gherkinDocument, uri, source, pickles);
} catch (ParserException e) {
throw new CucumberException("Failed to parse resource at: " + path.toString(), e);
throw new CucumberException("Failed to parse resource at: " + uri.toString(), e);
}
}

private static String read(Resource resource) {
try {
return Encoding.readFile(resource);
} catch (IOException e) {
throw new CucumberException("Failed to read resource:" + resource.getPath(), e);
throw new CucumberException("Failed to read resource:" + resource.getUri(), e);
}
}

Expand All @@ -58,7 +58,7 @@ private static List<CucumberPickle> compilePickles(GherkinDocument document, Ghe
GherkinDialect dialect = dialectProvider.getDialect(language, null);
return new Compiler().compile(document)
.stream()
.map(pickle -> new CucumberPickle(pickle, resource.getPath(), document, dialect))
.map(pickle -> new CucumberPickle(pickle, resource.getUri(), document, dialect))
.collect(Collectors.toList());
}
}
48 changes: 16 additions & 32 deletions core/src/main/java/io/cucumber/core/feature/FeaturePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;

import static io.cucumber.core.io.Classpath.CLASSPATH_SCHEME;
import static io.cucumber.core.io.Classpath.CLASSPATH_SCHEME_PREFIX;
import static io.cucumber.core.resource.ClasspathSupport.CLASSPATH_SCHEME_PREFIX;
import static io.cucumber.core.resource.ClasspathSupport.rootPackage;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -33,21 +32,21 @@ private FeaturePath() {

public static URI parse(String featureIdentifier) {
requireNonNull(featureIdentifier, "featureIdentifier may not be null");
if(featureIdentifier.isEmpty()){
if (featureIdentifier.isEmpty()) {
throw new IllegalArgumentException("featureIdentifier may not be empty");
}

// Legacy from the Cucumber Eclipse plugin
// Older versions of Cucumber allowed it.
if(CLASSPATH_SCHEME_PREFIX.equals(featureIdentifier)){
if (CLASSPATH_SCHEME_PREFIX.equals(featureIdentifier)) {
return rootPackage();
}

if (nonStandardPathSeparatorInUse(featureIdentifier)) {
String standardized = replaceNonStandardPathSeparator(featureIdentifier);
return parseAssumeFileScheme(standardized);
}

if (isWindowsOS() && pathContainsWindowsDrivePattern(featureIdentifier)) {
return parseAssumeFileScheme(featureIdentifier);
}
Expand All @@ -59,27 +58,23 @@ public static URI parse(String featureIdentifier) {
return parseAssumeFileScheme(featureIdentifier);
}

private static URI rootPackage() {
try {
return new URI(CLASSPATH_SCHEME, "/" ,null);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
private static URI parseProbableURI(String featureIdentifier) {
URI uri = URI.create(featureIdentifier);
if ("file".equals(uri.getScheme())) {
return parseAssumeFileScheme(uri.getSchemeSpecificPart());
}
return uri;
}

private static URI parseProbableURI(String featureIdentifier) {
return URI.create(featureIdentifier);
}

private static boolean isWindowsOS() {
private static boolean isWindowsOS() {
String osName = System.getProperty("os.name");
return normalize(osName).contains("windows");
}

private static boolean pathContainsWindowsDrivePattern(String featureIdentifier) {
return featureIdentifier.matches("^[a-zA-Z]:.*$");
}

private static boolean probablyURI(String featureIdentifier) {
return featureIdentifier.matches("^[a-zA-Z+.\\-]+:.*$");
}
Expand All @@ -94,25 +89,14 @@ private static boolean nonStandardPathSeparatorInUse(String featureIdentifier) {

private static URI parseAssumeFileScheme(String featureIdentifier) {
File featureFile = new File(featureIdentifier);
if (featureFile.isAbsolute()) {
return featureFile.toURI();
}

try {
URI root = new File("").toURI();
URI relative = root.relativize(featureFile.toURI());
// Scheme is lost by relativize
return new URI("file", relative.getSchemeSpecificPart(), relative.getFragment());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
return featureFile.toURI();
}

private static String normalize(final String value) {
if (value == null) {
return "";
}
return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
}

}
Loading