summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/JavaUtil.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2009-01-12 13:24:42 -0330
committerMatthew Newhook <matthew@zeroc.com>2009-01-12 13:24:42 -0330
commitccd83f8d813ca03a62eff8f2c3c360b3094c3be9 (patch)
tree11bc670c18a015c4c05184b63749f1a3d4169c87 /cpp/src/Slice/JavaUtil.cpp
parentSquashed commit of the following: (diff)
downloadice-ccd83f8d813ca03a62eff8f2c3c360b3094c3be9.tar.bz2
ice-ccd83f8d813ca03a62eff8f2c3c360b3094c3be9.tar.xz
ice-ccd83f8d813ca03a62eff8f2c3c360b3094c3be9.zip
Squashed commit of the following:
commit 0c7025d761813d2e121e8573ba16c14e5a6a4ea5 Author: Matthew Newhook <matthew@zeroc.com> Date: Mon Jan 12 08:09:36 2009 -0330 http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=3396 slice2java fails silently if it cannot create dir
Diffstat (limited to 'cpp/src/Slice/JavaUtil.cpp')
-rw-r--r--cpp/src/Slice/JavaUtil.cpp78
1 files changed, 66 insertions, 12 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 783180f60e1..725e5e60268 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -26,6 +26,49 @@ using namespace Slice;
using namespace IceUtil;
using namespace IceUtilInternal;
+Slice::FileException::FileException(const char* file, int line, const string& r) :
+ Exception(file, line),
+ _reason(r)
+{
+}
+
+Slice::FileException::~FileException() throw()
+{
+}
+
+const char* Slice::FileException::_name = "Slice::FileException";
+
+string
+Slice::FileException::ice_name() const
+{
+ return _name;
+}
+
+void
+Slice::FileException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ": " << _reason;
+}
+
+IceUtil::Exception*
+Slice::FileException::ice_clone() const
+{
+ return new FileException(*this);
+}
+
+void
+Slice::FileException::ice_throw() const
+{
+ throw *this;
+}
+
+string
+Slice::FileException::reason() const
+{
+ return _reason;
+}
+
Slice::JavaOutput::JavaOutput()
{
}
@@ -40,7 +83,7 @@ Slice::JavaOutput::JavaOutput(const char* s) :
{
}
-bool
+void
Slice::JavaOutput::openClass(const string& cls, const string& prefix)
{
string package;
@@ -81,6 +124,13 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix)
result = stat(path.c_str(), &st);
if(result == 0)
{
+ if(!(st.st_mode & S_IFDIR))
+ {
+ ostringstream os;
+ os << "failed to create package directory `" << path
+ << "': file already exists and is not a directory";
+ throw FileException(__FILE__, __LINE__, os.str());
+ }
continue;
}
#ifdef _WIN32
@@ -90,7 +140,9 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix)
#endif
if(result != 0)
{
- return false;
+ ostringstream os;
+ os << "cannot create directory `" << path << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
}
}
while(pos != string::npos);
@@ -123,11 +175,13 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix)
print(package.c_str());
print(";");
}
-
- return true;
}
-
- return false;
+ else
+ {
+ ostringstream os;
+ os << "cannot open file `" << path << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
+ }
}
void
@@ -172,22 +226,22 @@ Slice::JavaGenerator::~JavaGenerator()
assert(_out == 0);
}
-bool
+void
Slice::JavaGenerator::open(const string& absolute)
{
assert(_out == 0);
JavaOutput* out = createOutput();
- if(out->openClass(absolute, _dir))
+ try
{
- _out = out;
+ out->openClass(absolute, _dir);
}
- else
+ catch(const FileException&)
{
delete out;
+ throw;
}
-
- return _out != 0;
+ _out = out;
}
void