Compare commits

..

26 Commits

Author SHA1 Message Date
zzz
2c91155f73 Warn about SSL config, no migration yet 2025-10-16 10:33:21 -04:00
zzz
7cf2ff0642 context migration fixup for very old context files 2025-10-15 16:26:43 -04:00
zzz
cd29a14b5c Update to Jetty 12.0.28, add jars 2025-10-15 12:17:37 -04:00
zzz
9b6ffb8f6b eepsite migration part 3 - contexts 2025-10-15 11:37:45 -04:00
zzz
64260b5991 eepsite migration part 2 - jetty-gzip.xml 2025-10-11 15:12:05 -04:00
zzz
32ee72d58d Fix eepsite start via /configclients 2025-10-11 12:37:48 -04:00
zzz
6676eac9d1 eepsite migration part 1 - jetty.xml 2025-10-11 12:23:00 -04:00
zzz
dcb714d09f Debian: Increase min ant version 2025-10-11 09:44:32 -04:00
zzz
c40d3e0b0f Enforce min java version in build.xml 2025-10-11 09:44:32 -04:00
zzz
d77b394a1a Bump Java version in docs and installer configs 2025-10-11 09:44:32 -04:00
zzz
708c61eb78 Add custom error pages
Adapted from I2PPlus with permission, same license.
2025-10-11 09:44:32 -04:00
zzz
e8e193ec73 Custom error pages 2025-10-11 09:44:32 -04:00
zzz
03b2d0f6fb Prep for custom error pages 2025-10-11 09:44:32 -04:00
zzz
ccbb891be4 Add custom error handler for base context
Disable showing context and stack trace
2025-10-11 09:44:32 -04:00
zzz
631960aea2 Replace deprecated method 2025-10-11 09:44:31 -04:00
zzz
02ba7a6027 Fix XI2PLocationFilter for Jetty 12
- Fix IPv6 address comparison
- Add port to header
- Log tweaks
- Cleanups
2025-10-11 09:44:31 -04:00
zzz
1fd2d8e3a7 Convert CGI context to FCGI 2025-10-11 09:44:31 -04:00
zzz
7a3111a8ec Update license for Jetty 12 2025-10-11 09:44:31 -04:00
zzz
90ad471cc2 Use non-versioned file for slf4j2 jar 2025-10-11 09:44:31 -04:00
zzz
19b63cddde Debian updates for Trixie
untested
remove tomcat8 references
debian-alt TODO
2025-10-11 09:44:31 -04:00
zzz
8cc08863af Logging Javadoc 2025-10-11 09:44:30 -04:00
zzz
3d33557ebb Eepsite: Fix config class names, fix webapp environment 2025-10-11 09:44:30 -04:00
zzz
f8c6955121 Snark standalone 2025-10-11 09:44:30 -04:00
zzz
c635788cb4 Remove test log message 2025-10-11 09:44:30 -04:00
zzz
d089b15f71 Eepsite on Jetty 12
TODO:

- FCGI
- Migration
- Stop/restart
- Webapp deployer
2025-10-11 09:44:30 -04:00
zzz
01129f0218 Conversion to Jetty 12 / Java 17
- Basic console (tested)
- SSL console (tested)
- Auth (tested)
- Debug logging (tested)
- Console request log (tested)

- I2PControl separate port (untested)
- Eepsite request log (untested)

TODO:

- Eepsites + migration
- Debian with or without Jetty 12
- Snark standalone
- Tomcat upgrade
- Checkin jetty jars
- Cleanups
2025-10-11 09:44:10 -04:00
44 changed files with 383 additions and 124 deletions

View File

@@ -260,7 +260,7 @@ Applications:
Zxing 3.4.1:
See licenses/LICENSE-Apache2.0.txt
Jetty 12.0.21 (jetty-*.jar, org.mortbay.*.jar):
Jetty 12.0.28 (jetty-*.jar, org.mortbay.*.jar):
(not included in most distribution packages, except for jetty-i2p.jar)
See licenses/NOTICE-Jetty.txt
See licenses/LICENSE-Jetty.txt

View File

@@ -17,7 +17,7 @@
<property name="jetty.branch" value="stable-9" />
<property name="jetty.base" value="jetty-home-${jetty.ver}" />
<property name="jetty.sha1" value="6c8b834d313bcac2e6a2e42ebaf34a249887162a" />
<property name="jetty.sha1" value="bb0ce8db30693fa4c1450983434029e7441b8d4f" />
<property name="jetty.filename" value="${jetty.base}.zip" />
<property name="jetty.url" value="https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/${jetty.ver}/${jetty.filename}" />
<property name="verified.filename" value="verified.txt" />

View File

@@ -81,7 +81,19 @@ public class JettyStart implements ClientApp {
_args = args;
_jettys = new ArrayList<LifeCycle>(args.length);
_context = context;
parseArgs(args);
// To prevent console WebAppClassLoader from interfering
// by hiding jetty classses
// when an eepsite is started from /configclients
ClassLoader cl1 = ClassLoader.getSystemClassLoader();
ClassLoader cl2 = Thread.currentThread().getContextClassLoader();
if (cl1 != cl2)
Thread.currentThread().setContextClassLoader(cl1);
try {
parseArgs(args);
} finally {
if (cl1 != cl2)
Thread.currentThread().setContextClassLoader(cl2);
}
_state = INITIALIZED;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -11,10 +11,7 @@
# Note: Include the trailing slash! Don't surround the URL in quotes!
javasedocs.url=https://docs.oracle.com/javase/8/docs/api/
javaeedocs.url=https://docs.oracle.com/javaee/7/api/
# The following link is for 9.4.x
#jettydocs.url=http://download.eclipse.org/jetty/stable-9/apidocs/
# last one available on archive.eclipse.org
jettydocs.url=https://archive.eclipse.org/jetty/9.3.9.v20160517/apidocs/
jettydocs.url=https://javadoc.jetty.org/jetty-12/index.html
wrapperdocs.url=https://wrapper.tanukisoftware.com/jdoc/
# these are only for unit test javadocs
i2pdocs.url=http://docs.i2p-projekt.de/javadoc/

View File

@@ -15,7 +15,7 @@
and checksum in apps/jetty/build.xml
and versions in gradle.properties and apps/jetty/build.gradle
-->
<property name="jetty.ver" value="12.0.21" />
<property name="jetty.ver" value="12.0.28" />
<property name="tomcat.ver" value="9.0.107" />
<!-- You probably don't want to change anything from here down -->

View File

@@ -1,15 +1,3 @@
i2p (2.10.0-2~bionic+1) bionic; urgency=medium
* New upstream version 2.10.0
-- idk <hankhill19580@gmail.com> Sun, 14 Sep 2025 12:12:12 +0000
i2p (2.10.0-1~bionic+1) bionic; urgency=medium
* New upstream version 2.10.0
-- idk <hankhill19580@gmail.com> Wed, 10 Sep 2025 12:12:12 +0000
i2p (2.8.2-1~bionic+1) bionic; urgency=medium
* New upstream version 2.8.2

View File

@@ -1,9 +1,3 @@
i2p (2.10.0-2~focal+1) focal; urgency=medium
* New upstream version 2.10.0
-- idk <hankhill19580@gmail.com> Sun, 14 Sep 2025 12:12:12 +0000
i2p (2.10.0-1~focal+1) focal; urgency=medium
* New upstream version 2.10.0

View File

@@ -63,66 +63,60 @@ abstract class MigrateJetty {
private static boolean _wasChecked;
private static boolean _hasLatestJetty;
private static final String OLD_CLASS = "org.mortbay.jetty.Server";
private static final String OLD_CLASS_6 = "org.mortbay.start.Main";
private static final String NEW_CLASS = "net.i2p.jetty.JettyStart";
private static final String TEST_CLASS = "org.eclipse.jetty.server.Server";
private static final String BACKUP_SUFFIX = ".jetty6";
private static final String BACKUP_SUFFIX_8 = ".jetty8";
private static final String TEST_CLASS = "org.eclipse.jetty.util.component.Environment";
private static final String BACKUP_SUFFIX_9 = ".jetty9-id";
private static final String BACKUP_SUFFIX_9_2 = ".jetty93-save";
private static final String JETTY_TEMPLATE_DIR = "eepsite-jetty9";
private static final String JETTY_TEMPLATE_PKGDIR = "eepsite";
private static final String BASE_CONTEXT = "contexts/base-context.xml";
private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
private static final String PROP_JETTY9_MIGRATED = "router.startup.jetty9.migrated";
private static final String PROP_JETTY9_MIGRATED_2 = "router.startup.jetty-ids.migrated";
private static final String PROP_JETTY12_MIGRATED = "router.startup.jetty12.migrated";
/**
* For each entry in apps, if the main class is an old Jetty class,
* migrate it to the new Jetty class, and update the Jetty config files.
*/
public static void migrate(RouterContext ctx, List<ClientAppConfig> apps) {
if (ctx.getBooleanProperty(PROP_JETTY9_MIGRATED_2))
if (ctx.getBooleanProperty(PROP_JETTY12_MIGRATED))
return;
String installed = ctx.getProperty("router.firstVersion");
if (installed != null && VersionComparator.comp(installed, "2.9.0") >= 0) {
ctx.router().saveConfig(PROP_JETTY9_MIGRATED_2, "true");
if (installed != null && VersionComparator.comp(installed, "2.11.0") >= 0) {
ctx.router().saveConfig(PROP_JETTY12_MIGRATED, "true");
return;
}
boolean migrated2 = ctx.getBooleanProperty(PROP_JETTY9_MIGRATED_2);
if (!migrated2 && installed != null && VersionComparator.comp(installed, "2.9.0") >= 0) {
ctx.router().saveConfig(PROP_JETTY9_MIGRATED_2, "true");
migrated2 = true;
}
boolean migrated1 = ctx.getBooleanProperty(PROP_JETTY9_MIGRATED);
if (!migrated1 && installed != null && VersionComparator.comp(installed, "0.9.30") >= 0) {
ctx.router().saveConfig(PROP_JETTY9_MIGRATED, "true");
migrated1 = true;
}
boolean migration2success = false;
boolean migration3success = false;
for (int i = 0; i < apps.size(); i++) {
ClientAppConfig app = apps.get(i);
String client;
String client = "client application " + i + " [" + app.clientName +
"] from Jetty 9 to Jetty 12";
String backupSuffix;
if (migrated1) {
if (app.className.equals(NEW_CLASS)) {
client = "client application " + i + " [" + app.clientName +
"] to fix DTDs and duplicate ids";
backupSuffix = BACKUP_SUFFIX_9;
} else {
if (!app.className.equals(NEW_CLASS)) {
continue;
}
} else {
if (app.className.equals(NEW_CLASS)) {
client = "client application " + i + " [" + app.clientName +
"] from Jetty 7/8 to Jetty 9";
backupSuffix = BACKUP_SUFFIX_8;
} else if (app.className.equals(OLD_CLASS) || app.className.equals(OLD_CLASS_6)) {
client = "client application " + i + " [" + app.clientName +
"] from Jetty 5/6 " + app.className +
" to Jetty 9 " + NEW_CLASS;
backupSuffix = BACKUP_SUFFIX;
} else {
continue;
}
// migration from 0.9.29 or earlier (2017-02-27) straight to 2.11.0 or later
System.err.println("WARNING: Unable to migrate " + client +
", delete client or uninstall and reinstall I2P");
app.disabled = true;
continue;
}
if (!hasLatestJetty()) {
System.err.println("WARNING: Jetty 7 unavailable, cannot migrate " + client);
System.err.println("WARNING: Jetty 12 unavailable, cannot migrate " + client);
continue;
}
if (app.args == null)
@@ -132,15 +126,6 @@ abstract class MigrateJetty {
if (args.length == 0)
continue;
if (!migrated1) {
// migration from 0.9.29 or earlier (2017-02-27) straight to 2.9.0 or later
System.err.println("WARNING: Unable to migrate " + client +
", delete client or uninstall and reinstall I2P");
app.disabled = true;
continue;
}
System.err.println("Migrating " + client);
// migration 2 below here
@@ -148,46 +133,150 @@ abstract class MigrateJetty {
// Note that JettyStart automatically copies and adds jetty-gzip.xml
// to the command line, not in the arg list here,
// but it does not contain anything we need to fix.
for (String xml : args) {
if (!xml.endsWith(".xml"))
continue;
File xmlFile = new File(xml);
if (!xmlFile.isAbsolute())
xmlFile = new File(ctx.getAppDir(), xml);
if (!xmlFile.exists()) {
System.err.println("WARNING: XML file " + xmlFile +
" not found, cannot migrate " + client);
continue;
if (!migrated2) {
backupSuffix = BACKUP_SUFFIX_9;
for (String xml : args) {
if (!xml.endsWith(".xml"))
continue;
File xmlFile = new File(xml);
if (!xmlFile.isAbsolute())
xmlFile = new File(ctx.getAppDir(), xml);
if (!xmlFile.exists()) {
System.err.println("WARNING: XML file " + xmlFile +
" not found, cannot migrate " + client);
continue;
}
boolean ok = backupFile(xmlFile, backupSuffix);
if (!ok) {
System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
", cannot migrate " + client);
continue;
}
File tmpFile = new File(xmlFile + ".tmp");
try {
WorkingDir.migrateFileXML(xmlFile, tmpFile,
"<Ref id=", "<Ref refid=",
"/jetty/configure.dtd", "/jetty/configure_9_3.dtd");
ok = FileUtil.rename(tmpFile, xmlFile);
if (!ok)
throw new IOException();
} catch (IOException ioe) {
System.err.println("WARNING: Failed to migrate XML file " + xmlFile +
", cannot migrate " + client);
ioe.printStackTrace();
continue;
}
migration2success = true;
}
boolean ok = backupFile(xmlFile, backupSuffix);
if (!ok) {
System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
", cannot migrate " + client);
continue;
}
File tmpFile = new File(xmlFile + ".tmp");
try {
WorkingDir.migrateFileXML(xmlFile, tmpFile,
"<Ref id=", "<Ref refid=",
"/jetty/configure.dtd", "/jetty/configure_9_3.dtd");
ok = FileUtil.rename(tmpFile, xmlFile);
if (!ok)
throw new IOException();
} catch (IOException ioe) {
System.err.println("WARNING: Failed to migrate XML file " + xmlFile +
", cannot migrate " + client);
continue;
}
migration2success = true;
}
// migration 3 below here
if (true) {
backupSuffix = BACKUP_SUFFIX_9_2;
for (String xml : args) {
if (!xml.endsWith(".xml"))
continue;
File xmlFile = new File(xml);
if (!xmlFile.isAbsolute())
xmlFile = new File(ctx.getAppDir(), xml);
if (!xmlFile.exists()) {
System.err.println("WARNING: XML file " + xmlFile +
" not found, cannot migrate " + client);
continue;
}
boolean ok = backupFile(xmlFile, backupSuffix);
if (!ok) {
System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
", cannot migrate " + client);
continue;
}
File tmpFile = new File(xmlFile + ".tmp");
try {
WorkingDir.migrateFileXML(xmlFile, tmpFile,
"/jetty/configure_9_3.dtd", "/jetty/configure_10_0.dtd",
"This configuration supports Jetty 9.", "This configuration supports Jetty 12");
ok = FileUtil.rename(tmpFile, xmlFile);
if (!ok)
throw new IOException();
if (xmlFile.getName().equals("jetty-ssl.xml")) {
System.err.println("WARNING: SSL migration to Jetty 12 is not yet implemented.");
System.err.println("Cannot fully migrate " + client);
System.err.println("Remove jetty-ssl.xml from the command line for the client");
System.err.println("See http://zzz.i2p/topics/3702 for help on migrating SSL");
continue;
}
migrate9to12XML(xmlFile, tmpFile);
ok = FileUtil.rename(tmpFile, xmlFile);
if (!ok)
throw new IOException();
} catch (IOException ioe) {
System.err.println("WARNING: Failed to migrate XML file " + xmlFile +
", cannot migrate " + client);
ioe.printStackTrace();
continue;
}
migration3success = true;
}
// jetty-gzip.xml
File xmlFile = new File(args[0]);
if (!xmlFile.isAbsolute())
xmlFile = new File(ctx.getAppDir(), args[0]);
File base = xmlFile.getParentFile();
xmlFile = new File(base, "jetty-gzip.xml");
if (xmlFile.exists()) {
boolean ok = backupFile(xmlFile, backupSuffix);
if (ok)
ok = WorkingDir.copyFile(new File(ctx.getBaseDir(), "eepsite-jetty9.3/jetty-gzip.xml"), xmlFile);
if (ok)
System.err.println("Modified " + xmlFile);
else
System.err.println("WARNING: Failed to backup up XML file " + xmlFile +
", cannot migrate " + client);
}
// contexts/base-context.xml
xmlFile = new File(base, "contexts/base-context.xml");
if (xmlFile.exists()) {
try {
boolean ok = backupFile(xmlFile, backupSuffix);
if (ok) {
File tmpFile = new File(xmlFile + ".tmp");
migrateBaseContextXML(xmlFile, tmpFile);
ok = FileUtil.rename(tmpFile, xmlFile);
if (!ok)
throw new IOException();
System.err.println("Modified " + xmlFile);
}
} catch (IOException ioe) {
System.err.println("WARNING: Failed to migrate XML file " + xmlFile +
", cannot migrate " + client);
ioe.printStackTrace();
}
}
// contexts/cgi-context.xml
xmlFile = new File(base, "contexts/cgi-context.xml");
if (xmlFile.exists()) {
File save = new File(xmlFile + BACKUP_SUFFIX_9_2);
FileUtil.rename(xmlFile, save);
System.err.println("WARNING: CGI not supported on Jetty 12 and has been disabled.");
System.err.println(xmlFile + " moved to " + save);
System.err.println("See http://zzz.i2p/topics/3701 for help on migrating to FCGI if required");
}
}
System.err.println("Migrated " + client);
}
if (migration2success)
if (!migrated2 && migration2success)
ctx.router().saveConfig(PROP_JETTY9_MIGRATED_2, "true");
if (migration3success)
ctx.router().saveConfig(PROP_JETTY12_MIGRATED, "true");
}
/** do we have Jetty 7/8/9? */
/** do we have Jetty 12? */
private static boolean hasLatestJetty() {
if (!_wasChecked) {
try {
@@ -199,15 +288,6 @@ abstract class MigrateJetty {
return _hasLatestJetty;
}
/**
* Backup a file
* @return success
* @since Jetty 7
*/
private static boolean backupFile(File from) {
return backupFile(from, BACKUP_SUFFIX);
}
/**
* Backup a file with given suffix
* @return success
@@ -227,28 +307,215 @@ abstract class MigrateJetty {
return rv;
}
/**
* Backup a file and migrate new XML
* @return success
* @since Jetty 7
*/
private static boolean backupAndMigrateFile(File templateDir, File toDir, String filename, String fromString, String toString) {
File to = new File(toDir, filename);
boolean rv = backupFile(to);
boolean rv2 = WorkingDir.migrateJettyXml(templateDir, toDir, filename, fromString, toString);
return rv && rv2;
}
private static final String M1 = "<Set name=\"handler\"";
private static final String R1 =
" <Set name=\"defaultHandler\">\n" +
" <New id=\"DefaultHandler\" class=\"org.eclipse.jetty.server.handler.DefaultHandler\">\n" +
" <Set name=\"showContexts\">false</Set>\n" +
" </New>\n" +
" </Set>\n" +
" <Set name=\"handler\">\n" +
" <New id=\"Contexts\" class=\"org.eclipse.jetty.server.handler.ContextHandlerCollection\"/>\n" +
" </Set>\n";
private static final String R2 =
" <!-- Setup ee8 environment -->\n" +
" <!-- First call needed to initialize the class and prevent NPE -->\n" +
" <Call class=\"org.eclipse.jetty.util.component.Environment\" name=\"get\" >\n" +
" <Arg>foo</Arg>\n" +
" </Call>\n" +
" <New id=\"EBuilder\" class=\"org.eclipse.jetty.xml.EnvironmentBuilder\" >\n" +
" <Arg>ee8</Arg>\n" +
" </New>\n" +
" <Ref refid=\"EBuilder\">\n" +
" <Call id=\"Environment\" name=\"build\" />\n" +
" </Ref>\n" +
" <Ref refid=\"Environment\">\n" +
" <Call class=\"org.eclipse.jetty.util.Attributes\" name=\"setAttribute\">\n" +
" <Arg>contextHandlerClass</Arg>\n" +
" <Arg>org.eclipse.jetty.ee8.webapp.WebAppContext</Arg>\n" +
" </Call>\n" +
" </Ref>\n" +
" <Call class=\"org.eclipse.jetty.util.component.Environment\" name=\"set\" >\n" +
" <Arg>\n" +
" <Ref refid=\"Environment\"/>\n" +
" </Arg>\n" +
" </Call>\n";
private static final String D1 = "<Call name=\"setContextAttribute\"";
private static final String M3 = "<New class=\"org.eclipse.jetty.deploy.providers.WebAppProvider\"";
private static final String R3 =
" <New class=\"org.eclipse.jetty.deploy.providers.ContextProvider\">\n" +
" <Set name=\"EnvironmentName\">ee8</Set>\n" +
" <Set name=\"parentLoaderPriority\">true</Set>\n" +
" <Set name=\"configurationClasses\" property=\"jetty.deploy.configurationClasses\" />\n";
private static final String M4 = "<New id=\"WebAppProvider\" class=\"org.eclipse.jetty.deploy.providers.WebAppProvider\"";
private static final String R4 =
" <New id=\"WebAppProvider\" class=\"org.eclipse.jetty.deploy.providers.ContextProvider\">\n" +
" <Set name=\"EnvironmentName\">ee8</Set>\n" +
" <Set name=\"parentLoaderPriority\">true</Set>\n" +
" <Set name=\"configurationClasses\" property=\"jetty.deploy.configurationClasses\" />\n";
private static final String M5 = "<Set name=\"parentLoaderPriority\">false</Set>";
private static final String R5 = "<Set name=\"parentLoaderPriority\">true</Set>";
private static final String D2 = "<Ref refid=\"RequestLog\">";
/**
* Backup a file and copy new
* @return success
* @since Jetty 7
* Copy over a XML file with modifications.
* Will overwrite any existing newFile.
*
* @throws IOException on all errors
* @since 0.9.68
*/
private static boolean backupAndCopyFile(File templateDir, File toDir, String filename) {
File to = new File(toDir, filename);
boolean rv = backupFile(to);
File from = new File(templateDir, filename);
boolean rv2 = WorkingDir.copyFile(from, to);
return rv && rv2;
private static void migrate9to12XML(File oldFile, File newFile) throws IOException {
FileInputStream in = null;
PrintWriter out = null;
try {
in = new FileInputStream(oldFile);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(newFile), "UTF-8")));
String s = null;
while ((s = DataHelper.readLine(in)) != null) {
// readLine() doesn't strip \r
if (s.endsWith("\r"))
s = s.substring(0, s.length() - 1);
if (s.contains(M1)) {
// strip to second </Set>
String t;
int i = 0;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("</Set") && i++ > 0)
break;
}
out.println(R1);
out.println(R2);
} else if(s.contains(M3)) {
// strip to line before <Set name="monitoredDirName">
String t;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("\"monitoredDirName\""))
break;
}
out.println(R3);
out.println(t);
} else if(s.contains(M4)) {
// strip to line before <Set name="monitoredDirName">
String t;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("\"monitoredDirName\""))
break;
}
out.println(R4);
out.println(t);
} else if(s.contains(M5)) {
out.println(R5);
} else if(s.contains(D1)) {
// strip to </Call>
String t;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("</Call"))
break;
}
} else if(s.contains(D2)) {
// strip this and </Ref>, keep lines between
String t;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("</Ref"))
break;
out.println(t);
}
} else {
out.println(s);
}
}
out.println("<!-- Modified by I2P Jetty 12 migration script -->");
System.err.println("Copied " + oldFile + " with modifications");
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
if (out != null) out.close();
}
}
private static final String M10 = "jetty/configure.dtd";
private static final String R10 = "<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"http://www.eclipse.org/jetty/configure_10_0.dtd\">";
private static final String M11 = "org.eclipse.jetty.servlet.ServletContextHandler";
private static final String R11 = "<Configure class=\"org.eclipse.jetty.ee8.servlet.ServletContextHandler\">";
private static final String M12 = "<Set name=\"resourceBase\"";
private static final String R12 =
" <Set name=\"baseResourceAsString\"><Ref refid=\"baseroot\" /></Set>\n" +
" <Call name=\"setErrorHandler\">\n" +
" <Arg>\n" +
" <New class=\"net.i2p.servlet.I2PErrorHandler\">\n" +
" <Arg><Ref refid=\"baseroot\" /></Arg>\n" +
" </New>\n" +
" </Arg>\n" +
" </Call>";
private static final String M13 = "<Call name=\"setMimeTypes\"";
private static final String M14 = "org.eclipse.jetty.servlet.DefaultServlet";
private static final String R14 = "net.i2p.servlet.I2PDefaultServlet";
/**
* Copy over a XML file with modifications.
* Will overwrite any existing newFile.
*
* @throws IOException on all errors
* @since 0.9.68
*/
private static void migrateBaseContextXML(File oldFile, File newFile) throws IOException {
FileInputStream in = null;
PrintWriter out = null;
try {
in = new FileInputStream(oldFile);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(newFile), "UTF-8")));
String s = null;
while ((s = DataHelper.readLine(in)) != null) {
// readLine() doesn't strip \r
if (s.endsWith("\r"))
s = s.substring(0, s.length() - 1);
if (s.contains(M10)) {
out.println(R10);
} else if (s.contains(M11)) {
out.println(R11);
} else if (s.contains(M12)) {
int gt = s.indexOf('>');
int lt = s.lastIndexOf('<');
if (gt >= 0 && lt >= 0 && lt > gt) {
String rb = s.substring(gt + 1, lt).trim();
out.println(" <New id=\"baseroot\" class=\"java.lang.String\">");
out.println(" <Arg>" + rb + "</Arg>");
out.println(" </New>");
out.println(R12);
}
} else if (s.contains(M13)) {
// strip to matching </Call>
int i = 1;
String t;
while ((t = DataHelper.readLine(in)) != null) {
if (t.contains("<Call"))
i++;
if (t.contains("</Call"))
i--;
if (i == 0)
break;
}
} else if (s.contains(M14)) {
out.println(s.replace(M14, R14));
} else {
out.println(s);
}
}
out.println("<!-- Modified by I2P Jetty 12 migration script -->");
System.err.println("Copied " + oldFile + " with modifications");
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
if (out != null) out.close();
}
}
}

View File

@@ -246,7 +246,8 @@ public class WorkingDir {
success &= migrateJettyXml(oldEep, newEep, "jetty.xml", "./eepsite/", newPath);
success &= migrateJettyXml(oldEep, newEep, "jetty-ssl.xml", "./eepsite/", newPath);
success &= migrateJettyXml(oldEep, newEep, "contexts/base-context.xml", "./eepsite/", newPath);
success &= migrateJettyXml(oldEep, newEep, "contexts/cgi-context.xml", "./eepsite/", newPath);
// FCGI requires additional libs
//success &= migrateJettyXml(oldEep, newEep, "contexts/cgi-context.xml", "./eepsite/", newPath);
success &= migrateClientsConfig(oldDirf, dirf);
// for later news.xml updates (we don't copy initialNews.xml over anymore)
success &= (new SecureDirectory(dirf, "docs")).mkdir();