forked from I2P_Developers/i2p.i2p
Util: Consolidate FileFilters
This commit is contained in:
@ -19,6 +19,7 @@ import net.i2p.data.Base64;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
import net.i2p.util.SecureDirectory;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
|
||||
@ -98,13 +99,11 @@ class PersistNews {
|
||||
Log log = ctx.logManager().getLog(PersistNews.class);
|
||||
File dir = new File(ctx.getConfigDir(), DIR);
|
||||
List<NewsEntry> rv = new ArrayList<NewsEntry>();
|
||||
File[] files = dir.listFiles();
|
||||
File[] files = dir.listFiles(new FileSuffixFilter(PFX, SFX));
|
||||
if (files == null)
|
||||
return rv;
|
||||
for (File file : files) {
|
||||
String name = file.getName();
|
||||
if (!name.startsWith(PFX) || !name.endsWith(SFX))
|
||||
continue;
|
||||
XMLParser parser = new XMLParser(ctx);
|
||||
InputStream in = null;
|
||||
Node node;
|
||||
|
@ -30,6 +30,7 @@ import net.i2p.router.startup.LoadClientAppsJob;
|
||||
import net.i2p.router.update.ConsoleUpdateManager;
|
||||
import static net.i2p.update.UpdateType.*;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.Log;
|
||||
@ -415,13 +416,14 @@ public class PluginStarter implements Runnable {
|
||||
File consoleDir = new File(pluginDir, "console");
|
||||
Properties wprops = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
|
||||
File webappDir = new File(consoleDir, "webapps");
|
||||
String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance());
|
||||
if (fileNames != null) {
|
||||
File files[] = webappDir.listFiles(RouterConsoleRunner.WAR_FILTER);
|
||||
if (files != null) {
|
||||
if(!pluginWars.containsKey(appName))
|
||||
pluginWars.put(appName, new ConcurrentHashSet<String>());
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
try {
|
||||
String warName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
|
||||
String warName = files[i].getName();
|
||||
warName = warName.substring(0, warName.lastIndexOf(".war"));
|
||||
//log.error("Found webapp: " + warName);
|
||||
// check for duplicates in $I2P
|
||||
if (Arrays.asList(STANDARD_WEBAPPS).contains(warName)) {
|
||||
@ -432,12 +434,12 @@ public class PluginStarter implements Runnable {
|
||||
if (! "false".equals(enabled)) {
|
||||
if (log.shouldLog(Log.INFO))
|
||||
log.info("Starting webapp: " + warName);
|
||||
String path = new File(webappDir, fileNames[i]).getCanonicalPath();
|
||||
String path = files[i].getCanonicalPath();
|
||||
WebAppStarter.startWebApp(ctx, server, warName, path);
|
||||
pluginWars.get(appName).add(warName);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
log.error("Error resolving '" + fileNames[i] + "' in '" + webappDir, ioe);
|
||||
log.error("Error resolving '" + files[i] + "' in '" + webappDir, ioe);
|
||||
}
|
||||
}
|
||||
// Check for iconfile in plugin.properties
|
||||
@ -460,23 +462,21 @@ public class PluginStarter implements Runnable {
|
||||
// later in the classpath.
|
||||
File localeDir = new File(pluginDir, "console/locale");
|
||||
if (localeDir.exists() && localeDir.isDirectory()) {
|
||||
File[] files = localeDir.listFiles();
|
||||
File[] files = localeDir.listFiles(new FileSuffixFilter(".jar"));
|
||||
if (files != null) {
|
||||
boolean added = false;
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File f = files[i];
|
||||
if (f.getName().endsWith(".jar")) {
|
||||
try {
|
||||
addPath(f.toURI().toURL());
|
||||
log.info("INFO: Adding translation plugin to classpath: " + f);
|
||||
added = true;
|
||||
} catch (ClassCastException e) {
|
||||
log.logAlways(Log.WARN, "Java version: " + System.getProperty("java.version") +
|
||||
" does not support adding classpath element: " + f +
|
||||
" for plugin " + appName);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Plugin " + appName + " bad classpath element: " + f, e);
|
||||
}
|
||||
try {
|
||||
addPath(f.toURI().toURL());
|
||||
log.info("INFO: Adding translation plugin to classpath: " + f);
|
||||
added = true;
|
||||
} catch (ClassCastException e) {
|
||||
log.logAlways(Log.WARN, "Java version: " + System.getProperty("java.version") +
|
||||
" does not support adding classpath element: " + f +
|
||||
" for plugin " + appName);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("Plugin " + appName + " bad classpath element: " + f, e);
|
||||
}
|
||||
}
|
||||
if (added)
|
||||
|
@ -2,7 +2,7 @@ package net.i2p.router.web;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -35,6 +35,7 @@ import net.i2p.router.app.RouterApp;
|
||||
import net.i2p.router.news.NewsManager;
|
||||
import net.i2p.router.update.ConsoleUpdateManager;
|
||||
import net.i2p.util.Addresses;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.PortMapper;
|
||||
@ -140,6 +141,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
private static final String THREAD_NAME = "RouterConsole Jetty";
|
||||
public static final String PROP_DTG_ENABLED = "desktopgui.enabled";
|
||||
static final String PROP_ALLOWED_HOSTS = "routerconsole.allowedHosts";
|
||||
/** @since 0.9.34 */
|
||||
static final FileFilter WAR_FILTER = new WarFilenameFilter();
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -763,10 +766,11 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
List<String> notStarted = new ArrayList<String>();
|
||||
if (_server.isRunning()) {
|
||||
File dir = new File(_webAppsDir);
|
||||
String fileNames[] = dir.list(WarFilenameFilter.instance());
|
||||
if (fileNames != null) {
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
String appName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
|
||||
File files[] = dir.listFiles(WAR_FILTER);
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
String appName = files[i].getName();
|
||||
appName = appName.substring(0, appName.lastIndexOf(".war"));
|
||||
String enabled = props.getProperty(PREFIX + appName + ENABLED);
|
||||
if (appName.equals("addressbook")) {
|
||||
// addressbook.war is now empty, thread is started by SusiDNS
|
||||
@ -776,7 +780,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
}
|
||||
} else if (! "false".equals(enabled)) {
|
||||
try {
|
||||
String path = new File(dir, fileNames[i]).getCanonicalPath();
|
||||
String path = files[i].getCanonicalPath();
|
||||
WebAppStarter.startWebApp(_context, chColl, appName, path);
|
||||
if (enabled == null) {
|
||||
// do this so configclients.jsp knows about all apps from reading the config
|
||||
@ -1115,11 +1119,13 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
|
||||
}
|
||||
|
||||
static class WarFilenameFilter implements FilenameFilter {
|
||||
private static final WarFilenameFilter _filter = new WarFilenameFilter();
|
||||
public static WarFilenameFilter instance() { return _filter; }
|
||||
public boolean accept(File dir, String name) {
|
||||
return (name != null) && (name.endsWith(".war") && !name.equals(ROUTERCONSOLE + ".war"));
|
||||
private static class WarFilenameFilter extends FileSuffixFilter {
|
||||
private static final String RCWAR = ROUTERCONSOLE + ".war";
|
||||
|
||||
public WarFilenameFilter() { super(".war"); }
|
||||
|
||||
public boolean accept(File file) {
|
||||
return super.accept(file) && !file.getName().equals(RCWAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
|
||||
import org.apache.tomcat.SimpleInstanceManager;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
@ -180,11 +181,11 @@ public class WebAppConfiguration implements Configuration {
|
||||
// Java 9 - assume everything in lib/ is in the classpath
|
||||
// except addressbook.jar
|
||||
File libDir = new File(ctx.getBaseDir(), "lib");
|
||||
File[] files = libDir.listFiles();
|
||||
File[] files = libDir.listFiles(new FileSuffixFilter(".jar"));
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
String name = files[i].getName();
|
||||
if (name.endsWith(".jar") && !name.equals("addressbook.jar"))
|
||||
if (!name.equals("addressbook.jar"))
|
||||
rv.add(files[i].toURI());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
import net.i2p.router.crypto.FamilyKeyCrypto;
|
||||
import net.i2p.router.web.HelperBase;
|
||||
|
||||
@ -37,17 +38,11 @@ public class CertHelper extends HelperBase {
|
||||
// i2ptunnel clients
|
||||
File tunnelDir = new File(_context.getConfigDir(), I2PTUNNEL_DIR);
|
||||
boolean hasTunnels = false;
|
||||
File[] tunnels = tunnelDir.listFiles();
|
||||
File[] tunnels = tunnelDir.listFiles(new FileSuffixFilter("i2ptunnel-", ".local.crt"));
|
||||
if (tunnels != null) {
|
||||
for (int i = 0; i < tunnels.length; i++) {
|
||||
File f = tunnels[i];
|
||||
if (!f.isFile())
|
||||
continue;
|
||||
String name = f.getName();
|
||||
if (!name.endsWith(".local.crt"))
|
||||
continue;
|
||||
if (!name.startsWith("i2ptunnel-"))
|
||||
continue;
|
||||
String b32 = name.substring(10, name.length() - 10);
|
||||
output(_t("I2PTunnel") + ' ' + b32, f);
|
||||
hasTunnels = true;
|
||||
@ -59,17 +54,10 @@ public class CertHelper extends HelperBase {
|
||||
// SAM
|
||||
tunnelDir = new File(dir, SAM_DIR);
|
||||
hasTunnels = false;
|
||||
tunnels = tunnelDir.listFiles();
|
||||
tunnels = tunnelDir.listFiles(new FileSuffixFilter("sam-", ".local.crt"));
|
||||
if (tunnels != null) {
|
||||
for (int i = 0; i < tunnels.length; i++) {
|
||||
File f = tunnels[i];
|
||||
if (!f.isFile())
|
||||
continue;
|
||||
String name = f.getName();
|
||||
if (!name.endsWith(".local.crt"))
|
||||
continue;
|
||||
if (!name.startsWith("sam-"))
|
||||
continue;
|
||||
output("SAM", f);
|
||||
hasTunnels = true;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import net.i2p.crypto.SHA256Generator;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.web.HelperBase;
|
||||
import net.i2p.router.web.PluginStarter;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
@ -97,13 +98,12 @@ public class FileDumpHelper extends HelperBase {
|
||||
}
|
||||
|
||||
private static void dumpDir(StringBuilder buf, File dir, String suffix) {
|
||||
File[] files = dir.listFiles();
|
||||
File[] files = dir.listFiles(new FileSuffixFilter(suffix));
|
||||
if (files == null)
|
||||
return;
|
||||
Arrays.sort(files);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].getName().endsWith(suffix))
|
||||
dumpFile(buf, files[i]);
|
||||
dumpFile(buf, files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user