2
0
Fork 0

Added start of demo data of tech demo

This commit is contained in:
Willem Cazander 2012-05-07 16:29:20 +02:00
parent 2872143028
commit beb57fe92e
12 changed files with 321 additions and 0 deletions

View file

@ -0,0 +1,108 @@
package net.forwardfire.vasc.demo.tech.ui;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import net.forwardfire.vasc.core.VascController;
import org.apache.catalina.startup.Tomcat;
public class TomcatManager {
private Logger logger = null;
private Tomcat tomcat = null;
private VascController vascController = null;
public TomcatManager() {
logger = Logger.getLogger(TomcatManager.class.getName());
}
public void start() throws Exception {
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8899";
}
tomcat.setPort(Integer.valueOf(webPort));
if (System.getProperty("java.class.path").contains("classes")) {
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);
} else {
File techWarFile = null;
for (File file:new File("lib").listFiles()) {
if (file.getName().endsWith("war")) {
techWarFile = file;
break;
}
}
if (techWarFile==null) {
throw new NullPointerException("Could not locate war file in lib directory.");
}
File destDir = new File("tomcat.wars"+File.separator+techWarFile.getName());
if (destDir.exists()==false) {
destDir.mkdirs();
JarFile jar = new JarFile(techWarFile);
Enumeration<JarEntry> jars = jar.entries();
while (jars.hasMoreElements()) {
java.util.jar.JarEntry file = jars.nextElement();
java.io.File f = new java.io.File(destDir+File.separator+file.getName());
if (file.isDirectory()) {
f.mkdir();
continue;
}
InputStream is = jar.getInputStream(file);
FileOutputStream fos = new FileOutputStream(f);
while (is.available() > 0) {
fos.write(is.read()); // slow copy
}
fos.close();
is.close();
}
}
String deployPath = destDir.getAbsolutePath();
logger.info("Deploy war path: "+deployPath);
tomcat.addWebapp("/demo",deployPath);
}
instance = this;
tomcat.start();
}
public void stop() throws Exception {
if (tomcat==null) {
return;
}
tomcat.stop();
instance = null;
}
static private TomcatManager instance = null;
static public TomcatManager getInstance() {
return instance; // hackje to rm mvn 1-1 dep with ui
}
/**
* @return the vascController
*/
public VascController getVascController() {
return vascController;
}
/**
* @param vascController the vascController to set
*/
public void setVascController(VascController vascController) {
this.vascController = vascController;
}
}