logic: Save maven effective-pom output to file instead of using console output to avoid issues with color codes (issue #705)

This commit is contained in:
Eberhard Graether
2019-08-13 17:22:09 +02:00
parent 809f201583
commit 084bc3dc43
5 changed files with 25 additions and 43 deletions
+2
View File
@@ -14,6 +14,8 @@
/bin/test/data/TestSettings.xml
/bin/test/data/CommandlineTestSuite/settings.xml
/bin/test/data/ConfigManagerTestSuite/temp.xml
/bin/test/data/UtilityMavenTestSuite/effective-pom.xml
/bin/test/data/SourceGroupTestSuite/java_maven/input/sourcetrail_dependencies
/java_indexer/target/
@@ -42,7 +42,13 @@ std::vector<FilePath> SourceGroupJavaMaven::getAllSourcePaths() const
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_settings->getShouldIndexMavenTests());
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPath,
projectRootPath,
m_settings->getMavenDependenciesDirectoryPath(),
m_settings->getShouldIndexMavenTests()
);
dialogView->hideUnknownProgressDialog();
}
+11 -37
View File
@@ -124,12 +124,14 @@ namespace utility
}
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, bool addTestDirectories)
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories)
{
utility::setJavaHomeVariableIfNotExists();
FilePath outputPath = outputDirectoryPath.getConcatenated(FilePath("/effective-pom.xml"));
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" help:effective-pom -B",
"\"" + mavenPath.str() + "\" help:effective-pom -Doutput=\"" + outputPath.str(),
projectDirectoryPath,
60000
));
@@ -139,43 +141,15 @@ namespace utility
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return std::vector<FilePath>();
return {};
}
else if (!outputPath.exists())
{
LOG_ERROR("Maven effective-pom didn't generate an output file: " + outputPath.str());
return {};
}
size_t startLine = 0;
for (size_t i = 1; i <= outputAccess->getLineCount(); i++)
{
if (utility::isPrefix<std::string>("<", utility::trim(outputAccess->getLine(i))))
{
startLine = i;
break;
}
}
size_t endLine = outputAccess->getLineCount();
for (size_t i = outputAccess->getLineCount(); i > 0 ; i--)
{
if (utility::isPrefix<std::string>("<", utility::trim(outputAccess->getLine(i))))
{
endLine = i;
break;
}
}
for (size_t i = endLine + 1; i <= outputAccess->getLineCount(); i++)
{
if (utility::isPrefix<std::string>("[", utility::trim(outputAccess->getLine(i))))
{
break;
}
endLine = i;
}
std::string xmlContent = "";
for (const std::string& line: outputAccess->getLines(startLine, endLine))
{
xmlContent.append(line);
}
std::shared_ptr<TextAccess> xmlAccess = TextAccess::createFromString(xmlContent);
std::shared_ptr<TextAccess> xmlAccess = TextAccess::createFromFile(outputPath);
std::vector<FilePath> uncheckedDirectories;
fetchDirectories(uncheckedDirectories, xmlAccess,
+1 -1
View File
@@ -12,7 +12,7 @@ namespace utility
bool mavenCopyDependencies(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath);
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, bool addTestDirectories);
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories);
}
#endif // UTILITY_MAVEN_H
+4 -4
View File
@@ -21,7 +21,7 @@ public:
if (!mavenPathDetector->getPaths().empty())
{
std::vector<FilePath> result = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/simple_maven_project"), false
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/simple_maven_project"), FilePath(L"data/UtilityMavenTestSuite").makeAbsolute(), false
);
TS_ASSERT(utility::containsElement<FilePath>(
@@ -42,7 +42,7 @@ public:
if (!mavenPathDetector->getPaths().empty())
{
std::vector<FilePath> result = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/simple_maven_project"), true
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/simple_maven_project"), FilePath(L"data/UtilityMavenTestSuite").makeAbsolute(), true
);
TS_ASSERT(utility::containsElement<FilePath>(
@@ -63,7 +63,7 @@ public:
if (!mavenPathDetector->getPaths().empty())
{
std::vector<FilePath> result = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/nested_maven_project"), false
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/nested_maven_project"), FilePath(L"data/UtilityMavenTestSuite").makeAbsolute(), false
);
TS_ASSERT(utility::containsElement<FilePath>(
@@ -92,7 +92,7 @@ public:
if (!mavenPathDetector->getPaths().empty())
{
std::vector<FilePath> result = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/nested_maven_project"), true
mavenPathDetector->getPaths().front(), FilePath(L"data/UtilityMavenTestSuite/nested_maven_project"), FilePath(L"data/UtilityMavenTestSuite").makeAbsolute(), true
);
TS_ASSERT(utility::containsElement<FilePath>(