Unverified 提交 3f80639b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1108 from katzyn/SwitchSource

Get rid of SwitchSource
...@@ -95,15 +95,6 @@ To run the build tool in shell mode, use the command line option <code>-</code>: ...@@ -95,15 +95,6 @@ To run the build tool in shell mode, use the command line option <code>-</code>:
./build.sh - ./build.sh -
</pre> </pre>
<h3>Switching the Source Code</h3>
<p>
The source code uses Java 7 features.
To switch the source code to the installed version of Java, run:
</p>
<pre>
build switchSource
</pre>
<h2 id="build_targets">Build Targets</h2> <h2 id="build_targets">Build Targets</h2>
<p> <p>
The build system can generate smaller jar files as well. The following targets are currently supported: The build system can generate smaller jar files as well. The following targets are currently supported:
......
...@@ -21,6 +21,10 @@ Change Log ...@@ -21,6 +21,10 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #1106: Get rid of SwitchSource
</li>
<li>PR #1105: Assorted minor changes
</li>
<li>Issue #1102: CREATE SYNONYM rejects valid definition <li>Issue #1102: CREATE SYNONYM rejects valid definition
</li> </li>
<li>Issue #1048: 1.4.197 regression. org.h2.jdbc.JdbcSQLException: Timeout trying to lock table "SYS" <li>Issue #1048: 1.4.197 regression. org.h2.jdbc.JdbcSQLException: Timeout trying to lock table "SYS"
...@@ -35,6 +39,8 @@ Change Log ...@@ -35,6 +39,8 @@ Change Log
</li> </li>
<li>Issue #230: Renaming a column does not update foreign key constraint <li>Issue #230: Renaming a column does not update foreign key constraint
</li> </li>
<li>Issue #1091 Get rid if the New class
</li>
<li>PR #1087: improve performance of planning large queries <li>PR #1087: improve performance of planning large queries
</li> </li>
<li>Issue #394: Recover tool places COLLATION and BINARY_COLLATION after temporary tables <li>Issue #394: Recover tool places COLLATION and BINARY_COLLATION after temporary tables
......
...@@ -93,26 +93,19 @@ public class SysProperties { ...@@ -93,26 +93,19 @@ public class SysProperties {
Utils.getProperty("h2.bindAddress", null); Utils.getProperty("h2.bindAddress", null);
/** /**
* System property <code>h2.check</code> (default: true).<br /> * System property <code>h2.check</code>
* (default: true for JDK/JRE, false for Android).<br />
* Assertions in the database engine. * Assertions in the database engine.
*/ */
//## CHECK ##
public static final boolean CHECK = public static final boolean CHECK =
Utils.getProperty("h2.check", true); Utils.getProperty("h2.check", !"0.9".equals(Utils.getProperty("java.specification.version", null)));
/*/
public static final boolean CHECK = false;
//*/
/** /**
* System property <code>h2.check2</code> (default: false).<br /> * System property <code>h2.check2</code> (default: false).<br />
* Additional assertions in the database engine. * Additional assertions in the database engine.
*/ */
//## CHECK ##
public static final boolean CHECK2 = public static final boolean CHECK2 =
Utils.getProperty("h2.check2", false); Utils.getProperty("h2.check2", false);
/*/
public static final boolean CHECK2 = false;
//*/
/** /**
* System property <code>h2.clientTraceDirectory</code> (default: * System property <code>h2.clientTraceDirectory</code> (default:
......
...@@ -5,35 +5,8 @@ ...@@ -5,35 +5,8 @@
*/ */
package org.h2.tools; package org.h2.tools;
//## AWT ##
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.PopupMenu;
import java.awt.SystemColor;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.h2.server.ShutdownHandler; import org.h2.server.ShutdownHandler;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
...@@ -45,24 +18,13 @@ import org.h2.util.Utils; ...@@ -45,24 +18,13 @@ import org.h2.util.Utils;
* *
* @author Thomas Mueller, Ridvan Agar * @author Thomas Mueller, Ridvan Agar
*/ */
public class Console extends Tool implements public class Console extends Tool implements ShutdownHandler {
//## AWT ##
ActionListener, MouseListener, WindowListener, Server web;
//*/
ShutdownHandler { private Server tcp, pg;
//## AWT ## boolean isWindows;
private Frame frame;
private boolean trayIconUsed;
private Font font;
private Button startBrowser;
private TextField urlText;
private Object tray;
private Object trayIcon;
//*/
private Server web, tcp, pg;
private boolean isWindows;
private long lastOpenNs;
/** /**
* When running without options, -tcp, -web, -browser and -pg are started. * When running without options, -tcp, -web, -browser and -pg are started.
...@@ -99,7 +61,13 @@ ShutdownHandler { ...@@ -99,7 +61,13 @@ ShutdownHandler {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String... args) throws SQLException { public static void main(String... args) throws SQLException {
new Console().runTool(args); Console console;
try {
console = (Console) Utils.newInstance("org.h2.tools.GUIConsole");
} catch (Exception | NoClassDefFoundError e) {
console = new Console();
}
console.runTool(args);
} }
/** /**
...@@ -241,18 +209,9 @@ ShutdownHandler { ...@@ -241,18 +209,9 @@ ShutdownHandler {
} }
} }
//## AWT ## if (toolStart && webRunning){
if (toolStart && webRunning && !GraphicsEnvironment.isHeadless()) { show();
loadFont();
try {
if (!createTrayIcon()) {
showWindow();
}
} catch (Exception e) {
e.printStackTrace();
}
} }
//*/
// start browser in any case (even if the server is already running) // start browser in any case (even if the server is already running)
// because some people don't look at the output, // because some people don't look at the output,
...@@ -296,6 +255,9 @@ ShutdownHandler { ...@@ -296,6 +255,9 @@ ShutdownHandler {
} }
} }
void show() {
}
private void printProblem(Exception e, Server server) { private void printProblem(Exception e, Server server) {
if (server == null) { if (server == null) {
e.printStackTrace(); e.printStackTrace();
...@@ -305,19 +267,6 @@ ShutdownHandler { ...@@ -305,19 +267,6 @@ ShutdownHandler {
} }
} }
private static Image loadImage(String name) {
try {
byte[] imageData = Utils.getResource(name);
if (imageData == null) {
return null;
}
return Toolkit.getDefaultToolkit().createImage(imageData);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/** /**
* INTERNAL. * INTERNAL.
* Stop all servers that were started using the console. * Stop all servers that were started using the console.
...@@ -336,213 +285,9 @@ ShutdownHandler { ...@@ -336,213 +285,9 @@ ShutdownHandler {
pg.stop(); pg.stop();
pg = null; pg = null;
} }
//## AWT ##
if (frame != null) {
frame.dispose();
frame = null;
}
if (trayIconUsed) {
try {
// tray.remove(trayIcon);
Utils.callMethod(tray, "remove", trayIcon);
} catch (Exception e) {
// ignore
} finally {
trayIcon = null;
tray = null;
trayIconUsed = false;
}
System.gc();
// Mac OS X: Console tool process did not stop on exit
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if (os.contains("mac")) {
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("AWT-")) {
t.interrupt();
}
}
}
Thread.currentThread().interrupt();
// throw new ThreadDeath();
}
//*/
}
//## AWT ##
private void loadFont() {
if (isWindows) {
font = new Font("Dialog", Font.PLAIN, 11);
} else {
font = new Font("Dialog", Font.PLAIN, 12);
}
}
private boolean createTrayIcon() {
try {
// SystemTray.isSupported();
boolean supported = (Boolean) Utils.callStaticMethod(
"java.awt.SystemTray.isSupported");
if (!supported) {
return false;
}
PopupMenu menuConsole = new PopupMenu();
MenuItem itemConsole = new MenuItem("H2 Console");
itemConsole.setActionCommand("console");
itemConsole.addActionListener(this);
itemConsole.setFont(font);
menuConsole.add(itemConsole);
MenuItem itemStatus = new MenuItem("Status");
itemStatus.setActionCommand("status");
itemStatus.addActionListener(this);
itemStatus.setFont(font);
menuConsole.add(itemStatus);
MenuItem itemExit = new MenuItem("Exit");
itemExit.setFont(font);
itemExit.setActionCommand("exit");
itemExit.addActionListener(this);
menuConsole.add(itemExit);
// tray = SystemTray.getSystemTray();
tray = Utils.callStaticMethod("java.awt.SystemTray.getSystemTray");
// Dimension d = tray.getTrayIconSize();
Dimension d = (Dimension) Utils.callMethod(tray, "getTrayIconSize");
String iconFile;
if (d.width >= 24 && d.height >= 24) {
iconFile = "/org/h2/res/h2-24.png";
} else if (d.width >= 22 && d.height >= 22) {
// for Mac OS X 10.8.1 with retina display:
// the reported resolution is 22 x 22, but the image
// is scaled and the real resolution is 44 x 44
iconFile = "/org/h2/res/h2-64-t.png";
// iconFile = "/org/h2/res/h2-22-t.png";
} else {
iconFile = "/org/h2/res/h2.png";
}
Image icon = loadImage(iconFile);
// trayIcon = new TrayIcon(image, "H2 Database Engine",
// menuConsole);
trayIcon = Utils.newInstance("java.awt.TrayIcon",
icon, "H2 Database Engine", menuConsole);
// trayIcon.addMouseListener(this);
Utils.callMethod(trayIcon, "addMouseListener", this);
// tray.add(trayIcon);
Utils.callMethod(tray, "add", trayIcon);
this.trayIconUsed = true;
return true;
} catch (Exception e) {
return false;
}
}
private void showWindow() {
if (frame != null) {
return;
}
frame = new Frame("H2 Console");
frame.addWindowListener(this);
Image image = loadImage("/org/h2/res/h2.png");
if (image != null) {
frame.setIconImage(image);
}
frame.setResizable(false);
frame.setBackground(SystemColor.control);
GridBagLayout layout = new GridBagLayout();
frame.setLayout(layout);
// the main panel keeps everything together
Panel mainPanel = new Panel(layout);
GridBagConstraints constraintsPanel = new GridBagConstraints();
constraintsPanel.gridx = 0;
constraintsPanel.weightx = 1.0D;
constraintsPanel.weighty = 1.0D;
constraintsPanel.fill = GridBagConstraints.BOTH;
constraintsPanel.insets = new Insets(0, 10, 0, 10);
constraintsPanel.gridy = 0;
GridBagConstraints constraintsButton = new GridBagConstraints();
constraintsButton.gridx = 0;
constraintsButton.gridwidth = 2;
constraintsButton.insets = new Insets(10, 0, 0, 0);
constraintsButton.gridy = 1;
constraintsButton.anchor = GridBagConstraints.EAST;
GridBagConstraints constraintsTextField = new GridBagConstraints();
constraintsTextField.fill = GridBagConstraints.HORIZONTAL;
constraintsTextField.gridy = 0;
constraintsTextField.weightx = 1.0;
constraintsTextField.insets = new Insets(0, 5, 0, 0);
constraintsTextField.gridx = 1;
GridBagConstraints constraintsLabel = new GridBagConstraints();
constraintsLabel.gridx = 0;
constraintsLabel.gridy = 0;
Label label = new Label("H2 Console URL:", Label.LEFT);
label.setFont(font);
mainPanel.add(label, constraintsLabel);
urlText = new TextField();
urlText.setEditable(false);
urlText.setFont(font);
urlText.setText(web.getURL());
if (isWindows) {
urlText.setFocusable(false);
}
mainPanel.add(urlText, constraintsTextField);
startBrowser = new Button("Start Browser");
startBrowser.setFocusable(false);
startBrowser.setActionCommand("console");
startBrowser.addActionListener(this);
startBrowser.setFont(font);
mainPanel.add(startBrowser, constraintsButton);
frame.add(mainPanel, constraintsPanel);
int width = 300, height = 120;
frame.setSize(width, height);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width - width) / 2,
(screenSize.height - height) / 2);
try {
frame.setVisible(true);
} catch (Throwable t) {
// ignore
// some systems don't support this method, for example IKVM
// however it still works
}
try {
// ensure this window is in front of the browser
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);
} catch (Throwable t) {
// ignore
}
} }
private void startBrowser() { void openBrowser(String url) {
if (web != null) {
String url = web.getURL();
if (urlText != null) {
urlText.setText(url);
}
long now = System.nanoTime();
if (lastOpenNs == 0 || lastOpenNs + TimeUnit.MILLISECONDS.toNanos(100) < now) {
lastOpenNs = now;
openBrowser(url);
}
}
}
//*/
private void openBrowser(String url) {
try { try {
Server.openBrowser(url); Server.openBrowser(url);
} catch (Exception e) { } catch (Exception e) {
...@@ -550,151 +295,4 @@ ShutdownHandler { ...@@ -550,151 +295,4 @@ ShutdownHandler {
} }
} }
/**
* INTERNAL
*/
//## AWT ##
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("exit".equals(command)) {
shutdown();
} else if ("console".equals(command)) {
startBrowser();
} else if ("status".equals(command)) {
showWindow();
} else if (startBrowser == e.getSource()) {
// for some reason, IKVM ignores setActionCommand
startBrowser();
}
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
startBrowser();
}
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void mouseEntered(MouseEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void mouseExited(MouseEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void mousePressed(MouseEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void mouseReleased(MouseEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowClosing(WindowEvent e) {
if (trayIconUsed) {
frame.dispose();
frame = null;
} else {
shutdown();
}
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowActivated(WindowEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowClosed(WindowEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowDeactivated(WindowEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowDeiconified(WindowEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowIconified(WindowEvent e) {
// nothing to do
}
//*/
/**
* INTERNAL
*/
//## AWT ##
@Override
public void windowOpened(WindowEvent e) {
// nothing to do
}
//*/
} }
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.tools;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.PopupMenu;
import java.awt.SystemColor;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.h2.util.Utils;
/**
* Console for environments with AWT support.
*/
public class GUIConsole extends Console implements ActionListener, MouseListener, WindowListener {
private long lastOpenNs;
private Frame frame;
private boolean trayIconUsed;
private Font font;
private Button startBrowser;
private TextField urlText;
private Object tray;
private Object trayIcon;
@Override
void show() {
if (!GraphicsEnvironment.isHeadless()) {
loadFont();
try {
if (!createTrayIcon()) {
showWindow();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static Image loadImage(String name) {
try {
byte[] imageData = Utils.getResource(name);
if (imageData == null) {
return null;
}
return Toolkit.getDefaultToolkit().createImage(imageData);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public void shutdown() {
super.shutdown();
if (frame != null) {
frame.dispose();
frame = null;
}
if (trayIconUsed) {
try {
// tray.remove(trayIcon);
Utils.callMethod(tray, "remove", trayIcon);
} catch (Exception e) {
// ignore
} finally {
trayIcon = null;
tray = null;
trayIconUsed = false;
}
System.gc();
// Mac OS X: Console tool process did not stop on exit
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if (os.contains("mac")) {
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("AWT-")) {
t.interrupt();
}
}
}
Thread.currentThread().interrupt();
// throw new ThreadDeath();
}
}
private void loadFont() {
if (isWindows) {
font = new Font("Dialog", Font.PLAIN, 11);
} else {
font = new Font("Dialog", Font.PLAIN, 12);
}
}
private boolean createTrayIcon() {
try {
// SystemTray.isSupported();
boolean supported = (Boolean) Utils.callStaticMethod(
"java.awt.SystemTray.isSupported");
if (!supported) {
return false;
}
PopupMenu menuConsole = new PopupMenu();
MenuItem itemConsole = new MenuItem("H2 Console");
itemConsole.setActionCommand("console");
itemConsole.addActionListener(this);
itemConsole.setFont(font);
menuConsole.add(itemConsole);
MenuItem itemStatus = new MenuItem("Status");
itemStatus.setActionCommand("status");
itemStatus.addActionListener(this);
itemStatus.setFont(font);
menuConsole.add(itemStatus);
MenuItem itemExit = new MenuItem("Exit");
itemExit.setFont(font);
itemExit.setActionCommand("exit");
itemExit.addActionListener(this);
menuConsole.add(itemExit);
// tray = SystemTray.getSystemTray();
tray = Utils.callStaticMethod("java.awt.SystemTray.getSystemTray");
// Dimension d = tray.getTrayIconSize();
Dimension d = (Dimension) Utils.callMethod(tray, "getTrayIconSize");
String iconFile;
if (d.width >= 24 && d.height >= 24) {
iconFile = "/org/h2/res/h2-24.png";
} else if (d.width >= 22 && d.height >= 22) {
// for Mac OS X 10.8.1 with retina display:
// the reported resolution is 22 x 22, but the image
// is scaled and the real resolution is 44 x 44
iconFile = "/org/h2/res/h2-64-t.png";
// iconFile = "/org/h2/res/h2-22-t.png";
} else {
iconFile = "/org/h2/res/h2.png";
}
Image icon = loadImage(iconFile);
// trayIcon = new TrayIcon(image, "H2 Database Engine",
// menuConsole);
trayIcon = Utils.newInstance("java.awt.TrayIcon",
icon, "H2 Database Engine", menuConsole);
// trayIcon.addMouseListener(this);
Utils.callMethod(trayIcon, "addMouseListener", this);
// tray.add(trayIcon);
Utils.callMethod(tray, "add", trayIcon);
this.trayIconUsed = true;
return true;
} catch (Exception e) {
return false;
}
}
private void showWindow() {
if (frame != null) {
return;
}
frame = new Frame("H2 Console");
frame.addWindowListener(this);
Image image = loadImage("/org/h2/res/h2.png");
if (image != null) {
frame.setIconImage(image);
}
frame.setResizable(false);
frame.setBackground(SystemColor.control);
GridBagLayout layout = new GridBagLayout();
frame.setLayout(layout);
// the main panel keeps everything together
Panel mainPanel = new Panel(layout);
GridBagConstraints constraintsPanel = new GridBagConstraints();
constraintsPanel.gridx = 0;
constraintsPanel.weightx = 1.0D;
constraintsPanel.weighty = 1.0D;
constraintsPanel.fill = GridBagConstraints.BOTH;
constraintsPanel.insets = new Insets(0, 10, 0, 10);
constraintsPanel.gridy = 0;
GridBagConstraints constraintsButton = new GridBagConstraints();
constraintsButton.gridx = 0;
constraintsButton.gridwidth = 2;
constraintsButton.insets = new Insets(10, 0, 0, 0);
constraintsButton.gridy = 1;
constraintsButton.anchor = GridBagConstraints.EAST;
GridBagConstraints constraintsTextField = new GridBagConstraints();
constraintsTextField.fill = GridBagConstraints.HORIZONTAL;
constraintsTextField.gridy = 0;
constraintsTextField.weightx = 1.0;
constraintsTextField.insets = new Insets(0, 5, 0, 0);
constraintsTextField.gridx = 1;
GridBagConstraints constraintsLabel = new GridBagConstraints();
constraintsLabel.gridx = 0;
constraintsLabel.gridy = 0;
Label label = new Label("H2 Console URL:", Label.LEFT);
label.setFont(font);
mainPanel.add(label, constraintsLabel);
urlText = new TextField();
urlText.setEditable(false);
urlText.setFont(font);
urlText.setText(web.getURL());
if (isWindows) {
urlText.setFocusable(false);
}
mainPanel.add(urlText, constraintsTextField);
startBrowser = new Button("Start Browser");
startBrowser.setFocusable(false);
startBrowser.setActionCommand("console");
startBrowser.addActionListener(this);
startBrowser.setFont(font);
mainPanel.add(startBrowser, constraintsButton);
frame.add(mainPanel, constraintsPanel);
int width = 300, height = 120;
frame.setSize(width, height);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width - width) / 2,
(screenSize.height - height) / 2);
try {
frame.setVisible(true);
} catch (Throwable t) {
// ignore
// some systems don't support this method, for example IKVM
// however it still works
}
try {
// ensure this window is in front of the browser
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);
} catch (Throwable t) {
// ignore
}
}
private void startBrowser() {
if (web != null) {
String url = web.getURL();
if (urlText != null) {
urlText.setText(url);
}
long now = System.nanoTime();
if (lastOpenNs == 0 || lastOpenNs + TimeUnit.MILLISECONDS.toNanos(100) < now) {
lastOpenNs = now;
openBrowser(url);
}
}
}
/**
* INTERNAL
*/
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("exit".equals(command)) {
shutdown();
} else if ("console".equals(command)) {
startBrowser();
} else if ("status".equals(command)) {
showWindow();
} else if (startBrowser == e.getSource()) {
// for some reason, IKVM ignores setActionCommand
startBrowser();
}
}
/**
* INTERNAL
*/
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
startBrowser();
}
}
/**
* INTERNAL
*/
@Override
public void mouseEntered(MouseEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void mouseExited(MouseEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void mousePressed(MouseEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void mouseReleased(MouseEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowClosing(WindowEvent e) {
if (trayIconUsed) {
frame.dispose();
frame = null;
} else {
shutdown();
}
}
/**
* INTERNAL
*/
@Override
public void windowActivated(WindowEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowClosed(WindowEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowDeactivated(WindowEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowDeiconified(WindowEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowIconified(WindowEvent e) {
// nothing to do
}
/**
* INTERNAL
*/
@Override
public void windowOpened(WindowEvent e) {
// nothing to do
}
}
...@@ -50,6 +50,7 @@ import org.h2.tools.ChangeFileEncryption; ...@@ -50,6 +50,7 @@ import org.h2.tools.ChangeFileEncryption;
import org.h2.tools.Console; import org.h2.tools.Console;
import org.h2.tools.ConvertTraceFile; import org.h2.tools.ConvertTraceFile;
import org.h2.tools.DeleteDbFiles; import org.h2.tools.DeleteDbFiles;
import org.h2.tools.GUIConsole;
import org.h2.tools.Recover; import org.h2.tools.Recover;
import org.h2.tools.Restore; import org.h2.tools.Restore;
import org.h2.tools.RunScript; import org.h2.tools.RunScript;
...@@ -127,7 +128,7 @@ public class TestTools extends TestBase { ...@@ -127,7 +128,7 @@ public class TestTools extends TestBase {
private void testConsole() throws Exception { private void testConsole() throws Exception {
String old = System.getProperty(SysProperties.H2_BROWSER); String old = System.getProperty(SysProperties.H2_BROWSER);
Console c = new Console(); GUIConsole c = new GUIConsole();
c.setOut(new PrintStream(new ByteArrayOutputStream())); c.setOut(new PrintStream(new ByteArrayOutputStream()));
try { try {
......
...@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit; ...@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.h2.build.code.SwitchSource;
import org.h2.build.doc.XMLParser; import org.h2.build.doc.XMLParser;
/** /**
...@@ -231,34 +230,11 @@ public class Build extends BuildBase { ...@@ -231,34 +230,11 @@ public class Build extends BuildBase {
m.invoke(d, new File("coverage/report/index.html")); m.invoke(d, new File("coverage/report/index.html"));
} }
/**
* Switch the source code to the current JDK.
*/
@Description(summary = "Switch the source code to match the current JDK.")
public void switchSource() {
switchSource(true);
}
private static String getTargetJavaVersion() { private static String getTargetJavaVersion() {
return System.getProperty("version"); return System.getProperty("version");
} }
private static void switchSource(boolean enableCheck) {
try {
String version = getTargetJavaVersion();
String check = enableCheck ? "+CHECK" : "-CHECK";
if (version == null) {
SwitchSource.main("-dir", "src", "-auto", check);
} else {
SwitchSource.main("-dir", "src", "-version", version, check);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void compileMVStore(boolean debugInfo) { private void compileMVStore(boolean debugInfo) {
switchSource(debugInfo);
clean(); clean();
mkdir("temp"); mkdir("temp");
String classpath = "temp"; String classpath = "temp";
...@@ -282,7 +258,6 @@ public class Build extends BuildBase { ...@@ -282,7 +258,6 @@ public class Build extends BuildBase {
private void compile(boolean debugInfo, boolean clientOnly, private void compile(boolean debugInfo, boolean clientOnly,
boolean basicResourcesOnly) { boolean basicResourcesOnly) {
switchSource(debugInfo);
clean(); clean();
mkdir("temp"); mkdir("temp");
download(); download();
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.build.code;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
/**
* Switched source code to a specific Java version, automatically to the current
* version, or enable / disable other blocks of source code in Java files.
*/
public class SwitchSource {
private final ArrayList<String> enable = new ArrayList<>();
private final ArrayList<String> disable = new ArrayList<>();
/**
* This method is called when executing this application from the command
* line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws IOException {
new SwitchSource().run(args);
}
private void run(String... args) throws IOException {
String dir = null;
String version = null;
for (int i = 0; i < args.length; i++) {
String a = args[i];
if ("-dir".equals(a)) {
dir = args[++i];
} else if ("-auto".equals(a)) {
enable.add("AWT");
version = System.getProperty("java.specification.version");
} else if ("-version".equals(a)) {
version = args[++i];
} else if (a.startsWith("-")) {
String x = a.substring(1);
disable.add(x);
enable.remove(x);
} else if (a.startsWith("+")) {
String x = a.substring(1);
enable.add(x);
disable.remove(x);
} else {
showUsage();
return;
}
}
if (version == null) {
// ok
} else if ("1.5".equals(version)) {
disable.add("Java 1.6");
disable.add("Java 1.7");
} else if ("1.6".equals(version)) {
enable.add("Java 1.6");
disable.add("Java 1.7");
} else if (version.compareTo("1.7") >= 0) {
enable.add("Java 1.6");
enable.add("Java 1.7");
} else {
throw new IllegalArgumentException("version: " + version);
}
if (dir == null) {
showUsage();
} else {
process(new File(dir));
}
}
private void showUsage() {
System.out.println("Switched source code to a specific Java version.");
System.out.println("java "+getClass().getName() + "\n" +
" -dir <dir> The target directory\n" +
" [-version] Use the specified Java version (1.4 or newer)\n" +
" [-auto] Auto-detect Java version (1.4 or newer)\n" +
" [+MODE] Enable code labeled MODE\n" +
" [-MODE] Disable code labeled MODE");
}
private void process(File f) throws IOException {
String name = f.getName();
if (name.startsWith(".svn")) {
return;
} else if (name.endsWith(".java")) {
processFile(f);
} else if (f.isDirectory()) {
for (File file : f.listFiles()) {
process(file);
}
}
}
private void processFile(File f) throws IOException {
byte[] buffer;
try (RandomAccessFile read = new RandomAccessFile(f, "r")) {
long len = read.length();
if (len >= Integer.MAX_VALUE) {
throw new IOException("Files bigger than Integer.MAX_VALUE are not supported");
}
buffer = new byte[(int) len];
read.readFully(buffer);
}
boolean found = false;
// check for ## without creating a string
for (int i = 0; i < buffer.length - 1; i++) {
if (buffer[i] == '#' && buffer[i + 1] == '#') {
found = true;
break;
}
}
if (!found) {
return;
}
String source = new String(buffer);
String target = source;
for (String x : enable) {
target = replaceAll(target, "/*## " + x + " ##", "//## " + x + " ##");
}
for (String x : disable) {
target = replaceAll(target, "//## " + x + " ##", "/*## " + x + " ##");
}
if (!source.equals(target)) {
String name = f.getPath();
File fileNew = new File(name + ".new");
FileWriter write = new FileWriter(fileNew);
write.write(target);
write.close();
File fileBack = new File(name + ".bak");
fileBack.delete();
f.renameTo(fileBack);
File fileCopy = new File(name);
if (!fileNew.renameTo(fileCopy)) {
throw new IOException("Could not rename "
+ fileNew.getAbsolutePath() + " to " + name);
}
if (!fileBack.delete()) {
throw new IOException("Could not delete " + fileBack.getAbsolutePath());
}
// System.out.println(name);
}
}
private static String replaceAll(String s, String before, String after) {
int index = 0;
while (true) {
int next = s.indexOf(before, index);
if (next < 0) {
return s;
}
s = s.substring(0, next) + after + s.substring(next + before.length());
index = next + after.length();
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论