* @author Kerstin Breiteneder
* @author Christoph Wimberger
* @author Ivan Dubrov
+ * @author Jiri Bubnik
*/
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",
+ "lib/client", "lib/server", "lib/dcevm", "lib/server", "lib/dcevm",
"bin/java", "libjvm.dylib"),
LINUX("linux_i486_compiler2", "linux_amd64_compiler2",
- "lib/i386/client", "lib/i386/server", "lib/amd64/server",
+ "lib/i386/client", "lib/i386/server", "lib/i386/dcevm", "lib/amd64/server", "lib/amd64/dcevm",
"bin/java", "libjvm.so") {
@Override
public String[] paths() {
}
},
WINDOWS("windows_i486_compiler2", "windows_amd64_compiler2",
- "bin/client", "bin/server", "bin/server",
+ "bin/client", "bin/server", "bin/dcevm", "bin/server", "bin/dcevm",
"bin/java.exe", "jvm.dll") {
@Override
public String[] paths() {
System.getenv("JAVA_HOME") + "/..",
System.getenv("PROGRAMW6432") + "/JAVA",
System.getenv("PROGRAMFILES") + "/JAVA",
+ System.getenv("PROGRAMFILES(X86)") + "/JAVA",
System.getenv("SYSTEMDRIVE") + "/JAVA"};
}
};
private final String clientPath;
private final String server32Path;
+ private final String dcevm32Path;
private final String server64Path;
+ private final String dcevm64Path;
private final String javaExecutable;
private final String libraryName;
private ConfigurationInfo(String resourcePath32, String resourcePath64,
- String clientPath, String server32Path, String server64Path,
+ String clientPath,
+ String server32Path, String dcevm32Path,
+ String server64Path, String dcevm64Path,
String javaExecutable, String libraryName) {
this.resourcePath32 = resourcePath32;
this.resourcePath64 = resourcePath64;
this.clientPath = clientPath;
this.server32Path = server32Path;
+ this.dcevm32Path = dcevm32Path;
this.server64Path = server64Path;
+ this.dcevm64Path = dcevm64Path;
this.javaExecutable = javaExecutable;
this.libraryName = libraryName;
}
return server64Path;
}
+ public String getDcevm32Path() {
+ return dcevm32Path;
+ }
+
+ public String getDcevm64Path() {
+ return dcevm64Path;
+ }
+
public String getJavaExecutable() {
return javaExecutable;
}
return result.toString();
}
- public boolean isDCEInstalled(Path dir) throws IOException {
+ public boolean isDCEInstalled(Path dir, boolean altjvm) 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 (altjvm) {
+ Path altvm32Path = jreDir.resolve(getDcevm32Path());
+ Path altvm64Path = jreDir.resolve(getDcevm64Path());
+
+ return Files.exists(altvm32Path) || Files.exists(altvm64Path);
+ } else {
+ 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.");
+ 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);
}
- return Files.exists(clientBackup) || Files.exists(serverBackup);
}
- public String getVersionString(Path jreDir) throws IOException {
- return executeJava(jreDir, "-version");
+ public String getVersionString(Path jreDir, boolean altjvm) throws IOException {
+ try {
+ if (altjvm) {
+ return executeJava(jreDir, "-XXaltjvm=dcevm", "-version");
+ } else {
+ return executeJava(jreDir, "-version");
+ }
+ } catch (Throwable e) {
+ return e.getMessage();
+ }
}
public boolean is64Bit(Path jreDir) throws IOException {
- return getVersionString(jreDir).contains("64-Bit");
+ return getVersionString(jreDir, false).contains("64-Bit");
}
public String getJavaVersion(Path jreDir) throws IOException {
- return getVersionHelper(jreDir, ".*java version.*\"(.*)\".*", true);
+ return getVersionHelper(jreDir, ".*java version.*\"(.*)\".*", true, false);
}
- final public String getDCEVersion(Path jreDir) throws IOException {
- return getVersionHelper(jreDir, ".*Dynamic Code Evolution.*build ([^,]+),.*", false);
+ final public String getDCEVersion(Path jreDir, boolean altjvm) throws IOException {
+ return getVersionHelper(jreDir, ".*Dynamic Code Evolution.*build ([^,]+),.*", false, altjvm);
}
- private String getVersionHelper(Path jreDir, String regex, boolean javaVersion) throws IOException {
- String version = getVersionString(jreDir);
+ private String getVersionHelper(Path jreDir, String regex, boolean javaVersion, boolean altjvm) throws IOException {
+ String version = getVersionString(jreDir, altjvm);
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() + ".");
+ return "Could not get " + (javaVersion ? "java" : "dce") +
+ "version of " + jreDir.toAbsolutePath() + ".";
}
version = matcher.replaceFirst("$1");
* @author Kerstin Breiteneder
* @author Christoph Wimberger
* @author Ivan Dubrov
+ * @author Jiri Bubnik
*/
class InstallUninstallAction extends AbstractAction implements ListSelectionListener, Observer {
+ /**
+ * Buttons to add/remove DCEVM.
+ */
+ public static enum Type {
+ UNINSTALL("Uninstall"),
+ INSTALL("Replace by DCEVM"),
+ INSTALL_ALTJVM("Install DCEVM as altjvm");
+
+ String label;
+
+ Type(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+ }
+
private final JTable table;
- private final boolean install;
+ private final Type type;
private Installation installation;
- public InstallUninstallAction(boolean install, JTable t) {
- super(install ? "Install" : "Uninstall");
- this.install = install;
+ public InstallUninstallAction(Type type, JTable t) {
+ super(type.getLabel());
+ this.type = type;
setEnabled(false);
table = t;
t.getSelectionModel().addListSelectionListener(this);
public void actionPerformed(ActionEvent e) {
try {
- if (install) {
- getSelectedInstallation().installDCE();
+ if (type.equals(Type.INSTALL)) {
+ getSelectedInstallation().installDCE(false);
+ }
+ else if (type.equals(Type.INSTALL_ALTJVM)) {
+ getSelectedInstallation().installDCE(true);
} else {
getSelectedInstallation().uninstallDCE();
}
}
private void update() {
- if (install) {
+ if (type.equals(Type.INSTALL)) {
setEnabled(installation != null && !installation.isDCEInstalled());
+ } else if (type.equals(Type.INSTALL_ALTJVM)) {
+ setEnabled(installation != null && !installation.isDCEInstalledAltjvm());
} else {
- setEnabled(installation != null && installation.isDCEInstalled());
+ setEnabled(installation != null && (installation.isDCEInstalled() || installation.isDCEInstalledAltjvm()));
}
}
* @author Kerstin Breiteneder
* @author Christoph Wimberger
* @author Ivan Dubrov
+ * @author Jiri Bubnik
*/
public class Installation extends Observable {
private final ConfigurationInfo config;
private final boolean isJDK;
+
+ // DCEVM is installed over default JVM (either server or client)
private boolean installed;
+
+ // DCEVM is installed as an alternative DCEVM (in separate dcevm directory)
+ private boolean installedAltjvm;
+
+ // version of Java
private String version;
- private String dceVersion;
+ // version of DCEVM in main location (client/server)
+ private String versionDcevm;
+ // version of DCEVM in alternative location (dcevm altjvm)
+ private String versionDcevmAltjvm;
+
private boolean is64Bit;
public Installation(ConfigurationInfo config, Path path) throws IOException {
} 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.");
}
final public void update() throws IOException {
- installed = config.isDCEInstalled(file);
- if (installed) {
- dceVersion = config.getDCEVersion(file);
- }
+ installed = config.isDCEInstalled(file, false);
+ versionDcevm = installed ? config.getDCEVersion(file, false) : "";
+
+ installedAltjvm = config.isDCEInstalled(file, true);
+ versionDcevmAltjvm = installedAltjvm ? config.getDCEVersion(file, true) : "";
+
is64Bit = config.is64Bit(file);
}
return version;
}
- public String getDCEVersion() {
- return dceVersion;
+ public String getVersionDcevm() {
+ return versionDcevm;
+ }
+
+ public String getVersionDcevmAltjvm() {
+ return versionDcevmAltjvm;
}
public boolean isJDK() {
return is64Bit;
}
- public void installDCE() throws IOException {
- new Installer(config).install(file, is64Bit);
- installed = true;
+ public void installDCE(boolean altjvm) throws IOException {
+ new Installer(config).install(file, is64Bit, altjvm);
update();
setChanged();
notifyObservers();
public void uninstallDCE() throws IOException {
new Installer(config).uninstall(file, is64Bit);
installed = false;
+ installedAltjvm = false;
update();
setChanged();
notifyObservers();
return installed;
}
+ public boolean isDCEInstalledAltjvm() {
+ return installedAltjvm;
+ }
+
@Override
public boolean equals(Object obj) {
if (obj == null) {
break;
case 3:
if (inst.isDCEInstalled()) {
- l.setText("Yes (" + inst.getDCEVersion() + ")");
+ l.setText("Yes (" + inst.getVersionDcevm() + ")");
+ } else {
+ l.setText("No");
+ }
+ break;
+ case 4:
+ if (inst.isDCEInstalledAltjvm()) {
+ l.setText("Yes (" + inst.getVersionDcevmAltjvm() + ")");
} else {
l.setText("No");
}
}
public int getColumnCount() {
- return 4;
+ return 5;
}
public Object getValueAt(int rowIndex, int columnIndex) {
* @author Kerstin Breiteneder
* @author Christoph Wimberger
* @author Ivan Dubrov
+ * @author Jiri Bubnik
*/
public class Installer {
this.config = config;
}
- public void install(Path dir, boolean bit64) throws IOException {
+ public void install(Path dir, boolean bit64, boolean altjvm) 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);
- }
+ if (!altjvm) {
+ 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);
+ Path clientPath = dir.resolve(config.getClientPath());
+ if (Files.exists(clientPath) && !bit64) {
+ installClientServer(clientPath, false);
+ }
+ } else {
+ Path altjvmPath = dir.resolve(bit64 ? config.getDcevm64Path() : config.getDcevm32Path());
+ if (!Files.exists(altjvmPath)) {
+ Files.createDirectory(altjvmPath);
+ }
+ installClientServer(altjvmPath, bit64);
}
}
+ /**
+ * Try to uninstall DCEVM from all locations (skip if not exists).
+ */
public void uninstall(Path dir, boolean bit64) throws IOException {
if (config.isJDK(dir)) {
dir = dir.resolve(config.getJREDirectory());
if (Files.exists(clientPath) && !bit64) {
uninstallClientServer(clientPath);
}
+
+ Path dcevm32Path = dir.resolve(config.getDcevm32Path());
+ if (Files.exists(dcevm32Path)) {
+ Files.deleteIfExists(dcevm32Path.resolve(config.getLibraryName()));
+ Files.deleteIfExists(dcevm32Path.resolve(config.getBackupLibraryName()));
+ Files.delete(dcevm32Path);
+ }
+
+ Path dcevm64Path = dir.resolve(config.getDcevm64Path());
+ if (Files.exists(dcevm64Path)) {
+ Files.deleteIfExists(dcevm64Path.resolve(config.getLibraryName()));
+ Files.deleteIfExists(dcevm64Path.resolve(config.getBackupLibraryName()));
+ Files.delete(dcevm64Path);
+ }
+
}
public List<Installation> listInstallations() {
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);
+ }
- 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);
+ }
+
Files.copy(in, library);
}
- } catch (IOException e) {
- Files.move(backup, library, StandardCopyOption.REPLACE_EXISTING);
+ } catch (NullPointerException | IOException e) {
+ // try to restore original file
+ if (Files.exists(backup)) {
+ Files.move(backup, library, StandardCopyOption.REPLACE_EXISTING);
+ }
throw e;
}
}
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!
+ if (Files.exists(backup)) {
+ Files.delete(library);
+ Files.move(backup, library);
+ }
}
private List<Installation> scanPaths(String... dirPaths) {
scanDirectory(stream, installations);
} catch (Exception ex) {
// Ignore, try different directory
+ ex.printStackTrace();
}
}
}
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);
+ if (Files.isDirectory(path) && (config.isJDK(path) || config.isJRE(path))) {
+ try {
+ Installation inst = new Installation(config, path);
+ if (!installations.contains(inst)) {
+ installations.add(inst);
+ }
+ } catch (Exception ex) {
+ // FIXME: just ignore the installation for now..
+ ex.printStackTrace();
}
- } catch (Exception e) {
- // FIXME: just ignore the installation for now..
}
}
}
+
}
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("Enhance current Java (JRE/JDK) installations with DCEVM (http://github.com/dcevm/dcevm).");
+ licenseText.append("\n\nYou can either replace current Java VM or install DCEVM as alternative JVM (run with -XXaltjvm=dcevm command-line option).");
+ licenseText.append("\n\n\nThis 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);
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);
+ p.add(l, BorderLayout.NORTH);
table = new JTable(installations);
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getColumnModel().getColumn(0).setHeaderValue("Directory");
table.getColumnModel().getColumn(0).setPreferredWidth(300);
table.getColumnModel().getColumn(1).setHeaderValue("Java Version");
+ table.getColumnModel().getColumn(3).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setHeaderValue("Type");
- table.getColumnModel().getColumn(3).setHeaderValue("DCE");
+ table.getColumnModel().getColumn(3).setPreferredWidth(100);
+ table.getColumnModel().getColumn(3).setHeaderValue("Replaced by DCEVM?");
+ table.getColumnModel().getColumn(3).setPreferredWidth(200);
+ table.getColumnModel().getColumn(4).setHeaderValue("Installed altjvm?");
+ table.getColumnModel().getColumn(4).setPreferredWidth(200);
JScrollPane lists = new JScrollPane(table);
- lists.setPreferredSize(new Dimension(200, 200));
+ lists.setPreferredSize(new Dimension(900, 200));
p.add(lists, BorderLayout.CENTER);
return p;
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)));
+ right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.UNINSTALL, table)));
+ right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.INSTALL, table)));
+ right.add(new JButton(new InstallUninstallAction(InstallUninstallAction.Type.INSTALL_ALTJVM, table)));
JPanel bottom = new JPanel(new BorderLayout());
bottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));