@Test public void should_validate_single_select_list() { PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.SINGLE_SELECT_LIST).options("de", "en").build(); assertThat(def.validate(null).isValid()).isTrue(); assertThat(def.validate("").isValid()).isTrue(); assertThat(def.validate(" ").isValid()).isTrue(); assertThat(def.validate("de").isValid()).isTrue(); assertThat(def.validate("en").isValid()).isTrue(); assertThat(def.validate("fr").isValid()).isFalse(); assertThat(def.validate("fr").getErrorKey()).isEqualTo("notInOptions"); }
@Test public void should_create_property() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .defaultValue("world") .category("categ") .options("de", "en") .description("desc") .type(PropertyType.FLOAT) .onlyOnQualifiers(Qualifiers.MODULE) .multiValues(true) .propertySetKey("set") .build(); assertThat(def.key()).isEqualTo("hello"); assertThat(def.name()).isEqualTo("Hello"); assertThat(def.defaultValue()).isEqualTo("world"); assertThat(def.category()).isEqualTo("categ"); assertThat(def.options()).containsOnly("de", "en"); assertThat(def.description()).isEqualTo("desc"); assertThat(def.type()).isEqualTo(PropertyType.FLOAT); assertThat(def.global()).isFalse(); assertThat(def.qualifiers()).containsOnly(Qualifiers.MODULE); assertThat(def.multiValues()).isTrue(); assertThat(def.propertySetKey()).isEqualTo("set"); assertThat(def.fields()).isEmpty(); }
@Test public void return_single_select_list_property() { logIn(); propertyDefinitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.SINGLE_SELECT_LIST) .options("one", "two") .build()); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).hasSize(1); Definition definition = result.getDefinitions(0); assertThat(definition.getType()).isEqualTo(SINGLE_SELECT_LIST); assertThat(definition.getOptionsList()).containsExactly("one", "two"); }
.onQualifiers(Qualifiers.PROJECT) .defaultValue(SEVERITY_LIST.get(0)) .options(SEVERITY_LIST).build(), PropertyDefinition.builder(STASH_REVIEWER_APPROVAL_SEVERITY_THRESHOLD) .name("Threshold tie the approval to the severity of the found issues") .onQualifiers(Qualifiers.PROJECT) .defaultValue(SEVERITY_NONE) .options(SEVERITY_LIST_WITH_NONE).build(), PropertyDefinition.builder(STASH_TASK_SEVERITY_THRESHOLD) .name("Stash tasks severity threshold") .onQualifiers(Qualifiers.PROJECT) .defaultValue(SEVERITY_NONE) .options(SEVERITY_LIST_WITH_NONE).build(), PropertyDefinition.builder(STASH_INCLUDE_ANALYSIS_OVERVIEW) .name("Include Analysis Overview Comment")
PropertyDefinition.builder(GITLAB_BUILD_INIT_STATE).name("Build Initial State").description("State that should be the first when build commit status update is called.") .category(CATEGORY).subCategory(SUBCATEGORY).type(PropertyType.SINGLE_SELECT_LIST) .options(BuildInitState.PENDING.getMeaning(), BuildInitState.RUNNING.getMeaning()).defaultValue(BuildInitState.PENDING.getMeaning()).index(17).build(), PropertyDefinition.builder(GITLAB_DISABLE_GLOBAL_COMMENT).name("Disable global comment").description("Disable global comment, report only inline.") .category(CATEGORY).subCategory(SUBCATEGORY).type(PropertyType.BOOLEAN).defaultValue(String.valueOf(false)).index(18).build(), PropertyDefinition.builder(GITLAB_STATUS_NOTIFICATION_MODE).name("Status notification mode").description("Status notification mode: commit-status or exit-code") .category(CATEGORY).subCategory(SUBCATEGORY).type(PropertyType.SINGLE_SELECT_LIST) .options(StatusNotificationsMode.COMMIT_STATUS.getMeaning(), StatusNotificationsMode.EXIT_CODE.getMeaning(), StatusNotificationsMode.NOTHING.getMeaning()).defaultValue(StatusNotificationsMode.COMMIT_STATUS.getMeaning()) .index(19).build(), PropertyDefinition.builder(GITLAB_GLOBAL_TEMPLATE).name("Global template").description("Template for global comment in commit.").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.STRING).defaultValue("").index(24).build(), PropertyDefinition.builder(GITLAB_API_VERSION).name("Set GitLab API version").description("GitLab API version").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.SINGLE_SELECT_LIST).options(V3_API_VERSION, V4_API_VERSION).defaultValue(V4_API_VERSION).index(25).build(), PropertyDefinition.builder(GITLAB_ALL_ISSUES).name("All issues").description("Show all issues. (Default false, only new)").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.BOOLEAN).defaultValue(String.valueOf(false)).index(26).build(), PropertyDefinition.builder(GITLAB_JSON_MODE).name("Generate json report").description("Create a json report in root for GitLab EE").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.SINGLE_SELECT_LIST).options(JsonMode.NONE.name(), JsonMode.CODECLIMATE.name(), JsonMode.SAST.name()).defaultValue(JsonMode.NONE.name()).onlyOnQualifiers(Qualifiers.PROJECT).index(27).build(), PropertyDefinition.builder(GITLAB_QUERY_MAX_RETRY).name("Query max retry").description("Max retry for wait finish analyse for publish mode").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.INTEGER).defaultValue(String.valueOf(50)).index(28).build(), PropertyDefinition.builder(GITLAB_QUALITY_GATE_FAIL_MODE).name("Quality Gate fail mode").description("Quality gate fail mode: error or warn") .category(CATEGORY).subCategory(SUBCATEGORY).type(PropertyType.SINGLE_SELECT_LIST) .options(QualityGateFailMode.WARN.getMeaning(), QualityGateFailMode.ERROR.getMeaning()).defaultValue(QualityGateFailMode.ERROR.getMeaning()) .index(30).build(), PropertyDefinition.builder(GITLAB_ISSUE_FILTER).name("Issue filter").description("Filter on issue, if MAJOR then show only MAJOR, CRITICAL and BLOCKER") .category(CATEGORY).subCategory(SUBCATEGORY).type(PropertyType.SINGLE_SELECT_LIST) .options(Severity.INFO.name(), Severity.MINOR.name(), Severity.MAJOR.name(), Severity.CRITICAL.name(), Severity.BLOCKER.name()) .defaultValue(Severity.INFO.name())
.onQualifiers(Qualifiers.PROJECT) .type(PropertyType.SINGLE_SELECT_LIST) .options( DISABLED, Severity.INFO,
.subCategory(SUBCATEGORY_EMAIL) .type(SINGLE_SELECT_LIST) .options("ssl", "starttls") .build(), PropertyDefinition.builder(SMTP_USERNAME)
.type(SINGLE_SELECT_LIST) .defaultValue(LOGIN_STRATEGY_DEFAULT_VALUE) .options(LOGIN_STRATEGY_UNIQUE, LOGIN_STRATEGY_PROVIDER_ID) .index(7) .build(), .type(SINGLE_SELECT_LIST) .defaultValue(DIRECTORY_LOC_GLOBAL) .options(DIRECTORY_LOC_GLOBAL, DIRECTORY_LOC_USGOV, DIRECTORY_LOC_DE, DIRECTORY_LOC_CN) .index(8) .build(),
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = new ArrayList<>(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }
static List<PropertyDefinition> definitions() { return Arrays.asList(PropertyDefinition.builder(GITLAB_AUTH_ENABLED).name("Enabled").description("Enable Gitlab users to login. Value is ignored if client ID and secret are not defined.") .category(CATEGORY).subCategory(SUBCATEGORY).type(BOOLEAN).defaultValue(valueOf(false)).index(1).build(), PropertyDefinition.builder(GITLAB_AUTH_URL).name("GitLab url").description("URL to access GitLab.").category(CATEGORY).subCategory(SUBCATEGORY).defaultValue("https://gitlab.com") .index(2).build(), PropertyDefinition.builder(GITLAB_AUTH_APPLICATIONID).name("Application ID").description("Application ID provided by GitLab when registering the application.").category(CATEGORY) .subCategory(SUBCATEGORY).index(3).build(), PropertyDefinition.builder(GITLAB_AUTH_SECRET).name("Secret").description("Secret provided by GitLab when registering the application.").category(CATEGORY).subCategory(SUBCATEGORY) .index(4).build(), PropertyDefinition.builder(GITLAB_AUTH_ALLOWUSERSTOSIGNUP).name("Allow users to sign-up") .description("Allow new users to authenticate. When set to 'false', only existing users will be able to authenticate to the server.").category(CATEGORY) .subCategory(SUBCATEGORY).type(BOOLEAN).defaultValue(valueOf(true)).index(5).build(), PropertyDefinition.builder(GITLAB_AUTH_SCOPE).name("Gitlab access scope").description("Scope provided by GitLab when access user info.").category(CATEGORY).subCategory(SUBCATEGORY) .type(SINGLE_SELECT_LIST).options(NONE_SCOPE, READ_USER_SCOPE, API_SCOPE).defaultValue(READ_USER_SCOPE).index(6).build(), PropertyDefinition.builder(GITLAB_AUTH_GROUPS).name("Default groups").description("Set default groups for user").category(CATEGORY).subCategory(SUBCATEGORY).index(7).build(), PropertyDefinition.builder(GITLAB_AUTH_SYNC_USER_GROUPS).name("Synchronize user groups").description("Synchronize GitLab and Sonar user groups").category(CATEGORY) .subCategory(SUBCATEGORY).type(PropertyType.BOOLEAN).defaultValue(valueOf(false)).index(8).build(), PropertyDefinition.builder(GITLAB_AUTH_API_VERSION).name("Set GitLab API version").description("GitLab API version").category(CATEGORY).subCategory(SUBCATEGORY) .type(PropertyType.SINGLE_SELECT_LIST).options(V3_API_VERSION, V4_API_VERSION).defaultValue(V4_API_VERSION).index(9).build(), PropertyDefinition.builder(GITLAB_AUTH_USER_EXCEPTIONS).name("User exceptions").description("Comma separated list of usernames to keep intact").category(CATEGORY) .subCategory(SUBCATEGORY).type(PropertyType.STRING).defaultValue("").index(10).build(), PropertyDefinition.builder(GITLAB_AUTH_IGNORE_CERT).name("GitLab Ignore Certificate").description("Ignore Certificate for access GitLab."). category(CATEGORY).subCategory(SUBCATEGORY). type(PropertyType.BOOLEAN). defaultValue(String.valueOf(false)). index(11).build()); }
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(Arrays.asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = newArrayList(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }
.subCategory(SUBCATEGORY_EMAIL) .type(SINGLE_SELECT_LIST) .options("ssl", "starttls") .build(), PropertyDefinition.builder(SMTP_USERNAME)
.type(PropertyType.SINGLE_SELECT_LIST) .category("general") .options("a", "b") .build(), PropertyDefinition.builder("sonar.multiValues")
static PropertyDefinition create(Property annotation) { Builder builder = PropertyDefinition.builder(annotation.key()) .name(annotation.name()) .defaultValue(annotation.defaultValue()) .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) .options(asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) .deprecatedKey(annotation.deprecatedKey()); List<String> qualifiers = new ArrayList<>(); if (annotation.project()) { qualifiers.add(Qualifiers.PROJECT); } if (annotation.module()) { qualifiers.add(Qualifiers.MODULE); } if (annotation.global()) { builder.onQualifiers(qualifiers); } else { builder.onlyOnQualifiers(qualifiers); } return builder.build(); }