Console: Move initial news to jar

This commit is contained in:
zzz
2020-12-26 10:13:49 -05:00
parent eeaf6f3514
commit a45084cfc3
4 changed files with 23 additions and 11 deletions

View File

@ -140,6 +140,10 @@
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_nl_NL.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_nl.properties" />
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_pt_BR.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_pt.properties" />
<copy file="src/edu/internet2/ndt/locale/Tcpbw100_msgs_ru_RU.properties" tofile="build/obj/edu/internet2/ndt/locale/Tcpbw100_msgs_ru.properties" />
<mkdir dir="build/obj/net/i2p/router/news/resources" />
<copy todir="build/obj/net/i2p/router/news/resources" >
<fileset dir="../resources-news" />
</copy>
<jar destfile="./build/routerconsole.jar" basedir="./build/obj" excludes="net/i2p/router/web/helpers/**/* net/i2p/router/web/servlets/**/* net/i2p/router/web/resources/**/*">
<manifest>
<!-- DTG added in 0.8.4, not in the classpath for very old installs, before we changed wrapper.config to specify * -->
@ -160,7 +164,11 @@
<!-- newsxml.jar only (subset of routerconsole, no war) for Android -->
<target name="newsxmljar" depends="compileNewsOnly" >
<jar destfile="./build/newsxml.jar" basedir="./build/obj" includes="**/*.class">
<mkdir dir="build/obj/net/i2p/router/news/resources" />
<copy todir="build/obj/net/i2p/router/news/resources" >
<fileset dir="../resources-news" />
</copy>
<jar destfile="./build/newsxml.jar" basedir="./build/obj" includes="net/i2p/router/news/**/*" >
</jar>
</target>

View File

@ -1,7 +1,7 @@
package net.i2p.router.news;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
import java.text.DateFormat;
@ -190,12 +190,17 @@ public class NewsManager implements ClientApp {
}
private List<NewsEntry> parseInitialNews() {
File file = new File(_context.getBaseDir(), "docs/initialNews/initialNews.xml");
InputStream is = NewsManager.class.getResourceAsStream("/net/i2p/router/news/resources/docs/initialNews/initialNews.xml");
if (is == null) {
if (_log.shouldWarn())
_log.warn("failed to load initial news");
return Collections.emptyList();
}
Reader reader = null;
try {
char[] buf = new char[512];
StringBuilder out = new StringBuilder(2048);
reader = new TranslateReader(_context, BUNDLE_NAME, new FileInputStream(file));
reader = new TranslateReader(_context, BUNDLE_NAME, is);
int len;
while((len = reader.read(buf)) > 0) {
out.append(buf, 0, len);
@ -206,14 +211,17 @@ public class NewsManager implements ClientApp {
rv.get(0).updated = _context.clock().now();
} else {
if (_log.shouldWarn())
_log.warn("failed to load " + file);
_log.warn("failed to load initial news");
}
return rv;
} catch (IOException ioe) {
if (_log.shouldWarn())
_log.warn("failed to load " + file, ioe);
_log.warn("failed to load initial news", ioe);
return Collections.emptyList();
} finally {
try {
is.close();
} catch (IOException foo) {}
try {
if (reader != null)
reader.close();

View File

@ -1650,11 +1650,8 @@
<delete dir="./pkg-mavencentral" />
</target>
<!-- initialNews.xml files and GeoIP files -->
<!-- GeoIP file -->
<target name="prepConsoleDocs" depends="prepgeoupdate" >
<copy todir="pkg-temp/docs/initialNews/">
<fileset dir="installer/resources/initialNews/" />
</copy>
</target>
<target name="consoleDocs" depends="deletepkg-temp, prepConsoleDocs">
@ -3071,7 +3068,6 @@
<copy file="apps/addressbook/myhosts.txt" todir="pkg-temp/addressbook/" />
<!-- config.txt is in installer/resources/portable -->
<mkdir dir="pkg-temp/docs" />
<copy file="installer/resources/initialNews/initialNews.xml" tofile="pkg-temp/docs/news.xml" overwrite="true" />
<copy file="installer/resources/startconsole.html" todir="pkg-temp/docs/" />
<copy file="installer/resources/start.ico" todir="pkg-temp/docs/" />
<copy file="installer/resources/console.ico" todir="pkg-temp/docs/" />