Skip to content

Commit

Permalink
#753: Add support for Sonarqube 10.0
Browse files Browse the repository at this point in the history
Sonarqube 10 has removed legacy support for modules as well as removing
deprecated properties historically used for specifying branch targets.
Additionally, the interface for managing Sonarqube features has had a
method renamed, which makes the new version of Sonarqube binary
incompatible with the plugin. The references to Sonarqube's removed code
have been removed from the plugin, and the implementations of the
interface and Java agent that dynamically updates Sonarqube code that
also implements the interface have been updated to use the new method
name.
  • Loading branch information
mc1arke committed Apr 5, 2023
1 parent 344a37f commit 94dd33b
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 48 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fail-fast: false
matrix:
java:
- 11
- 17
steps:
-
name: Checkout
Expand All @@ -67,7 +67,7 @@ jobs:
./gradlew clean build
-
name: Archive artifact
if: success() && matrix.java == '11'
if: success() && matrix.java == '17'
uses: actions/upload-artifact@v3
with:
name: snapshot
Expand All @@ -87,7 +87,7 @@ jobs:
name: Set up Java
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
java-package: jdk
distribution: 'zulu'
-
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
name: Set up Java
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
java-package: jdk
distribution: 'zulu'
-
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Michael Clarke
* Copyright (C) 2020-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -40,7 +40,7 @@ repositories {
}
}

def sonarqubeVersion = '9.8.0.63668'
def sonarqubeVersion = '10.0.0.68432'
def sonarqubeLibDir = "${projectDir}/sonarqube-lib"
def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib"

Expand Down Expand Up @@ -100,7 +100,7 @@ jar {
'Plugin-License': 'GNU LGPL 3',
'Plugin-Version': "${project.version}",
'Plugin-Organization': 'Michael Clarke',
'Sonar-Version': "${sonarqubeVersion}",
'Sonar-Version': "9.14.0.375",
'Plugin-IssueTrackerUrl': 'https://github.com/mc1arke/sonarqube-community-branch-plugin/issues',
'Plugin-Key': 'communityBranchPlugin',
'Plugin-Class': 'com.github.mc1arke.sonarqube.plugin.CommunityBranchPluginBootstrap',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Michael Clarke
* Copyright (C) 2021-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -52,9 +52,9 @@ public static void premain(String args, Instrumentation instrumentation) throws

if (component == Component.CE) {
redefineEdition(instrumentation, "org.sonar.core.platform.PlatformEditionProvider", redefineOptionalEditionGetMethod());
redefineEdition(instrumentation, "org.sonar.server.almsettings.MultipleAlmFeature", redefineIsEnabledFlag());
redefineEdition(instrumentation, "org.sonar.server.almsettings.MultipleAlmFeature", redefineIsAvailableFlag());
} else if (component == Component.WEB) {
redefineEdition(instrumentation, "org.sonar.server.almsettings.MultipleAlmFeature", redefineIsEnabledFlag());
redefineEdition(instrumentation, "org.sonar.server.almsettings.MultipleAlmFeature", redefineIsAvailableFlag());
redefineEdition(instrumentation, "org.sonar.server.newcodeperiod.ws.SetAction", redefineConstructorEditionProviderField(EditionProvider.Edition.DEVELOPER));
redefineEdition(instrumentation, "org.sonar.server.newcodeperiod.ws.UnsetAction", redefineConstructorEditionProviderField(EditionProvider.Edition.DEVELOPER));
}
Expand Down Expand Up @@ -102,9 +102,9 @@ private static Redefiner redefineOptionalEditionGetMethod() {
};
}

private static Redefiner redefineIsEnabledFlag() {
private static Redefiner redefineIsAvailableFlag() {
return ctClass -> {
CtMethod ctMethod = ctClass.getDeclaredMethod("isEnabled");
CtMethod ctMethod = ctClass.getDeclaredMethod("isAvailable");
ctMethod.setBody("return true;");
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Michael Clarke
* Copyright (C) 2020-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -54,16 +54,13 @@ public class CommunityBranchConfigurationLoader implements BranchConfigurationLo
ScannerProperties.PULL_REQUEST_BASE));

private final System2 system2;
private final AnalysisWarnings analysisWarnings;
private final BranchConfigurationFactory branchConfigurationFactory;
private final List<BranchAutoConfigurer> autoConfigurers;

public CommunityBranchConfigurationLoader(System2 system2, AnalysisWarnings analysisWarnings,
BranchConfigurationFactory branchConfigurationFactory,
public CommunityBranchConfigurationLoader(System2 system2, BranchConfigurationFactory branchConfigurationFactory,
List<BranchAutoConfigurer> autoConfigurers) {
super();
this.system2 = system2;
this.analysisWarnings = analysisWarnings;
this.branchConfigurationFactory = branchConfigurationFactory;
this.autoConfigurers = autoConfigurers;
}
Expand Down Expand Up @@ -94,12 +91,6 @@ public BranchConfiguration load(Map<String, String> localSettings, ProjectBranch
}
}

if (null != localSettings.get(ScannerProperties.BRANCH_TARGET)) { //NOSONAR - purposefully checking for a deprecated parameter
String warning = String.format("Property '%s' is no longer supported", ScannerProperties.BRANCH_TARGET); //NOSONAR - reporting use of deprecated parameter
analysisWarnings.addUnique(warning);
LOGGER.warn(warning);
}

if (hasBranchParameters) {
String branch = StringUtils.trimToNull(localSettings.get(ScannerProperties.BRANCH_NAME));
return branchConfigurationFactory.createBranchConfiguration(branch, projectBranches);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2022 Michael Clarke
* Copyright (C) 2019-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -33,7 +33,7 @@ public String getName() {
}

@Override
public boolean isEnabled() {
public boolean isAvailable() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Michael Clarke
* Copyright (C) 2020-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -94,10 +94,8 @@ public ComponentDto createBranchComponent(DbSession dbSession, BranchSupport.Com

ComponentDto componentDto = mainComponentDto.copy()
.setUuid(branchUuid)
.setRootUuid(branchUuid)
.setBranchUuid(branchUuid)
.setUuidPath(ComponentDto.UUID_PATH_OF_ROOT)
.setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + branchUuid + ComponentDto.UUID_PATH_SEPARATOR)
.setMainBranchProjectUuid(mainComponentDto.uuid())
.setCreatedAt(new Date(clock.millis()));
dbClient.componentDao().insert(dbSession, componentDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Michael Clarke
* Copyright (C) 2022-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -32,7 +32,7 @@ public String getName() {
}

@Override
public boolean isEnabled() {
public boolean isAvailable() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Michael Clarke
* Copyright (C) 2021-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -76,7 +76,7 @@ void shouldRedefineMultipleAlmFeatureClassForWebLaunch() throws ReflectiveOperat
SonarRuntime sonarRuntime = mock(SonarRuntime.class);

SonarQubeFeature multipleAlmFeatureProvider = redefined.getConstructor(SonarRuntime.class).newInstance(sonarRuntime);
assertThat(multipleAlmFeatureProvider.isEnabled()).isTrue();
assertThat(multipleAlmFeatureProvider.isAvailable()).isTrue();
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ void shouldRedefineTargetClassesForCeLaunch() throws ReflectiveOperationExceptio

Class<MultipleAlmFeature> redefined = (Class<MultipleAlmFeature>) classLoader.loadClass(MultipleAlmFeature.class.getName(), result);
SonarQubeFeature multipleAlmFeatureProvider = redefined.getConstructor(SonarRuntime.class).newInstance(sonarRuntime);
assertThat(multipleAlmFeatureProvider.isEnabled()).isTrue();
assertThat(multipleAlmFeatureProvider.isAvailable()).isTrue();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Michael Clarke
* Copyright (C) 2020-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -31,7 +31,6 @@
import java.util.Optional;

import org.junit.jupiter.api.Test;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.System2;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.branch.BranchConfigurationLoader;
Expand All @@ -43,11 +42,10 @@
*/
class CommunityBranchConfigurationLoaderTest {

private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
private final System2 system2 = mock(System2.class);
private final BranchConfigurationFactory branchConfigurationFactory = mock(BranchConfigurationFactory.class);
private final BranchAutoConfigurer branchAutoConfigurer = mock(BranchAutoConfigurer.class);
private final BranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(system2, analysisWarnings, branchConfigurationFactory, List.of(branchAutoConfigurer));
private final BranchConfigurationLoader testCase = new CommunityBranchConfigurationLoader(system2, branchConfigurationFactory, List.of(branchAutoConfigurer));

@Test
void shouldReturnResultFromAutoConfigurerIfPresentAndNoParametersSpecified() {
Expand Down Expand Up @@ -87,7 +85,6 @@ void shouldCreateBranchConfigurationIfAnyBranchPropertiesSet() {
assertThat(actual).isSameAs(branchConfiguration);
verify(branchConfigurationFactory).createBranchConfiguration("branch", projectBranches);
verifyNoInteractions(branchAutoConfigurer);
verify(analysisWarnings).addUnique("Property 'sonar.branch.target' is no longer supported");
}

@Test
Expand All @@ -101,7 +98,6 @@ void shouldCreatePullConfigurationIfAnyPullRequestPropertiesSet() {
assertThat(actual).isSameAs(branchConfiguration);
verify(branchConfigurationFactory).createPullRequestConfiguration("key", "source", "target", projectBranches);
verifyNoInteractions(branchAutoConfigurer);
verifyNoInteractions(analysisWarnings);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2022 Michael Clarke
* Copyright (C) 2019-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -36,6 +36,6 @@ void shouldReturnNameThatFrontEndLooksFor() {

@Test
void shouldReturnEnabledForFeature() {
assertThat(underTest.isEnabled()).isTrue();
assertThat(underTest.isAvailable()).isTrue();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Michael Clarke
* Copyright (C) 2020-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -154,9 +154,7 @@ void shouldCreateComponentAndBranchDtoIfValidationPasses(String branchName, Stri
when(componentDto.copy()).thenReturn(copyComponentDto);
when(copyComponentDto.setBranchUuid(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setKey(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setRootUuid(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setUuidPath(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setModuleUuidPath(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setUuid(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setMainBranchProjectUuid(any())).thenReturn(copyComponentDto);
when(copyComponentDto.setCreatedAt(any())).thenReturn(copyComponentDto);
Expand Down Expand Up @@ -187,9 +185,7 @@ void shouldCreateComponentAndBranchDtoIfValidationPasses(String branchName, Stri

verify(componentDao).insert(dbSession, copyComponentDto);
verify(copyComponentDto).setUuid("uuid0");
verify(copyComponentDto).setRootUuid("uuid0");
verify(copyComponentDto).setUuidPath(".");
verify(copyComponentDto).setModuleUuidPath(".uuid0.");
verify(copyComponentDto).setMainBranchProjectUuid("componentUuid");
verify(copyComponentDto).setCreatedAt(new Date(12345678901234L));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Michael Clarke
* Copyright (C) 2022-2023 Michael Clarke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -33,7 +33,7 @@ void shouldMatchNameRequiredByFrontEnd() {

@Test
void shouldSetFeatureAsEnabled() {
assertThat(underTest.isEnabled()).isTrue();
assertThat(underTest.isAvailable()).isTrue();
}

}

0 comments on commit 94dd33b

Please sign in to comment.