Skip to content

Commit c7cf059

Browse files
Refactor tool UUID selection logic and update PMD version in configuration files
- Enhanced the `BuildDefaultConfigurationFiles` function to select tool UUIDs based on their versions. - Introduced a new helper function `selectCorrectToolUUID` for better clarity and maintainability. - Updated the expected PMD version in the integration test configuration files to 7.11.0. - Simplified cleanup logic in integration tests by consolidating the cleanup function.
1 parent 93746a6 commit c7cf059

File tree

4 files changed

+77
-57
lines changed

4 files changed

+77
-57
lines changed

cmd/configsetup/setup.go

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,20 @@ func createReviveConfigFile(config []domain.PatternConfiguration, toolsConfigDir
536536

537537
// BuildDefaultConfigurationFiles creates default configuration files for all tools
538538
func BuildDefaultConfigurationFiles(toolsConfigDir string, flags domain.InitFlags) error {
539-
// Get all supported tool UUIDs
539+
// Get default tool versions to determine correct UUIDs
540+
defaultVersions := plugins.GetToolVersions()
541+
542+
// Get unique tool names from metadata
543+
toolNames := make(map[string]struct{})
544+
for _, meta := range domain.SupportedToolsMetadata {
545+
toolNames[meta.Name] = struct{}{}
546+
}
547+
548+
// Convert tool names to correct UUIDs based on versions
540549
var allUUIDs []string
541-
for uuid := range domain.SupportedToolsMetadata {
542-
// Skip PMD7 and ESLint9 as per existing logic
543-
if uuid != domain.PMD7 && uuid != domain.ESLint9 {
550+
for toolName := range toolNames {
551+
uuid := selectCorrectToolUUID(toolName, defaultVersions)
552+
if uuid != "" {
544553
allUUIDs = append(allUUIDs, uuid)
545554
}
546555
}
@@ -648,18 +657,51 @@ func createRemoteToolConfigurationsForDiscovered(discoveredToolNames map[string]
648657
return createToolConfigurationFiles(configuredTools, initFlags)
649658
}
650659

660+
// selectCorrectToolUUID selects the correct UUID for a tool based on its version
661+
func selectCorrectToolUUID(toolName string, defaultVersions map[string]string) string {
662+
version, hasVersion := defaultVersions[toolName]
663+
664+
// Special case for PMD: choose PMD7 UUID for version 7.x, PMD UUID for version 6.x
665+
if toolName == "pmd" && hasVersion {
666+
if strings.HasPrefix(version, "7.") {
667+
return domain.PMD7
668+
} else {
669+
return domain.PMD
670+
}
671+
}
672+
673+
// Special case for ESLint: choose ESLint9 UUID for version 9.x, ESLint UUID for older versions
674+
if toolName == "eslint" && hasVersion {
675+
if strings.HasPrefix(version, "9.") {
676+
return domain.ESLint9
677+
} else {
678+
return domain.ESLint
679+
}
680+
}
681+
682+
// For other tools, find the first matching UUID
683+
for uuid, meta := range domain.SupportedToolsMetadata {
684+
if meta.Name == toolName {
685+
return uuid
686+
}
687+
}
688+
689+
return ""
690+
}
691+
651692
// createDefaultConfigurationsForSpecificTools creates default configurations for specific tools only
652693
func createDefaultConfigurationsForSpecificTools(discoveredToolNames map[string]struct{}, toolsConfigDir string, initFlags domain.InitFlags) error {
653694
fmt.Printf("Creating default configurations for %d discovered tools...\n", len(discoveredToolNames))
654695

655-
// Convert tool names to UUIDs
696+
// Get default tool versions to determine correct UUIDs
697+
defaultVersions := plugins.GetToolVersions()
698+
699+
// Convert tool names to UUIDs, selecting the correct UUID based on version
656700
var discoveredUUIDs []string
657701
for toolName := range discoveredToolNames {
658-
for uuid, meta := range domain.SupportedToolsMetadata {
659-
if meta.Name == toolName {
660-
discoveredUUIDs = append(discoveredUUIDs, uuid)
661-
break
662-
}
702+
uuid := selectCorrectToolUUID(toolName, defaultVersions)
703+
if uuid != "" {
704+
discoveredUUIDs = append(discoveredUUIDs, uuid)
663705
}
664706
}
665707

integration-tests/init-without-token/expected/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tools:
88
99
1010
11-
- pmd@6.55.0
11+
- pmd@7.11.0
1212
1313
1414

integration-tests/init-without-token/expected/tools-configs/ruleset.xml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<?xml version="1.0"?>
2-
<ruleset name="Codacy PMD Ruleset"
3-
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="Codacy PMD 7 Ruleset"
3+
xmlns="https://pmd.github.io/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
6-
<description>Codacy PMD Ruleset</description>
5+
xsi:schemaLocation="https://pmd.github.io/ruleset/2.0.0 https://pmd.github.io/schemas/pmd-7.0.0.xsd">
6+
<description>Codacy PMD 7 Ruleset</description>
77
<rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts"/>
88
<rule ref="category/apex/design.xml/ExcessiveClassLength"/>
99
<rule ref="category/apex/design.xml/ExcessiveParameterList"/>
@@ -33,16 +33,13 @@
3333
</rule>
3434
<rule ref="category/ecmascript/codestyle.xml/UnnecessaryBlock"/>
3535
<rule ref="category/ecmascript/errorprone.xml/EqualComparison"/>
36-
<rule ref="category/ecmascript/errorprone.xml/InnaccurateNumericLiteral"/>
3736
<rule ref="category/java/bestpractices.xml/AvoidReassigningParameters"/>
3837
<rule ref="category/java/bestpractices.xml/CheckResultSet"/>
39-
<rule ref="category/java/bestpractices.xml/JUnitTestsShouldIncludeAssert"/>
4038
<rule ref="category/java/bestpractices.xml/OneDeclarationPerLine">
4139
<properties>
4240
<property name="strictMode" value="false"/>
4341
</properties>
4442
</rule>
45-
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault"/>
4643
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
4744
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
4845
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
@@ -111,10 +108,9 @@
111108
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
112109
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass">
113110
<properties>
114-
<property name="annotations" value="org.springframework.beans.factory.annotation.Autowired,javax.inject.Inject"/>
111+
<property name="annotations" value="org.springframework.beans.factory.annotation.Autowired,javax.inject.Inject,com.google.inject.Inject,lombok.Builder"/>
115112
</properties>
116113
</rule>
117-
<rule ref="category/java/errorprone.xml/NonCaseLabelInSwitchStatement"/>
118114
<rule ref="category/java/errorprone.xml/NonStaticInitializer"/>
119115
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/>
120116
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
@@ -161,21 +157,6 @@
161157
</properties>
162158
</rule>
163159
<rule ref="category/pom/errorprone.xml/ProjectVersionAsDependencyVersion"/>
164-
<rule ref="category/vf/security.xml/VfCsrf"/>
165-
<rule ref="category/vf/security.xml/VfUnescapeEl"/>
166-
<rule ref="category/vm/bestpractices.xml/AvoidReassigningParameters"/>
167-
<rule ref="category/vm/bestpractices.xml/UnusedMacroParameter"/>
168-
<rule ref="category/vm/design.xml/AvoidDeeplyNestedIfStmts"/>
169-
<rule ref="category/vm/design.xml/CollapsibleIfStatements"/>
170-
<rule ref="category/vm/design.xml/ExcessiveTemplateLength">
171-
<properties>
172-
<property name="minimum" value="1000"/>
173-
</properties>
174-
</rule>
175-
<rule ref="category/vm/design.xml/NoInlineJavaScript"/>
176-
<rule ref="category/vm/design.xml/NoInlineStyles"/>
177-
<rule ref="category/vm/errorprone.xml/EmptyForeachStmt"/>
178-
<rule ref="category/vm/errorprone.xml/EmptyIfStmt"/>
179160
<rule ref="category/xml/errorprone.xml/MistypedCDATASection"/>
180161
<rule ref="category/xsl/codestyle.xml/UseConcatOnce"/>
181162
<rule ref="category/xsl/performance.xml/AvoidAxisNavigation">

integration-tests/run.sh

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ normalize_xml_config() {
426426
' "$file"
427427
}
428428

429+
# Shared cleanup function for test directories
430+
cleanup_codacy() {
431+
if [ -d ".codacy" ]; then
432+
rm -rf .codacy
433+
echo "🧹 Cleaned up .codacy directory"
434+
fi
435+
}
436+
429437
compare_files() {
430438
local expected_dir="$1"
431439
local actual_dir="$2"
@@ -486,19 +494,15 @@ run_init_test() {
486494

487495
cd "$test_dir" || exit 1
488496

489-
# Set up cleanup trap to ensure .codacy is always removed
490-
cleanup_codacy() {
491-
if [ -d ".codacy" ]; then
492-
rm -rf .codacy
493-
echo "🧹 Cleaned up .codacy directory"
494-
fi
495-
}
496-
trap cleanup_codacy EXIT
497-
497+
# Clean up any previous test results
498498
rm -rf .codacy
499499

500500
if [ "$use_token" = "true" ]; then
501-
[ -n "$CODACY_API_TOKEN" ] || { echo "❌ Skipping token-based test: CODACY_API_TOKEN not set"; return 0; }
501+
[ -n "$CODACY_API_TOKEN" ] || {
502+
echo "❌ Skipping token-based test: CODACY_API_TOKEN not set"
503+
cleanup_codacy
504+
return 0
505+
}
502506
"$CLI_PATH" init --api-token "$CODACY_API_TOKEN" --organization troubleshoot-codacy-dev --provider gh --repository codacy-cli-test
503507
else
504508
"$CLI_PATH" init
@@ -509,7 +513,8 @@ run_init_test() {
509513
echo "✅ Test $test_name completed successfully"
510514
echo "----------------------------------------"
511515

512-
# Cleanup will happen automatically via trap
516+
# Clean up test artifacts
517+
cleanup_codacy
513518
}
514519

515520
run_config_discover_test() {
@@ -521,15 +526,6 @@ run_config_discover_test() {
521526

522527
cd "$test_dir" || exit 1
523528

524-
# Set up cleanup trap to ensure .codacy is always removed
525-
cleanup_codacy() {
526-
if [ -d ".codacy" ]; then
527-
rm -rf .codacy
528-
echo "🧹 Cleaned up .codacy directory"
529-
fi
530-
}
531-
trap cleanup_codacy EXIT
532-
533529
# Clean up previous test results
534530
rm -rf .codacy
535531

@@ -580,7 +576,8 @@ EOF
580576
echo "✅ Test $test_name completed successfully"
581577
echo "----------------------------------------"
582578

583-
# Cleanup will happen automatically via trap
579+
# Clean up test artifacts
580+
cleanup_codacy
584581
}
585582

586583
# Run all tests

0 commit comments

Comments
 (0)