changeset 155:aba9dff6a61a

Add script to run Web Gateway in debug listening mode This patch adds a script that runs the Web Gateway listening for debugger on a socket. It also adds an IdeLauncher class designed to launch Web Gateway from IDE. The README.md is updated with usage instructions. Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-May/023206.html
author Jie Kang <jkang@redhat.com>
date Tue, 23 May 2017 09:20:31 -0400
parents b1bdc9e324c3
children 481aa587cdd0
files README.md distribution/pom.xml distribution/src/bin/thermostat-web-gateway-debug.sh ide-launcher/pom.xml ide-launcher/src/main/java/com/redhat/thermostat/gateway/ide/launcher/IdeLauncher.java pom.xml server/src/main/java/com/redhat/thermostat/gateway/server/Start.java
diffstat 7 files changed, 208 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Thu May 18 16:15:15 2017 +0200
+++ b/README.md	Tue May 23 09:20:31 2017 -0400
@@ -62,3 +62,18 @@
 ```
 services/*/*-swagger.json
 ```
+
+# How to debug after building
+
+## Run debug script
+
+This runs Thermostat Web Gateway listening on socket 5005 for a debugger to connect.
+
+```
+$ ./distribution/target/image/bin/thermostat-web-gateway-debug.sh
+```
+
+## Run IdeLauncher class
+
+This class is meant to run from IDE (Eclipse, Intellij, etc.) with configuration setting the environment variable `THERMOSTAT_GATEWAY_HOME` to `distribution/target/image`
+```
--- a/distribution/pom.xml	Thu May 18 16:15:15 2017 +0200
+++ b/distribution/pom.xml	Tue May 23 09:20:31 2017 -0400
@@ -158,6 +158,7 @@
                         <configuration>
                             <target>
                                 <chmod file="${project.build.directory}/image/bin/thermostat-web-gateway.sh" perm="755" />
+                                <chmod file="${project.build.directory}/image/bin/thermostat-web-gateway-debug.sh" perm="755" />
                                 <chmod file="${project.build.directory}/image/bin/thermostat-mongodb.sh" perm="755" />
                             </target>
                         </configuration>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/distribution/src/bin/thermostat-web-gateway-debug.sh	Tue May 23 09:20:31 2017 -0400
@@ -0,0 +1,72 @@
+#!/bin/bash
+#
+# Copyright 2012-2017 Red Hat, Inc.
+#
+# This file is part of Thermostat.
+#
+# Thermostat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# Thermostat is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Thermostat; see the file COPYING.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Linking this code with other modules is making a combined work
+# based on this code.  Thus, the terms and conditions of the GNU
+# General Public License cover the whole combination.
+#
+# As a special exception, the copyright holders of this code give
+# you permission to link this code with independent modules to
+# produce an executable, regardless of the license terms of these
+# independent modules, and to copy and distribute the resulting
+# executable under terms of your choice, provided that you also
+# meet, for each linked independent module, the terms and conditions
+# of the license of that module.  An independent module is a module
+# which is not derived from or based on this code.  If you modify
+# this code, you may extend this exception to your version of the
+# library, but you are not obligated to do so.  If you do not wish
+# to do so, delete this exception statement from your version.
+#
+
+_find_thermostat_gateway_home() {
+  # Compute THERMOSTAT_GATEWAY_HOME by finding the (symlink-resolved) location of the
+  # currently executing code's parent dir. See
+  # http://stackoverflow.com/a/246128/3561275 for implementation details.
+  SOURCE="${BASH_SOURCE[0]}"
+  while [ -h "$SOURCE" ]; do
+    DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
+    SOURCE="$(readlink "$SOURCE")"
+    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
+  done
+  DIR="$(cd -P "$(dirname "$SOURCE")" && cd .. && pwd)"
+  echo "$DIR"
+}
+
+if [ "$(uname -s | cut -b1-6)" == "CYGWIN" ]; then
+  ##echo "Running under Cygwin"
+  export CYGWIN_MODE=1
+else
+  ##echo "Running under Linux"
+  export CYGWIN_MODE=0
+fi
+
+if [[ "${THERMOSTAT_GATEWAY_HOME}" = "" ]]; then
+  THERMOSTAT_GATEWAY_HOME="$(_find_thermostat_gateway_home)"
+fi
+
+# on cygwin, convert to Windows format
+if [ $CYGWIN_MODE -eq 1 ]; then
+  THERMOSTAT_GATEWAY_HOME="`cygpath -w $THERMOSTAT_GATEWAY_HOME`"
+fi
+
+THERMOSTAT_GATEWAY_LIBS=${THERMOSTAT_GATEWAY_HOME}/libs
+
+export THERMOSTAT_GATEWAY_HOME
+java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -cp "${THERMOSTAT_GATEWAY_LIBS}/*" com.redhat.thermostat.gateway.server.Start
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ide-launcher/pom.xml	Tue May 23 09:20:31 2017 -0400
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2012-2017 Red Hat, Inc.
+
+ This file is part of Thermostat.
+
+ Thermostat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Thermostat is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Thermostat; see the file COPYING.  If not see
+ <http://www.gnu.org/licenses/>.
+
+ Linking this code with other modules is making a combined work
+ based on this code.  Thus, the terms and conditions of the GNU
+ General Public License cover the whole combination.
+
+ As a special exception, the copyright holders of this code give
+ you permission to link this code with independent modules to
+ produce an executable, regardless of the license terms of these
+ independent modules, and to copy and distribute the resulting
+ executable under terms of your choice, provided that you also
+ meet, for each linked independent module, the terms and conditions
+ of the license of that module.  An independent module is a module
+ which is not derived from or based on this code.  If you modify
+ this code, you may extend this exception to your version of the
+ library, but you are not obligated to do so.  If you do not wish
+ to do so, delete this exception statement from your version.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>thermostat-web-gateway</artifactId>
+        <groupId>com.redhat.thermostat</groupId>
+        <version>1.99.12-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>thermostat-web-gateway-ide-launcher</artifactId>
+    <name>Thermostat Web Gateway IDE Launcher</name>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>com.redhat.thermostat</groupId>
+            <artifactId>thermostat-web-gateway-distribution</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+        </dependency>
+    </dependencies>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ide-launcher/src/main/java/com/redhat/thermostat/gateway/ide/launcher/IdeLauncher.java	Tue May 23 09:20:31 2017 -0400
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.gateway.ide.launcher;
+
+import com.redhat.thermostat.gateway.server.Start;
+
+public class IdeLauncher {
+
+    public static void main(String[] args) {
+        Start start = new Start();
+        start.run();
+    }
+
+}
--- a/pom.xml	Thu May 18 16:15:15 2017 +0200
+++ b/pom.xml	Tue May 23 09:20:31 2017 -0400
@@ -53,7 +53,7 @@
         <module>distribution</module>
         <module>common</module>
         <module>services</module>
-
+        <module>ide-launcher</module>
         <module>tests</module>
     </modules>
 
--- a/server/src/main/java/com/redhat/thermostat/gateway/server/Start.java	Thu May 18 16:15:15 2017 +0200
+++ b/server/src/main/java/com/redhat/thermostat/gateway/server/Start.java	Tue May 23 09:20:31 2017 -0400
@@ -47,7 +47,7 @@
 
 public class Start {
 
-    public static void main(String[] args) {
+    public void run() {
         String gatewayHome = System.getenv(GlobalConstants.GATEWAY_HOME_ENV);
         if (gatewayHome == null) {
             throw new RuntimeException("Environment variable THERMOSTAT_GATEWAY_HOME not defined!");
@@ -74,16 +74,23 @@
         }
     }
 
-    private static void setServerConfig(CoreServerBuilder builder, ConfigurationFactory factory) {
+    private void setServerConfig(CoreServerBuilder builder, ConfigurationFactory factory) {
         Configuration globalConfig = factory.createGlobalConfiguration();
         builder.setServerConfiguration(globalConfig);
     }
 
-    private static void setServiceBuilder(CoreServerBuilder builder, ConfigurationFactory factory) {
+    private void setServiceBuilder(CoreServerBuilder builder, ConfigurationFactory factory) {
         Configuration globalServicesConfig = factory.createGlobalServicesConfig();
         CoreServiceBuilderFactory builderFactory = new CoreServiceBuilderFactory(factory);
         CoreServiceBuilder coreServiceBuilder = builderFactory.createBuilder(CoreServiceType.WEB_ARCHIVE);
         coreServiceBuilder.setConfiguration(globalServicesConfig);
         builder.setServiceBuilder(coreServiceBuilder);
     }
+
+    public static void main(String[] args) {
+        Start start = new Start();
+        start.run();
+    }
+
+
 }