Fix some warnings

This commit is contained in:
Minecon724 2024-10-27 13:45:40 +01:00
parent b720cce4d0
commit d8b0d2cdbc
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
9 changed files with 173 additions and 64 deletions

124
.idea/uiDesigner.xml Normal file
View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View file

@ -6,16 +6,16 @@ import java.util.concurrent.CompletableFuture;
public interface Downloader { public interface Downloader {
/** /**
* downloads a file and verifies it * downloads a file and verifies it
* @param url * @param url the file url to download from
* @param sha256hex * @param sha256hex the sha256 hash to verify
* @return a future which can throw ioexception or signatureexception * @return a future which can throw ioexception or signatureexception
*/ */
CompletableFuture<File> downloadAndVerify(String url, String sha256hex); CompletableFuture<File> downloadAndVerify(String url, String sha256hex);
/** /**
* moves source into destination * moves source into destination
* @param source * @param source source file
* @param destination * @param destination destination file (path)
* @return a future which can throw ioexception * @return a future which can throw ioexception
*/ */
CompletableFuture<Void> install(File source, File destination); CompletableFuture<Void> install(File source, File destination);

View file

@ -3,9 +3,9 @@ package eu.m724.jarupdater.environment;
import java.nio.file.Path; import java.nio.file.Path;
public class ConstantEnvironment implements Environment { public class ConstantEnvironment implements Environment {
private String runningVersion; private final String runningVersion;
private String channel; private final String channel;
private Path runningJarFilePath; private final Path runningJarFilePath;
public ConstantEnvironment(String runningVersion, String channel, Path runningJarFilePath) { public ConstantEnvironment(String runningVersion, String channel, Path runningJarFilePath) {
this.runningVersion = runningVersion; this.runningVersion = runningVersion;
@ -13,19 +13,8 @@ public class ConstantEnvironment implements Environment {
this.runningJarFilePath = runningJarFilePath; this.runningJarFilePath = runningJarFilePath;
} }
@Override @Override public String getRunningVersion() { return runningVersion; }
public String getRunningVersion() { @Override public String getChannel() { return channel; }
return runningVersion; @Override public Path getRunningJarFilePath() { return runningJarFilePath; }
}
@Override
public String getChannel() {
return channel;
}
@Override
public Path getRunningJarFilePath() {
return runningJarFilePath;
}
} }

View file

@ -3,7 +3,7 @@ package eu.m724.jarupdater.environment;
import java.nio.file.Path; import java.nio.file.Path;
public interface Environment { public interface Environment {
public String getRunningVersion(); String getRunningVersion();
public String getChannel(); String getChannel();
public Path getRunningJarFilePath(); Path getRunningJarFilePath();
} }

View file

@ -17,8 +17,8 @@ import com.google.gson.Gson;
import eu.m724.jarupdater.object.Version; import eu.m724.jarupdater.object.Version;
public class GiteaMetadataDAO implements MetadataDAO { public class GiteaMetadataDAO implements MetadataDAO {
private String url; private final String url;
private String branch; private final String branch;
public GiteaMetadataDAO(String url, String branch) { public GiteaMetadataDAO(String url, String branch) {
this.url = url; this.url = url;
@ -30,49 +30,43 @@ public class GiteaMetadataDAO implements MetadataDAO {
public CompletableFuture<List<String>> getChannels() { public CompletableFuture<List<String>> getChannels() {
String url = getFileUrl("channels.txt"); String url = getFileUrl("channels.txt");
CompletableFuture<List<String>> channelsFuture = return makeRequest(url).thenApply(response -> {
makeRequest(url).thenApply(response -> { if (response.statusCode() != 200)
if (response.statusCode() != 200) throw new CompletionException(new IOException("Server returned status code %d".formatted(response.statusCode())));
throw new CompletionException(new IOException("Server returned status code %d".formatted(response.statusCode())));
return response.body().lines().toList(); return response.body().lines().toList();
}); });
return channelsFuture;
} }
@Override @Override
public CompletableFuture<Version> getMetadata(String channel, String versionLabel) { public CompletableFuture<Version> getMetadata(String channel, String versionLabel) {
String url = getFileUrl(channel, versionLabel, "meta-v1.json"); String url = getFileUrl(channel, versionLabel, "meta-v1.json");
CompletableFuture<Version> metadataFuture = // not throwing nosuchversionexecpion because it's not possible to tell if the server is broken or it really doesn't exist
makeRequest(url).thenApply(response -> {
if (response.statusCode() != 200)
throw new CompletionException(new IOException("Server returned status code %d".formatted(response.statusCode())));
// not throwing nosuchversionexecpion because it's not possible to tell if the server is broken or it really doesn't exist
Version version = new Gson().fromJson(response.body(), Version.class); return makeRequest(url).thenApply(response -> {
return version; if (response.statusCode() != 200)
}); throw new CompletionException(new IOException("Server returned status code %d".formatted(response.statusCode())));
// not throwing nosuchversionexecpion because it's not possible to tell if the server is broken or it really doesn't exist
return metadataFuture; return new Gson().fromJson(response.body(), Version.class);
});
} }
private CompletableFuture<HttpResponse<String>> makeRequest(String url) { private CompletableFuture<HttpResponse<String>> makeRequest(String url) {
System.out.println("Request: " + url);
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url)) .uri(URI.create(url))
.header("User-Agent", "ju/1") // jar updater v1 .header("User-Agent", "ju/1") // jar updater v1
.build(); .build();
CompletableFuture<HttpResponse<String>> responseFuture = HttpClient.Builder httpClientBuilder = HttpClient.newBuilder()
HttpClient.newBuilder()
.followRedirects(Redirect.NORMAL) .followRedirects(Redirect.NORMAL)
.proxy(ProxySelector.getDefault()).build(). .proxy(ProxySelector.getDefault());
sendAsync(request, BodyHandlers.ofString());
return responseFuture; try (HttpClient httpClient = httpClientBuilder.build()) {
return httpClient.sendAsync(request, BodyHandlers.ofString());
}
} }
private String getFileUrl(String... paths) { private String getFileUrl(String... paths) {

View file

@ -14,8 +14,8 @@ public interface MetadataDAO {
/** /**
* get metadata of a version in channel * get metadata of a version in channel
* @param channel * @param channel the channel
* @param versionLabel * @param versionLabel basically version number
* @return a future which can throw ioexcpeitons or nosuchfilexxception * @return a future which can throw ioexcpeitons or nosuchfilexxception
*/ */
CompletableFuture<Version> getMetadata(String channel, String versionLabel); CompletableFuture<Version> getMetadata(String channel, String versionLabel);

View file

@ -8,10 +8,10 @@ import eu.m724.jarupdater.environment.Environment;
import eu.m724.jarupdater.object.Version; import eu.m724.jarupdater.object.Version;
public class MetadataFacade { public class MetadataFacade {
private Environment environment; private final Environment environment;
private MetadataDAO metadataDao; private final MetadataDAO metadataDao;
private HashMap<String, CompletableFuture<Version>> cache = new HashMap<>(); private final HashMap<String, CompletableFuture<Version>> cache = new HashMap<>();
private CompletableFuture<List<String>> channels = null; private CompletableFuture<List<String>> channels = null;
public MetadataFacade(Environment environment, MetadataDAO metadataDao) { public MetadataFacade(Environment environment, MetadataDAO metadataDao) {

View file

@ -1,9 +1,11 @@
package eu.m724.jarupdater.object; package eu.m724.jarupdater.object;
import java.io.IOException; import java.io.IOException;
import java.io.Serial;
public class NoSuchVersionException extends IOException { public class NoSuchVersionException extends IOException {
@Serial
private static final long serialVersionUID = 8435964987348892266L; private static final long serialVersionUID = 8435964987348892266L;
public NoSuchVersionException(String version) { public NoSuchVersionException(String version) {

View file

@ -74,8 +74,8 @@ public class Updater {
String url = latestVersion.getFileUrl(); String url = latestVersion.getFileUrl();
String hash = latestVersion.getSha256(); String hash = latestVersion.getSha256();
File file = downloader.downloadAndVerify(url, hash).join(); // TODO better way of catching exception?
return file; // TODO better way of catching exception? return downloader.downloadAndVerify(url, hash).join();
}); });
return downloaded; return downloaded;