Browse Source

Merge c3cbf55d25 into 45320512cf

pull/27/merge
Jiri Bubnik 6 years ago
parent
commit
c3c20801b8
No account linked to committer's email address

+ 30
- 0
installer/src/main/java/com/github/dcevm/installer/DcevmPatchNotFoundException.java View File

package com.github.dcevm.installer;

/**
* DCEVM patch does not exists for the version of Java.
*/
public class DcevmPatchNotFoundException extends Exception {
// Java version to patch
String javaVersion;

// install path
String installPath;

public DcevmPatchNotFoundException(String javaVersion, String installPath) {
this.javaVersion = javaVersion;
this.installPath = installPath;
}

@Override
public String getMessage() {
return "DCEVM patch is not available for Java version '" + getJavaVersion() + "' at '" + getInstallPath() + "'.";
}

public String getJavaVersion() {
return javaVersion;
}

public String getInstallPath() {
return installPath;
}
}

+ 5
- 0
installer/src/main/java/com/github/dcevm/installer/InstallUninstallAction.java View File

import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.IOException; import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;


} else { } else {
getSelectedInstallation().uninstallDCE(); getSelectedInstallation().uninstallDCE();
} }
} catch (AccessDeniedException ex) {
MainWindow.showAccessDeniedException(ex, table);
} catch (IOException ex) { } catch (IOException ex) {
MainWindow.showInstallerException(ex, table); MainWindow.showInstallerException(ex, table);
} catch (DcevmPatchNotFoundException ex) {
MainWindow.showPatchNotFoundException(ex, table);
} }
} }



+ 2
- 2
installer/src/main/java/com/github/dcevm/installer/Installation.java View File

return is64Bit; return is64Bit;
} }


public void installDCE(boolean altjvm) throws IOException {
new Installer(config).install(file, is64Bit, altjvm);
public void installDCE(boolean altjvm) throws IOException, DcevmPatchNotFoundException {
new Installer(config).install(getVersion(), file, is64Bit, altjvm);
update(); update();
setChanged(); setChanged();
notifyObservers(); notifyObservers();

+ 25
- 12
installer/src/main/java/com/github/dcevm/installer/Installer.java View File

this.config = config; this.config = config;
} }


public void install(Path dir, boolean bit64, boolean altjvm) throws IOException {
public void install(String javaVersion, Path dir, boolean bit64, boolean altjvm) throws IOException, DcevmPatchNotFoundException {
if (config.isJDK(dir)) { if (config.isJDK(dir)) {
dir = dir.resolve(config.getJREDirectory()); dir = dir.resolve(config.getJREDirectory());
} }
if (!altjvm) { if (!altjvm) {
Path serverPath = dir.resolve(config.getServerPath(bit64)); Path serverPath = dir.resolve(config.getServerPath(bit64));
if (Files.exists(serverPath)) { if (Files.exists(serverPath)) {
installClientServer(serverPath, bit64);
installClientServer(javaVersion, serverPath, bit64);
} }


Path clientPath = dir.resolve(config.getClientPath()); Path clientPath = dir.resolve(config.getClientPath());
if (Files.exists(clientPath) && !bit64) { if (Files.exists(clientPath) && !bit64) {
installClientServer(clientPath, false);
installClientServer(javaVersion, clientPath, false);
} }
} else { } else {
Path altjvmPath = dir.resolve(bit64 ? config.getDcevm64Path() : config.getDcevm32Path()); Path altjvmPath = dir.resolve(bit64 ? config.getDcevm64Path() : config.getDcevm32Path());
if (!Files.exists(altjvmPath)) { if (!Files.exists(altjvmPath)) {
Files.createDirectory(altjvmPath); Files.createDirectory(altjvmPath);
} }
installClientServer(altjvmPath, bit64);
installClientServer(javaVersion, altjvmPath, bit64);
} }
} }


return config; return config;
} }


private void installClientServer(Path path, boolean bit64) throws IOException {
String resource = config.getResourcePath(bit64) + "/product/" + config.getLibraryName();
private void installClientServer(String javaVersion, Path path, boolean bit64) throws IOException, DcevmPatchNotFoundException {
String resource = getVersionDir(javaVersion) + "/" + config.getResourcePath(bit64) + "/product/" + config.getLibraryName();


Path library = path.resolve(config.getLibraryName()); Path library = path.resolve(config.getLibraryName());
Path backup = path.resolve(config.getBackupLibraryName()); Path backup = path.resolve(config.getBackupLibraryName());


// backup any existing library (assume original JVM file)
if (Files.exists(library)) {
Files.move(library, backup);
}

try { try {
// install actual DCEVM file // install actual DCEVM file
try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) { try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) {
if (in == null) { if (in == null) {
throw new IOException("DCEVM not available for java at '" + path + "'. Missing resource " + resource);
String version = javaVersion + (bit64 ? " (64 bit)" : "");
throw new DcevmPatchNotFoundException(version, path.toString());
}

// backup any existing library (assume original JVM file)
if (Files.exists(library)) {
Files.move(library, backup);
} }


// install the new file
Files.copy(in, library); Files.copy(in, library);
} }
} catch (NullPointerException | IOException e) { } catch (NullPointerException | IOException e) {
} }
} }


/**
* Convert java version to a directory name containing associated installation resources.
*
* @param javaVersion full java version (such as 1.7.0_45)
* @return directory in which the installer is available (such as 1.7)
*/
private String getVersionDir(String javaVersion) {
String[] version = javaVersion.split("[\\.\\_]");
return version[0] + "." + version[1];
}

private void uninstallClientServer(Path path) throws IOException { private void uninstallClientServer(Path path) throws IOException {
Path library = path.resolve(config.getLibraryName()); Path library = path.resolve(config.getLibraryName());
Path backup = path.resolve(config.getBackupLibraryName()); Path backup = path.resolve(config.getBackupLibraryName());

+ 11
- 1
installer/src/main/java/com/github/dcevm/installer/MainWindow.java View File

import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.AccessDeniedException;


/** /**
* @author Kerstin Breiteneder * @author Kerstin Breiteneder
ex.printStackTrace(); ex.printStackTrace();


error += "\nPlease ensure that no other Java applications are running and you have sufficient permissions."; error += "\nPlease ensure that no other Java applications are running and you have sufficient permissions.";
JOptionPane.showMessageDialog(parent, error, ex.getMessage(), JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(parent, error, ex.getMessage() + "(" + ex.getClass().getName() + ")", JOptionPane.ERROR_MESSAGE);
}

public static void showPatchNotFoundException(DcevmPatchNotFoundException ex, Component parent) {
JOptionPane.showMessageDialog(parent, ex.getMessage(), "DCEVM patch not available", JOptionPane.ERROR_MESSAGE);
}


public static void showAccessDeniedException(AccessDeniedException ex, Component parent) {
JOptionPane.showMessageDialog(parent, "Please check system permissions for resource: " + ex.getMessage(), "Access denied", JOptionPane.ERROR_MESSAGE);
} }


private JComponent getBanner() { private JComponent getBanner() {

Loading…
Cancel
Save