Update .gitmodules, common-utils, and 7 more files...
This commit is contained in:
parent
95ae06052d
commit
c4f18294f1
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "common-utils"]
|
||||
path = common-utils
|
||||
url = https://git.ignuranza.net/tdlight-team/common-utils.git
|
@ -1 +0,0 @@
|
||||
Subproject commit 8da67564c5a006dd31c2d0528768af8f790c1a67
|
84
pom.xml
84
pom.xml
@ -7,9 +7,6 @@
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<!-- required for jdk9 -->
|
||||
<maven.compiler.source>10</maven.compiler.source>
|
||||
<maven.compiler.target>10</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@ -34,29 +31,6 @@
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>17.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>17.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.warp</groupId>
|
||||
<artifactId>common-utils</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.tdlight</groupId>
|
||||
<artifactId>tdlight-natives-linux-amd64</artifactId>
|
||||
@ -74,36 +48,36 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>templating-maven-plugin</artifactId>
|
||||
|
@ -59,7 +59,7 @@ public class Client extends NativeClient implements TelegramClient {
|
||||
throw new IllegalStateException("ClientActor is destroyed");
|
||||
}
|
||||
|
||||
var responseList = new ArrayList<Response>();
|
||||
ArrayList<Response> responseList = new ArrayList<>();
|
||||
if (eventIds == null) {
|
||||
eventIds = new long[eventSize];
|
||||
events = new Object[eventSize];
|
||||
@ -100,7 +100,7 @@ public class Client extends NativeClient implements TelegramClient {
|
||||
throw new IllegalStateException("ClientActor is destroyed");
|
||||
}
|
||||
|
||||
var responseList = receive(timeout, 1);
|
||||
List<Response> responseList = receive(timeout, 1);
|
||||
|
||||
if (responseList.size() < 1) {
|
||||
return null;
|
||||
|
@ -35,7 +35,7 @@ public class Init {
|
||||
*/
|
||||
public synchronized static void start() throws Throwable {
|
||||
if (!started) {
|
||||
var os = LoadLibrary.getOs();
|
||||
Os os = LoadLibrary.getOs();
|
||||
|
||||
if (os == Os.win) {
|
||||
LoadLibrary.load("libeay32");
|
||||
|
@ -1,7 +1,7 @@
|
||||
package it.tdlight.tdlight;
|
||||
|
||||
import it.tdlight.tdlib.NativeLog;
|
||||
import java.util.Objects;
|
||||
import it.tdlight.tdlight.utils.ObjectsUtils;
|
||||
|
||||
public class Log extends NativeLog {
|
||||
|
||||
@ -22,7 +22,7 @@ public class Log extends NativeLog {
|
||||
* @param fatalErrorCallback Callback that will be called when a fatal error happens. Pass null to restore default callback.
|
||||
*/
|
||||
public static void setFatalErrorCallback(FatalErrorCallbackPtr fatalErrorCallback) {
|
||||
Log.fatalErrorCallback = Objects.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr);
|
||||
Log.fatalErrorCallback = ObjectsUtils.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr);
|
||||
}
|
||||
|
||||
private static void onFatalError(String errorMessage) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
package it.tdlight.tdlight.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -68,8 +69,8 @@ public class LoadLibrary {
|
||||
return;
|
||||
}
|
||||
|
||||
var arch = getCpuArch();
|
||||
var os = getOs();
|
||||
Arch arch = getCpuArch();
|
||||
Os os = getOs();
|
||||
|
||||
if (arch == Arch.unknown) {
|
||||
throw new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown"));
|
||||
@ -99,7 +100,7 @@ public class LoadLibrary {
|
||||
private static void loadJarLibrary(String libname, Arch arch, Os os) throws IOException, CantLoadLibrary {
|
||||
Path tempPath = Files.createDirectories(librariesPath.resolve("version-" + libsVersion).resolve(libname));
|
||||
Path tempFile = Paths.get(tempPath.toString(), libname + getExt(os));
|
||||
var libInputStream = LoadLibrary.class.getResourceAsStream(createPath("libs", os.name(), arch.name(), libname) + getExt(os));
|
||||
InputStream libInputStream = LoadLibrary.class.getResourceAsStream(createPath("libs", os.name(), arch.name(), libname) + getExt(os));
|
||||
if (Files.notExists(tempFile)) {
|
||||
Files.copy(libInputStream, tempFile);
|
||||
}
|
||||
@ -109,7 +110,7 @@ public class LoadLibrary {
|
||||
|
||||
|
||||
private static Arch getCpuArch() {
|
||||
var architecture = System.getProperty("os.arch").trim();
|
||||
String architecture = System.getProperty("os.arch").trim();
|
||||
switch (architecture) {
|
||||
case "amd64":
|
||||
case "x86_64":
|
||||
@ -133,7 +134,7 @@ public class LoadLibrary {
|
||||
}
|
||||
|
||||
public static Os getOs() {
|
||||
var os = System.getProperty("os.name").toLowerCase().trim();
|
||||
String os = System.getProperty("os.name").toLowerCase().trim();
|
||||
if (os.contains("linux"))
|
||||
return Os.linux;
|
||||
if (os.contains("windows"))
|
||||
@ -150,7 +151,7 @@ public class LoadLibrary {
|
||||
}
|
||||
|
||||
private static String createPath(String... path) {
|
||||
var stringBuilder = new StringBuilder();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("/");
|
||||
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
|
67
src/main/java/it/tdlight/tdlight/utils/ObjectsUtils.java
Normal file
67
src/main/java/it/tdlight/tdlight/utils/ObjectsUtils.java
Normal file
@ -0,0 +1,67 @@
|
||||
package it.tdlight.tdlight.utils;
|
||||
|
||||
public class ObjectsUtils {
|
||||
/**
|
||||
* Returns the first argument if it is non-{@code null} and
|
||||
* otherwise returns the non-{@code null} second argument.
|
||||
*
|
||||
* @param obj an object
|
||||
* @param defaultObj a non-{@code null} object to return if the first argument
|
||||
* is {@code null}
|
||||
* @param <T> the type of the reference
|
||||
* @return the first argument if it is non-{@code null} and
|
||||
* otherwise the second argument if it is non-{@code null}
|
||||
* @throws NullPointerException if both {@code obj} is null and
|
||||
* {@code defaultObj} is {@code null}
|
||||
* @since 9
|
||||
*/
|
||||
public static <T> T requireNonNullElse(T obj, T defaultObj) {
|
||||
return (obj != null) ? obj : requireNonNull(defaultObj, "defaultObj");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified object reference is not {@code null}. This
|
||||
* method is designed primarily for doing parameter validation in methods
|
||||
* and constructors, as demonstrated below:
|
||||
* <blockquote><pre>
|
||||
* public Foo(Bar bar) {
|
||||
* this.bar = Objects.requireNonNull(bar);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param obj the object reference to check for nullity
|
||||
* @param <T> the type of the reference
|
||||
* @return {@code obj} if not {@code null}
|
||||
* @throws NullPointerException if {@code obj} is {@code null}
|
||||
*/
|
||||
public static <T> T requireNonNull(T obj) {
|
||||
if (obj == null)
|
||||
throw new NullPointerException();
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified object reference is not {@code null} and
|
||||
* throws a customized {@link NullPointerException} if it is. This method
|
||||
* is designed primarily for doing parameter validation in methods and
|
||||
* constructors with multiple parameters, as demonstrated below:
|
||||
* <blockquote><pre>
|
||||
* public Foo(Bar bar, Baz baz) {
|
||||
* this.bar = Objects.requireNonNull(bar, "bar must not be null");
|
||||
* this.baz = Objects.requireNonNull(baz, "baz must not be null");
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param obj the object reference to check for nullity
|
||||
* @param message detail message to be used in the event that a {@code
|
||||
* NullPointerException} is thrown
|
||||
* @param <T> the type of the reference
|
||||
* @return {@code obj} if not {@code null}
|
||||
* @throws NullPointerException if {@code obj} is {@code null}
|
||||
*/
|
||||
public static <T> T requireNonNull(T obj, String message) {
|
||||
if (obj == null)
|
||||
throw new NullPointerException(message);
|
||||
return obj;
|
||||
}
|
||||
}
|
@ -148,12 +148,12 @@ public class ScannerUtils {
|
||||
try {
|
||||
lock.lock();
|
||||
StringBuilder toPrint = new StringBuilder();
|
||||
var oldOut = System.out;
|
||||
var oldErr = System.err;
|
||||
PrintStream oldOut = System.out;
|
||||
PrintStream oldErr = System.err;
|
||||
System.setOut(emptyOut);
|
||||
System.setErr(emptyOut);
|
||||
oldOut.print("[" + displayName + "] " + question + ": ");
|
||||
var result = scanner.nextLine();
|
||||
String result = scanner.nextLine();
|
||||
System.setOut(oldOut);
|
||||
System.setErr(oldErr);
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user