Skip to content
Snippets Groups Projects
Select Git revision
  • 343b37af6cc6b5cddd501ee336972f6bd67ab51a
  • master default protected
  • exec_auto_adjust_trace
  • let_variables
  • v1.4.1
  • v1.4.0
  • v1.3.0
  • v1.2.0
  • v1.1.0
  • v1.0.0
10 results

Main.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Main.java 9.44 KiB
    package de.prob2.jupyter;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UncheckedIOException;
    import java.net.URISyntaxException;
    import java.nio.charset.StandardCharsets;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.nio.file.StandardCopyOption;
    import java.security.CodeSource;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import java.util.Arrays;
    import java.util.stream.Collectors;
    import java.util.stream.Stream;
    
    import com.google.inject.Guice;
    import com.google.inject.Injector;
    import com.google.inject.Stage;
    
    import io.github.spencerpark.jupyter.channels.JupyterConnection;
    import io.github.spencerpark.jupyter.kernel.KernelConnectionProperties;
    
    import org.jetbrains.annotations.Nullable;
    
    public final class Main {
    	private Main() {
    		super();
    		
    		throw new AssertionError();
    	}
    	
    	private static AssertionError die(final int status, final @Nullable Throwable cause) {
    		System.exit(status);
    		return new AssertionError("Unreachable", cause);
    	}
    	
    	private static AssertionError die(final int status) {
    		return die(status, null);
    	}
    	
    	private static Path getJarPath() {
    		try {
    			final CodeSource cs = Main.class.getProtectionDomain().getCodeSource();
    			if (cs == null) {
    				System.err.println("Unable to determine location of kernel jar file (CodeSource is null)");
    				throw die(1);
    			}
    			return Paths.get(cs.getLocation().toURI());
    		} catch (final RuntimeException | URISyntaxException e) {
    			System.err.println("Unable to determine location of kernel jar file");
    			e.printStackTrace();
    			throw die(1, e);
    		}
    	}
    	
    	private static Path getDestPath(final Path jarPath) {
    		return Paths.get(de.prob.Main.getProBDirectory(), "jupyter", jarPath.getFileName().toString());
    	}
    	
    	private static void copyJar(final Path jarPath, final Path destPath) {
    		System.out.println("Installing kernel jar file...");
    		System.out.println("Path to kernel jar file: " + jarPath);
    		System.out.println("Kernel jar will be copied to: " + destPath);
    		try {
    			Files.createDirectories(destPath.getParent());