Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [TCE-1039] Add parameter 'registryAddress' in order to support alternative registry addresses for duplication and complexity tools #512

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/codacy-analysis-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ run() {
--volume "$CODACY_CODE":"$CODACY_CODE" \
${output_volume} \
--volume /tmp:/tmp \
codacy/codacy-analysis-cli:${CODACY_ANALYSIS_CLI_VERSION} -- \
${REGISTRY_ADDRESS}codacy/codacy-analysis-cli:${CODACY_ANALYSIS_CLI_VERSION} -- \
"$@"
}

Expand Down Expand Up @@ -119,7 +119,6 @@ prep_args_with_output_absolute_path() {
ARGUMENTS_WITH_ABSOLUTE_PATH_OUTPUT="$new_args"
}


test_docker_socket

analysis_file "$@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ class ToolSelector(toolRepository: ToolRepository) {
registryAddress: String): Either[CLIError, Set[ITool]] = {

def duplicationToolsEither: Either[CLIError.CouldNotGetTools, Set[DuplicationTool]] =
duplicationToolCollector.fromLanguages(languages).left.map(e => CLIError.CouldNotGetTools(e.message))
duplicationToolCollector
.fromLanguages(languages, registryAddress)
.left
.map(e => CLIError.CouldNotGetTools(e.message))

def metricsToolsEither: Either[CLIError.CouldNotGetTools, Set[MetricsTool]] =
metricsToolCollector.fromLanguages(languages).left.map(e => CLIError.CouldNotGetTools(e.message))
metricsToolCollector.fromLanguages(languages, registryAddress).left.map(e => CLIError.CouldNotGetTools(e.message))

toolInputOpt match {
case None =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import scala.util.Try
import com.codacy.analysis.core.model.DuplicationToolSpec
import com.codacy.analysis.core.model.AnalyserError

class DuplicationTool(duplicationToolSpec: DuplicationToolSpec, val languageToRun: Language) extends ITool {
class DuplicationTool(duplicationToolSpec: DuplicationToolSpec, val languageToRun: Language, registryAddress: String)
extends ITool {

override def name: String = "duplication"
override def supportedLanguages: Set[Language] = duplicationToolSpec.languages
Expand All @@ -28,7 +29,9 @@ class DuplicationTool(duplicationToolSpec: DuplicationToolSpec, val languageToRu
maxToolMemory: Option[String] = None): Try[Set[DuplicationClone]] = {

val duplicationTool =
new traits.DuplicationTool(duplicationToolSpec.dockerImage, duplicationToolSpec.languages.toList)
new traits.DuplicationTool(
registryAddress + duplicationToolSpec.dockerImage,
duplicationToolSpec.languages.toList)

val dockerRunner = new BinaryDockerRunner[api.duplication.DuplicationClone](
duplicationTool,
Expand Down Expand Up @@ -77,12 +80,12 @@ class DuplicationToolCollector(toolRepository: ToolRepository) {

private val logger: org.log4s.Logger = getLogger

def fromLanguages(languages: Set[Language]): Either[AnalyserError, Set[DuplicationTool]] = {
def fromLanguages(languages: Set[Language], registryAddress: String): Either[AnalyserError, Set[DuplicationTool]] = {
toolRepository.listDuplicationTools().map { tools =>
languages.flatMap { lang =>
val collectedTools = tools.collect {
case tool if tool.languages.contains(lang) =>
new DuplicationTool(tool, lang)
new DuplicationTool(tool, lang, registryAddress)
}
if (collectedTools.isEmpty) {
logger.info(s"No duplication tools found for language ${lang.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.log4s.getLogger
import scala.concurrent.duration.Duration
import scala.util.Try

class MetricsTool(metricsToolSpec: MetricsToolSpec, val languageToRun: Language) extends ITool {
class MetricsTool(metricsToolSpec: MetricsToolSpec, val languageToRun: Language, registryAddress: String)
extends ITool {
override def name: String = "metrics"

override def supportedLanguages: Set[Language] = metricsToolSpec.languages.to[Set]
Expand All @@ -27,7 +28,8 @@ class MetricsTool(metricsToolSpec: MetricsToolSpec, val languageToRun: Language)
maxToolMemory: Option[String] = None): Try[List[FileMetrics]] = {
val request = MetricsRequest(directory.pathAsString)

val metricsTool = new traits.MetricsTool(metricsToolSpec.dockerImage, metricsToolSpec.languages.toList)
val metricsTool =
new traits.MetricsTool(registryAddress + metricsToolSpec.dockerImage, metricsToolSpec.languages.toList)

val dockerRunner = new BinaryDockerRunner[api.metrics.FileMetrics](
metricsTool,
Expand Down Expand Up @@ -75,12 +77,12 @@ class MetricsToolCollector(toolRepository: ToolRepository) {

private val logger: org.log4s.Logger = getLogger

def fromLanguages(languages: Set[Language]): Either[AnalyserError, Set[MetricsTool]] = {
def fromLanguages(languages: Set[Language], registryAddress: String): Either[AnalyserError, Set[MetricsTool]] = {
toolRepository.listMetricsTools().map { tools =>
languages.flatMap { lang =>
val collectedTools = tools.collect {
case tool if tool.languages.contains(lang) =>
new MetricsTool(tool, lang)
new MetricsTool(tool, lang, registryAddress)
}

if (collectedTools.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DuplicationToolSpec extends Specification with NoLanguageFeatures {

val result = for {
fileTarget <- FileCollector.defaultCollector().list(directory)
duplicationTool = new DuplicationTool(duplicationToolSpec, Languages.Javascript)
duplicationTool = new DuplicationTool(duplicationToolSpec, Languages.Javascript, "")
duplicationToolResult <- duplicationTool.run(directory, fileTarget.readableFiles)
} yield duplicationToolResult

Expand All @@ -60,7 +60,7 @@ class DuplicationToolSpec extends Specification with NoLanguageFeatures {

val result = for {
fileTarget <- FileCollector.defaultCollector().list(directory)
duplicationTool = new DuplicationTool(duplicationToolSpec, Languages.Javascript)
duplicationTool = new DuplicationTool(duplicationToolSpec, Languages.Javascript, "")
filteredFileTarget = fileTarget.readableFiles.filterNot(_.endsWith("test2.js"))
duplicationToolResult <- duplicationTool.run(directory, filteredFileTarget)
} yield duplicationToolResult
Expand All @@ -79,7 +79,7 @@ class DuplicationToolSpec extends Specification with NoLanguageFeatures {
val languagesWithTools: Set[Language] = Set(Languages.Java, Languages.Python, Languages.Ruby)
val duplicationToolCollector = new DuplicationToolCollector(ToolRepositoryMock)
s"detect the duplication tools for the given languages: ${languagesWithTools.mkString(", ")}" in {
val toolsEither = duplicationToolCollector.fromLanguages(languagesWithTools)
val toolsEither = duplicationToolCollector.fromLanguages(languagesWithTools, "")
toolsEither must beRight
val tools = toolsEither.right.get
tools must haveSize(3)
Expand All @@ -89,7 +89,7 @@ class DuplicationToolSpec extends Specification with NoLanguageFeatures {
val languagesWithoutTools: Set[Language] = Set(Languages.R, Languages.Elixir, Languages.Elm)

s"return no duplication tools for the given languages: ${languagesWithoutTools}" in {
val toolsEither = duplicationToolCollector.fromLanguages(languagesWithoutTools)
val toolsEither = duplicationToolCollector.fromLanguages(languagesWithoutTools, "")
toolsEither must beRight
val tools = toolsEither.right.get
tools should beEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MetricsToolSpec extends Specification with NoLanguageFeatures {
withClonedRepo("[email protected]:qamine-test/duplication-delta.git", commitUuid) { (_, directory) =>
val testProjectFileMetrics = List(jsTestMetrics)

val metricsTool = new MetricsTool(cloc, Languages.Javascript)
val metricsTool = new MetricsTool(cloc, Languages.Javascript, "")

val result = metricsTool.run(directory, Set(Source.File("test.js")))

Expand Down