Fix some warnings
This commit is contained in:
		
					parent
					
						
							
								b720cce4d0
							
						
					
				
			
			
				commit
				
					
						d8b0d2cdbc
					
				
			
		
					 9 changed files with 173 additions and 64 deletions
				
			
		
							
								
								
									
										124
									
								
								.idea/uiDesigner.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								.idea/uiDesigner.xml
									
										
									
										generated
									
									
									
										Normal 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>
 | 
			
		||||
| 
						 | 
				
			
			@ -6,16 +6,16 @@ import java.util.concurrent.CompletableFuture;
 | 
			
		|||
public interface Downloader {
 | 
			
		||||
	/**
 | 
			
		||||
	 * downloads a file and verifies it
 | 
			
		||||
	 * @param url
 | 
			
		||||
	 * @param sha256hex
 | 
			
		||||
	 * @param url the file url to download from
 | 
			
		||||
	 * @param sha256hex the sha256 hash to verify
 | 
			
		||||
	 * @return a future which can throw ioexception or signatureexception
 | 
			
		||||
	 */
 | 
			
		||||
	CompletableFuture<File> downloadAndVerify(String url, String sha256hex);
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * moves source into destination
 | 
			
		||||
	 * @param source
 | 
			
		||||
	 * @param destination
 | 
			
		||||
	 * @param source source file
 | 
			
		||||
	 * @param destination destination file (path)
 | 
			
		||||
	 * @return a future which can throw ioexception
 | 
			
		||||
	 */
 | 
			
		||||
	CompletableFuture<Void> install(File source, File destination);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@ package eu.m724.jarupdater.environment;
 | 
			
		|||
import java.nio.file.Path;
 | 
			
		||||
 | 
			
		||||
public class ConstantEnvironment implements Environment {
 | 
			
		||||
	private String runningVersion;
 | 
			
		||||
	private String channel;
 | 
			
		||||
	private Path runningJarFilePath;
 | 
			
		||||
	private final String runningVersion;
 | 
			
		||||
	private final String channel;
 | 
			
		||||
	private final Path runningJarFilePath;
 | 
			
		||||
	
 | 
			
		||||
	public ConstantEnvironment(String runningVersion, String channel, Path runningJarFilePath) {
 | 
			
		||||
		this.runningVersion = runningVersion;
 | 
			
		||||
| 
						 | 
				
			
			@ -13,19 +13,8 @@ public class ConstantEnvironment implements Environment {
 | 
			
		|||
		this.runningJarFilePath = runningJarFilePath;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String getRunningVersion() {
 | 
			
		||||
		return runningVersion;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String getChannel() {
 | 
			
		||||
		return channel;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public Path getRunningJarFilePath() {
 | 
			
		||||
		return runningJarFilePath;
 | 
			
		||||
	}
 | 
			
		||||
	@Override public String getRunningVersion() { return runningVersion; }
 | 
			
		||||
	@Override public String getChannel() { return channel; }
 | 
			
		||||
	@Override public Path getRunningJarFilePath() { return runningJarFilePath; }
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ package eu.m724.jarupdater.environment;
 | 
			
		|||
import java.nio.file.Path;
 | 
			
		||||
 | 
			
		||||
public interface Environment {
 | 
			
		||||
	public String getRunningVersion();
 | 
			
		||||
	public String getChannel();
 | 
			
		||||
	public Path getRunningJarFilePath();
 | 
			
		||||
	String getRunningVersion();
 | 
			
		||||
	String getChannel();
 | 
			
		||||
	Path getRunningJarFilePath();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,8 +17,8 @@ import com.google.gson.Gson;
 | 
			
		|||
import eu.m724.jarupdater.object.Version;
 | 
			
		||||
 | 
			
		||||
public class GiteaMetadataDAO implements MetadataDAO {
 | 
			
		||||
	private String url;
 | 
			
		||||
	private String branch;
 | 
			
		||||
	private final String url;
 | 
			
		||||
	private final String branch;
 | 
			
		||||
	
 | 
			
		||||
	public GiteaMetadataDAO(String url, String branch) {
 | 
			
		||||
		this.url = url;
 | 
			
		||||
| 
						 | 
				
			
			@ -30,49 +30,43 @@ public class GiteaMetadataDAO implements MetadataDAO {
 | 
			
		|||
	public CompletableFuture<List<String>> getChannels() {
 | 
			
		||||
		String url = getFileUrl("channels.txt");
 | 
			
		||||
 | 
			
		||||
		CompletableFuture<List<String>> channelsFuture =
 | 
			
		||||
				makeRequest(url).thenApply(response -> {
 | 
			
		||||
        return makeRequest(url).thenApply(response -> {
 | 
			
		||||
			if (response.statusCode() != 200)
 | 
			
		||||
                throw new CompletionException(new IOException("Server returned status code %d".formatted(response.statusCode())));
 | 
			
		||||
 | 
			
		||||
            return response.body().lines().toList();
 | 
			
		||||
        });
 | 
			
		||||
		
 | 
			
		||||
		return channelsFuture;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public CompletableFuture<Version> getMetadata(String channel, String versionLabel) {
 | 
			
		||||
		String url = getFileUrl(channel, versionLabel, "meta-v1.json");
 | 
			
		||||
 | 
			
		||||
		CompletableFuture<Version> metadataFuture =
 | 
			
		||||
				makeRequest(url).thenApply(response -> {
 | 
			
		||||
        // not throwing nosuchversionexecpion because it's not possible to tell if the server is broken or it really doesn't exist
 | 
			
		||||
 | 
			
		||||
        return 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 version;
 | 
			
		||||
            return new Gson().fromJson(response.body(), Version.class);
 | 
			
		||||
        });
 | 
			
		||||
		
 | 
			
		||||
		return metadataFuture;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	private CompletableFuture<HttpResponse<String>> makeRequest(String url) {
 | 
			
		||||
		System.out.println("Request: " + url);
 | 
			
		||||
		HttpRequest request = HttpRequest.newBuilder()
 | 
			
		||||
				.uri(URI.create(url))
 | 
			
		||||
				.header("User-Agent", "ju/1") // jar updater v1
 | 
			
		||||
				.build();
 | 
			
		||||
 | 
			
		||||
		CompletableFuture<HttpResponse<String>> responseFuture =
 | 
			
		||||
				HttpClient.newBuilder()
 | 
			
		||||
		HttpClient.Builder httpClientBuilder = HttpClient.newBuilder()
 | 
			
		||||
				.followRedirects(Redirect.NORMAL)
 | 
			
		||||
				.proxy(ProxySelector.getDefault()).build().
 | 
			
		||||
				sendAsync(request, BodyHandlers.ofString());
 | 
			
		||||
				.proxy(ProxySelector.getDefault());
 | 
			
		||||
 | 
			
		||||
		return responseFuture;
 | 
			
		||||
		try (HttpClient httpClient = httpClientBuilder.build()) {
 | 
			
		||||
			return httpClient.sendAsync(request, BodyHandlers.ofString());
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private String getFileUrl(String... paths) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,8 +14,8 @@ public interface MetadataDAO {
 | 
			
		|||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * get metadata of a version in channel
 | 
			
		||||
	 * @param channel
 | 
			
		||||
	 * @param versionLabel
 | 
			
		||||
	 * @param channel the channel
 | 
			
		||||
	 * @param versionLabel basically version number
 | 
			
		||||
	 * @return a future which can throw ioexcpeitons or nosuchfilexxception
 | 
			
		||||
	 */
 | 
			
		||||
    CompletableFuture<Version> getMetadata(String channel, String versionLabel);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,10 +8,10 @@ import eu.m724.jarupdater.environment.Environment;
 | 
			
		|||
import eu.m724.jarupdater.object.Version;
 | 
			
		||||
 | 
			
		||||
public class MetadataFacade {
 | 
			
		||||
	private Environment environment;
 | 
			
		||||
	private MetadataDAO metadataDao;
 | 
			
		||||
	private final Environment environment;
 | 
			
		||||
	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;
 | 
			
		||||
	
 | 
			
		||||
	public MetadataFacade(Environment environment, MetadataDAO metadataDao) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
package eu.m724.jarupdater.object;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
 | 
			
		||||
public class NoSuchVersionException extends IOException {
 | 
			
		||||
 | 
			
		||||
	@Serial
 | 
			
		||||
	private static final long serialVersionUID = 8435964987348892266L;
 | 
			
		||||
	
 | 
			
		||||
	public NoSuchVersionException(String version) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -74,8 +74,8 @@ public class Updater {
 | 
			
		|||
			String url = latestVersion.getFileUrl();
 | 
			
		||||
			String hash = latestVersion.getSha256();
 | 
			
		||||
 | 
			
		||||
			File file = downloader.downloadAndVerify(url, hash).join();
 | 
			
		||||
			return file; // TODO better way of catching exception?
 | 
			
		||||
			// TODO better way of catching exception?
 | 
			
		||||
            return downloader.downloadAndVerify(url, hash).join();
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
		return downloaded;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue