Skip to content

Commit

Permalink
Add a version command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
nck-mlcnv committed Oct 7, 2024
1 parent f36fd6b commit 9cddbe6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions graalvm/generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fi

# Run through multiple different execution paths, so that the tracing agent can generate complete configuration files.
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --help > /dev/null
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --version > /dev/null
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --dry-run -is "$SUITE" > /dev/null
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --dry-run "$SUITE" > /dev/null

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes><include>version.properties</include></includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/org/aksw/iguana/cc/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;


/**
Expand Down Expand Up @@ -36,6 +37,9 @@ public Path convert(String value) {

@Parameter(description = "suite file {yml,yaml,json}", arity = 1, required = true, converter = PathConverter.class)
private Path suitePath;

@Parameter(names = {"--version", "-v"}, description = "Outputs the version number of the program and result ontology.")
private boolean version;
}

private static final Logger LOGGER = LoggerFactory.getLogger(MainController.class);
Expand All @@ -45,7 +49,7 @@ public Path convert(String value) {
*
* @param argc The command line arguments that are passed to the program.
*/
public static void main(String[] argc) {
public static void main(String[] argc) throws IOException {
// Configurator.reconfigure(URI.create("log4j2.yml"));

var args = new Args();
Expand All @@ -55,6 +59,13 @@ public static void main(String[] argc) {
try {
jc.parse(argc);
} catch (ParameterException e) {
// The exception is also thrown when no suite file is provided. In the case where only the version option
// is provided, this would still throw. Therefore, we need to check if the version option is provided.
if (args.version) {
outputVersion();
System.exit(0);
}

System.err.println(e.getLocalizedMessage());
jc.usage();
System.exit(0);
Expand All @@ -63,6 +74,10 @@ public static void main(String[] argc) {
jc.usage();
System.exit(1);
}
if (args.version) {
outputVersion();
System.exit(0);
}

try {
Suite parse = IguanaSuiteParser.parse(args.suitePath, !args.ignoreShema);
Expand All @@ -74,4 +89,14 @@ public static void main(String[] argc) {
System.exit(0);
}

private static void outputVersion() throws IOException {
ClassLoader classloader = MainController.class.getClassLoader();
String properties = new String(Objects.requireNonNull(classloader.getResourceAsStream("version.properties")).readAllBytes());
String[] lines = properties.split("\\n");
String projectVersion = lines[0].split("=")[1];
String ontologyVersion = lines[1].split("=")[1];
System.out.println("IGUANA version: " + projectVersion);
System.out.println("Result ontology version: " + ontologyVersion);
}

}
2 changes: 2 additions & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=${project.version}
ontology_version=${ontology.version}

0 comments on commit 9cddbe6

Please sign in to comment.