mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-01-09 01:07:52 +01:00
Introduce constants GitHubProjectURL+ProjectName in SongodaCoreConstants
This commit is contained in:
parent
3722ebb46a
commit
17780fffdc
@ -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() {
|
||||
|
@ -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).
|
||||
* <p>
|
||||
* <b>!! Manually changing the values in this class has to be considered a breaking change. !!</b>
|
||||
*/
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
@ -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 + ")";
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Double> cache = new HashMap<>();
|
||||
|
||||
public static double eval(String toParse) {
|
||||
return eval(toParse, "SongodaCore Eval Engine");
|
||||
return eval(toParse, SongodaCoreConstants.getProjectName() + " Eval Engine");
|
||||
}
|
||||
|
||||
public static double eval(String toParse, String warningMessage) {
|
||||
|
@ -6,6 +6,7 @@ import org.opentest4j.TestSkippedException;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class SongodaCoreConstantsTest {
|
||||
@ -22,4 +23,14 @@ class SongodaCoreConstantsTest {
|
||||
|
||||
assertTrue(VERSION_PATTERN.matcher(coreVersion).matches(), "Version string is not a valid semver string: " + coreVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProjectName() {
|
||||
assertFalse(SongodaCoreConstants.getProjectName().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getGitHubProjectUrl() {
|
||||
assertFalse(SongodaCoreConstants.getGitHubProjectUrl().isEmpty());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user