-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable jbang [email protected] and jbang tree@https:/jbang.dev
- Loading branch information
1 parent
238ef90
commit 9d2ce04
Showing
4 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,18 +29,29 @@ The aliases you create are stored locally (see <<Local Alias Catalogs>>), but JB | |
You can access those catalogs explicitly (see <<Catalogs>>) but it is much easier to use what we call "implicit catalogs", which | ||
are aliases that have a special format and JBang is smart enough to know where to find their definition. | ||
|
||
There are two kinds, one that resolves to a Git backed service (github,gitlab and bitbucket) and one that resolves to | ||
https sites. | ||
|
||
Examples: | ||
|
||
`jbang [email protected]` will (because of the dot in the name) will lookup a catalog first at https://jbang.dev/jbang-catalog.json. | ||
|
||
`jbang hello@jbangdev` will run the alias `hello` as defined in `jbang-catalog.json` found in https://github.com/jbangdev/jbang-catalog. | ||
|
||
This allows anyone to provide a set of jbang scripts defined in their github, gitlab or bitbucket repositories. | ||
This allows anyone to provide a set of jbang scripts defined in their website or in a github, gitlab or bitbucket repositories. | ||
|
||
The full format is `<alias>@<user/org>(/repository)(/branch)(~path)` allowing you to do things like: | ||
The full format is `<alias>@<user/org>(/repository)(/branch)(~path)` or `<alias>@<hostname>(/path/to/catalog)` allowing you to do things like: | ||
|
||
.Implicit Catalog Examples: | ||
|==== | ||
|Command | Description | ||
|
||
|`jbang [email protected]` | ||
|`hello` alias found in `https://acme.corp/jbang-catalog.json` if available or the default branch searched on github, gitlab and bitbucket in that order. | ||
|
||
|`jbang [email protected]/a/path/to/jbang-catalog.json` | ||
|`hello` alias found in `https://acme.corp/a/path/to/jbang-catalog.json` if available. | ||
|
||
|`jbang hello@acme` | ||
|`hello` alias found in `acme/jbang-catalog/jbang-catalog.json` of the default branch searched on github, gitlab and bitbucket in that order. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dev.jbang; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import dev.jbang.catalog.Alias; | ||
import dev.jbang.catalog.ImplicitCatalogRef; | ||
|
||
/** | ||
* TODO: use mock to handle https lookups instead of jbang.dev | ||
*/ | ||
public class TestImplicitAlias extends BaseTest { | ||
|
||
@Test | ||
public void testGitImplicitCatalog() { | ||
assertThat(ImplicitCatalogRef.getImplicitCatalogUrl("jbangdev").get(), | ||
Matchers.equalTo("https://github.com/jbangdev/jbang-catalog/blob/HEAD/jbang-catalog.json")); | ||
assertThat(ImplicitCatalogRef.getImplicitCatalogUrl("jbangdev/jbang-examples").get(), | ||
Matchers.equalTo("https://github.com/jbangdev/jbang-examples/blob/HEAD/jbang-catalog.json")); | ||
} | ||
|
||
@Test | ||
public void testImplictURLAlias() { | ||
|
||
Alias url = Alias.get("[email protected]"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
@Test | ||
public void testImplictExplicitURLAlias() { | ||
|
||
Alias url = Alias.get("tree@https://xam.dk"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
// @Test needs fixing to not generate absolute paths but instead relative paths. | ||
public void testFileURLAlias() throws IOException { | ||
|
||
assertThat(jbangTempDir.resolve("inner").toFile().mkdirs(), Matchers.is(true)); | ||
|
||
Files.copy(examplesTestFolder.resolve("helloworld.java"), jbangTempDir.resolve("inner/helloworld.java")); | ||
String src = jbangTempDir.resolve("inner/helloworld.java").toString(); | ||
Path path = jbangTempDir.resolve("jbang-catalog.json"); | ||
|
||
checkedRun(null, "alias", "add", "-f", path.toString(), "--name=apptest", src); | ||
|
||
String url = "apptest@" + path.toUri(); | ||
assertThat(url, Matchers.stringContainsInOrder("file://")); | ||
|
||
Alias alias = Alias.get(url); | ||
|
||
assertThat(alias.scriptRef, Matchers.equalTo("helloworld.java")); | ||
|
||
} | ||
} |