From 665239fd37aba272b86b769766b42eb60ff49560 Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Sat, 26 Dec 2020 08:11:00 -0500 Subject: [PATCH] Router: Move continents.txt file into jar Move core resources directory to be consistent with the other subsystems --- build.xml | 2 -- core/java/build.xml | 7 +++++-- .../i2p/util => }/resources/dohservers.txt | 0 router/java/build.xml | 6 +++++- .../java/src/net/i2p/router/time/Zones.java | 19 +++++++------------ .../resources/continents.txt | 0 6 files changed, 17 insertions(+), 17 deletions(-) rename core/{java/src/net/i2p/util => }/resources/dohservers.txt (100%) rename {installer => router}/resources/continents.txt (100%) diff --git a/build.xml b/build.xml index 3a36de8b64..bf27fd748d 100644 --- a/build.xml +++ b/build.xml @@ -1827,7 +1827,6 @@ <copy file="build/addressbook.war" todir="pkg-temp/webapps/" /> <!-- decapitalized the file in 0.7.8 --> <copy file="installer/resources/countries.txt" todir="pkg-temp/geoip/" /> - <copy file="installer/resources/continents.txt" todir="pkg-temp/geoip/" /> <!-- <copy file="installer/resources/public-suffix-list.txt" todir="pkg-temp/geoip/" /> --> @@ -1846,7 +1845,6 @@ <!-- GeoIP files --> <target name="prepgeoupdate" depends="prepgeoupdate-unlesspkg" > <copy file="installer/resources/countries.txt" todir="pkg-temp/geoip/" /> - <copy file="installer/resources/continents.txt" todir="pkg-temp/geoip/" /> <!-- <copy file="installer/resources/public-suffix-list.txt" todir="pkg-temp/geoip/" /> --> diff --git a/core/java/build.xml b/core/java/build.xml index 895a93f978..217e5ae971 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -109,9 +109,12 @@ <target name="jar" depends="compile, bundle, jarUpToDate, listChangedFiles" unless="jar.uptodate" > <!-- set if unset --> <property name="workspace.changes.tr" value="" /> + <mkdir dir="build/obj/net/i2p/util/resources" /> + <copy todir="build/obj/net/i2p/util/resources" > + <fileset dir="../resources" /> + </copy> <jar destfile="./build/i2p.jar" > - <fileset dir="./build/obj" includes="**/*.class" /> - <fileset dir="./src" includes="net/i2p/util/resources/*" /> + <fileset dir="./build/obj" /> <!-- the getopt translation files --> <fileset dir="src" includes="${translation.includes}" /> <manifest> diff --git a/core/java/src/net/i2p/util/resources/dohservers.txt b/core/resources/dohservers.txt similarity index 100% rename from core/java/src/net/i2p/util/resources/dohservers.txt rename to core/resources/dohservers.txt diff --git a/router/java/build.xml b/router/java/build.xml index 0e1c3db210..8ff50285ea 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -70,7 +70,11 @@ <target name="jar" depends="compile, bundle, jarUpToDate, listChangedFiles" unless="jar.uptodate" > <!-- set if unset --> <property name="workspace.changes.tr" value="" /> - <jar destfile="./build/router.jar" basedir="./build/obj" includes="**/*.class" > + <mkdir dir="build/obj/net/i2p/router/util/resources" /> + <copy todir="build/obj/net/i2p/router/util/resources" > + <fileset dir="../resources" /> + </copy> + <jar destfile="./build/router.jar" basedir="./build/obj" > <manifest> <!-- so people with very old wrapper.config files will still work with Jetty 6 --> <attribute name="${manifest.classpath.name}" value="i2p.jar addressbook.jar jetty-i2p.jar jetty-rewrite-handler.jar jetty-start.jar jetty-util.jar" /> diff --git a/router/java/src/net/i2p/router/time/Zones.java b/router/java/src/net/i2p/router/time/Zones.java index d04c67408e..ad13c6e5d9 100644 --- a/router/java/src/net/i2p/router/time/Zones.java +++ b/router/java/src/net/i2p/router/time/Zones.java @@ -3,7 +3,7 @@ package net.i2p.router.time; import java.io.BufferedReader; import java.io.IOException; import java.io.File; -import java.io.FileInputStream; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Locale; @@ -87,20 +87,14 @@ class Zones { * ref: http://dev.maxmind.com/geoip/legacy/codes/country_continent/ */ private void readContinentFile() { - String geoDir = _context.getProperty(GeoIP.PROP_GEOIP_DIR, GeoIP.GEOIP_DIR_DEFAULT); - File geoFile = new File(geoDir); - if (!geoFile.isAbsolute()) - geoFile = new File(_context.getBaseDir(), geoDir); - geoFile = new File(geoFile, CONTINENT_FILE_DEFAULT); - if (!geoFile.exists()) { - //if (_log.shouldWarn()) - // _log.warn("Continent file not found: " + geoFile.getAbsolutePath()); + InputStream is = Zones.class.getResourceAsStream("/net/i2p/router/util/resources/" + CONTINENT_FILE_DEFAULT); + if (is == null) { + System.out.println("Continent file not found"); return; } BufferedReader br = null; try { - br = new BufferedReader(new InputStreamReader( - new FileInputStream(geoFile), "UTF-8")); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; while ((line = br.readLine()) != null) { try { @@ -118,8 +112,9 @@ class Zones { } catch (IndexOutOfBoundsException ioobe) {} } } catch (IOException ioe) { - System.out.println("Error reading the continent file " + geoFile.getAbsolutePath()); + System.out.println("Error reading the continent file"); } finally { + try { is.close(); } catch (IOException ioe) {} if (br != null) try { br.close(); } catch (IOException ioe) {} } } diff --git a/installer/resources/continents.txt b/router/resources/continents.txt similarity index 100% rename from installer/resources/continents.txt rename to router/resources/continents.txt -- GitLab