Commit 8edd03a4 authored by js9's avatar js9

Initial changes to how plugins are tried based on filenames:

* Replaced "Extensions" and "Filenames" with "FilePatterns" glob
* Removed unused "specifiedFilenames" flag in databse XML files
* Added "filePatternsStrict" flag for later use
* Added "opensWholeDirectory" flag for later use
* Updated all database *.xml and *info files with new usage
* Updated ITAPS cmake script for new usage (untested)
* Removed deprecation warning for old plugins; compile-time compatibility
  is now broken for these old plugins, so no runtime check is necessary



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@9289 18c085ea-50e0-402c-830e-de6fd14e8384
parent aa7407de
......@@ -39,6 +39,9 @@
# Made all messages 'STATUS', otherwise they appear as errors when using
# CMake gui.
#
# Jeremy Meredith, Mon Dec 28 16:05:49 EST 2009
# File extensions no longer exist; switched to file patterns.
#
#****************************************************************************/
FUNCTION(ITAPS_ADD_IMPLEMENTATION IMPL)
......@@ -88,12 +91,12 @@ FUNCTION(ITAPS_INCLUDE_DIRECTORIES IMPL)
ENDFOREACH(X)
ENDFUNCTION(ITAPS_INCLUDE_DIRECTORIES IMPL)
FUNCTION(ITAPS_FILE_EXTENSIONS IMPL)
FUNCTION(ITAPS_FILE_PATTERNS IMPL)
ITAPS_ADD_IMPLEMENTATION(${IMPL})
FOREACH(X ${ARGN})
ADD_UNIQUE_LIST_VALUE(ITAPS_${IMPL}_FILE_EXTENSIONS "ITAPS ${IMPL} file extensions" ${X})
ADD_UNIQUE_LIST_VALUE(ITAPS_${IMPL}_FILE_PATTERNS "ITAPS ${IMPL} file patterns" ${X})
ENDFOREACH(X)
ENDFUNCTION(ITAPS_FILE_EXTENSIONS IMPL)
ENDFUNCTION(ITAPS_FILE_PATTERNS IMPL)
FUNCTION(ITAPS_LINK_LIBRARIES IMPL)
ITAPS_ADD_IMPLEMENTATION(${IMPL})
......@@ -111,7 +114,7 @@ ENDFUNCTION(ITAPS_LINK_DIRECTORIES IMPL)
#
# Creates new ITAPS plugins for the implementations that have been defined via
# calls to ITAPS_INCLUDE_DIRECTORIES, ITAPS_FILE_EXTENSIONS, ITAPS_LINK_LIBRARIES,
# calls to ITAPS_INCLUDE_DIRECTORIES, ITAPS_FILE_PATTERNS, ITAPS_LINK_LIBRARIES,
# ITAPS_LINK_DIRECTORIES.
#
# Sets up cache variables:
......@@ -125,7 +128,7 @@ FUNCTION(CONFIGURE_ITAPS)
MESSAGE(STATUS "-- ${IMPL}")
# Just print info for now
#MESSAGE(STATUS " includes =${ITAPS_${IMPL}_INCLUDE_DIR}")
#MESSAGE(STATUS " extensions=${ITAPS_${IMPL}_FILE_EXTENSIONS}")
#MESSAGE(STATUS " patterns =${ITAPS_${IMPL}_FILE_PATTERNS}")
#MESSAGE(STATUS " libraries =${ITAPS_${IMPL}_LIB}}")
#MESSAGE(STATUS " libdirs =${ITAPS_${IMPL}_LIBRARY_DIR}}")
......@@ -159,16 +162,16 @@ FUNCTION(CONFIGURE_ITAPS)
# Assemble some extension code.
SET(defExt "")
SET(allExts ${ITAPS_${IMPL}_FILE_EXTENSIONS})
SET(allExts ${ITAPS_${IMPL}_FILE_PATTERNS})
FOREACH(ext ${allExts})
SET(defExt "${defExt}defaultExtensions.push_back(\"${ext}\");")
SET(defExt "${defExt}defaultPatterns.push_back(\"${ext}\");")
ENDFOREACH(ext)
STRING(LENGTH "${defExt}" SLEN)
STRING(REPLACE "ITAPS_C" ITAPS_${IMPL} NEWCONTENTS "${FILECONTENTS}")
IF(${F} MATCHES "ITAPS_CPluginInfo.C")
IF(${SLEN} GREATER 0)
STRING(REPLACE "defaultExtensions.push_back(\"cub\");" "${defExt}" EXTCONTENTS "${NEWCONTENTS}")
STRING(REPLACE "defaultPatterns.push_back(\"cub\");" "${defExt}" EXTCONTENTS "${NEWCONTENTS}")
SET(NEWCONTENTS "${EXTCONTENTS}")
UNSET(EXTCONTENTS)
ENDIF(${SLEN} GREATER 0)
......
......@@ -111,6 +111,11 @@ class DatabasePluginManager;
// Jeremy Meredith, Thu Aug 7 16:22:24 EDT 2008
// Use const char* for the functions likely to return a string literal.
//
// Jeremy Meredith, Mon Dec 28 15:08:45 EST 2009
// Changed file matching behavior to use patterns and a strictness
// flag. Made pure virtual so plugin developers will know to re-run info
// xml code generation tool. Removed deprecated versions of this code.
//
// ****************************************************************************
class PLUGIN_API GeneralDatabasePluginInfo
......@@ -122,10 +127,9 @@ class PLUGIN_API GeneralDatabasePluginInfo
virtual const char *GetID() const = 0;
virtual bool EnabledByDefault() const { return true; }
virtual bool HasWriter() const { return false; }
virtual std::vector<std::string> GetDfltExtsFromGen() const
{ std::vector<std::string> rv; return rv; };
virtual std::vector<std::string> GetFilenamesFromGen() const
{ std::vector<std::string> rv; return rv; };
virtual std::vector<std::string> GetDefaultFilePatterns() const = 0;
virtual bool AreDefaultFilePatternsStrict() const { return false; }
virtual bool OpensWholeDirectory() const { return false; }
};
class PLUGIN_API CommonDatabasePluginInfo : public virtual GeneralDatabasePluginInfo
......@@ -135,10 +139,6 @@ class PLUGIN_API CommonDatabasePluginInfo : public virtual GeneralDatabasePlugin
virtual ~CommonDatabasePluginInfo();
virtual DatabaseType GetDatabaseType() = 0;
virtual std::vector<std::string> GetDefaultExtensions()
{ std::vector<std::string> rv; return rv; };
virtual std::vector<std::string> GetFilenames()
{ std::vector<std::string> rv; return rv; };
virtual avtDatabase *SetupDatabase(const char * const *list,
int nList, int nBlock) = 0;
......
......@@ -45,6 +45,7 @@
#include <PluginBroadcaster.h>
#include <DebugStream.h>
#include <InvalidPluginException.h>
#include <Utility.h>
#include <visitstream.h>
#include <visit-config.h>
#include <string>
......@@ -145,6 +146,9 @@ DatabasePluginManager::Initialize(const PluginCategory pluginCategory,
// Creation: Thu Jun 18 11:30:15 PDT 2009
//
// Modifications:
// Jeremy Meredith, Tue Dec 29 11:40:42 EST 2009
// Replaced "Extensions" and "Filenames" with "FilePatterns". Added
// filePatternsStrict and opensWholeDirectory.
//
// ****************************************************************************
......@@ -154,8 +158,9 @@ DatabasePluginManager::BroadcastGeneralInfo(PluginBroadcaster *broadcaster)
PluginManager::BroadcastGeneralInfo(broadcaster);
broadcaster->BroadcastBoolVector(haswriter);
broadcaster->BroadcastStringVectorVector(extensions);
broadcaster->BroadcastStringVectorVector(filenames);
broadcaster->BroadcastStringVectorVector(filePatterns);
broadcaster->BroadcastBoolVector(filePatternsAreStrict);
broadcaster->BroadcastBoolVector(opensWholeDirectory);
}
// ****************************************************************************
......@@ -251,6 +256,11 @@ DatabasePluginManager::GetCommonPluginInfo(const string &id)
//
// Mark C. Miller, Mon Aug 6 13:36:16 PDT 2007
// Added code to update extensions and filenames.
//
// Jeremy Meredith, Tue Dec 29 11:40:42 EST 2009
// Replaced "Extensions" and "Filenames" with "FilePatterns". Added
// filePatternsStrict and opensWholeDirectory.
//
// ****************************************************************************
bool
......@@ -287,8 +297,9 @@ DatabasePluginManager::LoadGeneralPluginInfo()
versions .push_back(info->GetVersion());
enabled .push_back(info->EnabledByDefault());
haswriter .push_back(info->HasWriter());
extensions.push_back(info->GetDfltExtsFromGen());
filenames .push_back(info->GetFilenamesFromGen());
filePatterns.push_back(info->GetDefaultFilePatterns());
filePatternsAreStrict.push_back(info->AreDefaultFilePatternsStrict());
opensWholeDirectory.push_back(info->OpensWholeDirectory());
delete info;
return true;
}
......@@ -450,52 +461,83 @@ DatabasePluginManager::PluginHasWriter(const string &id)
}
// ****************************************************************************
// Method: DatabasePluginManager::PluginDefaultExtensions
// Method: DatabasePluginManager::PluginFilePatterns
//
// Purpose: Returns file extensions for a plugin
// Purpose:
// Returns file name patterns for a plugin
//
// Arguments:
// id the plugin id
//
// Programmer: Mark C. Miller
// Creation: August 3, 2007
// Programmer: Jeremy Meredith
// Creation: December 29, 2009
//
// ****************************************************************************
vector<string>
DatabasePluginManager::PluginFileExtensions(const string &id)
DatabasePluginManager::PluginFilePatterns(const string &id)
{
vector<string> retval;
if(allindexmap.find(id) != allindexmap.end())
{
int index = allindexmap[id];
if(index < names.size())
retval = extensions[index];
retval = filePatterns[index];
}
return retval;
}
// ****************************************************************************
// Method: DatabasePluginManager::PluginDefaultFilenames
// Method: DatabasePluginManager::PluginFilePatternsAreStrict
//
// Purpose: Returns filenames for a plugin
// Purpose:
// Returns true for a plugin filename patterns are intended
// to be interpreted strictly.
//
// Arguments:
// id the plugin id
//
// Programmer: Mark C. Miller
// Creation: August 3, 2007
// Programmer: Jeremy Meredith
// Creation: December 29, 2009
//
// ****************************************************************************
vector<string>
DatabasePluginManager::PluginFilenames(const string &id)
bool
DatabasePluginManager::PluginFilePatternsAreStrict(const string &id)
{
vector<string> retval;
bool retval = false;
if(allindexmap.find(id) != allindexmap.end())
{
int index = allindexmap[id];
if(index < names.size())
retval = filePatternsAreStrict[index];
}
return retval;
}
// ****************************************************************************
// Method: DatabasePluginManager::PluginOpensWholeDirectory
//
// Purpose:
// Returns true if a plugin is intended to be handed a whole
// directory to open, not just a single file.
//
// Arguments:
// id the plugin id
//
// Programmer: Jeremy Meredith
// Creation: December 29, 2009
//
// ****************************************************************************
bool
DatabasePluginManager::PluginOpensWholeDirectory(const string &id)
{
bool retval = false;
if(allindexmap.find(id) != allindexmap.end())
{
int index = allindexmap[id];
if(index < names.size())
retval = filenames[index];
retval = opensWholeDirectory[index];
}
return retval;
......@@ -519,6 +561,12 @@ DatabasePluginManager::PluginFilenames(const string &id)
// Kathleen Bonnell, Tue Sep 11 08:56:42 PDT 2007
// Replace 'and' with '&&' for compilation on windows.
//
// Jeremy Meredith, Tue Dec 29 11:42:47 EST 2009
// Replaced simple extension and full-filename matching with single
// comprehensive file pattern match. Broke compile compatibility with old
// plugins as part of this change, so removed code to check for deprecated
// *info generated code.
//
// ****************************************************************************
vector<string>
DatabasePluginManager::GetMatchingPluginIds(const char *filename, bool searchAll)
......@@ -551,87 +599,16 @@ DatabasePluginManager::GetMatchingPluginIds(const char *filename, bool searchAll
for (i=0; i<iMax; i++)
{
string id = searchAll ? GetAllID(i) : GetEnabledID(i);
CommonDatabasePluginInfo *info = GetCommonPluginInfo(id);
vector<string> patterns = PluginFilePatterns(id);
int nPatterns = patterns.size();
bool foundMatch = false;
//
// Check to see if there is an extension that matches.
// Look first using GeneralPluginInfo via PluginFileExtensions
// call (the newer way). If that yields nothing, then try the
// CommonPluginInfo via the GetDefaultExtensions (the old way).
//
int j;
vector<string> extensions = PluginFileExtensions(id);
int nextensions = extensions.size();
bool shouldIssueObsoletePluginWarning = false;
if (nextensions == 0)
{
if (info)
extensions = info->GetDefaultExtensions();
nextensions = extensions.size();
shouldIssueObsoletePluginWarning = nextensions > 0;
}
for (j=0; j<nextensions && !foundMatch; j++)
for (int j=0; j<nPatterns && !foundMatch; j++)
{
string ext = extensions[j];
if (ext[0] != '.')
{
ext = string(".") + extensions[j];
}
#if defined(_WIN32)
if (file.length() >= ext.length())
{
string fileExt(file.substr(file.length() - ext.length()));
foundMatch = (_stricmp(fileExt.c_str(), ext.c_str()) == 0);
}
#else
if (file.length() >= ext.length() &&
file.substr(file.length() - ext.length()) == ext)
{
foundMatch = true;
}
#endif
}
//
// Check to see if there is an exact name that matches.
// Again, get filenames first from GeneralPluginInfo and,
// failing that, then the older way (from CommonPluginInfo).
//
vector<string> filenames = PluginFilenames(id);
int nfiles = filenames.size();
if (nfiles == 0)
{
if (info)
filenames = info->GetFilenames();
nfiles = filenames.size();
shouldIssueObsoletePluginWarning |= nfiles > 0;
}
for (j=0; j<nfiles && !foundMatch; j++)
{
if (filenames[j] == file)
{
foundMatch = true;
}
foundMatch |= WildcardStringMatch(patterns[j], file);
}
if (foundMatch)
rv.push_back(id);
if (foundMatch && shouldIssueObsoletePluginWarning)
{
static bool issuedWarning = false;
if (!issuedWarning)
{
cerr << "Warning: For plugin id = \"" << id
<< "\", default file extensions/names found in" << endl;
cerr << "CommonPluginInfo indicating obsolete plugin code." << endl;
cerr << "Please re-generate the plugin info files using xml2info." << endl;
cerr << "This message will continue to appear, once per session," << endl;
cerr << "until the problem has been addressed." << endl;
issuedWarning = true;
}
}
}
return rv;
......
......@@ -86,8 +86,12 @@ class EngineDatabasePluginInfo;
// Removed singleton characteristics.
//
// Brad Whitlock, Wed Jun 17 10:24:46 PDT 2009
// I added arguments to Initialize and I overrode the new BroadcastGeneralInfo
// method.
// I added arguments to Initialize and I overrode the new
// BroadcastGeneralInfo method.
//
// Jeremy Meredith, Tue Dec 29 11:40:42 EST 2009
// Replaced "Extensions" and "Filenames" with "FilePatterns". Added
// filePatternsStrict and opensWholeDirectory.
//
// ****************************************************************************
......@@ -108,8 +112,9 @@ class PLUGIN_API DatabasePluginManager : public PluginManager
CommonDatabasePluginInfo *GetCommonPluginInfo(const std::string&);
EngineDatabasePluginInfo *GetEnginePluginInfo(const std::string&);
bool PluginHasWriter(const std::string&);
std::vector<std::string> PluginFileExtensions(const std::string&);
std::vector<std::string> PluginFilenames(const std::string&);
std::vector<std::string> PluginFilePatterns(const std::string&);
bool PluginFilePatternsAreStrict(const std::string&);
bool PluginOpensWholeDirectory(const std::string&);
std::vector<std::string> GetMatchingPluginIds(const char *fname,
bool searchAll = false);
......@@ -125,8 +130,9 @@ class PLUGIN_API DatabasePluginManager : public PluginManager
// arrays containing all plugins (appends the ones in PluginManager.C)
std::vector<bool> haswriter;
std::vector<std::vector<std::string> > extensions;
std::vector<std::vector<std::string> > filenames;
std::vector<std::vector<std::string> > filePatterns;
std::vector<bool> filePatternsAreStrict;
std::vector<bool> opensWholeDirectory;
// arrays containing enabled plugins
std::vector<CommonDatabasePluginInfo*> commonPluginInfo;
......
......@@ -363,6 +363,9 @@ CreateMessageStrings(char **lists, int *count, int nl)
// Brad Whitlock, Fri Apr 30 16:13:50 PST 2004
// I made it case insensitive on Windows.
//
// Jeremy Meredith, Mon Dec 28 15:40:12 EST 2009
// I made the case-insensitivity apply to all platforms.
//
// ****************************************************************************
bool
......@@ -372,7 +375,6 @@ WildcardStringMatch(const std::string &p, const std::string &s)
return WildcardStringMatch(p.c_str(), s.c_str());
}
#if defined(_WIN32)
inline bool
CaseInsensitiveCompare(char p, char s)
{
......@@ -392,7 +394,6 @@ CaseInsensitiveCompare(char p, char s)
return retval;
}
#endif
bool
WildcardStringMatch(const char *p, const char *s)
......@@ -416,12 +417,7 @@ WildcardStringMatch(const char *p, const char *s)
// and consume one char
if ( *p == '?' ||
(*p == '#' && *s >= '0' && *s <= '9') ||
#if defined(_WIN32)
CaseInsensitiveCompare(*p, *s)
#else
*p == *s
#endif
)
CaseInsensitiveCompare(*p, *s))
{
return WildcardStringMatch(&p[1], &s[1]);
}
......
<?xml version="1.0"?>
<Plugin name="ANALYZE" type="database" label="ANALYZE" version="1.0" enabled="true" dbtype="STSD" haswriter="false">
<Extensions>
img
hdr
</Extensions>
<FilePatterns>
*.img
*.hdr
</FilePatterns>
<Files components="M">
avtANALYZEFileFormat.C
DSRObject.C
......
......@@ -153,21 +153,55 @@ ANALYZEGeneralPluginInfo::HasWriter() const
return false;
}
// ****************************************************************************
// Method: ANALYZEGeneralPluginInfo::GetDfltExtsFromGen
// Method: ANALYZEGeneralPluginInfo::GetDefaultFilePatterns
//
// Purpose:
// Returns the default extensions for a ANALYZE database.
// Returns the default patterns for a ANALYZE database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
std::vector<std::string>
ANALYZEGeneralPluginInfo::GetDfltExtsFromGen() const
ANALYZEGeneralPluginInfo::GetDefaultFilePatterns() const
{
std::vector<std::string> defaultExtensions;
defaultExtensions.push_back("img");
defaultExtensions.push_back("hdr");
std::vector<std::string> defaultPatterns;
defaultPatterns.push_back("*.img");
defaultPatterns.push_back("*.hdr");
return defaultExtensions;
return defaultPatterns;
}
// ****************************************************************************
// Method: ANALYZEGeneralPluginInfo::AreDefaultFilePatternsStrict
//
// Purpose:
// Returns if the file patterns for a ANALYZE database are
// intended to be interpreted strictly by default.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
ANALYZEGeneralPluginInfo::AreDefaultFilePatternsStrict() const
{
return false;
}
// ****************************************************************************
// Method: ANALYZEGeneralPluginInfo::OpensWholeDirectory
//
// Purpose:
// Returns if the ANALYZE plugin opens a whole directory name
// instead of a single file.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
ANALYZEGeneralPluginInfo::OpensWholeDirectory() const
{
return false;
}
......@@ -71,7 +71,9 @@ class ANALYZEGeneralPluginInfo : public virtual GeneralDatabasePluginInfo
virtual const char *GetID() const;
virtual bool EnabledByDefault() const;
virtual bool HasWriter() const;
virtual std::vector<std::string> GetDfltExtsFromGen() const;
virtual std::vector<std::string> GetDefaultFilePatterns() const;
virtual bool AreDefaultFilePatternsStrict() const;
virtual bool OpensWholeDirectory() const;
};
class ANALYZECommonPluginInfo : public virtual CommonDatabasePluginInfo, public virtual ANALYZEGeneralPluginInfo
......
<?xml version="1.0"?>
<Plugin name="ANSYS" type="database" label="ANSYS" version="1.0" enabled="true" mdspecificcode="true" onlyengine="false" noengine="false" dbtype="STSD" haswriter="false" hasoptions="false">
<Extensions>
inp
</Extensions>
<FilePatterns>
*.inp
</FilePatterns>
<Attribute name="" purpose="" persistent="false">
</Attribute>
</Plugin>
......@@ -153,20 +153,54 @@ ANSYSGeneralPluginInfo::HasWriter() const
return false;
}
// ****************************************************************************
// Method: ANSYSGeneralPluginInfo::GetDfltExtsFromGen
// Method: ANSYSGeneralPluginInfo::GetDefaultFilePatterns
//
// Purpose:
// Returns the default extensions for a ANSYS database.
// Returns the default patterns for a ANSYS database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
std::vector<std::string>
ANSYSGeneralPluginInfo::GetDfltExtsFromGen() const
ANSYSGeneralPluginInfo::GetDefaultFilePatterns() const
{
std::vector<std::string> defaultExtensions;
defaultExtensions.push_back("inp");
std::vector<std::string> defaultPatterns;
defaultPatterns.push_back("*.inp");
return defaultExtensions;
return defaultPatterns;
}
// ****************************************************************************
// Method: ANSYSGeneralPluginInfo::AreDefaultFilePatternsStrict
//
// Purpose:
// Returns if the file patterns for a ANSYS database are
// intended to be interpreted strictly by default.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
ANSYSGeneralPluginInfo::AreDefaultFilePatternsStrict() const
{
return false;
}
// ****************************************************************************
// Method: ANSYSGeneralPluginInfo::OpensWholeDirectory
//
// Purpose: