diff --git a/sparql-anything-cli/src/main/java/io/github/sparqlanything/cli/CLI.java b/sparql-anything-cli/src/main/java/io/github/sparqlanything/cli/CLI.java index 82d6b420..7941e279 100644 --- a/sparql-anything-cli/src/main/java/io/github/sparqlanything/cli/CLI.java +++ b/sparql-anything-cli/src/main/java/io/github/sparqlanything/cli/CLI.java @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -87,11 +88,17 @@ public void parse(String[] args) throws ParseException { public String getQuery() throws IOException { String queryArgument = commandLine.getOptionValue(CLI.QUERY); + logger.trace("Parsing query argument {}", queryArgument); try{ + logger.trace("Trying interpreting as a URL..."); return IOUtils.toString(new URL(queryArgument).toURI(), Charset.defaultCharset()); } catch (MalformedURLException | URISyntaxException e) { - return queryArgument; + logger.trace("Trying interpreting as a file path..."); + if(new File(queryArgument).exists()) + return IOUtils.toString(new File(queryArgument).toURI(), Charset.defaultCharset()); } + logger.trace("Trying interpreting as a inline query..."); + return queryArgument; } void init(){ this.options = new Options(); diff --git a/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/CLITest.java b/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/CLITest.java index b2b7d348..85530dc2 100644 --- a/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/CLITest.java +++ b/sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/CLITest.java @@ -20,7 +20,6 @@ import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.io.StringReader; @@ -69,6 +68,14 @@ public void infileQueryWithValues() throws Exception { query(new String[]{"-q", queryFile, "-v", "loc=" + f, "-f", "CSV"}); } + @Test + public void infileQueryWithValuesAndPath() throws Exception { + String f = Objects.requireNonNull(getClass().getClassLoader().getResource("books.xml")).toURI().toString(); + String queryFile = Objects.requireNonNull(getClass().getClassLoader().getResource("CLITestOnFileQuery1.sparql")).getFile(); + System.out.println(queryFile); + query(new String[]{"-q", queryFile, "-v", "loc=" + f, "-f", "CSV"}); + } + @Test public void infileQuery() throws Exception { String f = Objects.requireNonNull(getClass().getClassLoader().getResource("books.xml")).toURI().toString();