Skip to content

Commit

Permalink
Path refactoring (#677)
Browse files Browse the repository at this point in the history
* Name refactoring

* Add option to CLI
  • Loading branch information
ladisgin committed Apr 2, 2024
1 parent d81bf92 commit a0f1871
Show file tree
Hide file tree
Showing 63 changed files with 587 additions and 482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.utbot.cpp.clion.plugin.utils.activeProject
import org.utbot.cpp.clion.plugin.utils.client
import testsgen.Testgen

class AskServerToGenerateBuildDir : UTBotBaseAction(UTBot.message("projectConfigure.generate.buildDir")) {
class AskServerToGenerateBuildDir : UTBotBaseAction(UTBot.message("projectConfigure.generate.buildRelDir")) {

override fun actionPerformed(e: AnActionEvent) = CreateBuildDirRequest(
GrpcRequestBuilderFactory(e.activeProject()).createProjectConfigRequestBuilder(Testgen.ConfigMode.CREATE_BUILD_DIR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CreateBuildDirRequest(
CreateBuildDirHandler(
client,
this,
UTBot.message("requests.buildDir.description.progress"),
UTBot.message("requests.buildRelDir.description.progress"),
cancellationJob
).handle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GrpcRequestBuilderFactory(
project.name,
project.path,
project.settings.storedSettings.testDirRelativePath,
project.settings.storedSettings.buildDirRelativePath
project.settings.storedSettings.buildDirRelPath
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal data class ProjectContextBuilder(
val projectName: String,
val projectPath: String,
val testDirRelativePath: String,
val buildDirRelativePath: String
val buildDirRelPath: String
) : GrpcRequestBuilder<Testgen.ProjectContext> {
override fun build(remoteMapping: RemoteMapping): Testgen.ProjectContext {
val projectNioPath = Paths.get(projectPath) // project path is not set by user, assuming it is valid
Expand All @@ -29,7 +29,7 @@ internal data class ProjectContextBuilder(
UTBot.message("settings.project.testsDir.wrong")
)
)
.setBuildDirRelativePath(buildDirRelativePath)
.setBuildDirRelPath(buildDirRelPath)
.setProjectName(projectName)
.setProjectPath(remoteMapping.convertToRemote(projectPath, UTBot.message("projectPath.wrong.conversion")))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class UTBotAllProjectSettings(val project: Project) {
val buildDirPath: Path
get() {
try {
return Paths.get(project.path).resolve(storedSettings.buildDirRelativePath)
return Paths.get(project.path).resolve(storedSettings.buildDirRelPath)
} catch (e: InvalidPathException) {
throw IllegalPathException(
UTBot.message(
"paths.invalid",
"relative path to build dir",
storedSettings.buildDirRelativePath
storedSettings.buildDirRelPath
),
storedSettings.buildDirRelativePath
storedSettings.buildDirRelPath
)
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ class UTBotAllProjectSettings(val project: Project) {

fun predictPaths() {
storedSettings.remotePath = UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
storedSettings.buildDirRelativePath = UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_BUILD_DIR
storedSettings.buildDirRelPath = UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_BUILD_DIR
storedSettings.targetPath = UTBotTarget.autoTarget.path
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
}

private fun Panel.createPathsSettings() {
row(UTBot.message("settings.project.buildDir")) {
textField().bindText(settings::buildDirRelativePath).columns(COLUMNS_LARGE)
row(UTBot.message("settings.project.buildRelDir")) {
textField().bindText(settings::buildDirRelPath).columns(COLUMNS_LARGE)
.validateInput(ValidationCondition(UTBot.message("validation.not.empty")) {
it.text.stripLeadingSlashes().isNotEmpty()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen

// serialized by the ide
data class State(
var buildDirRelativePath: String = DEFAULT_RELATIVE_PATH_TO_BUILD_DIR,
var buildDirRelPath: String = DEFAULT_RELATIVE_PATH_TO_BUILD_DIR,
var testsDirRelativePath: String = DEFAULT_TESTS_DIR_RELATIVE_PATH,
var targetPath: String = UTBotTarget.autoTarget.path,
var remotePath: String = REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO,
Expand All @@ -44,7 +44,7 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
var isPluginEnabled: Boolean = false
) {
fun fromSettingsModel(model: UTBotSettingsModel) {
buildDirRelativePath = model.projectSettings.buildDirRelativePath
buildDirRelPath = model.projectSettings.buildDirRelPath
testsDirRelativePath = model.projectSettings.testsDirRelativePath
targetPath = model.projectSettings.targetPath
remotePath = model.projectSettings.remotePath
Expand Down Expand Up @@ -129,10 +129,10 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
else
Paths.get(project.path).relativize(Paths.get(targetPath)).toString()

var buildDirRelativePath: String
get() = myState.buildDirRelativePath.stripLeadingSlashes()
var buildDirRelPath: String
get() = myState.buildDirRelPath.stripLeadingSlashes()
set(value) {
myState.buildDirRelativePath = value
myState.buildDirRelPath = value
}

var isPluginEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BuildOptionsStep(parentDisposable: Disposable, private val settingsModel:
addHtml("media/options_wizard_text.html")
panel {
row("Relative path to Build directory") {
textField().bindText(settingsModel.projectSettings::buildDirRelativePath).columns(COLUMNS_LARGE)
textField().bindText(settingsModel.projectSettings::buildDirRelPath).columns(COLUMNS_LARGE)
.validateWith(ValidationCondition(UTBot.message("validation.not.empty")) { it.text.isNotEmpty() })
}

Expand Down
6 changes: 3 additions & 3 deletions clion-plugin/src/main/resources/messages/UTBot.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
projectConfigure.configure=Configure Project
projectConfigure.generate.buildDir=Generate build directory
projectConfigure.generate.buildRelDir=Generate build directory
projectConfigure.generate.json=Generate Missing JSON Files
projectConfigure.reconfigure=Reset cache and configure project
wizard.show=Quickstart wizard
settings.project.sourcePaths=Source paths:
settings.project.buildDir=Build directory:
settings.project.buildRelDir=Build directory:
settings.project.target=target path:
settings.project.target.wrong.conversion=Possibly wrong target path. Could not create relative path from remote path
settings.project.testsDir=Tests directory:
Expand All @@ -28,7 +28,7 @@ requests.predicate.description.progress=Generating for predicate...
requests.coverage.description.progress=Requesting results and coverage...
requests.check.description.progress=Checking project configuration...
requests.json.description.progress=Generating json files...
requests.buildDir.description.progress=Creating build directory...
requests.buildRelDir.description.progress=Creating build directory...
uri.wiki=https://github.com/UnitTestBot/UTBotCpp/wiki
deployment.utbot.host.description=UTBot Server host address. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#deployment>Learn more</a>
deployment.utbot.port.description=UTBot Server port. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#utbot-port>Learn more</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ open class BaseBuildingTest {
Paths.get(File(".").canonicalPath).resolve("../integration-tests/c-example-mini").normalize()
protected val testsDirRelativePath = "cl-plugin-test-tests"
protected val testsDirectoryPath: Path = projectPath.resolve(testsDirRelativePath)
protected val buildDirRelativePath = "build"
protected val buildDirRelPath = "build"
protected val fixture: CodeInsightTestFixture = createFixture(projectPath)
protected val project: Project
get() = fixture.project
val settings = project.settings.storedSettings

init {
settings.buildDirRelativePath = buildDirRelativePath
settings.buildDirRelPath = buildDirRelPath
settings.testDirRelativePath = projectPath.relativize(testsDirectoryPath).toString()
settings.isPluginEnabled = true
project.logger.logWriters.let {
Expand All @@ -56,7 +56,7 @@ open class BaseBuildingTest {
projectName = project.name
testDirPath =
if (isRemote) "$remotePath/$testsDirRelativePath" else this@BaseBuildingTest.testsDirectoryPath.toString()
buildDirRelativePath = this@BaseBuildingTest.buildDirRelativePath
buildDirRelPath = this@BaseBuildingTest.buildDirRelPath
}.build()
}

Expand Down Expand Up @@ -89,4 +89,4 @@ open class BaseBuildingTest {

return event
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class BaseGenerationTestCase {
get() = project.client

init {
project.settings.storedSettings.buildDirRelativePath = buildDirName
project.settings.storedSettings.buildDirRelPath = buildDirName
project.settings.storedSettings.testDirRelativePath = projectPath.relativize(testsDirectoryPath).toString()
project.settings.storedSettings.isPluginEnabled = true
project.logger.logWriters.let {
Expand Down Expand Up @@ -102,4 +102,4 @@ abstract class BaseGenerationTestCase {
fixture.tearDown()
Logger.info("tearDownAll of BaseGenerationTest has finished!")
}
}
}
9 changes: 5 additions & 4 deletions server/proto/testgen.proto
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ message LogEntry {
message ProjectContext {
string projectName = 1;
string projectPath = 2;
string testDirPath = 3;
string buildDirRelativePath = 4;
string clientProjectPath = 5;
string itfPath = 6;
string clientProjectPath = 3;
string testDirRelPath = 4;
string reportDirRelPath = 5;
string buildDirRelPath = 6;
string itfRelPath = 7;
}

enum ErrorMode {
Expand Down
4 changes: 2 additions & 2 deletions server/src/KleeRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
std::function<void()> prepareTotal = [&]() {
testsWriter->writeReport(sarif::sarifPackResults(sarifResults),
"Sarif Report was created",
Paths::getUTBotReportDir(projectContext) / sarif::SARIF_FILE_NAME);
projectContext.getReportDirAbsPath() / sarif::SARIF_FILE_NAME);
};

testsWriter->writeTestsWithProgress(
testsMap,
"Running klee",
projectContext.testDirPath,
projectContext.getTestDirAbsPath(),
std::move(prepareTests),
std::move(prepareTotal));
}
Expand Down
Loading

0 comments on commit a0f1871

Please sign in to comment.