Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
recovering from borked local repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sgsinclair committed Jan 6, 2016
1 parent 96f82c9 commit 4547650
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ src/main/webapp/WEB-INF/classes
/_app
/dist
/VoyantServerNoNlp.zip
/VoyantServer.zip
/logs
12 changes: 6 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<property name="jarpath" location="lib"/>

<path id="project.jars">
<pathelement location="${jarpath}/jetty-all-8.1.9.v20130131.jar"/>
<pathelement location="${jarpath}/servlet-api-3.0.jar"/>
<pathelement location="${jarpath}/jetty-all-9.2.2.v20140723.jar"/>
<pathelement location="${jarpath}/servlet-api-3.1.0.jar"/>
</path>

<path id="project.class.path">
Expand Down Expand Up @@ -45,8 +45,8 @@
filesonly="true"
compress="true">
<fileset dir="${build}" />
<zipfileset src="${jarpath}/jetty-all-8.1.9.v20130131.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/servlet-api-3.0.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/jetty-all-9.2.2.v20140723.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/servlet-api-3.1.0.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Main-Class" value="org.voyanttools.server.ui.VoyantServerStart"/>
</manifest>
Expand All @@ -70,8 +70,8 @@
filesonly="true"
compress="true">
<fileset dir="${build}" />
<zipfileset src="${jarpath}/jetty-all-8.1.9.v20130131.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/servlet-api-3.0.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/jetty-all-9.2.2.v20140723.jar" excludes="META-INF/*" />
<zipfileset src="${jarpath}/servlet-api-3.1.0.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Main-Class" value="org.voyanttools.server.ui.VoyantServerStart"/>
<attribute name="appname" value="VoyantServer" />
Expand Down
Binary file removed lib/jetty-all-8.1.9.v20130131.jar
Binary file not shown.
Binary file added lib/jetty-all-9.2.2.v20140723.jar
Binary file not shown.
Binary file removed lib/servlet-api-3.0.jar
Binary file not shown.
Binary file added lib/servlet-api-3.1.0.jar
Binary file not shown.
18 changes: 16 additions & 2 deletions server-settings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### Settings for VoyantServer ###

# These are settings that define default values for VoyantServer. In most cases
# the indicated values can be used (or blank to use a default). You can also
# override the values in this settings file if you launch VoyantServer from the
# command line by using -Dorg.voyanttools.server.SETTING=VALUE. For instance:
# java -Dorg.voyanttools.server.memory=2048 -jar VoyantServer.jar headless=true

# The port to use for the web server (default is 8888). If a port is already in use,
# this can be changed (8889, etc.). If the server terminated unexpectedly the port
Expand All @@ -22,7 +28,7 @@ memory = 1024
# up an existing corpus automatically (/?corpus=id where id is replaced by the real
# corpus ID that you've created). If the data directory exists and you want to use it
# leave this value blank.
data_directory =
data_directory =

# The URI path (after the domain) to use (default is /). This is a good way to provide
# load a corpus by default, ex: uri_path = /?input=http://cbc.ca/news/ or /?corpus=333.333
Expand All @@ -37,4 +43,12 @@ uri_path = /
# VoyantServer is also a convenient way to host an instance of Voyant Tools that you might
# want to have more widely accessible, in which case you should comment out this line or remove
# the value.
host = 127.0.0.1
# host = 127.0.0.1

# By default VoyantServer will direct output to the console window within the VoyantServer
# application (this is a useful place to see what's happening, especially when things go
# wrong); when in headless mode, logs are simply directed to the standard output. This
# setting allows you to direct VoyantServer logs to a file instead, which is especially
# useful when you want to leave a server running and detached from the console
# value should be true or anything else for false (including blank).
logs_file =
69 changes: 65 additions & 4 deletions src/org/aw20/jettydesktop/ui/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
Expand All @@ -48,7 +51,7 @@ public class Executor extends Object {
private Process process;
private ExecutorInterface executorI;
private boolean bRun = true;
private ioConsumer ioconsumers[];
private Thread ioconsumers[];
private adminPortWatcher AdminPortWatcher = null;
private int adminPort;

Expand Down Expand Up @@ -81,6 +84,9 @@ else if (new File(JDK_HOME, "javaw").exists() )
List<String> programArgs = new ArrayList<String>();
programArgs.add(JDK_HOME);

// force UTF-8
programArgs.add("-Dfile.encoding=UTF-8");

if (options.getMemoryJVM() != null)
programArgs.add("-Xmx" + options.getMemoryJVM() + "m");

Expand Down Expand Up @@ -114,9 +120,26 @@ else if (new File(JDK_HOME, "javaw").exists() )
executorI.onServerStart();
}

ioconsumers = new ioConsumer[2];
ioconsumers[0] = new ioConsumer(process.getErrorStream());
ioconsumers = new Thread[2];
ioconsumers[1] = new ioConsumer(process.getInputStream());
if (options.getLogsFile()) {
File dir = new File(options.getDataFolder(), "logs");
if (dir.exists()==false) {
if (!dir.mkdir()) {
System.err.println("Can't create logs directory: "+dir);
throw new IOException("Can't create logs directory: "+dir);
}
}
File out = new File(dir, "jetty.log");
if (executorI!=null) {
executorI.onConsole("Logging to file: "+out.getAbsolutePath());
}
FileWriter outWriter = new FileWriter(out, true);
ioconsumers[0] = new ioFileConsumer(process.getErrorStream(), outWriter);
}
else {
ioconsumers[0] = new ioConsumer(process.getErrorStream());
}

if ( adminPort > 0 ){
try{
Expand Down Expand Up @@ -221,6 +244,44 @@ public void run() {
}
}
}

class ioFileConsumer extends Thread {
BufferedReader br;
PrintWriter wr;

public ioFileConsumer(InputStream io, Writer wr) {
br = new BufferedReader(new InputStreamReader(io));
this.wr = new PrintWriter(wr);
start();
}

public void run() {

while (bRun) {
String line;
try {
while ((line = br.readLine()) != null) {
if (executorI != null) {
wr.println(line);
wr.flush();
}
}
} catch (IOException e) {
break;
}
}

try {
br.close();
wr.close();
} catch (IOException e) {}


if (executorI != null) {
executorI.onServerExit();
}
}
}

public boolean isWebAppRunning() {
return true;
Expand All @@ -244,7 +305,7 @@ private String getClasspath(String usrdir) {
if (new File(usrdir, "VoyantServer.jar").isFile()) {
sb.append(usrdir + "VoyantServer.jar");
} else {
sb.append(usrdir + "bin").append(File.pathSeparator + usrdir + "lib" + File.separator + "jetty-all-8.1.9.v20130131.jar").append(File.pathSeparator + usrdir + "lib" + File.separator + "servlet-api-3.0.jar");
sb.append(usrdir + "bin").append(File.pathSeparator + usrdir + "lib" + File.separator + "jetty-all-9.2.2.v20140723.jar").append(File.pathSeparator + usrdir + "lib" + File.separator + "servlet-api-3.1.0.jar");
}

return sb.toString();
Expand Down
21 changes: 19 additions & 2 deletions src/org/aw20/jettydesktop/ui/ServerConfigMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public static ServerConfigMap getDefault(){
return new ServerConfigMap(){{
setName("");
setIP("127.0.0.1");
setPort("80");
setPort("8888");
setWebFolder("");
setCurrentJVM();
setMemoryJVM("64");
setMemoryJVM("1024");
setLogsFile(false);
}};
}

Expand Down Expand Up @@ -116,4 +117,20 @@ public void setDefaultJVMArgs(String args) {
public void setDefaultWebUri(String args) {
put("DEFAULTURI", args.trim() );
}

public void setLogsFile(boolean fileLogs) {
put("LOGSFILE", fileLogs ? "true" : "false");
}

public boolean getLogsFile() {
return this.containsKey("LOGSFILE") && get("LOGSFILE").equals("true");
}

public void setDataFolder(String folder) {
put("DATAFOLDER", folder);
}

public String getDataFolder() {
return get("DATAFOLDER");
}
}
54 changes: 43 additions & 11 deletions src/org/voyanttools/server/ui/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,80 @@
public class ServerConfig {

public static ServerConfigMap getStoredServerConfig() throws IOException {
return getStoredServerConfig(getFile());
}
public static ServerConfigMap getStoredServerConfig(File file) throws IOException {
ServerConfigMap serverConfigMap = new ServerConfigMap(){{
setName("Voyant");
setIP("");
setPort("8888");
setWebFolder(System.getProperty("user.dir") + File.separator + "_app");
setCurrentJVM();
setMemoryJVM("1024");
setLogsFile(false);
}};
Properties properties = new Properties();
File file = getFile();
serverConfigMap.put("lastModified", String.valueOf(file.lastModified()));
FileInputStream fis = new FileInputStream(file);
properties.load(fis);
fis.close();
for (String name : properties.stringPropertyNames()) {
String val = properties.getProperty(name).trim();
if (val.isEmpty()) { continue;}
String prop = System.getProperty("org.voyanttools.server."+name); // allow items to be overwritten on the command line
if (val.isEmpty() && prop==null) { continue;}
if (name.equals("port")) {
serverConfigMap.setPort(val);
serverConfigMap.setPort(prop==null ? val : prop);
}
else if (name.equals("memory")) {
serverConfigMap.setMemoryJVM(val);
serverConfigMap.setMemoryJVM(prop==null ? val : prop);
}
else if (name.equals("data_directory")) {
serverConfigMap.setDefaultJVMArgs((serverConfigMap.getDefaultJVMArgs()!=null ? serverConfigMap.getDefaultJVMArgs()+" " : "") +"-Djava.io.tmpdir="+val);
serverConfigMap.setDataFolder(prop==null ? val : prop);
}
else if (name.equals("uri_path")) {
serverConfigMap.setDefaultWebUri(val);
serverConfigMap.setDefaultWebUri(prop==null ? val : prop);
}
else if (name.equals("host")) {
serverConfigMap.setIP(val);
serverConfigMap.setIP(prop==null ? val : prop);
}
// else if (name.equals("logs_file")) {
// serverConfigMap.setLogsFile(prop==null ? val.equals("true") : prop.equals("true"));
// }
else {
serverConfigMap.put(name, properties.getProperty(name));
}
}
File f = new File("data");

// serverConfigMap.setDefaultJVMArgs((serverConfigMap.getDefaultJVMArgs()!=null ? serverConfigMap.getDefaultJVMArgs()+" " : "") +"OPTIONS=Server,jsp");
if (new File("data").exists() && (!serverConfigMap.containsKey("data_directory") || serverConfigMap.get("data_directory").isEmpty())) {
serverConfigMap.setDefaultJVMArgs((serverConfigMap.getDefaultJVMArgs()!=null ? serverConfigMap.getDefaultJVMArgs()+" " : "") +"-Djava.io.tmpdir="+new File(System.getProperty("user.dir"),"data") );
String dataFolder = serverConfigMap.getDataFolder();
if (dataFolder==null || dataFolder.isEmpty()) {
File dataFile = new File("data");
if (dataFile.exists()) {
serverConfigMap.setDataFolder(dataFile.getAbsolutePath());
}
else {
File voyantFile = new File(System.getProperty("java.io.tmpdir"), "VoyantServer");
if (!voyantFile.exists()) {
if (!voyantFile.mkdir()) {
throw new IOException("Can't create temporary directory: "+voyantFile);
}
}
serverConfigMap.setDataFolder(voyantFile.getAbsolutePath());
}
}

File dataFile = new File(serverConfigMap.getDataFolder());
if (!dataFile.exists()) {
throw new IOException("Data folder must already exist, VoyantServer won't create it: "+dataFile.getAbsolutePath());
}

// set java.io.tmpdir for voyant data
serverConfigMap.setDefaultJVMArgs((serverConfigMap.getDefaultJVMArgs()!=null ? serverConfigMap.getDefaultJVMArgs()+" " : "") +"-Djava.io.tmpdir="+new File(serverConfigMap.getDataFolder()).getAbsolutePath() );

String prop = System.getProperty("org.voyanttools.server.logs_file"); // allow items to be overwritten on the command line
if (prop!=null || properties.getProperty("logs_file", "").equals("true")) {
serverConfigMap.setLogsFile(prop==null ? true : prop.equals("true"));
}

return serverConfigMap;
}

Expand Down
27 changes: 20 additions & 7 deletions src/org/voyanttools/server/ui/VoyantServerStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -43,17 +44,29 @@ public class VoyantServerStart extends Start {
* @throws IOException
*
*/
public VoyantServerStart() throws IOException {
// loadSettings();
initialize();
public VoyantServerStart(ServerConfigMap serverConfigMap) throws IOException {
initialize(serverConfigMap);
}


public static void main(String[] args) {
File file = new File("server-settings.txt");
for (String arg : args) {
if (arg.startsWith("settings=") && arg.length()>9) {
file = new File(arg.substring(9));
}
}
final ServerConfigMap serverConfigMap;
try {
serverConfigMap = ServerConfig.getStoredServerConfig(file);
} catch (IOException e1) {
throw new RuntimeException(e1);
}

for (String string : args) {
if (string.contains("headless=true")) {
try {
VoyantServerStartHeadless voyantServerStartHeadless = new VoyantServerStartHeadless();
VoyantServerStartHeadless voyantServerStartHeadless = new VoyantServerStartHeadless(serverConfigMap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -74,7 +87,7 @@ public void run() {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "VoyantServer");

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
final VoyantServerStart window = new VoyantServerStart();
final VoyantServerStart window = new VoyantServerStart(serverConfigMap);
window.frame.setVisible(true);

if (System.getProperty("os.name").equals("Mac OS X"))
Expand All @@ -96,7 +109,7 @@ public void run()
});
}

private void initialize() throws IOException {
private void initialize(ServerConfigMap serverConfigMap) throws IOException {
frame = new JFrame();
frame.setTitle("Voyant Server");
frame.setBounds(100, 100, 610, 414);
Expand Down Expand Up @@ -140,7 +153,7 @@ public void actionPerformed(ActionEvent e) {
mnHelp.add(mntmSupportSite);

// We need to add a new tab
VoyantServerTab sT = new VoyantServerTab(this );
VoyantServerTab sT = new VoyantServerTab(this, serverConfigMap);

frame.getContentPane().add(sT, BorderLayout.CENTER);
}
Expand Down
4 changes: 1 addition & 3 deletions src/org/voyanttools/server/ui/VoyantServerStartHeadless.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public class VoyantServerStartHeadless implements ConfigActionInterface, Executo
* @throws IOException
*
*/
public VoyantServerStartHeadless() throws IOException {
ServerConfigMap serverConfigMap = ServerConfig.getStoredServerConfig();
public VoyantServerStartHeadless(ServerConfigMap serverConfigMap) throws IOException {
Executor executor = new Executor(serverConfigMap, this);

}

/* (non-Javadoc)
Expand Down
Loading

0 comments on commit 4547650

Please sign in to comment.