You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2007/06/22 01:18:41 UTC
svn commit: r549644 [5/8] - in /geronimo/sandbox/geronimo-netbeans-plugin:
./ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/geronimo/
src/main/java/org/apache/geronimo/netbeans/ src/main/java/org/ap...
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,276 @@
+package org.apache.geronimo.netbeans.ide;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import javax.enterprise.deploy.shared.ActionType;
+import javax.enterprise.deploy.shared.CommandType;
+import javax.enterprise.deploy.shared.StateType;
+import org.apache.geronimo.netbeans.GeronimoDeploymentManager;
+import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties;
+import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginUtils;
+import org.apache.geronimo.netbeans.util.GeronimoProperties;
+import org.netbeans.api.java.platform.JavaPlatform;
+import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
+import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport;
+import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
+import org.openide.ErrorManager;
+import org.openide.execution.NbProcessDescriptor;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
+import org.openide.windows.InputOutput;
+
+class GeronimoStartRunnable implements Runnable {
+
+ private final static String STARTUP_SH = "/bin/geronimo.sh";
+ private final static String STARTUP_BAT = "/bin/geronimo.bat";
+
+ private GeronimoDeploymentManager dm;
+ private String instanceName;
+ private GeronimoStartServer startServer;
+ private ProfilerServerSettings profilerSettings;
+
+ GeronimoStartRunnable(ProfilerServerSettings profilerSettings, GeronimoDeploymentManager dm,
+ GeronimoStartServer startServer) {
+ this.dm = dm;
+ this.instanceName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ this.startServer = startServer;
+ this.profilerSettings = profilerSettings;
+ }
+
+ public void run() {
+
+ InstanceProperties ip = dm.getInstanceProperties();
+
+ boolean free = checkPorts(ip);
+ if (!free) {
+ return;
+ }
+
+ Process serverProcess = createProcess(ip);
+ if (serverProcess == null) {
+ return;
+ }
+
+ LogWriter logWriter = createLogWriter();
+
+ waitForServerToStart(logWriter, serverProcess);
+ }
+
+ private String[] createEnvironment(final InstanceProperties ip) {
+
+ GeronimoProperties properties = dm.getProperties();
+
+ // set the JAVA_OPTS value
+ String javaOpts = properties.getJavaOpts();
+ StringBuilder javaOptsBuilder = new StringBuilder(javaOpts);
+ // use the IDE proxy settings if the 'use proxy' checkbox is selected
+ // do not override a property if it was set manually by the user
+ if (properties.getProxyEnabled()) {
+ final String[] PROXY_PROPS = { "http.proxyHost", // NOI18N
+ "http.proxyPort", // NOI18N
+ "http.nonProxyHosts", // NOI18N
+ "https.proxyHost", // NOI18N
+ "https.proxyPort", // NOI18N
+ };
+ for (String prop : PROXY_PROPS) {
+ if (javaOpts.indexOf(prop) == -1) {
+ String value = System.getProperty(prop);
+ if (value != null) {
+ if ("http.nonProxyHosts".equals(prop)) { // NOI18N
+ try {
+ // remove newline characters, as the value may
+ // contain them, see issue #81174
+ BufferedReader br = new BufferedReader(new StringReader(value));
+ String line = null;
+ StringBuilder noNL = new StringBuilder();
+ while ((line = br.readLine()) != null) {
+ noNL.append(line);
+ }
+ value = noNL.toString();
+
+ // enclose the host list in double quotes
+ // because it may contain spaces
+ value = "\"" + value + "\""; // NOI18N
+ } catch (IOException ioe) {
+ ErrorManager.getDefault()
+ .annotate(
+ ioe,
+ NbBundle.getMessage(GeronimoStartRunnable.class,
+ "ERR_NonProxyHostParsingError"));
+ ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ioe);
+ value = null;
+ }
+ }
+ if (value != null) {
+ javaOptsBuilder.append(" -D").append(prop).append("=").append(value); // NOI18N
+ }
+ }
+ }
+ }
+ }
+
+ if (startServer.getMode() == GeronimoStartServer.MODE.DEBUG
+ && javaOptsBuilder.toString().indexOf("-Xdebug") == -1) { // NOI18N
+ // if in debug mode and the debug options not specified manually
+ javaOptsBuilder.append(
+ " -classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address="). // NOI18N
+ append(dm.getDebuggingPort()).append(",server=y,suspend=n"); // NOI18N
+ } else if (startServer.getMode() == GeronimoStartServer.MODE.PROFILE) {
+ // get JVM arguments used for starting the server
+ String[] profJvmArgs = profilerSettings.getJvmArgs();
+ for (int i = 0; i < profJvmArgs.length; i++) {
+ javaOptsBuilder.append(" ").append(profJvmArgs[i]); // NOI18N
+ }
+ }
+
+ // create new environment for server
+ javaOpts = javaOptsBuilder.toString();
+
+ // get Java platform that will run the server
+ JavaPlatform platform = (startServer.getMode() != GeronimoStartServer.MODE.PROFILE ? properties
+ .getJavaPlatform() : profilerSettings.getJavaPlatform());
+ String javaHome = getJavaHome(platform);
+
+ String envp[] = new String[] { "JAVA=" + javaHome + "/bin/java", // NOI18N
+ "JAVA_HOME=" + javaHome, // NOI18N
+ "JAVA_OPTS=" + javaOpts, // NOI18N
+ };
+ return envp;
+ }
+
+ private boolean checkPorts(final InstanceProperties ip) {
+
+ try {
+ String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+
+ String strHTTPConnectorPort = ip.getProperty(GeronimoPluginProperties.PROPERTY_PORT);
+ int HTTPConnectorPort = new Integer(strHTTPConnectorPort).intValue();
+ if (!GeronimoPluginUtils.isPortFree(HTTPConnectorPort)) {
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage(
+ "MSG_START_SERVER_FAILED_HTTP_PORT_IN_USE", strHTTPConnectorPort));
+ return false;
+ }
+
+ String serverDir = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR);
+
+ String strRMINamingServicePort = GeronimoPluginUtils.getRMINamingServicePort(serverDir);
+ int RMINamingServicePort = new Integer(strRMINamingServicePort).intValue();
+ if (!GeronimoPluginUtils.isPortFree(RMINamingServicePort)) {
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage(
+ "MSG_START_SERVER_FAILED_RMI_PORT_IN_USE", strRMINamingServicePort));// NOI18N
+ return false;
+ }
+
+ } catch (NumberFormatException nfe) {
+ // continue and let server to report the problem
+ }
+
+ return true;
+ }
+
+ private NbProcessDescriptor createProcessDescriptor(InstanceProperties ip) {
+
+ final String serverLocation = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR);
+ final String serverRunFileName = serverLocation + (Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH);
+ if (!new File(serverRunFileName).exists()) {
+ final String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage("MSG_START_SERVER_FAILED_FNF"));// NOI18N
+ return null;
+ }
+ String args = "run";
+ return new NbProcessDescriptor(serverRunFileName, args);
+ }
+
+ private static String getJavaHome(JavaPlatform platform) {
+ FileObject fo = (FileObject) platform.getInstallFolders().iterator().next();
+ return FileUtil.toFile(fo).getAbsolutePath();
+ }
+
+ private String createProgressMessage(final String resName) {
+ return createProgressMessage(resName, null);
+ }
+
+ private String createProgressMessage(final String resName, final String param) {
+ return NbBundle.getMessage(GeronimoStartRunnable.class, resName, instanceName, param);
+ }
+
+ private Process createProcess(InstanceProperties ip) {
+
+ // TODO do we really have to stop the log writer?
+ if (startServer.getMode() == GeronimoStartServer.MODE.PROFILE) {
+
+ // stop logger if running
+ LogWriter logWriter = LogWriter.getInstance(instanceName);
+ if (logWriter != null && logWriter.isRunning())
+ logWriter.stop();
+ }
+
+ NbProcessDescriptor pd = createProcessDescriptor(ip);
+ if (pd == null) {
+ return null;
+ }
+
+ String envp[] = createEnvironment(ip);
+
+ try {
+ return pd.exec(null, envp, true, null);
+ } catch (java.io.IOException ioe) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
+
+ final String serverLocation = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR);
+ final String serverRunFileName = serverLocation + (Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH);
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage("MSG_START_SERVER_FAILED_PD",
+ serverRunFileName));
+
+ return null;
+ }
+ }
+
+ private InputOutput openConsole() {
+ InputOutput io = UISupport.getServerIO(dm.getUrl());
+ if (io == null) {
+ return null; // finish, it looks like this server instance has
+ // been unregistered
+ }
+
+ // clear the old output
+ try {
+ io.getOut().reset();
+ } catch (IOException ioe) {
+ // no op
+ }
+ io.select();
+
+ return io;
+ }
+
+ private void fireStartProgressEvent(StateType stateType, String msg) {
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.START,
+ stateType, msg));
+ }
+
+ private LogWriter createLogWriter() {
+ InputOutput io = openConsole();
+ return LogWriter.createInstance(io, instanceName);
+ }
+
+ private void waitForServerToStart(LogWriter logWriter, Process serverProcess) {
+
+ fireStartProgressEvent(StateType.RUNNING, createProgressMessage("MSG_START_SERVER_IN_PROGRESS"));
+
+ GeronimoStartServer.ACTION_STATUS status = logWriter.start(serverProcess, startServer);
+ if (status == GeronimoStartServer.ACTION_STATUS.SUCCESS) {
+ fireStartProgressEvent(StateType.COMPLETED, createProgressMessage("MSG_SERVER_STARTED"));
+ } else if (status == GeronimoStartServer.ACTION_STATUS.FAILURE) {
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage("MSG_START_SERVER_FAILED"));
+ } else if (status == GeronimoStartServer.ACTION_STATUS.UNKNOWN) {
+ fireStartProgressEvent(StateType.FAILED, createProgressMessage("MSG_StartServerTimeout"));
+ }
+
+ }
+
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartRunnable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,302 @@
+package org.apache.geronimo.netbeans.ide;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
+import java.io.IOException;
+import java.io.File;
+import javax.enterprise.deploy.shared.ActionType;
+import javax.enterprise.deploy.shared.CommandType;
+import javax.enterprise.deploy.shared.StateType;
+import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
+import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
+import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
+import org.openide.ErrorManager;
+import org.openide.util.RequestProcessor;
+import java.util.Vector;
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.status.ProgressEvent;
+import javax.enterprise.deploy.spi.status.ProgressListener;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
+import javax.enterprise.deploy.spi.status.ClientConfiguration;
+import javax.enterprise.deploy.spi.status.DeploymentStatus;
+import org.apache.geronimo.netbeans.GeronimoDeploymentManager;
+import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties;
+import org.openide.util.NbBundle;
+
+public class GeronimoStartServer extends StartServer implements ProgressObject {
+
+ static enum MODE {
+ RUN, DEBUG, PROFILE
+ };
+
+ static enum ACTION_STATUS {
+ SUCCESS, FAILURE, UNKNOWN
+ };
+
+ private MODE mode;
+
+ private GeronimoDeploymentManager dm;
+ private static Map isDebugModeUri = Collections.synchronizedMap((Map) new HashMap(2, 1));
+
+ public GeronimoStartServer(DeploymentManager dm) {
+ if (!(dm instanceof GeronimoDeploymentManager)) {
+ throw new IllegalArgumentException("");
+ }
+ this.dm = (GeronimoDeploymentManager) dm;
+ }
+
+ private void addDebugModeUri() {
+ isDebugModeUri.put(dm.getUrl(), new Object());
+ }
+
+ private void removeDebugModeUri() {
+ isDebugModeUri.remove(dm.getUrl());
+ }
+
+ private boolean existsDebugModeUri() {
+ return isDebugModeUri.containsKey(dm.getUrl());
+ }
+
+ public ProgressObject startDebugging(Target target) {
+ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.START,
+ StateType.RUNNING, NbBundle.getMessage(GeronimoStartServer.class, "MSG_START_SERVER_IN_PROGRESS",
+ serverName))); // NOI18N
+ mode = MODE.DEBUG;
+ RequestProcessor.getDefault().post(new GeronimoStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY);
+ addDebugModeUri();
+ return this;
+ }
+
+ public boolean isDebuggable(Target target) {
+ if (!existsDebugModeUri()) {
+ return false;
+ }
+ if (!isRunning()) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean supportsStartDebugging(Target target) {
+ return true;
+ }
+
+ public boolean supportsStartProfiling(Target target) {
+ return true;
+ }
+
+ public boolean isAlsoTargetServer(Target target) {
+ return true;
+ }
+
+ public ServerDebugInfo getDebugInfo(Target target) {
+ return new ServerDebugInfo("localhost", dm.getDebuggingPort());
+ }
+
+ /**
+ * Starts the server in profiling mode.
+ */
+ public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) {
+ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.START,
+ StateType.RUNNING, NbBundle.getMessage(GeronimoStartServer.class,
+ "MSG_START_PROFILED_SERVER_IN_PROGRESS", serverName))); // NOI18N
+ mode = MODE.PROFILE;
+ RequestProcessor.getDefault().post(new GeronimoStartRunnable(settings, dm, this), 0, Thread.NORM_PRIORITY);
+ removeDebugModeUri();
+ return this;
+ }
+
+ /**
+ * Indicates whether this server supports start/stop.
+ *
+ * @return true/false - supports/does not support
+ */
+ public boolean supportsStartDeploymentManager() {
+ return true;
+ }
+
+ /**
+ * Stops the server.
+ */
+ public ProgressObject stopDeploymentManager() {
+ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.STOP,
+ StateType.RUNNING, NbBundle.getMessage(GeronimoStartServer.class, "MSG_STOP_SERVER_IN_PROGRESS",
+ serverName)));// NOI18N
+ RequestProcessor.getDefault().post(new GeronimoStopRunnable(dm, this), 0, Thread.NORM_PRIORITY);
+ removeDebugModeUri();
+ return this;
+ }
+
+ /**
+ * Starts the server
+ */
+ public ProgressObject startDeploymentManager() {
+ String serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+ fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.START,
+ StateType.RUNNING, NbBundle.getMessage(GeronimoStartServer.class, "MSG_START_SERVER_IN_PROGRESS",
+ serverName)));// NOI18N
+ mode = MODE.RUN;
+ RequestProcessor.getDefault().post(new GeronimoStartRunnable(null, dm, this), 0, Thread.NORM_PRIORITY);
+ removeDebugModeUri();
+ return this;
+ }
+
+ public boolean needsStartForTargetList() {
+ return false;
+ }
+
+ public boolean needsStartForConfigure() {
+ return false;
+ }
+
+ public boolean needsStartForAdminConfig() {
+ return false;
+ }
+
+ private boolean isReallyRunning() {
+ final InstanceProperties ip = dm.getInstanceProperties();
+ if (ip == null) {
+ return false;
+ }
+ // this should prevent the thread from getting stuck if the server is in
+ // suspended state
+ SafeTrueTest test = new SafeTrueTest() {
+ public void run() {
+ ClassLoader oldLoader = null;
+ String checkingConfigName = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER);
+ String checkingServerDir = null;
+
+ try {
+ String serverDir = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR);
+
+ if (serverDir == null) {
+ result = false;
+ return;
+ }
+
+ checkingServerDir = new File(serverDir).getCanonicalPath();
+ } catch (IllegalStateException ex) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
+ result = false;
+ } catch (IOException ex) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
+ result = false;
+ }
+
+ result = false;
+ }
+ };
+
+ return safeTrueTest(test, 10000);
+ }
+
+ /** Safe true/false test useful. */
+ private abstract static class SafeTrueTest implements Runnable {
+ protected boolean result = false;
+
+ public abstract void run();
+
+ public final boolean result() {
+ return result;
+ }
+ };
+
+ /** Return the result of the test or false if the given time-out ran out. */
+ private boolean safeTrueTest(SafeTrueTest test, int timeout) {
+ try {
+ new RequestProcessor().post(test).waitFinished(timeout);
+ } catch (InterruptedException ignored) {
+ }
+ return test.result();
+ }
+
+ public boolean isRunning() {
+
+ InstanceProperties ip = dm.getInstanceProperties();
+ if (ip == null) {
+ return false;
+ }
+
+ if (!isReallyRunning()) {
+ dm.setRunningLastCheck(ip, Boolean.FALSE);
+ return false;
+ }
+
+ dm.setRunningLastCheck(ip, Boolean.TRUE);
+ return true;
+ }
+
+ // ---------- Implementation of ProgressObject interface
+ private Vector listeners = new Vector();
+ private DeploymentStatus deploymentStatus;
+
+ public void addProgressListener(ProgressListener pl) {
+ listeners.add(pl);
+ }
+
+ public void removeProgressListener(ProgressListener pl) {
+ listeners.remove(pl);
+ }
+
+ public void stop() throws OperationUnsupportedException {
+ throw new OperationUnsupportedException("");
+ }
+
+ public boolean isStopSupported() {
+ return false;
+ }
+
+ public void cancel() throws OperationUnsupportedException {
+ throw new OperationUnsupportedException("");
+ }
+
+ public boolean isCancelSupported() {
+ return false;
+ }
+
+ public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) {
+ return null;
+ }
+
+ public TargetModuleID[] getResultTargetModuleIDs() {
+ return new TargetModuleID[] {};
+ }
+
+ public DeploymentStatus getDeploymentStatus() {
+ return deploymentStatus;
+ }
+
+ /** Report event to any registered listeners. */
+ public void fireHandleProgressEvent(TargetModuleID targetModuleID, DeploymentStatus deploymentStatus) {
+ ProgressEvent evt = new ProgressEvent(this, targetModuleID, deploymentStatus);
+
+ this.deploymentStatus = deploymentStatus;
+
+ java.util.Vector targets = null;
+ synchronized (this) {
+ if (listeners != null) {
+ targets = (java.util.Vector) listeners.clone();
+ }
+ }
+
+ if (targets != null) {
+ for (int i = 0; i < targets.size(); i++) {
+ ProgressListener target = (ProgressListener) targets.elementAt(i);
+ target.handleProgressEvent(evt);
+ }
+ }
+ }
+
+ MODE getMode() {
+ return mode;
+ }
+
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStartServer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,166 @@
+package org.apache.geronimo.netbeans.ide;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import javax.enterprise.deploy.shared.ActionType;
+import javax.enterprise.deploy.shared.CommandType;
+import javax.enterprise.deploy.shared.StateType;
+import org.apache.geronimo.netbeans.GeronimoDeploymentManager;
+import org.apache.geronimo.netbeans.ide.ui.GeronimoPluginProperties;
+import org.apache.geronimo.netbeans.util.GeronimoProperties;
+import org.netbeans.api.java.platform.JavaPlatform;
+import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
+import org.openide.ErrorManager;
+import org.openide.execution.NbProcessDescriptor;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
+
+class GeronimoStopRunnable implements Runnable {
+
+ public static final boolean VERBOSE = System.getProperty("netbeans.serverplugins.geronimo.logging") != null;
+
+ private final static String SHUTDOWN_SH = "/bin/geronimo.sh";
+ private final static String SHUTDOWN_BAT = "/bin/geronimo.bat";
+
+ private static int TIMEOUT = 300000;
+
+ private GeronimoDeploymentManager dm;
+ private GeronimoStartServer startServer;
+
+ GeronimoStopRunnable(GeronimoDeploymentManager dm, GeronimoStartServer startServer) {
+ this.dm = dm;
+ this.startServer = startServer;
+ }
+
+ private String[] createEnvironment() {
+
+ GeronimoProperties properties = dm.getProperties();
+
+ JavaPlatform platform = properties.getJavaPlatform();
+ FileObject fo = (FileObject) platform.getInstallFolders().iterator().next();
+ String javaHome = FileUtil.toFile(fo).getAbsolutePath();
+ List<String> envp = new ArrayList<String>(3);
+ envp.add("JAVA=" + javaHome + "/bin/java"); // NOI18N
+ envp.add("JAVA_HOME=" + javaHome); // NOI18N
+ if (Utilities.isWindows()) {
+ // the shutdown script should not wait for a key press
+ envp.add("NOPAUSE=true"); // NOI18N
+ }
+ return (String[]) envp.toArray(new String[envp.size()]);
+ }
+
+ public void run() {
+
+ InstanceProperties ip = dm.getInstanceProperties();
+
+ String configName = ip.getProperty("server");
+ String serverName = ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
+
+ String serverLocation = ip.getProperty(GeronimoPluginProperties.PROPERTY_SERVER_DIR);
+ String serverStopFileName = serverLocation + (Utilities.isWindows() ? SHUTDOWN_BAT : SHUTDOWN_SH);
+
+ File serverStopFile = new File(serverStopFileName);
+ if (!serverStopFile.exists()) {
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE,
+ CommandType.STOP, StateType.FAILED, NbBundle.getMessage(GeronimoStopRunnable.class,
+ "MSG_STOP_SERVER_FAILED_FNF", serverName)));// NOI18N
+ return;
+ }
+
+ GeronimoProperties properties = dm.getProperties();
+ StringBuilder credentialsParams = new StringBuilder(32);
+ credentialsParams.append(" --user ").append(properties.getUsername()).append(" --password ").append(
+ properties.getPassword());
+ NbProcessDescriptor pd = (startServer.getMode() == GeronimoStartServer.MODE.PROFILE ? new NbProcessDescriptor(
+ serverStopFileName, "--halt=0 " + credentialsParams) : // NOI18N
+ new NbProcessDescriptor(serverStopFileName, "stop " + credentialsParams)); // NOI18N
+
+ Process stoppingProcess = null;
+ try {
+ String envp[] = createEnvironment();
+ stoppingProcess = pd.exec(null, envp, true, null);
+ } catch (java.io.IOException ioe) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
+
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE,
+ CommandType.STOP, StateType.FAILED, NbBundle.getMessage(GeronimoStopRunnable.class,
+ "MSG_STOP_SERVER_FAILED_PD", serverName, serverStopFileName)));// NOI18N
+
+ return;
+ }
+
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.STOP,
+ StateType.RUNNING, NbBundle.getMessage(GeronimoStopRunnable.class, "MSG_STOP_SERVER_IN_PROGRESS",
+ serverName)));
+
+ if (VERBOSE) {
+ System.out.println("GeronimoStopRunnable: Entering the loop"); // NOI18N
+ }
+
+ int elapsed = 0;
+ while (elapsed < TIMEOUT) {
+ // check whether the stopping process did not fail
+ try {
+ int processExitValue = stoppingProcess.exitValue();
+ if (VERBOSE) {
+ System.out.println("GeronimoStopRunnable: the stopping process has terminated with the exit value "
+ + processExitValue); // NOI18N
+ }
+ if (processExitValue != 0) {
+ // stopping process failed
+ String msg = NbBundle.getMessage(GeronimoStopRunnable.class, "MSG_STOP_SERVER_FAILED", serverName);
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE,
+ CommandType.STOP, StateType.FAILED, msg));
+ return;
+ }
+ } catch (IllegalThreadStateException e) {
+ // process is still running
+ }
+ if (startServer.isRunning()) {
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE,
+ CommandType.STOP, StateType.RUNNING, NbBundle.getMessage(GeronimoStopRunnable.class,
+ "MSG_STOP_SERVER_IN_PROGRESS", serverName)));// NOI18N
+ if (VERBOSE) {
+ System.out.println("GeronimoStopRunnable: STOPPING message fired"); // NOI18N
+ }
+ try {
+ elapsed += 500;
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ } else {
+ if (VERBOSE) {
+ System.out
+ .println("GeronimoStopRunnable: Geronimo has been stopped, going to stop the Log Writer thread");
+ }
+ final LogWriter logWriter = LogWriter.getInstance(ip.getProperty(InstanceProperties.DISPLAY_NAME_ATTR));
+ if (logWriter != null && logWriter.isRunning()) {
+ logWriter.waitForServerProcessFinished(10000);
+ logWriter.stop();
+ }
+
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE,
+ CommandType.STOP, StateType.COMPLETED, NbBundle.getMessage(GeronimoStopRunnable.class,
+ "MSG_SERVER_STOPPED", serverName)));// NOI18N
+ if (VERBOSE) {
+ System.out.println("GeronimoStopRunnable: STOPPED message fired"); // NOI18N
+ }
+
+ return;
+ }
+ }
+
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.STOP,
+ StateType.FAILED, NbBundle.getMessage(GeronimoStopRunnable.class, "MSG_StopServerTimeout")));
+ if (stoppingProcess != null) {
+ stoppingProcess.destroy();
+ }
+
+ if (VERBOSE) {
+ System.out.println("GeronimoStopRunnable: TIMEOUT EXPIRED"); // NOI18N
+ }
+ }
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/GeronimoStopRunnable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,511 @@
+package org.apache.geronimo.netbeans.ide;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import javax.enterprise.deploy.shared.ActionType;
+import javax.enterprise.deploy.shared.CommandType;
+import javax.enterprise.deploy.shared.StateType;
+import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport;
+import org.openide.ErrorManager;
+import org.openide.util.NbBundle;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.windows.InputOutput;
+import org.openide.windows.OutputWriter;
+
+public final class LogWriter {
+
+ public static final boolean VERBOSE = System.getProperty("netbeans.serverplugins.geronimo.logging") != null;
+
+ private final static int DELAY = 500;
+ private static final int START_TIMEOUT = 900000;
+
+ /**
+ * Lock used to avoid a reader switching while the reader is used
+ */
+ private final Object READER_LOCK = new Object();
+
+ /**
+ * Lock used for synchronizing a server startup thread and a logger thread checking for the server to start
+ */
+ private final Object START_LOCK = new Object();
+
+ // enumeration of the source types the reader can read from
+ private static enum LOGGER_TYPE {
+ PROCESS, FILE
+ };
+
+ // indicates the type of source the reader is reading from
+ private LOGGER_TYPE type;
+
+ private static final String THREAD_NAME = "Geronimo Log Writer"; // NOI18N
+ private static final String STOPPER_THREAD_NAME = "Geronimo Log Writer Stopper"; // NOI18N
+
+ private GeronimoStartServer.ACTION_STATUS actionStatus = GeronimoStartServer.ACTION_STATUS.UNKNOWN;
+
+ GeronimoStartServer startServer;
+
+ // output pane's writer
+ private final OutputWriter out;
+ // server output reader
+ volatile private BufferedReader reader;
+ // server instance name
+ private final String instanceName;
+ // server process
+ private Process process;
+ // server log file
+ private File logFile;
+
+ Thread logWriterThread;
+
+ private static HashMap<String, LogWriter> instances = new HashMap<String, LogWriter>();
+
+ private boolean read;
+
+ private String trailingLine = "";
+
+ private LogWriter(InputOutput io, String instanceName) {
+ this.out = (io != null ? io.getOut() : null);
+ this.instanceName = instanceName;
+ }
+
+ synchronized public static LogWriter createInstance(InputOutput io, String instanceName) {
+ LogWriter instance = getInstance(instanceName);
+ if (instance == null) {
+ instance = new LogWriter(io, instanceName);
+ instances.put(instanceName, instance);
+ }
+ return instance;
+ }
+
+ synchronized public static LogWriter getInstance(String instanceName) {
+ return instances.get(instanceName);
+ }
+
+ /**
+ * Starts reading of the server log file and writing its content into the output console
+ */
+ public void start(File logFile) {
+ try {
+ this.logFile = logFile;
+ this.reader = new BufferedReader(new FileReader(logFile));
+ } catch (FileNotFoundException ioe) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
+ }
+
+ // start the logging thread
+ startWriter(new LineProcessor() {
+ // only lines with the 'INFO' level severity are written into the
+ // output pane
+ public void processLine(String line) {
+ if (out != null) {
+ if (line != null && line.indexOf(" INFO ") != -1) {
+ out.println(line);
+ }
+ }
+ }
+ }, LOGGER_TYPE.FILE);
+ }
+
+ /**
+ * Starts reading data piped from standard output stream of the server process. It is expected that the this method
+ * is called during the server startup. The startup progress is currently done by checking the outgoing messages for
+ * some keywords occurence.
+ *
+ * The calling thread is blocked waiting until it is notified when the server startup has finished.
+ *
+ * @return true when the server startup was succesfull, false otherwise
+ */
+ GeronimoStartServer.ACTION_STATUS start(Process process, final GeronimoStartServer startServer) {
+ this.process = process;
+ this.startServer = startServer;
+ this.reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+ // start the logging thread
+ startWriter(new LineProcessor() {
+
+ // flag saying whether the the startup progress must be checked or
+ // not
+ // it is set to false after the server is started or if the server
+ // startup is not successfull
+ private boolean checkStartProgress = true;
+
+ public void processLine(String line) {
+ // all lines are written to the output pane
+ if (line != null) {
+ if (out != null) {
+ out.println(line);
+ }
+ if (checkStartProgress) {
+ checkStartProgress(line);
+ }
+ }
+ }
+
+ /**
+ * Fires the progress events when the server startup process begins and finishes (either sucessfully or not)
+ */
+ private void checkStartProgress(String line) {
+
+ if (line.indexOf("Booting Geronimo Kernel") > -1) {
+ if (VERBOSE) {
+ System.out.println("STARTING message fired"); // NOI18N
+ }
+ fireStartProgressEvent(StateType.RUNNING, createProgressMessage("MSG_START_SERVER_IN_PROGRESS")); // NOI18N
+ } else if (line.indexOf("Geronimo Application Server started") > -1) {
+ if (VERBOSE) {
+ System.out.println("STARTED message fired"); // NOI18N
+ }
+ checkStartProgress = false;
+ actionStatus = GeronimoStartServer.ACTION_STATUS.SUCCESS;
+ notifyStartupThread();
+ } else if (line.indexOf("Shutdown complete") > -1) { // NOI18N
+ checkStartProgress = false;
+ actionStatus = GeronimoStartServer.ACTION_STATUS.FAILURE;
+ notifyStartupThread();
+ }
+ }
+
+ }, LOGGER_TYPE.PROCESS);
+
+ try {
+ synchronized (START_LOCK) {
+ long start = System.currentTimeMillis();
+ // the calling thread is blocked until the server startup has
+ // finished or START_TIMEOUT millis has elapsed
+ START_LOCK.wait(START_TIMEOUT);
+ if (System.currentTimeMillis() - start >= START_TIMEOUT) {
+ if (VERBOSE) {
+ System.out.println("Startup thread TIMEOUT EXPIRED");
+ }
+ actionStatus = GeronimoStartServer.ACTION_STATUS.UNKNOWN;
+ } else {
+ if (VERBOSE) {
+ System.out.println("Startup thread NOTIFIED");
+ }
+ }
+ }
+ } catch (InterruptedException ex) {
+ // noop
+ }
+
+ return actionStatus;
+ }
+
+ private void notifyStartupThread() {
+ synchronized (START_LOCK) {
+ START_LOCK.notify();
+ }
+ }
+
+ private void fireStartProgressEvent(StateType stateType, String msg) {
+ startServer.fireHandleProgressEvent(null, new GeronimoDeploymentStatus(ActionType.EXECUTE, CommandType.START,
+ stateType, msg));
+ }
+
+ private String createProgressMessage(final String resName) {
+ return NbBundle.getMessage(LogWriter.class, resName, instanceName);
+ }
+
+ /**
+ * Common interface for processing the line read from the server output
+ */
+ private interface LineProcessor {
+ void processLine(String line);
+ }
+
+ /**
+ * Starts the log writer thread. If the old thread is still running then the old thread is interrupted. The old
+ * thread is running when is of LOGGER_TYPE.FILE type and the server is stopped outside of the IDE because there is
+ * no way how to check the server process status when we don't have access to the server process.
+ *
+ * The thread reading from the server process (LOGGER_TYPE.PROCESS type) is periodically checking the server process
+ * exit value and finishes when the server process has exited.
+ *
+ * The thread reading from the server log file periodically checks the server log file size to ensure that the input
+ * stream is valid, i.e. reading from the same file as the server process log file.
+ *
+ * The method is also responsible for the correct switching between the threads with different LOGGER_TYPE
+ */
+ private void startWriter(final LineProcessor lineProcessor, final LOGGER_TYPE type) {
+
+ if (isRunning()) {
+ // logger reading the log file is not stopped when the server is
+ // stopped outside of the IDE
+ logWriterThread.interrupt();
+ if (VERBOSE) {
+ System.out.println("************INTERRUPT thread " + logWriterThread.getId());
+ }
+ }
+
+ this.type = type;
+
+ logWriterThread = new Thread(THREAD_NAME) {
+ public void run() {
+ if (VERBOSE) {
+ System.out.println("************START thread " + Thread.currentThread().getId());
+ }
+ read = true;
+ boolean interrupted = false;
+ long lastFileSize = -1;
+ boolean checkProfiler = (startServer != null && startServer.getMode() == GeronimoStartServer.MODE.PROFILE);
+ while (read) {
+ // if in profiling mode, server startup (incl. blocked for
+ // Profiler direct attach)
+ // is checked by determining Profiler agent status using
+ // ProfilerSupport.getState()
+ // STATE_INACTIVE means that Profiler agent failed to start,
+ // which also breaks server VM
+ if (checkProfiler) {
+ int state = ProfilerSupport.getState();
+ if (state == ProfilerSupport.STATE_BLOCKING || state == ProfilerSupport.STATE_RUNNING
+ || state == ProfilerSupport.STATE_PROFILING) {
+ fireStartProgressEvent(StateType.COMPLETED,
+ createProgressMessage("MSG_PROFILED_SERVER_STARTED"));
+ checkProfiler = false;
+ notifyStartupThread();
+ } else if (state == ProfilerSupport.STATE_INACTIVE) {
+ fireStartProgressEvent(StateType.FAILED,
+ createProgressMessage("MSG_START_PROFILED_SERVER_FAILED"));
+ process.destroy();
+ notifyStartupThread();
+ break;
+ }
+ }
+
+ boolean ready = processInput(lineProcessor, type);
+ if (type == LOGGER_TYPE.FILE) {
+ if (ready) { // some input was read, remember the
+ // file size
+ lastFileSize = logFile.length();
+ }
+ // nothing was read, compare the current file size with
+ // the remembered one
+ else if (lastFileSize != logFile.length()) {
+ // file size has changed nevertheless there is
+ // nothing to read -> refresh needed
+ if (VERBOSE) {
+ System.out.println("!!!!!!!!!DIFFERENCE found");
+ }
+ refresh();
+ }
+ } else {
+ try {
+ process.exitValue();
+ // reaching this line means that the process already
+ // exited
+ break;
+ } catch (IllegalThreadStateException itse) {
+ // noop process has not exited yet
+ }
+ }
+ try {
+ Thread.sleep(DELAY); // give the server some time to
+ // write the output
+ } catch (InterruptedException e) {
+ interrupted = true;
+ break;
+ }
+ }
+
+ // print the remaining message from the server process after it
+ // has stopped, see the issue #81951
+ lineProcessor.processLine(trailingLine);
+
+ if (VERBOSE) {
+ System.out.println("************FINISH thread " + Thread.currentThread().getId());
+ }
+ if (!interrupted) {
+ // reset the read flag and remove instance from the map when
+ // the thread exiting is 'natural',
+ // i.e. caused by a server process exiting or by calling
+ // stop() on the instance.
+ // the thread interruption means that another thread is
+ // going to start execution
+ read = false;
+ instances.remove(instanceName);
+ }
+ }
+ };
+ logWriterThread.start();
+
+ }
+
+ /**
+ * Sets the read flag to false to announce running thread that is must stop running.
+ */
+ void stop() {
+ read = false;
+ }
+
+ boolean isRunning() {
+ return read;
+ }
+
+ /**
+ * If the logger is of type FILE then closes the current reader, resets the output pane and creates new input
+ * reader.
+ */
+ public void refresh() {
+ if (type == LOGGER_TYPE.PROCESS || logFile == null) {
+ return;
+ }
+
+ synchronized (READER_LOCK) {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
+ }
+ }
+ try {
+ if (out != null) {
+ out.reset();
+ }
+ if (VERBOSE) {
+ System.out.println("REFRESHING the output pane");
+ }
+ reader = new BufferedReader(new FileReader(logFile));
+ } catch (IOException e) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
+ }
+ }
+ }
+
+ /**
+ * The method is reading the lines from the reader until no input is avalable.
+ *
+ * @return true if at least one line was available on the input, false otherwise
+ */
+ private boolean processInput(LineProcessor lineProcessor, final LOGGER_TYPE type) {
+ synchronized (READER_LOCK) {
+ boolean ready = false;
+ try {
+ if (type == LOGGER_TYPE.PROCESS) {
+ while (reader.ready()) {
+ // reader.readLine() was hanging on Windows, thus
+ // replaced by own readLine() method
+ // see issue #81951
+ ready = readLine(lineProcessor);
+ }
+ } else {
+ while (reader.ready()) {
+ String line = reader.readLine();
+ lineProcessor.processLine(line);
+ ready = true;
+ }
+ }
+ } catch (IOException e) {
+ ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
+ }
+ return ready;
+ }
+ }
+
+ /**
+ * According to the issue #81951, the BefferedReader.read() method must be used instead of the
+ * BefferedReader.readLine() method, otherwise it hangs on Windows in the underlying native method call after the
+ * server process has been stopped. On Linux the BefferedReader.readLine() method correctly returns.
+ *
+ * Parsing is done manually to simulate behavior of the BefferedReader.readLine() method. According to this, a line
+ * is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return
+ * followed immediately by a line feed.
+ *
+ * The method is processing each line read using the given LineProcessor. The remaining text (following the last
+ * line) is remembered for the next reading in the instance variable.
+ *
+ * The method is not able to discover whether there will be some additional reading or not, thus theoretically there
+ * are several events when the remaining text might not be processed. The first kind of event is when the server
+ * process has been started or some other event has occured (e.g. deploying) which causes the server process to log
+ * but not to stop. It is not possible to discover that no other input will be read and if the last logged line is
+ * not ended by the 'new-line' character(s) then the remaing text is printed out not until the next input is read.
+ * The second kind of event is when the server process has been stopped. The log writer thread is finished in this
+ * case and has opportunity to write out the remaing text.
+ */
+ private boolean readLine(LineProcessor lineProcessor) throws IOException {
+ char[] cbuf = new char[128];
+ int size = -1;
+ if ((size = reader.read(cbuf)) != -1) {
+ // prepend the text from the last reading to the text actually read
+ String lines = (trailingLine != null ? trailingLine : "");
+ lines += new String(cbuf, 0, size);
+ int tlLength = (trailingLine != null ? trailingLine.length() : 0);
+ int start = 0;
+ for (int i = 0; i < size; i++) {// going through the text read and
+ // searching for the new line
+ // we see '\n' or '\r', *not* '\r\n'
+ if (cbuf[i] == '\r' && (i + 1 == size || cbuf[i + 1] != '\n') || cbuf[i] == '\n') {
+ String line = lines.substring(start, tlLength + i);
+ // move start to the character right after the new line
+ start = tlLength + (i + 1);
+ lineProcessor.processLine(line);
+ } else // we see '\r\n'
+ if (cbuf[i] == '\r' && (i + 1 < size) && cbuf[i + 1] == '\n') {
+ String line = lines.substring(start, tlLength + i);
+ // skip the '\n' character
+ i += 1;
+ // move start to the character right after the new line
+ start = tlLength + (i + 1);
+ lineProcessor.processLine(line);
+ }
+ }
+ if (start < lines.length()) {
+ // new line was not found at the end of the input, the remaing
+ // text is stored for the next reading
+ trailingLine = lines.substring(start);
+ } else {
+ // null and not empty string to indicate that there is no valid
+ // input to write out;
+ // an empty string means that a new line character may be
+ // written out according
+ // to the LineProcessor implementation
+ trailingLine = null;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * The method is used to either for blocking a caller until the server process has exited (when the logger is of
+ * PROCESS type) or sleeps some piece of time to allow the logging thread to finish its work. After returning from
+ * this call the caller may expect that no other input is going to be read and is safe to stop the logger by calling
+ * stop() method.
+ *
+ * @param milliseconds
+ * the time the caller is blocked waiting for the server process to exit, otherwise the waiting is
+ * terminated. It may help when the process has not exited exists in some non-defined state
+ */
+ void waitForServerProcessFinished(long milliseconds) {
+ Task t = new RequestProcessor(STOPPER_THREAD_NAME, 1, true).post(new Runnable() {
+ public void run() {
+ try {
+ if (VERBOSE) {
+ System.out.println(STOPPER_THREAD_NAME + ": WAITING for the server process to stop");
+ }
+ if (type == LOGGER_TYPE.PROCESS) {
+ process.waitFor();
+ } else {
+ Thread.sleep(2000);
+ }
+ } catch (InterruptedException ex) {
+ // noop
+ }
+ }
+ });
+ try {
+ t.waitFinished(milliseconds);
+ } catch (InterruptedException ex) {
+ // noop
+ } finally {
+ t.cancel();
+ }
+ }
+
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/LogWriter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,89 @@
+package org.apache.geronimo.netbeans.ide.ui;
+
+import java.io.File;
+import org.openide.WizardDescriptor;
+import org.openide.util.HelpCtx;
+import java.awt.Component;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.openide.util.NbBundle;
+
+public class AddServerLocationPanel implements WizardDescriptor.Panel, ChangeListener {
+ private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
+
+ private GeronimoInstantiatingIterator instantiatingIterator;
+
+ private AddServerLocationVisualPanel component;
+ private WizardDescriptor wizard;
+ private transient Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
+
+ public AddServerLocationPanel(GeronimoInstantiatingIterator instantiatingIterator) {
+ this.instantiatingIterator = instantiatingIterator;
+ }
+
+ public void stateChanged(ChangeEvent ev) {
+ fireChangeEvent(ev);
+ }
+
+ private void fireChangeEvent(ChangeEvent ev) {
+ Iterator<ChangeListener> it;
+ synchronized (listeners) {
+ it = new HashSet<ChangeListener>(listeners).iterator();
+ }
+ while (it.hasNext()) {
+ it.next().stateChanged(ev);
+ }
+ }
+
+ public Component getComponent() {
+ if (component == null) {
+ component = new AddServerLocationVisualPanel();
+ component.addChangeListener(this);
+ }
+ return component;
+ }
+
+ public HelpCtx getHelp() {
+ return new HelpCtx("j2eeplugins_registering_app_server_geronimo_location"); // NOI18N
+ }
+
+ public boolean isValid() {
+ String locationStr = ((AddServerLocationVisualPanel) getComponent()).getInstallLocation();
+ File location = new File(locationStr);
+ if (!GeronimoPluginUtils.isGoodServerLocation(location)) {
+ wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerLocationPanel.class,
+ "MSG_InvalidServerLocation")); // NOI18N
+ return false;
+ }
+
+ wizard.putProperty(PROP_ERROR_MESSAGE, null);
+ GeronimoPluginProperties.getInstance().setInstallLocation(
+ ((AddServerLocationVisualPanel) getComponent()).getInstallLocation());
+ GeronimoPluginProperties.getInstance().saveProperties();
+ instantiatingIterator.setInstallLocation(locationStr);
+ return true;
+ }
+
+ public void removeChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.remove(l);
+ }
+ }
+
+ public void addChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.add(l);
+ }
+ }
+
+ public void readSettings(Object settings) {
+ if (wizard == null)
+ wizard = (WizardDescriptor) settings;
+ }
+
+ public void storeSettings(Object settings) {
+ }
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationPanel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,214 @@
+package org.apache.geronimo.netbeans.ide.ui;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.swing.JFileChooser;
+import javax.swing.JPanel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.openide.util.NbBundle;
+
+public class AddServerLocationVisualPanel extends JPanel {
+
+ private final Set<ChangeListener> listeners = new HashSet<ChangeListener>();
+ private static JFileChooser chooser = null;
+ private static final long serialVersionUID = 1L;
+
+ /** Creates new form AddServerLocationVisualPanel */
+ public AddServerLocationVisualPanel() {
+ initComponents();
+ setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_ServerLocation"));
+ locationTextField.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ locationChanged();
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ locationChanged();
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ locationChanged();
+ }
+ });
+ }
+
+ public String getInstallLocation() {
+ return locationTextField.getText();
+ }
+
+ public void addChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.add(l);
+ }
+ }
+
+ public void removeChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.remove(l);
+ }
+ }
+
+ private void fireChangeEvent() {
+ Iterator<ChangeListener> it;
+ synchronized (listeners) {
+ it = new HashSet<ChangeListener>(listeners).iterator();
+ }
+ ChangeEvent ev = new ChangeEvent(this);
+ while (it.hasNext()) {
+ it.next().stateChanged(ev);
+ }
+ }
+
+ private void locationChanged() {
+ locationTextField.getText();
+ // TODO: Help user to find the proper directory
+ // pop up a window to choose a server installation directory from
+ fireChangeEvent();
+ }
+
+ private String browseInstallLocation() {
+ String insLocation = null;
+ JFileChooser chooser = getJFileChooser();
+ int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerLocationVisualPanel.class,
+ "LBL_ChooseButton")); // NOI18N
+
+ if (returnValue == JFileChooser.APPROVE_OPTION) {
+ insLocation = chooser.getSelectedFile().getAbsolutePath();
+ }
+ return insLocation;
+ }
+
+ private JFileChooser getJFileChooser() {
+ // JFileChooser chooser = new JFileChooser();
+
+ if (chooser == null) {
+
+ chooser = new JFileChooser();
+
+ chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); // NOI18N
+ chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
+
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); // NOI18N
+ chooser.setMultiSelectionEnabled(false);
+ chooser.addChoosableFileFilter(new dirFilter());
+ chooser.setAcceptAllFileFilterUsed(false);
+ chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class,
+ "LBL_ChooserName")); // NOI18N
+
+ chooser.getAccessibleContext().setAccessibleName(
+ NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); // NOI18N
+ chooser.getAccessibleContext().setAccessibleDescription(
+ NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); // NOI18N
+ }
+
+ // set the current directory
+ File currentLocation = new File(locationTextField.getText());
+ if (currentLocation.exists() && currentLocation.isDirectory()) {
+ chooser.setCurrentDirectory(currentLocation.getParentFile());
+ chooser.setSelectedFile(currentLocation);
+ }
+
+ return chooser;
+ }
+
+ private void initComponents() {
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ // jTextArea1 = new javax.swing.JTextArea();
+ jLabel1 = new javax.swing.JLabel();
+ locationTextField = new javax.swing.JTextField();
+ jButton1 = new javax.swing.JButton();
+ jPanel1 = new javax.swing.JPanel();
+
+ setLayout(new java.awt.GridBagLayout());
+
+ jLabel1.setLabelFor(locationTextField);
+ org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(AddServerLocationVisualPanel.class,
+ "LBL_InstallLocation"));
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ add(jLabel1, gridBagConstraints);
+ locationTextField.setColumns(15);
+ locationTextField.getAccessibleContext().setAccessibleDescription(
+ NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
+ locationTextField.getAccessibleContext().setAccessibleName(
+ NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_InstallLocation"));
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
+ add(locationTextField, gridBagConstraints);
+
+ org.openide.awt.Mnemonics.setLocalizedText(jButton1, NbBundle.getMessage(AddServerLocationVisualPanel.class,
+ "LBL_BrowseButton"));
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
+ add(jButton1, gridBagConstraints);
+ jButton1.getAccessibleContext().setAccessibleName(
+ NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_BrowseButton"));
+ jButton1.getAccessibleContext().setAccessibleDescription("ACSD_Browse_Button_InstallLoc");
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridwidth = 3;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.weighty = 1.0;
+ add(jPanel1, gridBagConstraints);
+ jPanel1.getAccessibleContext().setAccessibleName("TITLE_AddServerLocationPanel");
+ // jPanel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerLocationVisualPanel.class,
+ // "TITLE_AddServerLocationPanel"));
+ jPanel1.getAccessibleContext().setAccessibleDescription("AddServerLocationPanel_Desc");
+
+ if (GeronimoPluginProperties.getInstance().getInstallLocation() != null) {
+ locationTextField.setText(GeronimoPluginProperties.getInstance().getInstallLocation());
+ }
+
+ }
+
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
+ String newLoc = browseInstallLocation();
+ if ((newLoc != null) && (!newLoc.equals("")))
+ locationTextField.setText(newLoc);
+ }
+
+ private static class dirFilter extends javax.swing.filechooser.FileFilter {
+
+ public boolean accept(File f) {
+ if (!f.exists() || !f.canRead() || !f.isDirectory()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public String getDescription() {
+ return NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_DirType");
+ }
+
+ }
+
+ private javax.swing.JButton jButton1;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JTextField locationTextField;
+
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerLocationVisualPanel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java?view=auto&rev=549644
==============================================================================
--- geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java (added)
+++ geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java Thu Jun 21 16:18:31 2007
@@ -0,0 +1,93 @@
+package org.apache.geronimo.netbeans.ide.ui;
+
+import java.awt.Component;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.openide.WizardDescriptor;
+import org.openide.util.HelpCtx;
+
+public class AddServerPropertiesPanel implements WizardDescriptor.Panel, ChangeListener {
+
+ private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
+ private WizardDescriptor wizard;
+ private AddServerPropertiesVisualPanel component;
+ private GeronimoInstantiatingIterator instantiatingIterator;
+
+ /** Creates a new instance of AddServerPropertiesPanel */
+ public AddServerPropertiesPanel(GeronimoInstantiatingIterator instantiatingIterator) {
+ this.instantiatingIterator = instantiatingIterator;
+ }
+
+ public boolean isValid() {
+ AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel) getComponent();
+
+ String host = panel.getHost();
+ String port = panel.getPort();
+
+ wizard.putProperty(PROP_ERROR_MESSAGE, null);
+
+ instantiatingIterator.setHost(host);
+ instantiatingIterator.setPort(port);
+ instantiatingIterator
+ .setDeployDir(GeronimoPluginUtils.getDeployDir(instantiatingIterator.getInstallLocation()));
+
+ return true;
+ }
+
+ public Component getComponent() {
+ if (component == null) {
+ component = new AddServerPropertiesVisualPanel();
+ component.addChangeListener(this);
+ }
+ return component;
+ }
+
+ public void stateChanged(ChangeEvent ev) {
+ fireChangeEvent(ev);
+ }
+
+ private void fireChangeEvent(ChangeEvent ev) {
+ // @todo implement it
+ Iterator it;
+ synchronized (listeners) {
+ it = new HashSet(listeners).iterator();
+ }
+ while (it.hasNext()) {
+ ((ChangeListener) it.next()).stateChanged(ev);
+ }
+ }
+
+ private transient Set listeners = new HashSet(1);
+
+ public void removeChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.remove(l);
+ }
+ }
+
+ public void addChangeListener(ChangeListener l) {
+ synchronized (listeners) {
+ listeners.add(l);
+ }
+ }
+
+ public void readSettings(Object settings) {
+ if (wizard == null)
+ wizard = (WizardDescriptor) settings;
+ }
+
+ public void storeSettings(Object settings) {
+ }
+
+ public HelpCtx getHelp() {
+ return new HelpCtx("j2eeplugins_registering_app_server_geronimo_properties"); // NOI18N
+ }
+
+ void installLocationChanged() {
+ if (component != null)
+ component.installLocationChanged();
+ }
+}
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/geronimo-netbeans-plugin/src/main/java/org/apache/geronimo/netbeans/ide/ui/AddServerPropertiesPanel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain