Skip to content

Commit

Permalink
#754 #782: Add support for Sonarqube 10.1
Browse files Browse the repository at this point in the history
    based on the branch: feature/sonarqube-10_0-support

    1. upgrade sonarqubeVersion to '10.0.0.68432'
    2. fixed dbClient.componentDao().insert(DbSession session, ComponentDto item, boolean isMainBranch)
    3. fixed UT code
  • Loading branch information
bluebu committed Jul 21, 2023
1 parent ebe6388 commit 86df03a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,17 @@ public ComponentDto createBranchComponent(DbSession dbSession, BranchSupport.Com
.setUuidPath(ComponentDto.UUID_PATH_OF_ROOT)
.setMainBranchProjectUuid(mainComponentDto.uuid())
.setCreatedAt(new Date(clock.millis()));
dbClient.componentDao().insert(dbSession, componentDto);
dbClient.componentDao().insert(dbSession, componentDto, mainComponentBranchDto.isMain());

BranchDto branchDto = new BranchDto()
.setProjectUuid(mainComponentDto.uuid())
.setUuid(branchUuid);
.setUuid(branchUuid)
.setIsMain(mainComponentBranchDto.isMain());
componentKey.getPullRequestKey().ifPresent(pullRequestKey -> branchDto.setBranchType(BranchType.PULL_REQUEST)
.setExcludeFromPurge(false)
.setKey(pullRequestKey));
componentKey.getBranchName().ifPresent(branchName -> branchDto.setBranchType(BranchType.BRANCH)
.setExcludeFromPurge(isBranchExcludedFromPurge(projectConfigurationLoader.loadProjectConfiguration(dbSession, mainComponentDto), branchName))
.setExcludeFromPurge(isBranchExcludedFromPurge(projectConfigurationLoader.loadProjectConfiguration(dbSession, branchDto.getProjectUuid()), branchName))
.setKey(branchName));
dbClient.branchDao().insert(dbSession, branchDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
import java.lang.instrument.UnmodifiableClassException;
import java.lang.reflect.Field;
import java.util.Optional;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.SonarRuntime;
import org.sonar.core.documentation.DefaultDocumentationLinkGenerator;
import org.sonar.core.documentation.DocumentationLinkGenerator;
import org.sonar.core.platform.EditionProvider;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.db.DbClient;
Expand Down Expand Up @@ -85,6 +86,7 @@ void shouldRedefineMultipleAlmFeatureClassForWebLaunch() throws ReflectiveOperat
void shouldRedefineSetActionClassForWebLaunch() throws ReflectiveOperationException, IOException, UnmodifiableClassException, IllegalClassFormatException {
CustomClassloader classLoader = new CustomClassloader();
Instrumentation instrumentation = mock(Instrumentation.class);
DocumentationLinkGenerator documentationLinkGenerator = mock(DefaultDocumentationLinkGenerator.class);

CommunityBranchAgent.premain("web", instrumentation);

Expand All @@ -104,8 +106,8 @@ void shouldRedefineSetActionClassForWebLaunch() throws ReflectiveOperationExcept
PlatformEditionProvider platformEditionProvider = mock(PlatformEditionProvider.class);
NewCodePeriodDao newCodePeriodDao = mock(NewCodePeriodDao.class);

Object setAction = setActionClass.getConstructor(DbClient.class, UserSession.class, ComponentFinder.class, PlatformEditionProvider.class, NewCodePeriodDao.class)
.newInstance(dbClient, userSession, componentFinder, platformEditionProvider, newCodePeriodDao);
Object setAction = setActionClass.getConstructor(DbClient.class, UserSession.class, ComponentFinder.class, PlatformEditionProvider.class, NewCodePeriodDao.class, DocumentationLinkGenerator.class)
.newInstance(dbClient, userSession, componentFinder, platformEditionProvider, newCodePeriodDao, documentationLinkGenerator);

Field editionProviderField = setActionClass.getDeclaredField("editionProvider");
editionProviderField.setAccessible(true);
Expand All @@ -119,6 +121,7 @@ void shouldRedefinesUnsetActionClassForWebLaunch() throws IOException, Unmodifia

Instrumentation instrumentation = mock(Instrumentation.class);
CommunityBranchAgent.premain("web", instrumentation);
DocumentationLinkGenerator documentationLinkGenerator = mock(DefaultDocumentationLinkGenerator.class);

ArgumentCaptor<ClassFileTransformer> classFileTransformerArgumentCaptor = ArgumentCaptor.forClass(ClassFileTransformer.class);
verify(instrumentation).retransformClasses(UnsetAction.class);
Expand All @@ -135,8 +138,8 @@ void shouldRedefinesUnsetActionClassForWebLaunch() throws IOException, Unmodifia
PlatformEditionProvider platformEditionProvider = mock(PlatformEditionProvider.class);
NewCodePeriodDao newCodePeriodDao = mock(NewCodePeriodDao.class);

Object setAction = unsetActionClass.getConstructor(DbClient.class, UserSession.class, ComponentFinder.class, PlatformEditionProvider.class, NewCodePeriodDao.class)
.newInstance(dbClient, userSession, componentFinder, platformEditionProvider, newCodePeriodDao);
Object setAction = unsetActionClass.getConstructor(DbClient.class, UserSession.class, ComponentFinder.class, PlatformEditionProvider.class, NewCodePeriodDao.class, DocumentationLinkGenerator.class)
.newInstance(dbClient, userSession, componentFinder, platformEditionProvider, newCodePeriodDao, documentationLinkGenerator);

Field editionProviderField = unsetActionClass.getDeclaredField("editionProvider");
editionProviderField.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void shouldCreateComponentAndBranchDtoIfValidationPasses(String branchName, Stri
BranchDto branchDto = mock(BranchDto.class);
when(branchDto.getUuid()).thenReturn("componentUuid");
when(branchDto.getKey()).thenReturn("nonDummy");
when(branchDto.isMain()).thenReturn(true);

when(clock.millis()).thenReturn(12345678901234L);

Expand All @@ -183,7 +184,7 @@ void shouldCreateComponentAndBranchDtoIfValidationPasses(String branchName, Stri

ComponentDto result = underTest.createBranchComponent(dbSession, componentKey, componentDto, branchDto);

verify(componentDao).insert(dbSession, copyComponentDto);
verify(componentDao).insert(dbSession, copyComponentDto, branchDto.isMain());
verify(copyComponentDto).setUuid("uuid0");
verify(copyComponentDto).setUuidPath(".");
verify(copyComponentDto).setMainBranchProjectUuid("componentUuid");
Expand All @@ -199,7 +200,7 @@ void shouldCreateComponentAndBranchDtoIfValidationPasses(String branchName, Stri
.setExcludeFromPurge(excludedFromPurge)
.setProjectUuid("componentUuid")
.setKey(branchType == BranchType.BRANCH ? branchName : pullRequestKey)
.setUuid("uuid0"));
.setUuid("uuid0").setIsMain(branchDto.isMain()));
}

}

0 comments on commit 86df03a

Please sign in to comment.