Search in sources :

Example 1 with Languages

use of org.sonar.api.resources.Languages in project sonarqube by SonarSource.

the class ExportAction method define.

@Override
public void define(WebService.NewController controller) {
    NewAction action = controller.createAction("export").setSince("5.2").setDescription("Export a quality profile.").setResponseExample(getClass().getResource("export-example.xml")).setHandler(this);
    action.createParam(PARAM_PROFILE_NAME).setDescription("The name of the quality profile to export. If left empty, will export the default profile for the language.").setExampleValue("My Sonar way");
    action.createParam(PARAM_LANGUAGE).setDescription("The language for the quality profile.").setExampleValue(LanguageParamUtils.getExampleValue(languages)).setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)).setRequired(true);
    Set<String> exporterKeys = Arrays.stream(languages.all()).map(language -> exporters.exportersForLanguage(language.getKey())).flatMap(Collection::stream).map(ProfileExporter::getKey).collect(Collectors.toSet());
    if (!exporterKeys.isEmpty()) {
        action.createParam(PARAM_FORMAT).setDescription("Output format. If left empty, the same format as api/qualityprofiles/backup is used. " + "Possible values are described by api/qualityprofiles/exporters.").setPossibleValues(exporterKeys).setDeprecatedKey("format", "6.3");
    }
}
Also used : Arrays(java.util.Arrays) QProfileExporters(org.sonar.server.qualityprofile.QProfileExporters) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) WsUtils.checkFound(org.sonar.server.ws.WsUtils.checkFound) Response(org.sonar.api.server.ws.Response) OutputStreamWriter(java.io.OutputStreamWriter) ProfileExporter(org.sonar.api.profiles.ProfileExporter) MediaTypes(org.sonarqube.ws.MediaTypes) Nullable(javax.annotation.Nullable) OutputStream(java.io.OutputStream) Collection(java.util.Collection) Stream(org.sonar.api.server.ws.Response.Stream) LanguageParamUtils(org.sonar.server.util.LanguageParamUtils) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) IOException(java.io.IOException) NewAction(org.sonar.api.server.ws.WebService.NewAction) StandardCharsets(java.nio.charset.StandardCharsets) DbClient(org.sonar.db.DbClient) Writer(java.io.Writer) QProfileBackuper(org.sonar.server.qualityprofile.QProfileBackuper) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Collection(java.util.Collection) NewAction(org.sonar.api.server.ws.WebService.NewAction)

Example 2 with Languages

use of org.sonar.api.resources.Languages in project sonarqube by SonarSource.

the class ComponentsWsTest method setUp.

@Before
public void setUp() {
    Languages languages = mock(Languages.class, RETURNS_DEEP_STUBS);
    when(languages.all()).thenReturn(new Language[0]);
    WsTester tester = new WsTester(new ComponentsWs(new AppAction(mock(DbClient.class), userSessionRule, mock(ComponentFinder.class)), new SuggestionsAction(mock(DbClient.class), mock(ComponentIndex.class)), new SearchAction(mock(DbClient.class), mock(ResourceTypes.class), mock(I18n.class), userSessionRule, languages, TestDefaultOrganizationProvider.fromUuid("foo"))));
    controller = tester.controller("api/components");
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) ResourceTypes(org.sonar.api.resources.ResourceTypes) DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) Languages(org.sonar.api.resources.Languages) ComponentIndex(org.sonar.server.component.index.ComponentIndex) I18n(org.sonar.api.i18n.I18n) Before(org.junit.Before)

Example 3 with Languages

use of org.sonar.api.resources.Languages in project sonarqube by SonarSource.

the class DeleteActionTest method setUp.

@Before
public void setUp() {
    xoo1 = LanguageTesting.newLanguage("xoo1");
    xoo2 = LanguageTesting.newLanguage("xoo2");
    tester = new WsTester(new QProfilesWs(mock(RuleActivationActions.class), mock(BulkRuleActivationActions.class), new DeleteAction(new Languages(xoo1, xoo2), new QProfileFactory(dbClient, defaultOrganizationProvider), dbClient, new QProfileWsSupport(userSessionRule, defaultOrganizationProvider))));
}
Also used : QProfileFactory(org.sonar.server.qualityprofile.QProfileFactory) WsTester(org.sonar.server.ws.WsTester) Languages(org.sonar.api.resources.Languages) Before(org.junit.Before)

Example 4 with Languages

use of org.sonar.api.resources.Languages in project sonarqube by SonarSource.

the class QProfileRefTest method define_ws_parameters.

@Test
public void define_ws_parameters() {
    WsTester wsTester = new WsTester();
    WebService.NewController controller = wsTester.context().createController("api/qualityprofiles");
    WebService.NewAction newAction = controller.createAction("do").setHandler((request, response) -> {
    });
    Languages languages = new Languages(new FakeLanguage("java"), new FakeLanguage("js"));
    QProfileRef.defineParams(newAction, languages);
    controller.done();
    WebService.Action action = wsTester.controller("api/qualityprofiles").action("do");
    assertThat(action.param("language")).isNotNull();
    assertThat(action.param("language").possibleValues()).containsOnly("java", "js");
    assertThat(action.param("profileKey")).isNotNull();
    assertThat(action.param("profileName")).isNotNull();
}
Also used : WsTester(org.sonar.server.ws.WsTester) WebService(org.sonar.api.server.ws.WebService) Languages(org.sonar.api.resources.Languages) Test(org.junit.Test)

Example 5 with Languages

use of org.sonar.api.resources.Languages in project sonarqube by SonarSource.

the class SearchActionTest method setUp.

@Before
public void setUp() {
    xoo1 = LanguageTesting.newLanguage("xoo1");
    xoo2 = LanguageTesting.newLanguage("xoo2");
    Languages languages = new Languages(xoo1, xoo2);
    ws = new WsActionTester(new SearchAction(new SearchDataLoader(languages, new QProfileLookup(dbClient), new QProfileFactory(dbClient, defaultOrganizationProvider), dbClient, new ComponentFinder(dbClient), activeRuleIndex), languages));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) QProfileFactory(org.sonar.server.qualityprofile.QProfileFactory) Languages(org.sonar.api.resources.Languages) WsActionTester(org.sonar.server.ws.WsActionTester) QProfileLookup(org.sonar.server.qualityprofile.QProfileLookup) Before(org.junit.Before)

Aggregations

Languages (org.sonar.api.resources.Languages)16 Test (org.junit.Test)10 MapSettings (org.sonar.api.config.MapSettings)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 Settings (org.sonar.api.config.Settings)5 Before (org.junit.Before)4 WsTester (org.sonar.server.ws.WsTester)4 DbClient (org.sonar.db.DbClient)3 QProfileFactory (org.sonar.server.qualityprofile.QProfileFactory)3 I18n (org.sonar.api.i18n.I18n)2 WebService (org.sonar.api.server.ws.WebService)2 MessageException (org.sonar.api.utils.MessageException)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 QProfileExporters (org.sonar.server.qualityprofile.QProfileExporters)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 StandardCharsets (java.nio.charset.StandardCharsets)1