summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2007-05-16 13:14:53 +0000
committerDwayne Boone <dwayne@zeroc.com>2007-05-16 13:14:53 +0000
commit97471800e2eea67243ef838a74634b83a51f9cb9 (patch)
treedc4427a9b5baf9c332570f53fd89c1458bef9051 /cpp
parentFixed mono compile errors (diff)
downloadice-97471800e2eea67243ef838a74634b83a51f9cb9.tar.bz2
ice-97471800e2eea67243ef838a74634b83a51f9cb9.tar.xz
ice-97471800e2eea67243ef838a74634b83a51f9cb9.zip
Bug 1625 - unused property warning
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES4
-rw-r--r--cpp/config/PropertyNames.def1
-rw-r--r--cpp/src/Ice/Instance.cpp17
-rw-r--r--cpp/src/Ice/PropertiesI.cpp65
-rw-r--r--cpp/src/Ice/PropertiesI.h12
-rw-r--r--cpp/src/Ice/PropertyNames.cpp3
-rw-r--r--cpp/src/Ice/PropertyNames.h2
7 files changed, 83 insertions, 21 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index a3a84b23fb5..0aaf25ced36 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,10 @@
Changes since version 3.2.X (binary incompabible)
-------------------------------------------------
+- Added a new property, Ice.Warn.UnusedProperties. If set to 1, when
+ the communicator is destroyed a warning will be printed listing all
+ properties that were set, but never read. Default is 0.
+
- Added what() member to IceUtil::Exception, so a single catch handler
can be used for Ice exceptions:
diff --git a/cpp/config/PropertyNames.def b/cpp/config/PropertyNames.def
index 1556885be3e..901f54d3d64 100644
--- a/cpp/config/PropertyNames.def
+++ b/cpp/config/PropertyNames.def
@@ -193,6 +193,7 @@ Ice:
Warn.Dispatch
Warn.Endpoints
Warn.UnknownProperties
+ Warn.UnusedProperties
CacheMessageBuffers
IceBox:
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 81dfa2fc9bc..7fd7ef6c555 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -24,7 +24,7 @@
#include <Ice/LocalException.h>
#include <Ice/ObjectAdapterFactory.h>
#include <Ice/Exception.h>
-#include <Ice/Properties.h>
+#include <Ice/PropertiesI.h>
#include <Ice/LoggerI.h>
#include <Ice/Network.h>
#include <Ice/EndpointFactoryManager.h>
@@ -33,6 +33,7 @@
#include <Ice/DynamicLibrary.h>
#include <Ice/PluginManagerI.h>
#include <Ice/Initialize.h>
+#include <Ice/LoggerUtil.h>
#include <IceUtil/StringUtil.h>
#include <stdio.h>
@@ -936,6 +937,20 @@ IceInternal::Instance::destroy()
{
serverThreadPool->joinWithAllThreads();
}
+
+ if(_initData.properties->getPropertyAsInt("Ice.Warn.UnusedProperties") > 0)
+ {
+ set<string> unusedProperties = static_cast<PropertiesI*>(_initData.properties.get())->getUnusedProperties();
+ if(unusedProperties.size() != 0)
+ {
+ Warning out(_initData.logger);
+ out << "The following properties were set but never read:";
+ for(set<string>::const_iterator p = unusedProperties.begin(); p != unusedProperties.end(); ++p)
+ {
+ out << "\n " << *p;
+ }
+ }
+ }
return true;
}
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp
index 86ddccf7cae..7b868d451e8 100644
--- a/cpp/src/Ice/PropertiesI.cpp
+++ b/cpp/src/Ice/PropertiesI.cpp
@@ -25,10 +25,11 @@ Ice::PropertiesI::getProperty(const string& key)
{
IceUtil::Mutex::Lock sync(*this);
- map<string, string>::const_iterator p = _properties.find(key);
+ map<string, PropertyValue>::iterator p = _properties.find(key);
if(p != _properties.end())
{
- return p->second;
+ p->second.used = true;
+ return p->second.value;
}
else
{
@@ -41,10 +42,11 @@ Ice::PropertiesI::getPropertyWithDefault(const string& key, const string& value)
{
IceUtil::Mutex::Lock sync(*this);
- map<string, string>::const_iterator p = _properties.find(key);
+ map<string, PropertyValue>::iterator p = _properties.find(key);
if(p != _properties.end())
{
- return p->second;
+ p->second.used = true;
+ return p->second.value;
}
else
{
@@ -63,10 +65,11 @@ Ice::PropertiesI::getPropertyAsIntWithDefault(const string& key, Int value)
{
IceUtil::Mutex::Lock sync(*this);
- map<string, string>::const_iterator p = _properties.find(key);
+ map<string, PropertyValue>::iterator p = _properties.find(key);
if(p != _properties.end())
{
- istringstream v(p->second);
+ p->second.used = true;
+ istringstream v(p->second.value);
if(!(v >> value) || !v.eof())
{
return 0;
@@ -82,12 +85,13 @@ Ice::PropertiesI::getPropertiesForPrefix(const string& prefix)
IceUtil::Mutex::Lock sync(*this);
PropertyDict result;
- map<string, string>::const_iterator p;
+ map<string, PropertyValue>::iterator p;
for(p = _properties.begin(); p != _properties.end(); ++p)
{
if(prefix.empty() || p->first.compare(0, prefix.size(), prefix) == 0)
{
- result.insert(*p);
+ p->second.used = true;
+ result[p->first] = p->second.value;
}
}
@@ -140,7 +144,13 @@ Ice::PropertiesI::setProperty(const string& key, const string& value)
//
if(!value.empty())
{
- _properties[key] = value;
+ PropertyValue pv = { value, false };
+ map<string, PropertyValue>::const_iterator p = _properties.find(key);
+ if(p != _properties.end())
+ {
+ pv.used = p->second.used;
+ }
+ _properties[key] = pv;
}
else
{
@@ -155,10 +165,10 @@ Ice::PropertiesI::getCommandLineOptions()
StringSeq result;
result.reserve(_properties.size());
- map<string, string>::const_iterator p;
+ map<string, PropertyValue>::const_iterator p;
for(p = _properties.begin(); p != _properties.end(); ++p)
{
- result.push_back("--" + p->first + "=" + p->second);
+ result.push_back("--" + p->first + "=" + p->second.value);
}
return result;
}
@@ -234,6 +244,21 @@ Ice::PropertiesI::clone()
return new PropertiesI(this);
}
+set<string>
+Ice::PropertiesI::getUnusedProperties()
+{
+ IceUtil::Mutex::Lock sync(*this);
+ set<string> unusedProperties;
+ for(map<string, PropertyValue>::const_iterator p = _properties.begin(); p != _properties.end(); ++p)
+ {
+ if(!p->second.used)
+ {
+ unusedProperties.insert(p->first);
+ }
+ }
+ return unusedProperties;
+}
+
Ice::PropertiesI::PropertiesI(const PropertiesI* p) :
_properties(p->_properties),
_converter(p->_converter)
@@ -250,12 +275,14 @@ Ice::PropertiesI::PropertiesI(StringSeq& args, const PropertiesPtr& defaults, co
{
if(defaults != 0)
{
- _properties = defaults->getPropertiesForPrefix("");
+ _properties = static_cast<PropertiesI*>(defaults.get())->_properties;
}
StringSeq::iterator q = args.begin();
- if(_properties.find("Ice.ProgramName") == _properties.end())
+
+ map<string, PropertyValue>::iterator p = _properties.find("Ice.ProgramName");
+ if(p == _properties.end())
{
if(q != args.end())
{
@@ -266,9 +293,15 @@ Ice::PropertiesI::PropertiesI(StringSeq& args, const PropertiesPtr& defaults, co
//
string name = *q;
replace(name.begin(), name.end(), '\\', '/');
- setProperty("Ice.ProgramName", name);
+
+ PropertyValue pv = { name, true };
+ _properties["Ice.ProgramName"] = pv;
}
}
+ else
+ {
+ p->second.used = true;
+ }
StringSeq tmp;
@@ -309,7 +342,6 @@ Ice::PropertiesI::PropertiesI(StringSeq& args, const PropertiesPtr& defaults, co
args = parseIceCommandLineOptions(args);
}
-
void
Ice::PropertiesI::parseLine(const string& line, const StringConverterPtr& converter)
{
@@ -408,5 +440,6 @@ Ice::PropertiesI::loadConfig()
}
}
- setProperty("Ice.Config", value);
+ PropertyValue pv = { value, true };
+ _properties["Ice.Config"] = pv;
}
diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h
index a5d78edb9d1..369460addd7 100644
--- a/cpp/src/Ice/PropertiesI.h
+++ b/cpp/src/Ice/PropertiesI.h
@@ -14,6 +14,8 @@
#include <Ice/Properties.h>
#include <Ice/StringConverter.h>
+#include <set>
+
namespace Ice
{
@@ -33,6 +35,8 @@ public:
virtual void load(const std::string&);
virtual PropertiesPtr clone();
+ std::set<std::string> getUnusedProperties();
+
private:
PropertiesI(const StringConverterPtr&);
PropertiesI(StringSeq&, const PropertiesPtr&, const StringConverterPtr&);
@@ -42,12 +46,16 @@ private:
friend ICE_API PropertiesPtr createProperties(StringSeq&, const PropertiesPtr&, const StringConverterPtr&);
friend ICE_API PropertiesPtr createProperties(int&, char*[], const PropertiesPtr&, const StringConverterPtr&);
-
void parseLine(const std::string&, const StringConverterPtr&);
void loadConfig();
- std::map<std::string, std::string> _properties;
+ struct PropertyValue
+ {
+ std::string value;
+ bool used;
+ };
+ std::map<std::string, PropertyValue> _properties;
const StringConverterPtr _converter;
};
diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp
index dce071b8cde..0744d7d004e 100644
--- a/cpp/src/Ice/PropertyNames.cpp
+++ b/cpp/src/Ice/PropertyNames.cpp
@@ -7,7 +7,7 @@
//
// **********************************************************************
-// Generated by makeprops.py from file `../config/PropertyNames.def', Tue Feb 20 11:10:03 2007
+// Generated by makeprops.py from file `../config/PropertyNames.def', Tue May 15 12:31:29 2007
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -95,6 +95,7 @@ const char* IceInternal::PropertyNames::IceProps[] =
"Ice.Warn.Dispatch",
"Ice.Warn.Endpoints",
"Ice.Warn.UnknownProperties",
+ "Ice.Warn.UnusedProperties",
"Ice.CacheMessageBuffers",
0
};
diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h
index 7b680bb595a..30edd10e84e 100644
--- a/cpp/src/Ice/PropertyNames.h
+++ b/cpp/src/Ice/PropertyNames.h
@@ -7,7 +7,7 @@
//
// **********************************************************************
-// Generated by makeprops.py from file `../config/PropertyNames.def', Tue Feb 20 11:10:03 2007
+// Generated by makeprops.py from file `../config/PropertyNames.def', Tue May 15 12:31:29 2007
// IMPORTANT: Do not edit this file -- any edits made here will be lost!