aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Dubrov <idubrov@guidewire.com>2014-04-28 09:21:47 -0700
committerIvan Dubrov <idubrov@guidewire.com>2014-04-28 09:21:47 -0700
commit23e82f9bc83bdf3f30b44354d3096c02a8473abc (patch)
tree0d6ae93600da728cef31f47ca554178c77336f5d
parentb558a45203fb1cd3778086b24858dde84572c7ac (diff)
downloaddcevm-23e82f9bc83bdf3f30b44354d3096c02a8473abc.tar.gz
dcevm-23e82f9bc83bdf3f30b44354d3096c02a8473abc.zip
Moving installer from the separate branchlight-jdk8u5+36
-rw-r--r--installer/build.gradle68
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/AddDirectoryAction.java72
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/ConfigurationInfo.java255
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/InstallUninstallAction.java102
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/Installation.java128
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/InstallationTableCellRenderer.java76
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/InstallationsTableModel.java70
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/Installer.java138
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/Main.java55
-rw-r--r--installer/src/main/java/com/github/dcevm/installer/MainWindow.java156
-rw-r--r--installer/src/main/resources/com/github/dcevm/installer/splash.pngbin0 -> 21587 bytes
11 files changed, 1120 insertions, 0 deletions
diff --git a/installer/build.gradle b/installer/build.gradle
new file mode 100644
index 00000000..f49ba255
--- /dev/null
+++ b/installer/build.gradle
@@ -0,0 +1,68 @@
+import java.nio.file.FileVisitResult
+import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
+import java.nio.file.SimpleFileVisitor
+import java.nio.file.StandardCopyOption
+import java.nio.file.attribute.BasicFileAttributes
+
+apply plugin: 'java'
+apply plugin: 'idea'
+
+jar {
+ manifest {
+ attributes("Main-Class": "com.github.dcevm.installer.Main")
+ }
+}
+
+project.ext {
+ processedData = Paths.get("$buildDir/data")
+ // Should be populated by build server from the DCEVM upstream job
+ dataSource = Paths.get("$buildDir/rawdata")
+}
+
+sourceSets {
+ main {
+ output.dir(processedData.toFile(), builtBy: 'copyData')
+ }
+}
+
+task copyData << {
+ Files.createDirectories(processedData)
+ Files.walkFileTree(dataSource, new CopyDataVisitor(project));
+}
+
+class CopyDataVisitor extends SimpleFileVisitor<Path> {
+ def project
+
+ CopyDataVisitor(prj) {
+ project = prj
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+ Path rel = project.dataSource.relativize(dir)
+ if (rel.nameCount > 4) {
+ rel = rel.subpath(4, rel.nameCount);
+ if (rel.fileName.toString() == 'fastdebug') {
+ // Do not copy fastdebug versions
+ return FileVisitResult.SKIP_SUBTREE;
+ }
+ def targetPath = project.processedData.resolve(rel);
+ if(!Files.exists(targetPath)){
+ Files.createDirectory(targetPath);
+ }
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Path rel = project.dataSource.relativize(file)
+ if (rel.nameCount > 4) {
+ rel = rel.subpath(4, rel.nameCount);
+ def targetPath = project.processedData.resolve(rel);
+ Files.copy(file, targetPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/AddDirectoryAction.java b/installer/src/main/java/com/github/dcevm/installer/AddDirectoryAction.java
new file mode 100644
index 00000000..94af7852
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/AddDirectoryAction.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.prefs.Preferences;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+class AddDirectoryAction extends AbstractAction {
+
+ private final Component parent;
+ private final InstallationsTableModel installations;
+ private final ConfigurationInfo config;
+
+ public AddDirectoryAction(Component parent, InstallationsTableModel inst, ConfigurationInfo config) {
+ super("Add installation directory...");
+ this.parent = parent;
+ this.installations = inst;
+ this.config = config;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Select a Java installation directory...");
+ fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ fc.setAcceptAllFileFilterUsed(false);
+ Preferences p = Preferences.userNodeForPackage(Installer.class);
+ final String prefID = "defaultDirectory";
+ fc.setCurrentDirectory(new File(p.get(prefID, ".")));
+
+ if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
+
+ Path dir = fc.getSelectedFile().toPath();
+ p.put(prefID, dir.getParent().toString());
+ try {
+ installations.add(new Installation(config, dir));
+ } catch (IOException ex) {
+ MainWindow.showInstallerException(ex, parent);
+ }
+ }
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/ConfigurationInfo.java b/installer/src/main/java/com/github/dcevm/installer/ConfigurationInfo.java
new file mode 100644
index 00000000..cb28045f
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/ConfigurationInfo.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+public enum ConfigurationInfo {
+
+ // Note: 32-bit is not supported on Mac OS X
+ MAC_OS(null, "bsd_amd64_compiler2",
+ "lib/client", "lib/server", "lib/server",
+ "bin/java", "libjvm.dylib"),
+ LINUX("linux_i486_compiler2", "linux_amd64_compiler2",
+ "lib/i386/client", "lib/i386/server", "lib/amd64/server",
+ "bin/java", "libjvm.so") {
+ @Override
+ public String[] paths() {
+ return new String[]{"/usr/java", "/usr/lib/jvm"};
+ }
+ },
+ WINDOWS("windows_i486_compiler2", "windows_amd64_compiler2",
+ "bin/client", "bin/server", "bin/server",
+ "bin/java.exe", "jvm.dll") {
+ @Override
+ public String[] paths() {
+ return new String[]{
+ System.getenv("JAVA_HOME") + "/..",
+ System.getenv("PROGRAMW6432") + "/JAVA",
+ System.getenv("PROGRAMFILES") + "/JAVA",
+ System.getenv("SYSTEMDRIVE") + "/JAVA"};
+ }
+ };
+
+ private final String resourcePath32;
+ private final String resourcePath64;
+
+ private final String clientPath;
+ private final String server32Path;
+ private final String server64Path;
+
+ private final String javaExecutable;
+ private final String libraryName;
+
+ private ConfigurationInfo(String resourcePath32, String resourcePath64,
+ String clientPath, String server32Path, String server64Path,
+ String javaExecutable, String libraryName) {
+ this.resourcePath32 = resourcePath32;
+ this.resourcePath64 = resourcePath64;
+ this.clientPath = clientPath;
+ this.server32Path = server32Path;
+ this.server64Path = server64Path;
+ this.javaExecutable = javaExecutable;
+ this.libraryName = libraryName;
+ }
+
+ public String getResourcePath(boolean bit64) {
+ return bit64 ? resourcePath64 : resourcePath32;
+ }
+
+ public String getResourcePath32() {
+ return resourcePath32;
+ }
+
+ public String getResourcePath64() {
+ return resourcePath64;
+ }
+
+ public String getClientPath() {
+ return clientPath;
+ }
+
+ public String getServerPath(boolean bit64) {
+ return bit64 ? server64Path : server32Path;
+ }
+
+ public String getServer32Path() {
+ return server32Path;
+ }
+
+ public String getServer64Path() {
+ return server64Path;
+ }
+
+ public String getJavaExecutable() {
+ return javaExecutable;
+ }
+
+ public String getLibraryName() {
+ return libraryName;
+ }
+
+ public String getBackupLibraryName() {
+ return libraryName + ".backup";
+ }
+
+ public String[] paths() {
+ return new String[0];
+ }
+
+ public static ConfigurationInfo current() {
+ String os = System.getProperty("os.name").toLowerCase();
+
+ if (os.contains("windows")) {
+ return ConfigurationInfo.WINDOWS;
+ } else if (os.contains("mac") || os.contains("darwin")) {
+ return ConfigurationInfo.MAC_OS;
+ } else if (os.contains("unix") || os.contains("linux")) {
+ return ConfigurationInfo.LINUX;
+ }
+ throw new IllegalStateException("OS is unsupported: " + os);
+ }
+
+ // Utility methods to query installation directories
+ public boolean isJRE(Path directory) {
+ if (Files.isDirectory(directory) && directory.getFileName().toString().startsWith("jre")) {
+ if (!Files.exists(directory.resolve(getJavaExecutable()))) {
+ return false;
+ }
+
+ Path client = directory.resolve(getClientPath());
+ if (Files.exists(client)) {
+ if (!Files.exists(client.resolve(getLibraryName()))) {
+ return Files.exists(client.resolve(getBackupLibraryName()));
+ }
+ }
+
+ Path server = directory.resolve(getServer64Path());
+ if (Files.exists(server)) {
+ if (!Files.exists(server.resolve(getLibraryName()))) {
+ return Files.exists(server.resolve(getBackupLibraryName()));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isJDK(Path directory) {
+ if (Files.isDirectory(directory)) {
+ Path jreDir = directory.resolve(getJREDirectory());
+ return isJRE(jreDir);
+ }
+ return false;
+ }
+
+ public String executeJava(Path jreDir, String... params) throws IOException {
+ Path executable = jreDir.resolve(getJavaExecutable());
+ String[] commands = new String[params.length + 1];
+ System.arraycopy(params, 0, commands, 1, params.length);
+ commands[0] = executable.toAbsolutePath().toString();
+ Process p = Runtime.getRuntime().exec(commands);
+
+ StringBuilder result = new StringBuilder();
+ try (InputStream in = p.getErrorStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ result.append(line);
+ result.append('\n');
+ }
+ }
+ return result.toString();
+ }
+
+ public boolean isDCEInstalled(Path dir) throws IOException {
+ Path jreDir;
+ if (isJDK(dir)) {
+ jreDir = dir.resolve("jre");
+ } else {
+ jreDir = dir;
+ }
+ Path clientPath = jreDir.resolve(getClientPath());
+ Path clientBackup = clientPath.resolve(getBackupLibraryName());
+
+ Path serverPath = jreDir.resolve(getServer32Path());
+ if (!Files.exists(serverPath)) {
+ serverPath = jreDir.resolve(getServer64Path());
+ }
+ Path serverBackup = serverPath.resolve(getBackupLibraryName());
+
+ if (Files.exists(clientPath) && Files.exists(serverPath)) {
+ if (Files.exists(clientBackup) != Files.exists(serverBackup)) {
+ throw new IllegalStateException(jreDir.toAbsolutePath() + " has invalid state.");
+ }
+ }
+ return Files.exists(clientBackup) || Files.exists(serverBackup);
+ }
+
+ public String getVersionString(Path jreDir) throws IOException {
+ return executeJava(jreDir, "-version");
+ }
+
+ public boolean is64Bit(Path jreDir) throws IOException {
+ return getVersionString(jreDir).contains("64-Bit");
+ }
+
+ public String getJavaVersion(Path jreDir) throws IOException {
+ return getVersionHelper(jreDir, ".*java version.*\"(.*)\".*", true);
+ }
+
+ final public String getDCEVersion(Path jreDir) throws IOException {
+ return getVersionHelper(jreDir, ".*Dynamic Code Evolution.*build ([^,]+),.*", false);
+ }
+
+ private String getVersionHelper(Path jreDir, String regex, boolean javaVersion) throws IOException {
+ String version = getVersionString(jreDir);
+ version = version.replaceAll("\n", "");
+ Matcher matcher = Pattern.compile(regex).matcher(version);
+
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("Could not get " + (javaVersion ? "java" : "dce") +
+ "version of " + jreDir.toAbsolutePath() + ".");
+ }
+
+ version = matcher.replaceFirst("$1");
+ return version;
+ }
+
+ public String getJREDirectory() {
+ return "jre";
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/InstallUninstallAction.java b/installer/src/main/java/com/github/dcevm/installer/InstallUninstallAction.java
new file mode 100644
index 00000000..78cb8698
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/InstallUninstallAction.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.util.Observable;
+import java.util.Observer;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+class InstallUninstallAction extends AbstractAction implements ListSelectionListener, Observer {
+
+ private final JTable table;
+ private final boolean install;
+ private Installation installation;
+
+ public InstallUninstallAction(boolean install, JTable t) {
+ super(install ? "Install" : "Uninstall");
+ this.install = install;
+ setEnabled(false);
+ table = t;
+ t.getSelectionModel().addListSelectionListener(this);
+ }
+
+ private Installation getSelectedInstallation() {
+ InstallationsTableModel itm = (InstallationsTableModel) table.getModel();
+ int sel = table.getSelectedRow();
+ if (sel < 0) {
+ return null;
+ } else {
+ return itm.getInstallationAt(sel);
+ }
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ try {
+ if (install) {
+ getSelectedInstallation().installDCE();
+ } else {
+ getSelectedInstallation().uninstallDCE();
+ }
+ } catch (IOException ex) {
+ MainWindow.showInstallerException(ex, table);
+ }
+ }
+
+ private void setCurrentInstallation(Installation i) {
+ if (installation != null) {
+ installation.deleteObserver(this);
+ }
+ installation = i;
+ if (installation != null) {
+ installation.addObserver(this);
+ }
+ update();
+ }
+
+ public void valueChanged(ListSelectionEvent e) {
+ Installation i = getSelectedInstallation();
+ setCurrentInstallation(i);
+ }
+
+ private void update() {
+ if (install) {
+ setEnabled(installation != null && !installation.isDCEInstalled());
+ } else {
+ setEnabled(installation != null && installation.isDCEInstalled());
+ }
+ }
+
+ public void update(Observable o, Object arg) {
+ update();
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/Installation.java b/installer/src/main/java/com/github/dcevm/installer/Installation.java
new file mode 100644
index 00000000..133e5a1c
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/Installation.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Observable;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+public class Installation extends Observable {
+
+ private final Path file;
+ private final ConfigurationInfo config;
+
+ private final boolean isJDK;
+ private boolean installed;
+ private String version;
+ private String dceVersion;
+ private boolean is64Bit;
+
+ public Installation(ConfigurationInfo config, Path path) throws IOException {
+ this.config = config;
+ try {
+ file = path.toRealPath();
+ } catch (IOException ex) {
+ throw new IllegalArgumentException(path.toAbsolutePath() + " is no JRE or JDK-directory.");
+ }
+ isJDK = config.isJDK(file);
+ if (!isJDK && !config.isJRE(file)) {
+ throw new IllegalArgumentException(path.toAbsolutePath() + " is no JRE or JDK-directory.");
+ }
+
+ version = config.getJavaVersion(file);
+ update();
+ }
+
+ final public void update() throws IOException {
+ installed = config.isDCEInstalled(file);
+ if (installed) {
+ dceVersion = config.getDCEVersion(file);
+ }
+ is64Bit = config.is64Bit(file);
+ }
+
+ public Path getPath() {
+ return file;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getDCEVersion() {
+ return dceVersion;
+ }
+
+ public boolean isJDK() {
+ return isJDK;
+ }
+
+ public boolean is64Bit() {
+ return is64Bit;
+ }
+
+ public void installDCE() throws IOException {
+ new Installer(config).install(file, is64Bit);
+ installed = true;
+ update();
+ setChanged();
+ notifyObservers();
+ }
+
+ public void uninstallDCE() throws IOException {
+ new Installer(config).uninstall(file, is64Bit);
+ installed = false;
+ update();
+ setChanged();
+ notifyObservers();
+ }
+
+ public boolean isDCEInstalled() {
+ return installed;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Installation other = (Installation) obj;
+ return !(this.file != other.file && (this.file == null || !this.file.equals(other.file)));
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 97 * hash + (this.file != null ? this.file.hashCode() : 0);
+ return hash;
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/InstallationTableCellRenderer.java b/installer/src/main/java/com/github/dcevm/installer/InstallationTableCellRenderer.java
new file mode 100644
index 00000000..c15fe688
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/InstallationTableCellRenderer.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.swing.*;
+import javax.swing.table.DefaultTableCellRenderer;
+import java.awt.*;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+class InstallationTableCellRenderer extends DefaultTableCellRenderer {
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+
+ if (c instanceof JLabel && value instanceof Installation) {
+ JLabel l = (JLabel) c;
+ Installation inst = (Installation) value;
+
+ switch (column) {
+ case 0:
+ l.setText(inst.getPath().toAbsolutePath().toString());
+ break;
+ case 1:
+ l.setText(inst.getVersion());
+ break;
+ case 2:
+ l.setText(inst.isJDK() ? "JDK" : "JRE");
+ if (inst.is64Bit()) {
+ l.setText(l.getText() + " (64 Bit)");
+ }
+ break;
+ case 3:
+ if (inst.isDCEInstalled()) {
+ l.setText("Yes (" + inst.getDCEVersion() + ")");
+ } else {
+ l.setText("No");
+ }
+ break;
+ }
+ }
+
+ return c;
+ }
+
+ @Override
+ public void setText(String text) {
+ super.setText(text);
+ setToolTipText(text);
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/InstallationsTableModel.java b/installer/src/main/java/com/github/dcevm/installer/InstallationsTableModel.java
new file mode 100644
index 00000000..c5014627
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/InstallationsTableModel.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.swing.table.AbstractTableModel;
+import java.util.ArrayList;
+import java.util.Observable;
+import java.util.Observer;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+class InstallationsTableModel extends AbstractTableModel implements Observer {
+
+ private final ArrayList<Installation> installations;
+
+ public InstallationsTableModel() {
+ installations = new ArrayList<Installation>();
+ }
+
+ public int getRowCount() {
+ return installations.size();
+ }
+
+ public int getColumnCount() {
+ return 4;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ return installations.get(rowIndex);
+ }
+
+ public Installation getInstallationAt(int row) {
+ return installations.get(row);
+ }
+
+ public void add(Installation i) {
+ installations.add(i);
+ i.addObserver(this);
+ fireTableDataChanged();
+ }
+
+ public void update(Observable o, Object arg) {
+ int row = installations.indexOf(o);
+ fireTableRowsUpdated(row, row);
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/Installer.java b/installer/src/main/java/com/github/dcevm/installer/Installer.java
new file mode 100644
index 00000000..93399365
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/Installer.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+public class Installer {
+
+ private ConfigurationInfo config;
+
+ public Installer(ConfigurationInfo config) {
+ this.config = config;
+ }
+
+ public void install(Path dir, boolean bit64) throws IOException {
+ if (config.isJDK(dir)) {
+ dir = dir.resolve(config.getJREDirectory());
+ }
+
+ Path serverPath = dir.resolve(config.getServerPath(bit64));
+ if (Files.exists(serverPath)) {
+ installClientServer(serverPath, bit64);
+ }
+
+ Path clientPath = dir.resolve(config.getClientPath());
+ if (Files.exists(clientPath) && !bit64) {
+ installClientServer(clientPath, false);
+ }
+ }
+
+ public void uninstall(Path dir, boolean bit64) throws IOException {
+ if (config.isJDK(dir)) {
+ dir = dir.resolve(config.getJREDirectory());
+ }
+
+ Path serverPath = dir.resolve(config.getServerPath(bit64));
+ if (Files.exists(serverPath)) {
+ uninstallClientServer(serverPath);
+ }
+
+ Path clientPath = dir.resolve(config.getClientPath());
+ if (Files.exists(clientPath) && !bit64) {
+ uninstallClientServer(clientPath);
+ }
+ }
+
+ public List<Installation> listInstallations() {
+ return scanPaths(config.paths());
+ }
+
+ public ConfigurationInfo getConfiguration() {
+ return config;
+ }
+
+ private void installClientServer(Path path, boolean bit64) throws IOException {
+ String resource = config.getResourcePath(bit64) + "/product/" + config.getLibraryName();
+
+ Path library = path.resolve(config.getLibraryName());
+ Path backup = path.resolve(config.getBackupLibraryName());
+
+
+ Files.move(library, backup);
+ try {
+ try (InputStream in = getClass().getClassLoader().getResourceAsStream(resource)) {
+ Files.copy(in, library);
+ }
+ } catch (IOException e) {
+ Files.move(backup, library, StandardCopyOption.REPLACE_EXISTING);
+ throw e;
+ }
+ }
+
+ private void uninstallClientServer(Path path) throws IOException {
+ Path library = path.resolve(config.getLibraryName());
+ Path backup = path.resolve(config.getBackupLibraryName());
+
+ Files.delete(library);
+ Files.move(backup, library); // FIXME: if fails, JRE is inconsistent!
+ }
+
+ private List<Installation> scanPaths(String... dirPaths) {
+ List<Installation> installations = new ArrayList<>();
+ for (String dirPath : dirPaths) {
+ Path dir = Paths.get(dirPath);
+ if (Files.isDirectory(dir)) {
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
+ scanDirectory(stream, installations);
+ } catch (Exception ex) {
+ // Ignore, try different directory
+ }
+ }
+ }
+ return installations;
+ }
+
+ private void scanDirectory(DirectoryStream<Path> stream, List<Installation> installations) {
+ for (Path path : stream) {
+ try {
+ Installation inst = new Installation(config, path);
+ if (!installations.contains(inst)) {
+ installations.add(inst);
+ }
+ } catch (Exception e) {
+ // FIXME: just ignore the installation for now..
+ }
+ }
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/Main.java b/installer/src/main/java/com/github/dcevm/installer/Main.java
new file mode 100644
index 00000000..4d360f91
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/Main.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.swing.JOptionPane;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Thomas Wuerthinger
+ */
+public class Main {
+
+ public static void main(String[] args) {
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (Exception e) {
+ // Ignore everything
+ }
+
+ MainWindow w;
+ try {
+ w = new MainWindow();
+ w.setLocationRelativeTo(null);
+ w.setVisible(true);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ JOptionPane.showMessageDialog(null, ex.getMessage(), ex.getMessage(), JOptionPane.ERROR_MESSAGE);
+ }
+
+ }
+}
diff --git a/installer/src/main/java/com/github/dcevm/installer/MainWindow.java b/installer/src/main/java/com/github/dcevm/installer/MainWindow.java
new file mode 100644
index 00000000..d253b44d
--- /dev/null
+++ b/installer/src/main/java/com/github/dcevm/installer/MainWindow.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.github.dcevm.installer;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+/**
+ * @author Kerstin Breiteneder
+ * @author Christoph Wimberger
+ * @author Ivan Dubrov
+ */
+public class MainWindow extends JFrame {
+
+ private final InstallationsTableModel installations;
+ private JTable table;
+
+ public MainWindow() {
+ super("Dynamic Code Evolution VM Installer");
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ Installer installer = new Installer(ConfigurationInfo.current());
+ installations = new InstallationsTableModel();
+ for (Installation i : installer.listInstallations()) {
+ installations.add(i);
+ }
+ add(getBanner(), BorderLayout.NORTH);
+ add(getCenterPanel(), BorderLayout.CENTER);
+ add(getBottomPanel(), BorderLayout.SOUTH);
+
+ if (table.getRowCount() > 0) {
+ table.setRowSelectionInterval(0, 0);
+ }
+
+ pack();
+ setMinimumSize(getSize());
+ }
+
+ static void showInstallerException(Exception ex, Component parent) {
+ Throwable e = ex;
+ String error = e.getMessage();
+ e = e.getCause();
+
+ while (e != null) {
+ error += "\n" + e.getMessage();
+ e = e.getCause();
+ }
+
+ 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);
+ }
+
+ private JComponent getBanner() {
+ try {
+ BufferedImage img = ImageIO.read(getClass().getResource("splash.png"));
+ JLabel title = new JLabel(new ImageIcon(img));
+ title.setPreferredSize(new Dimension(img.getWidth() + 10, img.getHeight()));
+ title.setOpaque(true);
+ title.setBackground(new Color(238, 238, 255));
+ return title;
+ } catch (IOException ex) {
+ }
+ return new JLabel();
+ }
+
+ private JComponent getCenterPanel() {
+ JPanel center = new JPanel(new BorderLayout());
+ center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ center.setBackground(Color.WHITE);
+ JTextArea license = new javax.swing.JTextArea();
+ license.setLineWrap(true);
+ license.setWrapStyleWord(true);
+ license.setEditable(false);
+ license.setFont(license.getFont().deriveFont(11.0f));
+ StringBuilder licenseText = new StringBuilder();
+ licenseText.append("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 only, as published by the Free Software Foundation.\n\nThis code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details (a copy is included in the LICENSE file that accompanied this code).\n\nYou should have received a copy of the GNU General Public License version 2 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.");
+ licenseText.append("\n\n\nASM LICENSE TEXT:\nCopyright (c) 2000-2005 INRIA, France Telecom\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
+ license.setText(licenseText.toString());
+ JScrollPane licenses = new JScrollPane(license, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ licenses.setPreferredSize(new Dimension(150, 150));
+ center.add(licenses, BorderLayout.NORTH);
+ center.add(getChooserPanel(), BorderLayout.CENTER);
+ return center;
+ }
+
+ private JComponent getChooserPanel() {
+ JPanel p = new JPanel(new BorderLayout());
+ p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
+ p.setOpaque(false);
+
+ JLabel l = new JLabel("Please choose installation directory:");
+ l.setVerticalAlignment(JLabel.NORTH);
+ l.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
+ p.add(l, BorderLayout.WEST);
+
+ table = new JTable(installations);
+ table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ table.setColumnSelectionAllowed(false);
+ table.setDefaultRenderer(Object.class, new InstallationTableCellRenderer());
+ table.getColumnModel().getColumn(0).setHeaderValue("Directory");
+ table.getColumnModel().getColumn(0).setPreferredWidth(300);
+ table.getColumnModel().getColumn(1).setHeaderValue("Java Version");
+ table.getColumnModel().getColumn(2).setHeaderValue("Type");
+ table.getColumnModel().getColumn(3).setHeaderValue("DCE");
+ JScrollPane lists = new JScrollPane(table);
+ lists.setPreferredSize(new Dimension(200, 200));
+ p.add(lists, BorderLayout.CENTER);
+
+ return p;
+ }
+
+ private JComponent getBottomPanel() {
+
+ JPanel left = new JPanel(new FlowLayout());
+ left.add(new JButton(new AddDirectoryAction(this, installations, ConfigurationInfo.current())));
+
+ JPanel right = new JPanel(new FlowLayout());
+ //right.add(new JButton(new TestAction(table, installer)));
+ right.add(new JButton(new InstallUninstallAction(false, table)));
+ right.add(new JButton(new InstallUninstallAction(true, table)));
+
+ JPanel bottom = new JPanel(new BorderLayout());
+ bottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+ bottom.add(left, BorderLayout.WEST);
+ bottom.add(right, BorderLayout.EAST);
+
+ return bottom;
+ }
+}
+
diff --git a/installer/src/main/resources/com/github/dcevm/installer/splash.png b/installer/src/main/resources/com/github/dcevm/installer/splash.png
new file mode 100644
index 00000000..fd49c0a4
--- /dev/null
+++ b/installer/src/main/resources/com/github/dcevm/installer/splash.png
Binary files differ