@@ -0,0 +1,30 @@ | |||
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; | |||
} | |||
} |
@@ -28,6 +28,7 @@ import javax.swing.event.ListSelectionEvent; | |||
import javax.swing.event.ListSelectionListener; | |||
import java.awt.event.ActionEvent; | |||
import java.io.IOException; | |||
import java.nio.file.AccessDeniedException; | |||
import java.util.Observable; | |||
import java.util.Observer; | |||
@@ -90,8 +91,12 @@ class InstallUninstallAction extends AbstractAction implements ListSelectionList | |||
} else { | |||
getSelectedInstallation().uninstallDCE(); | |||
} | |||
} catch (AccessDeniedException ex) { | |||
MainWindow.showAccessDeniedException(ex, table); | |||
} catch (IOException ex) { | |||
MainWindow.showInstallerException(ex, table); | |||
} catch (DcevmPatchNotFoundException ex) { | |||
MainWindow.showPatchNotFoundException(ex, table); | |||
} | |||
} | |||
@@ -106,8 +106,8 @@ public class Installation extends Observable { | |||
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(); | |||
setChanged(); | |||
notifyObservers(); |
@@ -43,7 +43,7 @@ public class Installer { | |||
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)) { | |||
dir = dir.resolve(config.getJREDirectory()); | |||
} | |||
@@ -51,19 +51,19 @@ public class Installer { | |||
if (!altjvm) { | |||
Path serverPath = dir.resolve(config.getServerPath(bit64)); | |||
if (Files.exists(serverPath)) { | |||
installClientServer(serverPath, bit64); | |||
installClientServer(javaVersion, serverPath, bit64); | |||
} | |||
Path clientPath = dir.resolve(config.getClientPath()); | |||
if (Files.exists(clientPath) && !bit64) { | |||
installClientServer(clientPath, false); | |||
installClientServer(javaVersion, clientPath, false); | |||
} | |||
} else { | |||
Path altjvmPath = dir.resolve(bit64 ? config.getDcevm64Path() : config.getDcevm32Path()); | |||
if (!Files.exists(altjvmPath)) { | |||
Files.createDirectory(altjvmPath); | |||
} | |||
installClientServer(altjvmPath, bit64); | |||
installClientServer(javaVersion, altjvmPath, bit64); | |||
} | |||
} | |||
@@ -109,24 +109,26 @@ public class Installer { | |||
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 backup = path.resolve(config.getBackupLibraryName()); | |||
// backup any existing library (assume original JVM file) | |||
if (Files.exists(library)) { | |||
Files.move(library, backup); | |||
} | |||
try { | |||
// install actual DCEVM file | |||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) { | |||
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); | |||
} | |||
} catch (NullPointerException | IOException e) { | |||
@@ -138,6 +140,17 @@ public class Installer { | |||
} | |||
} | |||
/** | |||
* 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 { | |||
Path library = path.resolve(config.getLibraryName()); | |||
Path backup = path.resolve(config.getBackupLibraryName()); |
@@ -28,6 +28,7 @@ import javax.swing.*; | |||
import java.awt.*; | |||
import java.awt.image.BufferedImage; | |||
import java.io.IOException; | |||
import java.nio.file.AccessDeniedException; | |||
/** | |||
* @author Kerstin Breiteneder | |||
@@ -73,7 +74,16 @@ public class MainWindow extends JFrame { | |||
ex.printStackTrace(); | |||
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() { |