keep track of generated default module order, so it stays unique

add comments
This commit is contained in:
adam-m 2012-09-21 15:12:49 -04:00
parent 7f7b8213b7
commit 6ef2834317
4 changed files with 44 additions and 19 deletions

View File

@ -81,6 +81,8 @@ public class IngestManager {
private final IngestMonitor ingestMonitor = new IngestMonitor(); private final IngestMonitor ingestMonitor = new IngestMonitor();
//module loader //module loader
private IngestModuleLoader moduleLoader = null; private IngestModuleLoader moduleLoader = null;
//property file name id for the module
final static String MODULE_PROPERTIES = "ingest";
/** /**
* Possible events about ingest modules Event listeners can get the event * Possible events about ingest modules Event listeners can get the event

View File

@ -78,6 +78,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.openide.filesystems.Repository; import org.openide.filesystems.Repository;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
/** /**
* Class responsible for discovery and loading ingest modules specified in * Class responsible for discovery and loading ingest modules specified in
@ -114,13 +115,15 @@ public final class IngestModuleLoader {
private final List<IngestModuleAbstractFile> filePipeline; private final List<IngestModuleAbstractFile> filePipeline;
private final List<IngestModuleImage> imagePipeline; private final List<IngestModuleImage> imagePipeline;
private static final Logger logger = Logger.getLogger(IngestModuleLoader.class.getName()); private static final Logger logger = Logger.getLogger(IngestModuleLoader.class.getName());
//for default module order if not specified/invalid
private int currentLast = 0;
private ClassLoader classLoader; private ClassLoader classLoader;
private PropertyChangeSupport pcs; private PropertyChangeSupport pcs;
private static final String ENCODING = "UTF-8"; private static final String ENCODING = "UTF-8";
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
private SimpleDateFormat dateFormatter; private SimpleDateFormat dateFormatter;
//used to specify default unique module order of autodiscovered modules
//if not specified
private int numModDiscovered = 0;
private static String CUR_MODULES_DISCOVERED_SETTING = "curModulesDiscovered";
//events supported //events supported
enum Event { enum Event {
@ -133,6 +136,17 @@ public final class IngestModuleLoader {
filePipeline = new ArrayList<IngestModuleAbstractFile>(); filePipeline = new ArrayList<IngestModuleAbstractFile>();
imagePipeline = new ArrayList<IngestModuleImage>(); imagePipeline = new ArrayList<IngestModuleImage>();
dateFormatter = new SimpleDateFormat(DATE_FORMAT); dateFormatter = new SimpleDateFormat(DATE_FORMAT);
String numModDiscoveredStr = ModuleSettings.getConfigSetting(IngestManager.MODULE_PROPERTIES, CUR_MODULES_DISCOVERED_SETTING);
if (numModDiscoveredStr != null) {
try {
numModDiscovered = Integer.valueOf(numModDiscoveredStr);
} catch (NumberFormatException e) {
numModDiscovered = 0;
logger.log(Level.WARNING, "Could not parse numModDiscovered setting, defaulting to 0", e);
}
}
pcs = new PropertyChangeSupport(this); pcs = new PropertyChangeSupport(this);
registerModulesChange(); registerModulesChange();
} }
@ -580,8 +594,10 @@ public final class IngestModuleLoader {
/** /**
* Set a new order of the module * Set a new order of the module
*
* @param pipeLineType pipeline type where the module to reorder is present * @param pipeLineType pipeline type where the module to reorder is present
* @param moduleLocation loaded module name (location), fully qualified class path * @param moduleLocation loaded module name (location), fully qualified
* class path
* @param newOrder new order to set * @param newOrder new order to set
*/ */
void setModuleOrder(XmlPipelineRaw.PIPELINE_TYPE pipeLineType, String moduleLocation, int newOrder) throws IngestModuleLoaderException { void setModuleOrder(XmlPipelineRaw.PIPELINE_TYPE pipeLineType, String moduleLocation, int newOrder) throws IngestModuleLoaderException {
@ -601,10 +617,13 @@ public final class IngestModuleLoader {
XmlModuleRaw modRaw = new XmlModuleRaw(); XmlModuleRaw modRaw = new XmlModuleRaw();
modRaw.arguments = ""; //default, no arguments modRaw.arguments = ""; //default, no arguments
modRaw.location = moduleLocation; modRaw.location = moduleLocation;
modRaw.order = Integer.MAX_VALUE - (currentLast++); //add to end modRaw.order = Integer.MAX_VALUE - (numModDiscovered++); //add to end
modRaw.type = XmlModuleRaw.MODULE_TYPE.PLUGIN.toString(); modRaw.type = XmlModuleRaw.MODULE_TYPE.PLUGIN.toString();
modRaw.valid = false; //to be validated modRaw.valid = false; //to be validated
//save the current numModDiscovered
ModuleSettings.setConfigSetting(IngestManager.MODULE_PROPERTIES, CUR_MODULES_DISCOVERED_SETTING, Integer.toString(numModDiscovered));
//find the pipeline of that type //find the pipeline of that type
XmlPipelineRaw pipeline = null; XmlPipelineRaw pipeline = null;
for (XmlPipelineRaw rawP : this.pipelinesXML) { for (XmlPipelineRaw rawP : this.pipelinesXML) {
@ -958,8 +977,11 @@ public final class IngestModuleLoader {
try { try {
module.order = Integer.parseInt(moduleOrder); module.order = Integer.parseInt(moduleOrder);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.log(Level.WARNING, "Invalid module order, need integer: " + moduleOrder); logger.log(Level.WARNING, "Invalid module order, need integer: " + moduleOrder + ", adding to end of the list");
module.order = Integer.MAX_VALUE - (currentLast++); module.order = Integer.MAX_VALUE - (numModDiscovered++);
//save the current numModDiscovered
ModuleSettings.setConfigSetting(IngestManager.MODULE_PROPERTIES, CUR_MODULES_DISCOVERED_SETTING, Integer.toString(numModDiscovered));
} }
module.type = moduleType; module.type = moduleType;
pipelineRaw.modules.add(module); pipelineRaw.modules.add(module);

View File

@ -108,7 +108,7 @@ public class IngestServices {
* Gets a configuration setting for a module * Gets a configuration setting for a module
* @param moduleName moduleName identifier unique to that module * @param moduleName moduleName identifier unique to that module
* @param settingName setting name to retrieve * @param settingName setting name to retrieve
* @return setting value for the module / setting name * @return setting value for the module / setting name, or null if not found
*/ */
public String getConfigSetting(String moduleName, String settingName) { public String getConfigSetting(String moduleName, String settingName) {
return ModuleSettings.getConfigSetting(moduleName, settingName); return ModuleSettings.getConfigSetting(moduleName, settingName);

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Contains only the modules that ship with Autopsy --> <!-- Default initial pipeline_config.xml
Contains only the core ingest modules that ship with Autopsy -->
<PIPELINE_CONFIG> <PIPELINE_CONFIG>
<PIPELINE type="FileAnalysis"> <PIPELINE type="FileAnalysis">
<MODULE order="1" type="plugin" location="org.sleuthkit.autopsy.hashdatabase.HashDbIngestModule" arguments="" /> <MODULE order="1" type="plugin" location="org.sleuthkit.autopsy.hashdatabase.HashDbIngestModule" arguments="" />