From 3f31bb8a3a51ca3634bcfe800d4e9c093049d404 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Mon, 14 May 2012 22:01:04 +0200 Subject: [PATCH] wip commit --- .../main/directory/config/logging.properties | 28 +++++- .../main/directory/config/server.properties | 6 ++ .../src/main/scripts/run.bat | 2 +- .../src/main/scripts/run.sh | 2 +- .../vasc/demo/tech/core/DemoVascManager.java | 5 +- .../forwardfire/vasc/demo/tech/ui/TechUI.java | 86 ++++++++++--------- .../vasc/demo/tech/ui/TomcatManager.java | 34 +++++++- .../demo/tech/ui/components/JMainPanel.java | 4 +- .../resources/META-INF/root-bundle.properties | 2 +- 9 files changed, 118 insertions(+), 51 deletions(-) create mode 100644 vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/server.properties diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/logging.properties b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/logging.properties index 7262f15..7557f89 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/logging.properties +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/logging.properties @@ -1,4 +1,30 @@ # -# +# Vasc Demo Tech logging config. # +# Only log to a file +handlers=java.util.logging.FileHandler + +# default file output is in startup directory. +java.util.logging.FileHandler.pattern=logs/vasc-demo-tech.log +java.util.logging.FileHandler.limit=0 +java.util.logging.FileHandler.count=1 +java.util.logging.FileHandler.encoding=UTF8 +java.util.logging.FileHandler.formatter=net.forwardfire.vasc.demo.tech.ui.PatternLogFormatter + +# The PatternLogFormatter lets you customise the log output; +# %d = Formated date string %s =-Source method +# %l = Logger level %c = Source Class +# %n = Logger name %C = Source Class Simple +# %m = Logger message %S = Stacktrace +# %t = Thread ID %r = Return/newline +#net.forwardfire.vasc.demo.tech.ui.PatternLogFormatter.log_pattern=%d %l [%C.%s] %m%r +#net.forwardfire.vasc.demo.tech.ui.PatternLogFormatter.log_error_pattern=%d %l [%C.%s] %m%r%S +#net.forwardfire.vasc.demo.tech.ui.PatternLogFormatter.date_pattern=yyyy-MM-dd HH:mm:ss + +# Default global logging level. +.level=INFO + +# Different log levels for packages. +net.forwardfire.vasc.demo.level=INFO + diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/server.properties b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/server.properties new file mode 100644 index 0000000..287acee --- /dev/null +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/directory/config/server.properties @@ -0,0 +1,6 @@ + +gui=true +editor=true +contextPath=/demo +host=localhost +port=8899 diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.bat b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.bat index 417ce0e..98faaaa 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.bat +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.bat @@ -32,7 +32,7 @@ set MAIN_CLASS=net.forwardfire.vasc.demo.tech.ui.TechUI set CP=lib\* :: Launch application -java %JAVA_OPTS% -cp "%CP%" %MAIN_CLASS% -gui +java %JAVA_OPTS% -cp "%CP%" %MAIN_CLASS% endlocal :: EOF diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.sh b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.sh index be32aef..237670d 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.sh +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-build/src/main/scripts/run.sh @@ -32,7 +32,7 @@ MAIN_CLASS="net.forwardfire.vasc.demo.tech.ui.TechUI"; CP=`echo lib/*.jar | sed 's/ /:/g'`; # Launch application -$JAVA $JAVA_OPTS -cp $CP $MAIN_CLASS -gui; +$JAVA $JAVA_OPTS -cp $CP $MAIN_CLASS; # EOF diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-core/src/main/java/net/forwardfire/vasc/demo/tech/core/DemoVascManager.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-core/src/main/java/net/forwardfire/vasc/demo/tech/core/DemoVascManager.java index a49abe6..94c17d0 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-core/src/main/java/net/forwardfire/vasc/demo/tech/core/DemoVascManager.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-core/src/main/java/net/forwardfire/vasc/demo/tech/core/DemoVascManager.java @@ -75,8 +75,7 @@ public class DemoVascManager { // Config some defaults vecc.setDefaultPageSize(200); vecc.setDefaultPageSizeMax(1500); - - initEditor(); + } catch (VascException e) { throw new RuntimeException(e); } @@ -93,7 +92,7 @@ public class DemoVascManager { logger.info("Stop manager, cleared all."); } - private void initEditor() { + public void startEditor() { try { VascParser parser = new VascParser(vascController); parser.addGlobalELBean("vascController", vascController); diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TechUI.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TechUI.java index 505bbf7..37aaa57 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TechUI.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TechUI.java @@ -29,10 +29,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.ArrayList; import java.util.EventObject; -import java.util.Iterator; -import java.util.List; +import java.util.Properties; +import java.util.logging.FileHandler; import java.util.logging.Handler; import java.util.logging.LogManager; import java.util.logging.Logger; @@ -68,7 +67,7 @@ public class TechUI extends SingleFrameApplication { LogFactory.getLog(TechUI.class); // init JULI so reconfig is done once. - File logConfig = new File("logfile.properties"); + File logConfig = new File("config/logging.properties"); if (logConfig.exists()) { InputStream in = null; try { @@ -124,44 +123,48 @@ public class TechUI extends SingleFrameApplication { // First parse user program arguments. String serverHost = null; String serverPort = null; - List arguList = new ArrayList(argu.length); - for (String a:argu) { - arguList.add(a); - } - Iterator arguIterator = arguList.iterator(); - while (arguIterator.hasNext()) { - String arg = arguIterator.next(); - if ("-v".equals(arg)) { - System.out.println(); - System.out.println("Optional:"); - System.out.println(" -host Sets the http hostname."); - System.out.println(" -port Sets the http port."); - System.out.println(" -gui Sets gui mode."); - System.out.println(" -h Print help. (this)"); - System.out.println(); - System.exit(1); - } - if ("-gui".equals(arg)) { - showGui = true; - } - if ("-port".equals(arg)) { - if (arguIterator.hasNext()==false) { - System.out.println("No argument for -port given."); - return; + String contextPath = null; + boolean editor = false; + showGui = false; + + File propFile = new File("config/server.properties"); + if (propFile.exists()) { + + InputStream in = null; + try { + in = new FileInputStream(propFile); + Properties p = new Properties(); + p.load(in); + serverHost = p.getProperty("host"); + serverPort = p.getProperty("port"); + contextPath = p.getProperty("contextPath"); + if ("true".equalsIgnoreCase(p.getProperty("gui"))) { + showGui = true; + } else { + showGui = false; + } + if ("true".equalsIgnoreCase(p.getProperty("editor"))) { + editor = true; + } else { + editor = false; + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (in!=null) { + try { + in.close(); + } catch (IOException e) { + } } - serverPort = arguIterator.next(); - System.exit(1); - } - if ("-host".equals(arg)) { - if (arguIterator.hasNext()==false) { - System.out.println("No argument for -host given."); - return; - } - serverHost = arguIterator.next(); - System.exit(1); } + } else { + serverHost = "localhost"; + serverPort = "8899"; } + setupLogging(); logger.info("Starting Vasc-Demo-Tech-UI."); @@ -176,9 +179,11 @@ public class TechUI extends SingleFrameApplication { } } - vascManager = new DemoVascManager(); vascManager.start(); + if (editor) { + vascManager.startEditor(); + } deployManager = new DeployManager(); deployManager.setDeployDir(deployDir); @@ -193,6 +198,9 @@ public class TechUI extends SingleFrameApplication { if (serverPort!=null) { tomcatManager.setPort(new Integer(serverPort)); } + if (contextPath!=null) { + tomcatManager.setContextPath(contextPath); + } Thread t = new Thread(new Runnable() { public void run() { diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TomcatManager.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TomcatManager.java index 55cae71..b172f88 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TomcatManager.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/TomcatManager.java @@ -10,7 +10,9 @@ import java.util.logging.Logger; import net.forwardfire.vasc.core.VascController; +import org.apache.catalina.startup.Bootstrap; import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.valves.AccessLogValve; public class TomcatManager { @@ -20,11 +22,13 @@ public class TomcatManager { private String hostname = null; private Integer port = null; private File workDir = null; + private String contextPath = null; public TomcatManager() { logger = Logger.getLogger(TomcatManager.class.getName()); hostname = "localhost"; port = 8899; + contextPath = "/demo"; } public void start() throws Exception { @@ -36,11 +40,21 @@ public class TomcatManager { tomcat.setPort(getPort()); tomcat.setHostname(getHostname()); - if (System.getProperty("java.class.path").contains("classes")) { + tomcat.init(); + + if (TechUI.getInstance().isMavenRun()==false) { + AccessLogValve accessLog = new AccessLogValve(); + accessLog.setDirectory("../logs"); + accessLog.setSuffix(".log"); + accessLog.setPattern("%h %l %u %t "%r" %s %b"); + tomcat.getHost().getPipeline().addValve(accessLog); + } + + if (TechUI.getInstance().isMavenRun()) { String webappPathLocation = "../vasc-demo-tech-web/src/main/webapp/"; String deployPath = new File(webappPathLocation).getAbsolutePath(); logger.info("Deploy demo app from workspace path: "+deployPath); - tomcat.addWebapp("/demo",deployPath); + tomcat.addWebapp(getContextPath(),deployPath); } else { File techWarFile = null; @@ -76,7 +90,7 @@ public class TomcatManager { } String deployPath = destDir.getAbsolutePath(); logger.info("Deploy war path: "+deployPath); - tomcat.addWebapp("/demo",deployPath); + tomcat.addWebapp(getContextPath(),deployPath); } tomcat.start(); } @@ -143,4 +157,18 @@ public class TomcatManager { public void setWorkDir(File workDir) { this.workDir = workDir; } + + /** + * @return the contextPath + */ + public String getContextPath() { + return contextPath; + } + + /** + * @param contextPath the contextPath to set + */ + public void setContextPath(String contextPath) { + this.contextPath = contextPath; + } } diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/components/JMainPanel.java b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/components/JMainPanel.java index 18e05d0..b5563eb 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/components/JMainPanel.java +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/java/net/forwardfire/vasc/demo/tech/ui/components/JMainPanel.java @@ -283,12 +283,12 @@ public class JMainPanel extends JPanel { } if (keys.isEmpty()==false) { Properties p = new Properties(); - File dataDir = new File("auto/data"); + File dataDir = new File("data"); if (dataDir.exists()==false) { dataDir.mkdirs(); } - File resourceFile = new File("auto/data/vasc-bundle.properties"); + File resourceFile = new File("data/vasc-bundle.properties"); if (resourceFile.exists()) { readPropertiesFile(p,resourceFile); } diff --git a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/resources/META-INF/root-bundle.properties b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/resources/META-INF/root-bundle.properties index a9c0585..d488f0b 100644 --- a/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/resources/META-INF/root-bundle.properties +++ b/vasc-demo/vasc-demo-tech/vasc-demo-tech-ui/src/main/resources/META-INF/root-bundle.properties @@ -2,7 +2,7 @@ # bundle list to merge and load bundle1.uri=net.forwardfire.vasc.demo.tech.ui.resources.TechUI -bundle2.uri=auto/data/vasc-bundle.properties +bundle2.uri=data/vasc-bundle.properties bundle2.type=FILE bundle2.optional=true