diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 6ee841d8..81025e23 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -44,7 +44,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public class SongodaCore { - private static final Logger logger = Logger.getLogger("SongodaCore"); + private static final Logger logger = Logger.getLogger(SongodaCoreConstants.getProjectName()); /** * Whenever we make a major change to the core GUI, updater, @@ -64,6 +64,7 @@ public class SongodaCore { /** * This is specific to the website api + * * @deprecated Seems useless and will probably be removed in the near future */ @Deprecated @@ -326,7 +327,7 @@ public class SongodaCore { } public static String getPrefix() { - return "[SongodaCore] "; + return "[" + SongodaCoreConstants.getProjectName() + "] "; } public static Logger getLogger() { diff --git a/Core/src/main/java/com/songoda/core/SongodaCoreConstants.java b/Core/src/main/java/com/songoda/core/SongodaCoreConstants.java index b8c5bfea..bc9e8bc8 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCoreConstants.java +++ b/Core/src/main/java/com/songoda/core/SongodaCoreConstants.java @@ -1,9 +1,11 @@ package com.songoda.core; -/* - * Return values in this class are automatically replaced by a maven plugin after the project has been compiled. +/** + * Some return values in this class are automatically replaced by a maven plugin after the project has been compiled. * This allows for properties to be defined at one place without relying on a text file * that needs to be inside the final jar (might get lost when this lib is shaded into other projects). + *
+ * !! Manually changing the values in this class has to be considered a breaking change. !!
*/
public class SongodaCoreConstants {
private SongodaCoreConstants() {
@@ -13,4 +15,12 @@ public class SongodaCoreConstants {
public static String getCoreVersion() {
return "UNKNOWN_VESION";
}
+
+ public static String getProjectName() {
+ return "SongodaCore";
+ }
+
+ public static String getGitHubProjectUrl() {
+ return "https://github.com/craftaro/SongodaCore";
+ }
}
diff --git a/Core/src/main/java/com/songoda/core/http/SimpleHttpClient.java b/Core/src/main/java/com/songoda/core/http/SimpleHttpClient.java
index 3ce9e606..d1ca8819 100644
--- a/Core/src/main/java/com/songoda/core/http/SimpleHttpClient.java
+++ b/Core/src/main/java/com/songoda/core/http/SimpleHttpClient.java
@@ -1,6 +1,6 @@
package com.songoda.core.http;
-import com.songoda.core.SongodaCore;
+import com.songoda.core.SongodaCoreConstants;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -8,14 +8,24 @@ import java.net.HttpURLConnection;
import java.net.URL;
public class SimpleHttpClient implements HttpClient {
+ private static final String USER_AGENT = generateUserAgent();
+
public @NotNull HttpResponse get(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setInstanceFollowRedirects(true);
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
- connection.setRequestProperty("User-Agent", "SongodaCore/" + SongodaCore.getVersion() + " (+https://github.com/songoda/SongodaCore)");
+ connection.setRequestProperty("User-Agent", USER_AGENT);
return new HttpResponseImpl(connection);
}
+
+ private static String generateUserAgent() {
+ String projectName = SongodaCoreConstants.getProjectName();
+ String version = SongodaCoreConstants.getCoreVersion();
+ String projectUrl = SongodaCoreConstants.getGitHubProjectUrl();
+
+ return projectName + "/" + version + " (+" + projectUrl + ")";
+ }
}
diff --git a/Core/src/main/java/com/songoda/core/math/MathUtils.java b/Core/src/main/java/com/songoda/core/math/MathUtils.java
index c336d24c..b46e6345 100644
--- a/Core/src/main/java/com/songoda/core/math/MathUtils.java
+++ b/Core/src/main/java/com/songoda/core/math/MathUtils.java
@@ -1,5 +1,7 @@
package com.songoda.core.math;
+import com.songoda.core.SongodaCoreConstants;
+
import java.util.HashMap;
import java.util.Map;
@@ -7,7 +9,7 @@ public class MathUtils {
private static final Map