Commit b840a243 authored by Lorenz Haas's avatar Lorenz Haas Committed by David Schulz

Beautifier: Prevent writing of an empty documentation file

Only keep successfully created documentation files. Thus the automatic
generation of a file can be triggered again.

Change-Id: I8ec3becfd2f3387f18635741dd11288cb72c372d
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 2a4cb11d
......@@ -115,6 +115,12 @@ QString ArtisticStyleSettings::documentationFilePath() const
void ArtisticStyleSettings::createDocumentationFile() const
{
QProcess process;
process.start(command(), QStringList() << QLatin1String("-h"));
process.waitForFinished(2000); // show help should be really fast.
if (process.error() != QProcess::UnknownError)
return;
QFile file(documentationFilePath());
const QFileInfo fi(file);
if (!fi.exists())
......@@ -122,12 +128,7 @@ void ArtisticStyleSettings::createDocumentationFile() const
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
return;
QProcess process;
process.start(command(), QStringList() << QLatin1String("-h"));
process.waitForFinished(2000); // show help should be really fast.
if (process.error() != QProcess::UnknownError)
return;
bool contextWritten = false;
QXmlStreamWriter stream(&file);
stream.setAutoFormatting(true);
stream.writeStartDocument(QLatin1String("1.0"), true);
......@@ -169,6 +170,7 @@ void ArtisticStyleSettings::createDocumentationFile() const
+ QLatin1String("</p>");
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
stream.writeEndElement();
contextWritten = true;
}
keys.clear();
docu.clear();
......@@ -180,6 +182,13 @@ void ArtisticStyleSettings::createDocumentationFile() const
stream.writeEndElement();
stream.writeEndDocument();
// An empty file causes error messages and a contextless file preventing this function to run
// again in order to generate the documentation successfully. Thus delete the file.
if (!contextWritten) {
file.close();
file.remove();
}
}
} // namespace ArtisticStyle
......
......@@ -114,6 +114,12 @@ QString UncrustifySettings::documentationFilePath() const
void UncrustifySettings::createDocumentationFile() const
{
QProcess process;
process.start(command(), QStringList() << QLatin1String("--show-config"));
process.waitForFinished(2000); // show config should be really fast.
if (process.error() != QProcess::UnknownError)
return;
QFile file(documentationFilePath());
const QFileInfo fi(file);
if (!fi.exists())
......@@ -121,12 +127,7 @@ void UncrustifySettings::createDocumentationFile() const
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
return;
QProcess process;
process.start(command(), QStringList() << QLatin1String("--show-config"));
process.waitForFinished(2000); // show config should be really fast.
if (process.error() != QProcess::UnknownError)
return;
bool contextWritten = false;
QXmlStreamWriter stream(&file);
stream.setAutoFormatting(true);
stream.writeStartDocument(QLatin1String("1.0"), true);
......@@ -158,6 +159,7 @@ void UncrustifySettings::createDocumentationFile() const
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLKEY), keyword);
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
stream.writeEndElement();
contextWritten = true;
break;
} else {
docu << subline;
......@@ -167,6 +169,13 @@ void UncrustifySettings::createDocumentationFile() const
stream.writeEndElement();
stream.writeEndDocument();
// An empty file causes error messages and a contextless file preventing this function to run
// again in order to generate the documentation successfully. Thus delete the file.
if (!contextWritten) {
file.close();
file.remove();
}
}
} // namespace Uncrustify
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment