i2psnark standalone:

- Cherry-pick fixes from psi's github i2psnark_rpc branch
- Fix up Jetty XML file for Jetty 8
- Start with JettyStart
- Add UrlLauncher to launch browser
- Move RunStandalone to standalone/ directory
- Fix up paths in CSS files during build
- Force startup delay to 0 when in router context
- Fix theme selection when not in router context
- Adjust CSS and image paths when not in router context
- Add hosts.txt so announces work
This commit is contained in:
zzz
2016-06-10 19:10:59 +00:00
parent 63272d3cfc
commit e27af374b0
9 changed files with 326 additions and 159 deletions

View File

@ -50,6 +50,10 @@
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
<!-- jsp-api.jar only present for debian builds -->
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
<!-- jetty-i2p.jar only for RunStandalone -->
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />
<!-- systray.jar only for RunStandalone -->
<pathelement location="../../systray/java/build/systray.jar" />
</classpath>
</javac>
</target>
@ -71,7 +75,7 @@
<target name="jar" depends="builddep, compile, jarUpToDate, listChangedFiles" unless="jar.uptodate" >
<!-- set if unset -->
<property name="workspace.changes.tr" value="" />
<jar destfile="./build/i2psnark.jar" basedir="./build/obj" includes="**/*.class" excludes="**/web/* **/messages_*.class">
<jar destfile="./build/i2psnark.jar" basedir="./build/obj" includes="**/*.class" excludes="**/web/* **/messages_*.class, **/standalone/*">
<manifest>
<attribute name="Main-Class" value="org.klomp.snark.CommandLine" />
<attribute name="Class-Path" value="i2p.jar mstreaming.jar streaming.jar" />
@ -179,29 +183,111 @@
<zipfileset dir="./dist/" prefix="i2psnark/" />
</zip>
</target>
<target name="standalone_prep" depends="war">
<!-- make a fat jar for standalone -->
<target name="standalone_jar" depends="war">
<jar destfile="build/i2psnark-standalone.jar">
<fileset dir="build/obj" includes="**/standalone/*.class" />
<zipfileset src="build/i2psnark.jar" />
<zipfileset src="../../../core/java/build/i2p.jar" />
<zipfileset src="../../jetty/jettylib/commons-logging.jar" />
<zipfileset src="../../jetty/jettylib/jasper-runtime.jar" />
<zipfileset src="../../jetty/jettylib/javax.servlet.jar" />
<zipfileset src="../../jetty/jettylib/jetty-continuation.jar" />
<zipfileset src="../../jetty/jettylib/jetty-deploy.jar" />
<zipfileset src="../../jetty/jettylib/jetty-http.jar" />
<zipfileset src="../../jetty/jettylib/jetty-i2p.jar" />
<zipfileset src="../../jetty/jettylib/jetty-io.jar" />
<zipfileset src="../../jetty/jettylib/jetty-security.jar" />
<zipfileset src="../../jetty/jettylib/jetty-servlet.jar" />
<zipfileset src="../../jetty/jettylib/jetty-util.jar" />
<zipfileset src="../../jetty/jettylib/jetty-webapp.jar" />
<zipfileset src="../../jetty/jettylib/jetty-xml.jar" />
<zipfileset src="../../jetty/jettylib/org.mortbay.jetty.jar" />
<zipfileset src="../../ministreaming/java/build/mstreaming.jar" />
<zipfileset src="../../streaming/java/build/streaming.jar" />
<zipfileset src="../../systray/java/build/systray.jar" />
<manifest>
<attribute name="Main-Class" value="org.klomp.snark.standalone.RunStandalone"/>
<attribute name="Implementation-Version" value="${full.version}" />
<attribute name="Built-By" value="${build.built-by}" />
<attribute name="Build-Date" value="${build.timestamp}" />
<attribute name="Base-Revision" value="${workspace.version}" />
<attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
</manifest>
</jar>
</target>
<!-- add css, image, and js files for standalone snark to the war -->
<target name="standalone_war" depends="war">
<mkdir dir="build/standalone-resources/.resources/themes/snark" />
<copy todir="build/standalone-resources/.resources/themes/snark" >
<fileset dir="../../../installer/resources/themes/snark/" />
</copy>
<replace dir="build/standalone-resources/.resources/themes/snark"
summary="true"
token="url('/themes/"
value="url('/i2psnark/.resources/themes/" >
<include name="**/*.css" />
</replace>
<replace dir="build/standalone-resources/.resources/themes/snark"
summary="true"
token="url('../../console/images/"
value="url('/i2psnark/.resources/themes/snark/ubergine/images/" >
<include name="**/*.css" />
</replace>
<replace dir="build/standalone-resources/.resources/themes/snark"
summary="true"
token="url('../../console/dark/images/"
value="url('/i2psnark/.resources/themes/snark/ubergine/images/" >
<include name="**/*.css" />
</replace>
<replace dir="build/standalone-resources/.resources/themes/snark"
summary="true"
token="url(&quot;../../console/light/images/"
value="url(&quot;/i2psnark/.resources/themes/snark/ubergine/images/" >
<include name="**/*.css" />
</replace>
<replace dir="build/standalone-resources/.resources/themes/snark"
summary="true"
token="url('images/"
value="url('/i2psnark/.resources/themes/snark/ubergine/images/" >
<include name="**/*.css" />
</replace>
<copy todir="build/standalone-resources/.resources/themes/snark/ubergine/images" >
<!-- we really don't need all of these -->
<fileset dir="../../../installer/resources/themes/console/images/" />
</copy>
<copy file="../../../installer/resources/themes/console/dark/images/transparent.gif"
todir="build/standalone-resources/.resources/themes/snark/ubergine/images" />
<copy file="../../../installer/resources/themes/console/dark/images/header.png"
todir="build/standalone-resources/.resources/themes/snark/ubergine/images" />
<mkdir dir="build/standalone-resources/.resources/js" />
<copy file="../../routerconsole/jsp/js/ajax.js" todir="build/standalone-resources/.resources/js" />
<zip destfile="../i2psnark.war" update="true" duplicate="preserve" >
<fileset dir="build/standalone-resources" />
</zip>
</target>
<target name="standalone_prep" depends="standalone_jar, standalone_war">
<delete dir="./dist" />
<mkdir dir="./dist" />
<copy file="../launch-i2psnark" todir="./dist/" />
<mkdir dir="./dist/contexts" />
<!-- todo put in root context.xml -->
<mkdir dir="./dist/docroot" />
<!-- todo put in index.html to redirect -->
<mkdir dir="./dist/webapps" />
<copy file="../i2psnark.war" tofile="./dist/webapps/i2psnark.war" />
<mkdir dir="./dist/lib" />
<copy file="./build/i2psnark.jar" tofile="./dist/lib/i2psnark.jar" />
<copy file="../../../core/java/build/i2p.jar" tofile="./dist/lib/i2p.jar" />
<copy file="../../jetty/jettylib/commons-el.jar" tofile="./dist/lib/commons-el.jar" />
<copy file="../../jetty/jettylib/commons-logging.jar" tofile="./dist/lib/commons-logging.jar" />
<copy file="../../jetty/jettylib/javax.servlet.jar" tofile="./dist/lib/javax.servlet.jar" />
<copy file="../../jetty/jettylib/org.mortbay.jetty.jar" tofile="./dist/lib/org.mortbay.jetty.jar" />
<copy file="../../jetty/jettylib/jasper-runtime.jar" tofile="./dist/lib/jasper-runtime.jar" />
<copy file="../../ministreaming/java/build/mstreaming.jar" tofile="./dist/lib/mstreaming.jar" />
<copy file="../../streaming/java/build/streaming.jar" tofile="./dist/lib/streaming.jar" />
<copy file="../jetty-i2psnark.xml" tofile="./dist/jetty-i2psnark.xml" />
<copy file="./build/i2psnark-standalone.jar" tofile="./dist/i2psnark.jar" />
<copy file="../readme-standalone.txt" tofile="./dist/readme.txt" />
<!-- temp so announces work -->
<copy file="../../../installer/resources/hosts.txt" tofile="./dist/hosts.txt" />
<copy todir="./dist/licenses" >
<fileset dir="../../../licenses" includes="LICENSE-GPLv2.txt, ABOUT-Jetty.html" />
</copy>
<mkdir dir="./dist/logs" />
<zip destfile="i2psnark-standalone.zip">
<zipfileset dir="./dist/" prefix="i2psnark/" />
</zip>
</target>
<target name="clean">

View File

@ -388,6 +388,8 @@ public class SnarkManager implements CompleteListener {
}
private int getStartupDelayMinutes() {
if (!_context.isRouterContext())
return 0;
try {
return Integer.parseInt(_config.getProperty(PROP_STARTUP_DELAY));
} catch (NumberFormatException nfe) {
@ -675,7 +677,8 @@ public class SnarkManager implements CompleteListener {
* @return String[] -- Array of all the themes found, non-null, unsorted
*/
public String[] getThemes() {
String[] themes;
String[] themes;
if (_context.isRouterContext()) {
// "docs/themes/snark/"
File dir = new File(_context.getBaseDir(), "docs/themes/snark");
FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } };
@ -689,8 +692,10 @@ public class SnarkManager implements CompleteListener {
} else {
themes = new String[0];
}
// return the map.
return themes;
} else {
themes = new String[] { "light", "ubergine", "vanilla" };
}
return themes;
}
@ -815,7 +820,7 @@ public class SnarkManager implements CompleteListener {
}
}
if (startDelay != null){
if (startDelay != null && _context.isRouterContext()) {
int minutes = _util.getStartupDelay();
try { minutes = Integer.parseInt(startDelay.trim()); } catch (NumberFormatException nfe) {}
if ( minutes != _util.getStartupDelay()) {

View File

@ -0,0 +1,62 @@
package org.klomp.snark.standalone;
import java.io.File;
import net.i2p.I2PAppContext;
import net.i2p.apps.systray.UrlLauncher;
import net.i2p.jetty.JettyStart;
/**
* @since moved from ../web and fixed in 0.9.27
*/
public class RunStandalone {
private final JettyStart _jettyStart;
private final I2PAppContext _context;
private int _port = 8002;
private String _host = "127.0.0.1";
private RunStandalone(String args[]) throws Exception {
_context = I2PAppContext.getGlobalContext();
File base = _context.getBaseDir();
File xml = new File(base, "jetty-i2psnark.xml");
_jettyStart = new JettyStart(_context, null, new String[] { xml.getAbsolutePath() } );
if (args.length > 1) {
_port = Integer.parseInt(args[1]);
}
if (args.length > 0) {
_host = args[0];
}
}
/**
* Usage: RunStandalone [host [port]] (but must match what's in the jetty-i2psnark.xml file)
*/
public static void main(String args[]) {
try {
RunStandalone runner = new RunStandalone(args);
runner.start();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void start() {
try {
_jettyStart.startup();
String url = "http://" + _host + ':' + _port + "/i2psnark/";
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {}
UrlLauncher launch = new UrlLauncher(_context, null, new String[] { url } );
launch.startup();
} catch (Exception e) {
e.printStackTrace();
}
}
public void stop() {
_jettyStart.shutdown(null);
}
}

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.text.Collator;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -192,7 +191,10 @@ public class I2PSnarkServlet extends BasicServlet {
return;
}
_themePath = "/themes/snark/" + _manager.getTheme() + '/';
if (_context.isRouterContext())
_themePath = "/themes/snark/" + _manager.getTheme() + '/';
else
_themePath = _contextPath + WARBASE + "themes/snark/" + _manager.getTheme() + '/';
_imgPath = _themePath + "images/";
req.setCharacterEncoding("UTF-8");
@ -285,8 +287,9 @@ public class I2PSnarkServlet extends BasicServlet {
if (!isConfigure) {
delay = _manager.getRefreshDelaySeconds();
if (delay > 0) {
String jsPfx = _context.isRouterContext() ? "" : ".resources";
//out.write("<meta http-equiv=\"refresh\" content=\"" + delay + ";/i2psnark/" + peerString + "\">\n");
out.write("<script src=\"/js/ajax.js\" type=\"text/javascript\"></script>\n" +
out.write("<script src=\"" + jsPfx + "/js/ajax.js\" type=\"text/javascript\"></script>\n" +
"<script type=\"text/javascript\">\n" +
"var failMessage = \"<div class=\\\"routerdown\\\"><b>" + _t("Router is down") + "<\\/b><\\/div>\";\n" +
"function requestAjax1() { ajax(\"" + _contextPath + "/.ajax/xhr1.html" +
@ -324,17 +327,19 @@ public class I2PSnarkServlet extends BasicServlet {
out.write(_t("I2PSnark"));
else
out.write(_contextName);
out.write("</a> <a href=\"http://forum.i2p/viewforum.php?f=21\" class=\"snarkRefresh\" target=\"_blank\">");
out.write(_t("Forum"));
out.write("</a>\n");
sortedTrackers = _manager.getSortedTrackers();
for (Tracker t : sortedTrackers) {
if (t.baseURL == null || !t.baseURL.startsWith("http"))
continue;
if (_manager.util().isKnownOpenTracker(t.announceURL))
continue;
out.write(" <a href=\"" + t.baseURL + "\" class=\"snarkRefresh\" target=\"_blank\">" + t.name + "</a>");
if (_context.isRouterContext()) {
out.write("<a href=\"http://forum.i2p/viewforum.php?f=21\" class=\"snarkRefresh\" target=\"_blank\">");
out.write(_t("Forum"));
out.write("</a>\n");
for (Tracker t : sortedTrackers) {
if (t.baseURL == null || !t.baseURL.startsWith("http"))
continue;
if (_manager.util().isKnownOpenTracker(t.announceURL))
continue;
out.write(" <a href=\"" + t.baseURL + "\" class=\"snarkRefresh\" target=\"_blank\">" + t.name + "</a>");
}
}
}
out.write("</div>\n");
@ -2229,12 +2234,14 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("</select><br>" +
"<tr><td>");
out.write(_t("Startup delay"));
out.write(": <td><input name=\"startupDelay\" size=\"4\" class=\"r\" value=\"" + _manager.util().getStartupDelay() + "\"> ");
out.write(_t("minutes"));
out.write("<br>\n" +
if (_context.isRouterContext()) {
out.write(_t("Startup delay"));
out.write(": <td><input name=\"startupDelay\" size=\"4\" class=\"r\" value=\"" + _manager.util().getStartupDelay() + "\"> ");
out.write(_t("minutes"));
out.write("<br>\n" +
"<tr><td>");
"<tr><td>");
}
out.write(_t("Page size"));
out.write(": <td><input name=\"pageSize\" size=\"4\" maxlength=\"6\" class=\"r\" value=\"" + _manager.getPageSize() + "\"> ");
out.write(_t("torrents"));

View File

@ -1,61 +0,0 @@
package org.klomp.snark.web;
import java.io.File;
import net.i2p.I2PAppContext;
import net.i2p.util.FileUtil;
//import org.eclipse.jetty.server.Server;
/**
* @deprecated does not work
*/
@Deprecated
public class RunStandalone {
/****
static {
System.setProperty("org.mortbay.http.Version.paranoid", "true");
System.setProperty("org.mortbay.xml.XmlParser.NotValidating", "true");
}
****/
private RunStandalone(String args[]) {}
public static void main(String args[]) {
RunStandalone runner = new RunStandalone(args);
runner.start();
}
public void start() {
throw new RuntimeException("unsupported");
/****
File workDir = new File(I2PAppContext.getGlobalContext().getTempDir(), "jetty-work");
boolean workDirRemoved = FileUtil.rmdir(workDir, false);
if (!workDirRemoved)
System.err.println("ERROR: Unable to remove Jetty temporary work directory");
boolean workDirCreated = workDir.mkdirs();
if (!workDirCreated)
System.err.println("ERROR: Unable to create Jetty temporary work directory");
try {
_server = new Server("jetty-i2psnark.xml");
// just blow up NPE if we don't have a context
(_server.getContexts()[0]).setTempDirectory(workDir);
_server.start();
} catch (Exception e) {
e.printStackTrace();
}
****/
}
public void stop() {
throw new RuntimeException("unsupported");
/****
try {
_server.stop();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
****/
}
}