Skip to content

Commit

Permalink
fix(#1049): Add JBang support
Browse files Browse the repository at this point in the history
- Add new connector module to run JBang from Citrus tests
- Adds a new JBang test action to run a JBang script with a spawned process
- Include XML and YAML test DSL support for the JBang test action
- Install JBang in CI workflows
  • Loading branch information
christophd committed Oct 7, 2024
1 parent 80bf284 commit 397827c
Show file tree
Hide file tree
Showing 37 changed files with 2,584 additions and 4 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ jobs:
java -version
./mvnw -version
- name: Build Citrus
run: ./mvnw --no-transfer-progress -T1C install
run: |
echo "Install JBang via SDKMAN"
curl -s "https://get.sdkman.io" | bash
source "/home/runner/.sdkman/bin/sdkman-init.sh"
sdk install jbang
jbang --version
./mvnw --no-transfer-progress -T1C install
11 changes: 10 additions & 1 deletion .github/workflows/lts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ jobs:
java -version
./mvnw -version
- name: Build Citrus
run: ./mvnw --no-transfer-progress -T1C -Djava.version=${{ matrix.version }} install
run: |
echo "Install JBang via SDKMAN"
curl -s "https://get.sdkman.io" | bash
source "/home/runner/.sdkman/bin/sdkman-init.sh"
sdk install jbang
jbang --version
./mvnw --no-transfer-progress -T1C -Djava.version=${{ matrix.version }} install
5 changes: 5 additions & 0 deletions catalog/citrus-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@
<artifactId>citrus-sql</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-jbang-connector</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>

<!-- Tools -->
<dependency>
Expand Down
54 changes: 54 additions & 0 deletions connectors/citrus-jbang-connector/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-connectors</artifactId>
<version>4.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>citrus-jbang-connector</artifactId>
<name>Citrus :: Connectors :: JBang</name>

<dependencies>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-base</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>

<!-- Test scoped dependencies -->
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-test-support</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-xml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-yaml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.citrusframework.jbang;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

/**
* @author Christoph Deppisch
*/
public final class JBangSettings {

private static final String JBANG_PROPERTY_PREFIX = "citrus.jbang.";
private static final String JBANG_ENV_PREFIX = "CITRUS_JBANG_";

private static final String TRUST_URLS_PROPERTY = JBANG_PROPERTY_PREFIX + "trust.urls";
private static final String TRUST_URLS_ENV = JBANG_ENV_PREFIX + "TRUST_URLS";

private static final String JBANG_AUTO_DOWNLOAD_PROPERTY = JBANG_PROPERTY_PREFIX + "auto.download";
private static final String JBANG_AUTO_DOWNLOAD_ENV = JBANG_ENV_PREFIX + "AUTO_DOWNLOAD";
private static final String JBANG_AUTO_DOWNLOAD_DEFAULT = "true";

private static final String JBANG_DOWNLOAD_URL_PROPERTY = JBANG_PROPERTY_PREFIX + "download.url";
private static final String JBANG_DOWNLOAD_URL_ENV = JBANG_ENV_PREFIX + "DOWNLOAD_URL";
private static final String JBANG_DOWNLOAD_URL_DEFAULT = "https://jbang.dev/releases/latest/download/jbang.zip";

private static final String WORK_DIR_PROPERTY = JBANG_PROPERTY_PREFIX + "work.dir";
private static final String WORK_DIR_ENV = JBANG_ENV_PREFIX + "WORK_DIR";
private static final String WORK_DIR_DEFAULT = ".citrus-jbang";

private static final String DUMP_PROCESS_OUTPUT_PROPERTY = JBANG_PROPERTY_PREFIX + "dump.process.output";
private static final String DUMP_PROCESS_OUTPUT_ENV = JBANG_ENV_PREFIX + "DUMP_PROCESS_OUTPUT";
private static final String DUMP_PROCESS_OUTPUT_DEFAULT = "false";

private JBangSettings() {
// prevent instantiation of utility class
}

/**
* JBang download url.
* @return
*/
public static String getJBangDownloadUrl() {
return System.getProperty(JBANG_DOWNLOAD_URL_PROPERTY,
System.getenv(JBANG_DOWNLOAD_URL_ENV) != null ? System.getenv(JBANG_DOWNLOAD_URL_ENV) : JBANG_DOWNLOAD_URL_DEFAULT);
}

/**
* JBang local work dir.
* @return
*/
public static Path getWorkDir() {
String workDir = Optional.ofNullable(System.getProperty(WORK_DIR_PROPERTY, System.getenv(WORK_DIR_ENV))).orElse(WORK_DIR_DEFAULT);

Path path = Paths.get(workDir);
if (path.isAbsolute()) {
return path.toAbsolutePath();
} else {
return Paths.get("").toAbsolutePath().resolve(workDir).toAbsolutePath();
}
}

/**
* JBang trust URLs.
* @return
*/
public static String[] getTrustUrls() {
return Optional.ofNullable(System.getProperty(TRUST_URLS_PROPERTY, System.getenv(TRUST_URLS_ENV)))
.map(urls -> urls.split(","))
.orElseGet(() -> new String[]{});
}

/**
* When set to true JBang binary is downloaded automatically when not present on host.
* @return
*/
public static boolean isAutoDownload() {
return Boolean.parseBoolean(System.getProperty(JBANG_AUTO_DOWNLOAD_PROPERTY,
System.getenv(JBANG_AUTO_DOWNLOAD_ENV) != null ? System.getenv(JBANG_AUTO_DOWNLOAD_ENV) : JBANG_AUTO_DOWNLOAD_DEFAULT));
}

/**
* When set to true JBang process output will be redirected to a file in the current working directory.
* @return
*/
public static boolean isDumpProcessOutput() {
return Boolean.parseBoolean(System.getProperty(DUMP_PROCESS_OUTPUT_PROPERTY,
System.getenv(DUMP_PROCESS_OUTPUT_ENV) != null ? System.getenv(DUMP_PROCESS_OUTPUT_ENV) : DUMP_PROCESS_OUTPUT_DEFAULT));
}

}
Loading

0 comments on commit 397827c

Please sign in to comment.