Skip to content

Commit

Permalink
[rewrite] #1281 wip - this is not going to be easy :|
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Oct 4, 2020
1 parent 62b91f4 commit 47761ba
Show file tree
Hide file tree
Showing 14 changed files with 1,340 additions and 47 deletions.
6 changes: 3 additions & 3 deletions karate-core/src/main/java/com/intuit/karate/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class FileUtils {
public static final String THIS_COLON = "this:";
public static final String FILE_COLON = "file:";
public static final String SRC_TEST_JAVA = "src/test/java";
public static final String SRC_TEST_RESOURCES = "src/test/resources";
public static final String SRC_TEST_RESOURCES = "src/test/resources";
private static final ClassLoader CLASS_LOADER = FileUtils.class.getClassLoader();

private FileUtils() {
Expand Down Expand Up @@ -167,7 +167,7 @@ public static String removePrefix(String text) {
return pos == -1 ? text : text.substring(pos + 1);
}

private static StringUtils.Pair parsePathAndTags(String text) {
public static StringUtils.Pair parsePathAndTags(String text) {
int pos = text.indexOf('@');
if (pos == -1) {
text = StringUtils.trimToEmpty(text);
Expand All @@ -188,7 +188,7 @@ public static Feature parseFeatureAndCallTag(String path) {

public static Resource toResource(String path, ScenarioContext context) {
if (isClassPath(path)) {
return new Resource(context, path);
return new Resource(context.classLoader, path);
} else if (isFilePath(path)) {
String temp = removePrefix(path);
return new Resource(new File(temp), path);
Expand Down
5 changes: 2 additions & 3 deletions karate-core/src/main/java/com/intuit/karate/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.intuit.karate;

import com.intuit.karate.core.ScenarioContext;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -84,9 +83,9 @@ public Resource(Path path) {
this(path, null, -1);
}

public Resource(ScenarioContext sc, String relativePath) {
public Resource(ClassLoader cl, String relativePath) {
String strippedPath = FileUtils.removePrefix(relativePath);
URL url = sc.getResource(strippedPath);
URL url = cl.getResource(strippedPath);
if (url != null) {
this.path = FileUtils.urlToPath(url, strippedPath);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public Config getConfig() {

public URL getResource(String name) {
return classLoader.getResource(name);
}
}

public InputStream getResourceAsStream(String name) {
return classLoader.getResourceAsStream(name);
Expand Down
Loading

0 comments on commit 47761ba

Please sign in to comment.