API for Orekit version number?

Hi all,

While looking at NtripClient class (answering to NTRIP client authentication thread), I stumbled upon a hard-coded constant:

    /** User-agent header value. */
    private static final String USER_AGENT_HEADER_VALUE = "NTRIP orekit/11.0";

This constant is recommended in the RTCM/NTRIP protocol and must have the pattern with NTRIP, software name and software version (plus possible additional text, we don’t set anything here).

I was wondering if we should not add somewhere an API for getting the current Orekit version and build this header value using this API.

Where should such a method go? I was thinking of OrekitConfiguration but it seems weird to me.

Good idea!

Maybe inside an application.properties file in the src/main/resources?

Something like

project.version=12.0

Excellent idea!

Would however such a property be available for users?

I think we shall add a new class: OrekitProperties. Something like:

public final class OrekitProperties {
   private static final String FILE_NAME = "product.properties";
   private static final Properties PROPERTIES;

   /** Private constructor for final class. */
   private OrekitProperties() {
      // nothing to do
   }

   /** Get the value corresponding to the given property.
     * @param property to find
     * @return the value of the property
     */
   public static String get(final String property) {
      try {
         if (PROPERTIES == null) {
             PROPERTIES = new Properties();
             PROPERTIES.load(OrekitProperties.class.getClassLoader().getResourcesAsStream(FILENAME));
         }
         PROPERTIES.get(property)
      } catch (Exception e) {
            throw new OrekitException(OrekitMessage.NOT_EXISTING_PROPERTY, property):
      }
   }
}

Note that I wrote the code directly in the forum. Maybe some adjustments are needed

1 Like

We could also add the following method inside OrekitProperties:

/** Get the current version of the project.
  * @return the current version of the project
  */
public static String getProjectVersion() {
   return get("project.version");
}

That’s OK if we only have a small number of properties (which will be the case for Orekit).

Could also integrate it with maven so we don’t forget to update it. E.g.

  <build>
    <!-- File subset of resources to place version number in a properties file -->
    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>${basedir}/src/main/resources/...</directory>
        <targetPath>${project.build.outputDirectory}/...</targetPath>
        <filtering>true</filtering>
      </resource>
    </resources>

    <plugins>
      <!-- add version information -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <!-- 1.4 does not work with git repositories. -->
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>create</goal>
            </goals>
          </execution>
        </executions>
      </plugin

In a properties file:

version=${project.version}
commit=${buildNumber}
3 Likes