Skip to content

Commit

Permalink
logic: Save maven effective-pom output to file instead of using conso…
Browse files Browse the repository at this point in the history
…le output to avoid issues with color codes (issue CoatiSoftware#705)
  • Loading branch information
egraether committed Aug 13, 2019
1 parent 809f201 commit 084bc3d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
8 changes: 7 additions & 1 deletion src/lib_java/project/SourceGroupJavaMaven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
44 changes: 9 additions & 35 deletions src/lib_java/utility/utilityMaven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
Expand All @@ -139,43 +141,15 @@ namespace utility
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return std::vector<FilePath>();
return {};
}

size_t startLine = 0;
for (size_t i = 1; i <= outputAccess->getLineCount(); i++)
else if (!outputPath.exists())
{
if (utility::isPrefix<std::string>("<", utility::trim(outputAccess->getLine(i))))
{
startLine = i;
break;
}
LOG_ERROR("Maven effective-pom didn't generate an output file: " + outputPath.str());
return {};
}

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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib_java/utility/utilityMaven.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/test/UtilityMavenTestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UtilityMavenTestSuite : public CxxTest::TestSuite
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>(
Expand All @@ -42,7 +42,7 @@ class UtilityMavenTestSuite : public CxxTest::TestSuite
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>(
Expand All @@ -63,7 +63,7 @@ class UtilityMavenTestSuite : public CxxTest::TestSuite
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>(
Expand Down Expand Up @@ -92,7 +92,7 @@ class UtilityMavenTestSuite : public CxxTest::TestSuite
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>(
Expand Down

0 comments on commit 084bc3d

Please sign in to comment.