Skip to content

Commit

Permalink
Refactor version handling: introduce VersionProvider for dynamic vers…
Browse files Browse the repository at this point in the history
…ion information and update command annotations
  • Loading branch information
remiceres committed Dec 9, 2024
1 parent b4dc84e commit 706464c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 19 deletions.
8 changes: 2 additions & 6 deletions src/main/java/fr/inria/corese/command/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import picocli.CommandLine.Help.Ansi.Style;
import picocli.CommandLine.Help.ColorScheme;

@Command(name = "Corese-command", version = App.version, mixinStandardHelpOptions = true, subcommands = {
Convert.class, Sparql.class, Shacl.class, RemoteSparql.class, Canonicalize.class, GenerateCompletion.class
})

@Command(name = "Corese-command", versionProvider = VersionProvider.class, mixinStandardHelpOptions = true, subcommands = {
Convert.class, Sparql.class, Shacl.class, RemoteSparql.class, Canonicalize.class, GenerateCompletion.class })
public final class App implements Runnable {

public final static String version = "4.5.1";

public static void main(String[] args) {
// Define the color scheme
ColorScheme colorScheme = new ColorScheme.Builder()
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/fr/inria/corese/command/VersionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.inria.corese.command;

import fr.inria.corese.core.util.CoreseInfo;
import picocli.CommandLine;

/**
* Custom version provider for dynamic version information
*/
public class VersionProvider implements CommandLine.IVersionProvider {

// Version of Corese-Command
public final static String commandVersion = "4.5.1";

@Override
public String[] getVersion() {
return new String[] {
"Corese-Command Version: " + commandVersion,
"Based on Corese-Core Version: " + CoreseInfo.getVersion()
};
}

/**
* Get the version of Corese-Command
*
* @return the version of Corese-Command
*/
public static String getCommandVersion() {
return commandVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Optional;
import java.util.concurrent.Callable;

import fr.inria.corese.command.App;
import fr.inria.corese.command.VersionProvider;
import fr.inria.corese.command.utils.ConfigManager;
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
import fr.inria.corese.core.util.Property;
Expand All @@ -19,7 +19,7 @@
*
* This class provides common options and methods for all commands.
*/
@Command(version = App.version)
@Command(versionProvider = VersionProvider.class)
public abstract class AbstractCommand implements Callable<Integer> {

///////////////
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/fr/inria/corese/command/programs/Convert.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.inria.corese.command.programs;

import fr.inria.corese.command.App;
import fr.inria.corese.command.utils.exporter.rdf.EnumRdfOutputFormat;
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
Expand All @@ -9,7 +8,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "convert", version = App.version, description = "Convert an RDF file from one serialization format to another.", mixinStandardHelpOptions = true)
@Command(name = "convert", description = "Convert an RDF file from one serialization format to another.", mixinStandardHelpOptions = true)
public class Convert extends AbstractInputCommand {

@Option(names = { "-f", "-if",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import com.github.jsonldjava.shaded.com.google.common.io.Files;

import fr.inria.corese.command.App;
import fr.inria.corese.command.utils.http.EnumRequestMethod;
import fr.inria.corese.command.utils.http.SparqlHttpClient;
import fr.inria.corese.command.utils.loader.sparql.SparqlQueryLoader;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "remote-sparql", version = App.version, description = "Execute a SPARQL query on a remote endpoint.", mixinStandardHelpOptions = true)
@Command(name = "remote-sparql", description = "Execute a SPARQL query on a remote endpoint.", mixinStandardHelpOptions = true)
public class RemoteSparql extends AbstractCommand {

@Option(names = { "-q",
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/fr/inria/corese/command/programs/Shacl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.inria.corese.command.programs;

import fr.inria.corese.command.App;
import fr.inria.corese.command.utils.TestType;
import fr.inria.corese.command.utils.exporter.rdf.EnumRdfOutputFormat;
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
Expand All @@ -10,7 +9,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "shacl", version = App.version, description = "Run SHACL validation on a RDF dataset.", mixinStandardHelpOptions = true)
@Command(name = "shacl", description = "Run SHACL validation on a RDF dataset.", mixinStandardHelpOptions = true)
public class Shacl extends AbstractInputCommand {

@Option(names = { "-f", "-if",
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fr/inria/corese/command/programs/Sparql.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package fr.inria.corese.command.programs;

import fr.inria.corese.command.App;
import fr.inria.corese.command.utils.exporter.sparql.EnumResultFormat;
import fr.inria.corese.command.utils.exporter.sparql.SparqlResultExporter;
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
import fr.inria.corese.command.utils.loader.sparql.SparqlQueryLoader;
import fr.inria.corese.core.Graph;
import fr.inria.corese.core.query.QueryProcess;
import fr.inria.corese.core.kgram.core.Mappings;
import fr.inria.corese.core.query.QueryProcess;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "sparql", version = App.version, description = "Run a SPARQL query.", mixinStandardHelpOptions = true)
@Command(name = "sparql", description = "Run a SPARQL query.", mixinStandardHelpOptions = true)
public class Sparql extends AbstractInputCommand {

@Option(names = { "-f", "-if",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.apache.commons.lang3.tuple.Pair;

import fr.inria.corese.command.App;
import fr.inria.corese.command.VersionProvider;
import fr.inria.corese.command.utils.TestType;
import fr.inria.corese.core.Graph;
import fr.inria.corese.core.query.QueryProcess;
Expand Down Expand Up @@ -43,7 +43,7 @@ public class SparqlHttpClient {

private int redirectCount = 0;
private int maxRedirects = 5;
private final String USERAGENT = "Corese-Command/" + App.version;
private final String USERAGENT = "Corese-Command/" + VersionProvider.getCommandVersion();

/////////////////
// Constructor //
Expand Down

0 comments on commit 706464c

Please sign in to comment.