diff --git a/build.gradle b/build.gradle index 49fda4df..a8e8d57b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ plugins { + id 'de.fuerstenau.buildconfig' version '1.1.8' id 'idea' id 'java' id 'org.jetbrains.intellij' version '0.3.10' @@ -11,6 +12,13 @@ sourceCompatibility = 1.8 def hasPyCharm = project.hasProperty('pycharmPath') +buildConfig { + appName 'ugent-dodona' + version = project.version + packageName = 'be.ugent.piedcler.dodona.plugin' + clsName = 'BuildConfig' +} + intellij { version ideaVersion pluginName 'ugent-dodona' diff --git a/src/main/java/be/ugent/piedcler/dodona/plugin/Api.java b/src/main/java/be/ugent/piedcler/dodona/plugin/Api.java index 7d9a9164..644d3d83 100644 --- a/src/main/java/be/ugent/piedcler/dodona/plugin/Api.java +++ b/src/main/java/be/ugent/piedcler/dodona/plugin/Api.java @@ -17,13 +17,11 @@ * Interface to the API. */ public final class Api { - private static final String USER_AGENT = "DodonaPlugin/1.1.0"; - @Nullable private static DodonaClient instance; /** - * Removes the instance of the dodona client, may be called by the + * Removes the instance of the Dodona client, may be called by the * SettingsHelper. */ public static void clearInstance() { @@ -35,16 +33,26 @@ public static void clearInstance() { * the caller since the instance will become invalid upon changing the * settings. * - * @return + * @return Dodona instance */ public static DodonaClient getInstance() { if (instance == null) { instance = DodonaBuilder.builder() .setApiToken(SettingsHelper.getApiKey()) .setBaseUrl(SettingsHelper.getDodonaUrl()) - .setUserAgent(USER_AGENT) + .setUserAgent(getUserAgent()) .build(); } return instance; } + + /** + * Gets the user agent to send in API calls. + * + * @return the user agent + */ + private static String getUserAgent() { + final String version = BuildConfig.VERSION; + return String.format("DodonaPlugin/JetBrains-%s", version); + } }