Skip to content

Commit

Permalink
fix: Fixed relative path handling in FileRef and URLRef (quarkusio#538)
Browse files Browse the repository at this point in the history
[patch]
  • Loading branch information
quintesse authored and maxandersen committed Nov 24, 2020
1 parent ac1cb4c commit 822a1a4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions itests/jbang-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"echo": {
"script-ref": "echo.java",
"description": "echo echo echo description"
},
"resource": {
"script-ref": "res/resource.java"
}
},
"description": "JBang test scripts"
Expand Down
17 changes: 17 additions & 0 deletions itests/res/resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//FILES resource.properties renamed.properties=resource.properties
//FILES META-INF/application.properties=resource.properties

import java.io.InputStream;
import java.util.Properties;

class resource {

public static void main(String[] args) throws Exception {
Properties prop = new Properties();
try(InputStream is = resource.class.getClassLoader().getResourceAsStream("resource.properties")) {
prop.load(is);
}
System.out.println("hello " + prop.getProperty("message"));
}
}
1 change: 1 addition & 0 deletions itests/res/resource.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message=properties
25 changes: 16 additions & 9 deletions itests/run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ Scenario: java launch helloworld with jfr
When command('jbang --jfr helloworld.java')
Then match out contains "Started recording 1. No limit specified, using maxsize=250MB as default."


Scenario: java run multiple sources
When command('jbang --verbose one.java')
Then match out contains "Two"

Scenario: java run multiple matching sources
When command('jbang RootOne.java')
Then match out contains "NestedOne"
Then match out contains "NestedTwo"
Scenario: java run multiple matching sources
When command('jbang RootOne.java')
Then match out contains "NestedOne"
Then match out contains "NestedTwo"

Scenario: java run multiple files
When command('jbang res/resource.java')
Then match out contains "hello properties"

Scenario: java run multiple files using alias
When command('jbang resource')
Then match out contains "hello properties"

Scenario: java run with agent
When command('jbang --verbose --javaagent=JULAgent.java=options JULTest.java World')
Then match err contains "info World"
Then match err contains "options"
Scenario: java run with agent
When command('jbang --verbose --javaagent=JULAgent.java=options JULTest.java World')
Then match err contains "info World"
Then match err contains "options"
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/FileRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private Path from() {
throw new IllegalStateException("Only relative paths allowed in //FILES. Found absolute path: " + p);
}

return Paths.get(source.getOriginalFile()).resolveSibling(p);
return Paths.get(source.getScriptResource().getOriginalResource()).resolveSibling(p);
}

protected Path to(Path parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/URLRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ URI from() {
}

try {
return new URI(source.getOriginalFile()).resolve(p);
return new URI(source.getScriptResource().getOriginalResource()).resolve(p);
} catch (URISyntaxException e) {
throw new IllegalStateException("Could not resolve URI", e);
}
Expand Down

0 comments on commit 822a1a4

Please sign in to comment.