Skip to content

Commit

Permalink
Merge commit '0b8293870809fb62d714a86f1e0c49cf485995e0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvandisseldorp committed Jun 24, 2024
2 parents 6a85085 + 0b82938 commit 8e0bc38
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
57 changes: 33 additions & 24 deletions ksml-runner/src/main/java/io/axual/ksml/runner/KSMLRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import io.axual.ksml.client.serde.ResolvingDeserializer;
import io.axual.ksml.client.serde.ResolvingSerializer;
Expand Down Expand Up @@ -88,32 +87,14 @@ public class KSMLRunner {
public static void main(String[] args) {
try {
// Load name and version from manifest
var executableName = "KSML Runner";
var executableVersion = "";
try {
ClassLoader cl = KSMLRunner.class.getClassLoader();

try (InputStream url = cl.getResourceAsStream("META-INF/MANIFEST.MF")) {
Manifest manifest = new Manifest(url);
Attributes attr = manifest.getMainAttributes();
String attrName = attr.getValue("Implementation-Title");
if (attrName != null) {
executableName = attrName;
}

String attrVersion = attr.getValue("Implementation-Version");
if (attrVersion != null) {
executableVersion = attrVersion;
}
}
} catch (IOException e) {
log.info("Could not load manifest file, using default values");
}
var ksmlTitle = determineTitle();

// Check if we need to output the schema and then exit
checkForSchemaOutput(args);

log.info("Starting {} {}", executableName, executableVersion);
log.info("Starting {}", ksmlTitle);

// Begin loading config file
final var configFile = new File(args.length == 0 ? DEFAULT_CONFIG_FILE_SHORT : args[0]);
if (!configFile.exists()) {
log.error("Configuration file '{}' not found", configFile);
Expand Down Expand Up @@ -257,6 +238,34 @@ public static void main(String[] args) {
}
}

private static String determineTitle() {
var ksmlTitle = "KSML";

try {
ClassLoader cl = KSMLRunner.class.getClassLoader();

try (InputStream url = cl.getResourceAsStream("ksml/ksml-info.properties")) {
Properties ksmlInfo = new Properties();
ksmlInfo.load(url);
var titleBuilder = new StringBuilder()
.append(ksmlInfo.getProperty("name", "KSML"));
if (ksmlInfo.containsKey("version")) {
titleBuilder.append(" ").append(ksmlInfo.getProperty("version"));
}
if (ksmlInfo.containsKey("buildTime")) {
titleBuilder.append(" (")
.append(ksmlInfo.getProperty("buildTime"))
.append(")");
}
ksmlTitle = titleBuilder.toString();
}

} catch (IOException e) {
log.info("Could not load manifest file, using default values");
}
return ksmlTitle;
}

private static void checkForSchemaOutput(String[] args) {
// Check if the runner was started with "--schema". If so, then we output the JSON schema to validate the
// KSML definitions with on stdout and exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void start() throws Exception {
public synchronized void stop() {
Optional.ofNullable(httpServer).ifPresent(HTTPServer::close);
httpServer = null;
collectorList.forEach(registry::unregister);
Optional.ofNullable(registry).ifPresent(r -> collectorList.forEach(r::unregister));
registry = null;
collectorList.clear();
}

Expand Down
3 changes: 3 additions & 0 deletions ksml-runner/src/main/resources/ksml/ksml-info.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name=${project.name}
version=${project.version}
buildTime=${maven.build.timestamp}
3 changes: 3 additions & 0 deletions ksml-runner/src/test/resources/ksml/ksml-info.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name=ksml-for-testing
version=testing
buildTime=2024-01-01T01:00:00Z
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<maven.enforcer.plugin.version>3.4.1</maven.enforcer.plugin.version>
<maven.exec.plugin.version>3.2.0</maven.exec.plugin.version>
<maven.license.plugin.version>2.4.0</maven.license.plugin.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>

<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
<maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>
Expand Down Expand Up @@ -535,6 +536,12 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.plugin.version}</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down

0 comments on commit 8e0bc38

Please sign in to comment.