repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1 value |
|---|---|---|---|---|---|---|
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlBlockAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.util.stream.Collectors;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import static org.assertj.core.util.Preconditions.checkArgument;
public abstract class HtmlBlockAssert<T extends HtmlBlockAssert<T>> extends AbstractAssert<T, Element> {
static final String PRINT_FRAGMENT_TEMPLATE = "\n---fragment---\n%s\n---fragment---";
private static final String NO_LINK_IN_BLOC = "no link in bloc";
public HtmlBlockAssert(Element v, Class<T> selfType) {
super(v, selfType);
}
/**
* Verifies the current block contains a single link with the specified piece of text.
*/
public T withLinkOn(String linkText) {
return withLinkOn(linkText, 1);
}
/**
* Verifies the current block contains {@code times} links with the specified piece of text.
*/
public T withLinkOn(String linkText, int times) {
checkArgument(times >= 1, "times must be >= 1");
isNotNull();
Elements as = actual.select("a");
Assertions.assertThat(as)
.describedAs(NO_LINK_IN_BLOC + PRINT_FRAGMENT_TEMPLATE, actual)
.isNotEmpty();
long count = as.stream().filter(t -> linkText.equals(t.text())).count();
if (count != times) {
failWithMessage("link on text \"%s\" found %s times in bloc (expected %s). \n Got: %s", linkText, count, times, asyncLinksToString(as));
}
return myself;
}
/**
* Verifies the current block contains a link with the specified text and href.
*/
public T withLink(String linkText, String href) {
isNotNull();
Elements as = actual.select("a");
Assertions.assertThat(as)
.describedAs(NO_LINK_IN_BLOC + PRINT_FRAGMENT_TEMPLATE, actual)
.isNotEmpty();
if (as.stream().noneMatch(t -> linkText.equals(t.text()) && href.equals(t.attr("href")))) {
failWithMessage(
"link with text \"%s\" and href \"%s\" not found in block. \n Got: %s" + PRINT_FRAGMENT_TEMPLATE,
linkText, href, asyncLinksToString(as), actual);
}
return myself;
}
public T withoutLink() {
isNotNull();
Assertions.assertThat(actual.select("a")).isEmpty();
return myself;
}
private static Object asyncLinksToString(Elements linkElements) {
return new Object() {
@Override
public String toString() {
return linkElements.stream()
.map(a -> "<a href=\"" + a.attr("href") + "\">" + a.text() + "<a>")
.collect(Collectors.joining("\n"));
}
};
}
public T withEmphasisOn(String emphasisText) {
isNotNull();
Elements emphases = actual.select("em");
Assertions.assertThat(emphases)
.describedAs("no <em> in block")
.isNotEmpty();
Assertions.assertThat(emphases.stream().map(Element::text))
.contains(emphasisText);
return myself;
}
public T withSmallOn(String emphasisText) {
isNotNull();
Elements smalls = actual.select("small");
Assertions.assertThat(smalls)
.describedAs("no <small> in block")
.isNotEmpty();
Assertions.assertThat(smalls.stream().map(Element::text))
.contains(emphasisText);
return myself;
}
}
| 4,066 | 30.045802 | 142 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlFragmentAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.util.Iterator;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import static java.util.stream.Collectors.toList;
import static org.sonar.test.html.HtmlParagraphAssert.verifyIsParagraph;
public class HtmlFragmentAssert extends AbstractAssert<HtmlFragmentAssert, String> {
public HtmlFragmentAssert(String s) {
super(s, HtmlFragmentAssert.class);
}
public static HtmlFragmentAssert assertThat(String s) {
return new HtmlFragmentAssert(s);
}
public HtmlParagraphAssert hasParagraph() {
isNotNull();
Document document = Jsoup.parseBodyFragment(actual);
Iterator<Element> blockIt = document.body().children().stream()
.filter(Element::isBlock)
.collect(toList())
.iterator();
Assertions.assertThat(blockIt.hasNext())
.describedAs("no bloc in fragment")
.isTrue();
Element firstBlock = blockIt.next();
verifyIsParagraph(firstBlock);
return new HtmlParagraphAssert(firstBlock, blockIt);
}
/**
* Convenience method.
* Sames as {@code hasParagraph().withText(text)}.
*/
public HtmlParagraphAssert hasParagraph(String text) {
return hasParagraph()
.withText(text);
}
}
| 2,182 | 30.185714 | 84 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlListAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.jsoup.nodes.Element;
public class HtmlListAssert extends HtmlBlockAssert<HtmlListAssert> {
private final Iterator<Element> nextBlocks;
public HtmlListAssert(Element list, Iterator<Element> nextBlocks) {
super(list, HtmlListAssert.class);
this.nextBlocks = nextBlocks;
}
static void verifyIsList(Element element) {
Assertions.assertThat(element.tagName())
.describedAs(
"next block is neither a <%s> nor a <%s> (got <%s>):" + PRINT_FRAGMENT_TEMPLATE,
"ul", "ol", element.tagName(), element.toString())
.isIn("ul", "ol");
}
/**
* Verifies the text of every items in the current list is equal to the specified strings, in order.
*/
public HtmlListAssert withItemTexts(String firstItemText, String... otherItemsText) {
isNotNull();
List<String> itemsText = actual.children()
.stream()
.filter(t -> t.tagName().equals("li"))
.map(Element::text)
.collect(Collectors.toList());
String[] itemTexts = Stream.concat(
Stream.of(firstItemText),
Arrays.stream(otherItemsText))
.toArray(String[]::new);
Assertions.assertThat(itemsText)
.describedAs(PRINT_FRAGMENT_TEMPLATE, actual)
.containsOnly(itemTexts);
return this;
}
/**
* Convenience method.
* Sames as {@code hasParagraph().withText(text)}.
*/
public HtmlParagraphAssert hasParagraph(String text) {
return hasParagraph()
.withText(text);
}
/**
* Verifies next paragraph is empty or contains only " "
*/
public HtmlParagraphAssert hasEmptyParagraph() {
Element paragraph = hasParagraphImpl();
Assertions.assertThat(paragraph.text())
.describedAs(PRINT_FRAGMENT_TEMPLATE, paragraph)
.isIn("", "\u00A0");
return new HtmlParagraphAssert(paragraph, nextBlocks);
}
public HtmlParagraphAssert hasParagraph() {
Element element = hasParagraphImpl();
return new HtmlParagraphAssert(element, nextBlocks);
}
private Element hasParagraphImpl() {
isNotNull();
Assertions.assertThat(nextBlocks.hasNext())
.describedAs("no more block")
.isTrue();
Element element = nextBlocks.next();
HtmlParagraphAssert.verifyIsParagraph(element);
return element;
}
}
| 3,313 | 29.40367 | 102 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/HtmlParagraphAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import static java.util.Collections.emptyList;
public class HtmlParagraphAssert extends HtmlBlockAssert<HtmlParagraphAssert> {
private final Iterator<Element> nextBlocks;
public HtmlParagraphAssert(Element paragraph, Iterator<Element> nextBlocks) {
super(paragraph, HtmlParagraphAssert.class);
this.nextBlocks = nextBlocks;
}
static void verifyIsParagraph(Element element) {
Assertions.assertThat(element.tagName())
.describedAs(
"next block is not a <%s> (got <%s>):" + PRINT_FRAGMENT_TEMPLATE,
"p", element.tagName(), element.toString())
.isEqualTo("p");
}
/**
* Verify the next block exists, is a paragraph and returns an Assert on this block.
*/
public HtmlParagraphAssert hasParagraph() {
return new HtmlParagraphAssert(hasParagraphImpl(), nextBlocks);
}
private Element hasParagraphImpl() {
isNotNull();
Assertions.assertThat(nextBlocks.hasNext())
.describedAs("no more bloc")
.isTrue();
Element element = nextBlocks.next();
verifyIsParagraph(element);
return element;
}
/**
* Convenience method.
* Sames as {@code hasParagraph().withText(text)}.
*/
public HtmlParagraphAssert hasParagraph(String text) {
return hasParagraph()
.withText(text);
}
/**
* Verifies next paragraph is empty or contains only " "
*/
public HtmlParagraphAssert hasEmptyParagraph() {
Element paragraph = hasParagraphImpl();
Assertions.assertThat(paragraph.text())
.describedAs(PRINT_FRAGMENT_TEMPLATE, paragraph)
.isIn("", "\u00A0");
return new HtmlParagraphAssert(paragraph, nextBlocks);
}
/**
* Verifies there is no more block.
*/
public void noMoreBlock() {
isNotNull();
Assertions.assertThat(nextBlocks.hasNext())
.describedAs("there are still some paragraph. Next one:" + PRINT_FRAGMENT_TEMPLATE,
new Object() {
@Override
public String toString() {
return nextBlocks.next().toString();
}
})
.isFalse();
}
/**
* Verifies the current block as the specified text, ignoring lines.
*/
public HtmlParagraphAssert withText(String text) {
isNotNull();
Assertions.assertThat(actual.text())
.describedAs(PRINT_FRAGMENT_TEMPLATE, actual)
.isEqualTo(text);
return this;
}
/**
* Verifies the current block has all and only the specified lines, in order.
*/
public HtmlParagraphAssert withLines(String firstLine, String... otherLines) {
isNotNull();
List<String> actualLines = toLines(actual);
String[] expectedLines = Stream.concat(
Stream.of(firstLine),
Arrays.stream(otherLines))
.toArray(String[]::new);
Assertions.assertThat(actualLines)
.describedAs(PRINT_FRAGMENT_TEMPLATE, actual)
.containsExactly(expectedLines);
return this;
}
private static List<String> toLines(Element parent) {
Iterator<Node> iterator = parent.childNodes().iterator();
if (!iterator.hasNext()) {
return emptyList();
}
List<String> actualLines = new ArrayList<>(parent.childNodeSize());
StringBuilder currentLine = null;
while (iterator.hasNext()) {
Node node = iterator.next();
if (node instanceof TextNode) {
if (currentLine == null) {
currentLine = new StringBuilder(node.toString());
} else {
currentLine.append(node.toString());
}
} else if (node instanceof Element) {
Element element = (Element) node;
if (element.tagName().equals("br")) {
actualLines.add(currentLine == null ? "" : currentLine.toString());
currentLine = null;
} else {
if (currentLine == null) {
currentLine = new StringBuilder(element.text());
} else {
currentLine.append(element.text());
}
}
} else {
throw new IllegalStateException("unsupported node " + node.getClass());
}
if (!iterator.hasNext()) {
actualLines.add(currentLine == null ? "" : currentLine.toString());
currentLine = null;
}
}
return actualLines;
}
/**
* Convenience method.
* Same as {@code hasList().withItemTexts("foo", "bar")}.
*/
public HtmlListAssert hasList(String firstItemText, String... otherItemsText) {
return hasList()
.withItemTexts(firstItemText, otherItemsText);
}
public HtmlListAssert hasList() {
isNotNull();
Assertions.assertThat(nextBlocks.hasNext())
.describedAs("no more block")
.isTrue();
Element element = nextBlocks.next();
HtmlListAssert.verifyIsList(element);
return new HtmlListAssert(element, nextBlocks);
}
}
| 5,879 | 28.108911 | 89 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/MimeMessageAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.io.IOException;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
public final class MimeMessageAssert extends AbstractAssert<MimeMessageAssert, MimeMessage> {
public MimeMessageAssert(MimeMessage mimeMessage) {
super(mimeMessage, MimeMessageAssert.class);
}
public static MimeMessageAssert assertThat(MimeMessage m) {
return new MimeMessageAssert(m);
}
public MultipartMessageAssert isMultipart() {
isNotNull();
try {
Object content = actual.getContent();
Assertions.assertThat(content).isInstanceOf(MimeMultipart.class);
MimeMultipart m = (MimeMultipart) content;
return new MultipartMessageAssert(m);
} catch (MessagingException | IOException e) {
throw new IllegalStateException(e);
}
}
/**
* Convenience method for {@code isMultipart().isHtml()}.
*/
public HtmlFragmentAssert isHtml() {
return isMultipart()
.isHtml();
}
public MimeMessageAssert hasRecipient(String userEmail) {
isNotNull();
try {
Assertions
.assertThat(actual.getHeader("To", null))
.isEqualTo(String.format("<%s>", userEmail));
} catch (MessagingException e) {
throw new IllegalStateException(e);
}
return this;
}
public MimeMessageAssert subjectContains(String text) {
isNotNull();
try {
Assertions.assertThat(actual.getSubject()).contains(text);
} catch (MessagingException e) {
throw new IllegalStateException(e);
}
return this;
}
}
| 2,538 | 28.183908 | 93 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/MultipartMessageAssert.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.html;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
public class MultipartMessageAssert extends AbstractAssert<MultipartMessageAssert, Multipart> {
private final Iterator<BodyPart> bodyParts;
MultipartMessageAssert(MimeMultipart m) {
super(m, MultipartMessageAssert.class);
try {
this.bodyParts = new BodyPartIterator(m, m.getCount());
} catch (MessagingException e) {
throw new IllegalStateException(e);
}
}
public HtmlFragmentAssert isHtml() {
isNotNull();
Assertions
.assertThat(bodyParts.hasNext())
.describedAs("no more body part")
.isTrue();
try {
BodyPart bodyPart = bodyParts.next();
return new HtmlFragmentAssert((String) bodyPart.getContent());
} catch (MessagingException | IOException e) {
throw new IllegalStateException(e);
}
}
private static class BodyPartIterator implements Iterator<BodyPart> {
private final int count;
private final MimeMultipart m;
private int index = 0;
public BodyPartIterator(MimeMultipart m, int count) {
this.m = m;
this.count = count;
}
@Override
public boolean hasNext() {
return index < count;
}
@Override
public BodyPart next() {
if (index >= count) {
throw new NoSuchElementException("no more body part");
}
try {
BodyPart next = m.getBodyPart(index);
index++;
return next;
} catch (MessagingException e) {
throw new IllegalStateException(e);
}
}
}
}
| 2,675 | 28.406593 | 95 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/html/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.test.html;
import javax.annotation.ParametersAreNonnullByDefault;
| 959 | 39 | 75 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.i18n;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.io.IOUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class BundleSynchronizedMatcher extends BaseMatcher<String> {
public static final String L10N_PATH = "/org/sonar/l10n/";
private String bundleName;
private SortedMap<String, String> missingKeys;
private SortedMap<String, String> additionalKeys;
@Override
public boolean matches(Object arg0) {
if (!(arg0 instanceof String)) {
return false;
}
bundleName = (String) arg0;
// Find the bundle that needs to be verified
InputStream bundleInputStream = getBundleFileInputStream(bundleName);
// Find the default bundle which the provided one should be compared to
InputStream defaultBundleInputStream = getDefaultBundleFileInputStream(bundleName);
// and now let's compare!
try {
// search for missing keys
missingKeys = retrieveMissingTranslations(bundleInputStream, defaultBundleInputStream);
// and now for additional keys
bundleInputStream = getBundleFileInputStream(bundleName);
defaultBundleInputStream = getDefaultBundleFileInputStream(bundleName);
additionalKeys = retrieveMissingTranslations(defaultBundleInputStream, bundleInputStream);
// And fail only if there are missing keys
return missingKeys.isEmpty();
} catch (IOException e) {
fail("An error occurred while reading the bundles: " + e.getMessage());
return false;
} finally {
IOUtils.closeQuietly(bundleInputStream);
IOUtils.closeQuietly(defaultBundleInputStream);
}
}
@Override
public void describeTo(Description description) {
// report file
File dumpFile = new File("build/l10n/" + bundleName + ".report.txt");
// prepare message
StringBuilder details = prepareDetailsMessage(dumpFile);
description.appendText(details.toString());
// print report in target directory
printReport(dumpFile, details.toString());
}
private StringBuilder prepareDetailsMessage(File dumpFile) {
StringBuilder details = new StringBuilder("\n=======================\n'");
details.append(bundleName);
details.append("' is not up-to-date.");
print("\n\n Missing translations are:", missingKeys, details);
print("\n\nThe following translations do not exist in the reference bundle:", additionalKeys, details);
details.append("\n\nSee report file located at: ");
details.append(dumpFile.getAbsolutePath());
details.append("\n=======================");
return details;
}
private static void print(String title, SortedMap<String, String> translations, StringBuilder to) {
if (!translations.isEmpty()) {
to.append(title);
for (Map.Entry<String, String> entry : translations.entrySet()) {
to.append("\n").append(entry.getKey()).append("=").append(entry.getValue());
}
}
}
private void printReport(File dumpFile, String details) {
if (dumpFile.exists()) {
dumpFile.delete();
}
dumpFile.getParentFile().mkdirs();
try (Writer writer = new OutputStreamWriter(new FileOutputStream(dumpFile), StandardCharsets.UTF_8)) {
writer.write(details);
} catch (IOException e) {
throw new IllegalStateException("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'", e);
}
}
protected static SortedMap<String, String> retrieveMissingTranslations(InputStream bundle, InputStream referenceBundle) throws IOException {
SortedMap<String, String> missingKeys = new TreeMap<>();
Properties bundleProps = loadProperties(bundle);
Properties referenceProperties = loadProperties(referenceBundle);
for (Map.Entry<Object, Object> entry : referenceProperties.entrySet()) {
String key = (String) entry.getKey();
if (!bundleProps.containsKey(key)) {
missingKeys.put(key, (String) entry.getValue());
}
}
return missingKeys;
}
protected static Properties loadProperties(InputStream inputStream) throws IOException {
Properties props = new Properties();
props.load(inputStream);
return props;
}
protected static InputStream getBundleFileInputStream(String bundleName) {
InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + bundleName);
assertNotNull("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle);
return bundle;
}
protected static InputStream getDefaultBundleFileInputStream(String bundleName) {
String defaultBundleName = extractDefaultBundleName(bundleName);
InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + defaultBundleName);
assertNotNull("Default bundle '" + defaultBundleName + "' could not be found: add a dependency to the corresponding plugin in your POM.", bundle);
return bundle;
}
protected static String extractDefaultBundleName(String bundleName) {
int firstUnderScoreIndex = bundleName.indexOf('_');
assertTrue("The bundle '" + bundleName + "' is a default bundle (without locale), so it can't be compared.", firstUnderScoreIndex > 0);
return bundleName.substring(0, firstUnderScoreIndex) + ".properties";
}
}
| 6,513 | 37.093567 | 150 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.i18n;
import java.io.File;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.sonar.test.TestUtils;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
public final class I18nMatchers {
private I18nMatchers() {
}
/**
* Returns a matcher which checks that a translation bundle is up to date with the corresponding default one found in the classpath.
*
* @return the matcher
*/
public static BundleSynchronizedMatcher isBundleUpToDate() {
return new BundleSynchronizedMatcher();
}
/**
* Checks that all the translation bundles found on the classpath are up to date with the corresponding default ones found in the classpath.
*/
public static void assertBundlesUpToDate() {
File bundleFolder = getResource(BundleSynchronizedMatcher.L10N_PATH);
if (bundleFolder == null || !bundleFolder.isDirectory()) {
fail("No bundle found in: " + BundleSynchronizedMatcher.L10N_PATH);
}
Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[] {"properties"}, false);
Map<String, String> failedAssertionMessages = new HashMap<>();
for (File bundle : bundles) {
String bundleName = bundle.getName();
if (bundleName.indexOf('_') > 0) {
try {
assertThat(bundleName, isBundleUpToDate());
} catch (AssertionError e) {
failedAssertionMessages.put(bundleName, e.getMessage());
}
}
}
if (!failedAssertionMessages.isEmpty()) {
StringBuilder message = new StringBuilder();
message.append(failedAssertionMessages.size());
message.append(" bundles are not up-to-date: ");
message.append(String.join(", ", failedAssertionMessages.keySet()));
message.append("\n\n");
message.append(String.join("\n\n", failedAssertionMessages.values()));
fail(message.toString());
}
}
private static File getResource(String path) {
String resourcePath = path;
if (!resourcePath.startsWith("/")) {
resourcePath = "/" + resourcePath;
}
URL url = TestUtils.class.getResource(resourcePath);
if (url != null) {
return FileUtils.toFile(url);
}
return null;
}
}
| 3,153 | 33.282609 | 142 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/main/java/org/sonar/test/i18n/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.test.i18n;
import javax.annotation.ParametersAreNonnullByDefault;
| 959 | 39 | 75 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/EventAssertTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.test.EventAssert.assertThatEvent;
public class EventAssertTest {
@Test
public void isValid_no_field() {
assertThatThrownBy(() -> assertThatEvent("line without field").isValid())
.isInstanceOf(AssertionError.class)
.hasMessage("Invalid line in event: 'line without field'");
}
@Test
public void isValid_unknown_field() {
assertThatThrownBy(() -> assertThatEvent("field: value").isValid())
.isInstanceOf(AssertionError.class)
.hasMessage("Unknown field in event: 'field'");
}
@Test
public void isValid_correct() {
assertThatEvent("").isValid();
assertThatEvent("\n\n").isValid();
assertThatEvent("data: D").isValid();
assertThatEvent("event: E\ndata: D").isValid();
}
@Test
public void hasField_invalid() {
assertThatThrownBy(() -> assertThatEvent("line without field").hasField("event"))
.isInstanceOf(AssertionError.class)
.hasMessage("Invalid line in event: 'line without field'");
}
@Test
public void hasField_no_field() {
assertThatThrownBy(() -> assertThatEvent("event: E").hasField("data"))
.isInstanceOf(AssertionError.class)
.hasMessage("Expected event to contain field 'data'. Actual event was: 'event: E'");
}
@Test
public void hasField_correct() {
assertThatEvent("event: E\ndata: D").hasField("data");
assertThatEvent("event: E\ndata: D").hasField("event");
}
@Test
public void hasType_invalid() {
assertThatThrownBy(() -> assertThatEvent("line without field").hasType("E"))
.isInstanceOf(AssertionError.class)
.hasMessage("Invalid line in event: 'line without field'");
}
@Test
public void hasType_without_type() {
assertThatThrownBy(() -> assertThatEvent("data: D").hasType("E"))
.isInstanceOf(AssertionError.class)
.hasMessage("Expected event to contain field 'event'. Actual event was: 'data: D'");
}
@Test
public void hasType_correct() {
assertThatEvent("event: E\ndata: D").hasType("E");
}
@Test
public void hasData_invalid() {
assertThatThrownBy(() -> assertThatEvent("line without field").hasData("D"))
.isInstanceOf(AssertionError.class)
.hasMessage("Invalid line in event: 'line without field'");
}
@Test
public void hasData_correct() {
assertThatEvent("data:D").hasData("D");
}
@Test
public void hasJsonData_invalid() {
assertThatThrownBy(() -> assertThatEvent("line without field").hasJsonData(getClass().getResource("EventAssertTest/sample.json")))
.isInstanceOf(AssertionError.class)
.hasMessage("Invalid line in event: 'line without field'");
}
@Test
public void hasJsonData_correct() {
assertThatEvent("data: {}").hasJsonData(getClass().getResource("EventAssertTest/sample.json"));
}
}
| 3,749 | 32.482143 | 134 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test;
import java.io.File;
import java.net.URL;
import org.junit.ComparisonFailure;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.fail;
import static org.sonar.test.JsonAssert.assertJson;
public class JsonAssertTest {
@Test
public void isSimilarAs_strings() {
assertJson("{}").isSimilarTo("{}");
try {
assertJson("{}").isSimilarTo("[]");
fail();
} catch (ComparisonFailure error) {
assertThat(error.getMessage()).isEqualTo("Not a super-set of expected JSON - expected:<[[]]> but was:<[{}]>");
assertThat(error.getActual()).isEqualTo("{}");
assertThat(error.getExpected()).isEqualTo("[]");
}
}
@Test
public void isSimilarAs_urls() {
URL url1 = getClass().getResource("JsonAssertTest/sample1.json");
URL url2 = getClass().getResource("JsonAssertTest/sample2.json");
assertJson(url1).isSimilarTo(url1);
assertThatThrownBy(() -> assertJson(url1).isSimilarTo(url2))
.isInstanceOf(AssertionError.class);
}
@Test
public void actual_can_be_superset_of_expected() {
assertJson("{\"foo\": \"bar\"}").isSimilarTo("{}");
assertThatThrownBy(() -> assertJson("{}").isSimilarTo("{\"foo\": \"bar\"}"))
.isInstanceOf(AssertionError.class);
}
@Test
public void fail_to_load_url() {
assertThatThrownBy(() -> assertJson(new File("target/missing").toURI().toURL()))
.isInstanceOf(IllegalStateException.class);
}
@Test
public void enable_strict_order_of_arrays() {
assertThatThrownBy(() -> assertJson("[1,2]").withStrictArrayOrder().isSimilarTo("[2, 1]"))
.isInstanceOf(AssertionError.class);
}
@Test
public void enable_strict_timezone() {
assertThatThrownBy(() -> assertJson("[\"2010-05-18T15:50:45+0100\"]").withStrictTimezone().isSimilarTo("[\"2010-05-18T16:50:45+0200\"]"))
.isInstanceOf(AssertionError.class);
}
@Test
public void ignore_fields() {
assertJson("{\"foo\": \"bar\"}")
.ignoreFields("ignore-me")
.isSimilarTo("{\"foo\": \"bar\", \"ignore-me\": \"value\"}");
}
}
| 3,033 | 32.340659 | 141 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class JsonComparisonTest {
@Test(expected = IllegalStateException.class)
public void fail_if_invalid_json() {
areSimilar("{]", "");
}
@Test
public void syntax_agnostic() {
assertThat(areSimilar("{}", " { } ")).isTrue();
assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\": \"bar\" \n }")).isTrue();
}
@Test
public void object() {
assertThat(areSimilar("{}", "{}")).isTrue();
// exactly the same
assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\":\"bar\"}")).isTrue();
// same key but different value
assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\":\"baz\"}")).isFalse();
// missing key
assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"xxx\":\"bar\"}")).isFalse();
// expected json can be a subset of actual json
assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"xxx\":\"bar\", \"foo\": \"bar\"}")).isTrue();
}
@Test
public void strict_order_of_array() {
assertThat(isSimilar_strict_array_order("[]", "[]")).isTrue();
assertThat(isSimilar_strict_array_order("[1, 2]", "[1, 2]")).isTrue();
assertThat(isSimilar_strict_array_order("[1, 2]", "[1]")).isFalse();
assertThat(isSimilar_strict_array_order("[1, 2]", "[2, 1]")).isFalse();
assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , 2, 3]")).isFalse();
assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , false]")).isFalse();
assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , 3.14]")).isFalse();
}
@Test
public void lenient_order_of_array() {
assertThat(areSimilar("[]", "[]")).isTrue();
assertThat(areSimilar("[1, 2]", "[1, 2]")).isTrue();
assertThat(areSimilar("[1, 2]", "[1]")).isFalse();
assertThat(areSimilar("[1, 2]", "[2, 1]")).isTrue();
assertThat(areSimilar("[1, 2]", "[1 , 2, 3]")).isFalse();
assertThat(areSimilar("[1, 2]", "[1 , false]")).isFalse();
assertThat(areSimilar("[1, 2]", "[1 , 3.14]")).isFalse();
}
@Test
public void lenient_order_of_arrays_by_default() {
assertThat(new JsonComparison().isStrictArrayOrder()).isFalse();
}
@Test
public void null_value() {
assertThat(areSimilar("[null]", "[null]")).isTrue();
assertThat(areSimilar("[null]", "[]")).isFalse();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": null}")).isTrue();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": \"bar\"}")).isFalse();
assertThat(areSimilar("{\"foo\": 3}", "{\"foo\": null}")).isFalse();
assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": null}")).isFalse();
assertThat(areSimilar("{\"foo\": false}", "{\"foo\": null}")).isFalse();
assertThat(areSimilar("{\"foo\": true}", "{\"foo\": null}")).isFalse();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": 3}")).isFalse();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": 3.14}")).isFalse();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": false}")).isFalse();
assertThat(areSimilar("{\"foo\": null}", "{\"foo\": true}")).isFalse();
}
@Test
public void maps_and_arrays() {
assertThat(areSimilar("[]", "{}")).isFalse();
assertThat(areSimilar("{}", "[]")).isFalse();
// map of array
assertThat(areSimilar("{\"foo\": []}", "{\"foo\": []}")).isTrue();
assertThat(areSimilar("{\"foo\": [1, 3]}", "{\"foo\": [1, 3], \"bar\": [1, 3]}")).isTrue();
assertThat(areSimilar("{\"foo\": []}", "{\"foo\": []}")).isTrue();
assertThat(areSimilar("{\"foo\": [1, 2]}", "{\"foo\": [1, 3]}")).isFalse();
// array of maps
assertThat(areSimilar("[{}]", "[{}]")).isTrue();
assertThat(areSimilar("[{}]", "[{\"foo\": 1}]")).isTrue();
// exactly the sames
assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"2\":\"4\"}]")).isTrue();
// different value
assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"2\":\"3\"}]")).isFalse();
// missing key
assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"5\":\"10\"}]")).isFalse();
}
@Test
public void lenient_timezone() {
// lenient mode by default
assertThat(new JsonComparison().isStrictTimezone()).isFalse();
// same instant, same timezone
assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue();
// same instant, but different timezone
assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isTrue();
// different time
assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse();
}
@Test
public void strict_timezone() {
assertThat(new JsonComparison().withTimezone().isStrictTimezone()).isTrue();
// same instant, same timezone
assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue();
assertThat(isSimilar_strict_timezone("[\"2010-05-18T15:50:45+0100\"]", "[\"2010-05-18T15:50:45+0100\"]")).isTrue();
// same instant, but different timezone
assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isFalse();
// different time
assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse();
}
@Test
public void compare_doubles() {
assertThat(areSimilar("{\"foo\": true}", "{\"foo\": false}")).isFalse();
assertThat(areSimilar("{\"foo\": true}", "{\"foo\": true}")).isTrue();
assertThat(areSimilar("{\"foo\": true}", "{\"foo\": \"true\"}")).isFalse();
assertThat(areSimilar("{\"foo\": true}", "{\"foo\": 1}")).isFalse();
}
@Test
public void compare_booleans() {
assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": 3.14000000}")).isTrue();
assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": 3.1400001}")).isTrue();
}
private boolean areSimilar(String expected, String actual) {
return new JsonComparison().areSimilar(expected, actual);
}
private boolean isSimilar_strict_timezone(String expected, String actual) {
return new JsonComparison().withTimezone().areSimilar(expected, actual);
}
private boolean isSimilar_strict_array_order(String expected, String actual) {
return new JsonComparison().withStrictArrayOrder().areSimilar(expected, actual);
}
}
| 7,365 | 40.150838 | 138 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class TestUtilsTest {
@Test
public void hasOnlyPrivateConstructors() {
assertThat(TestUtils.hasOnlyPrivateConstructors(TestUtils.class)).isTrue();
assertThat(TestUtils.hasOnlyPrivateConstructors(OnlyPrivateConstructors.class)).isTrue();
assertThat(TestUtils.hasOnlyPrivateConstructors(MixOfPublicAndPrivateConstructors.class)).isFalse();
try {
TestUtils.hasOnlyPrivateConstructors(FailToInstantiate.class);
fail();
} catch (IllegalStateException e) {
// ok
}
}
public static class OnlyPrivateConstructors {
private OnlyPrivateConstructors() {
}
private OnlyPrivateConstructors(int i) {
}
public static void foo() {
}
}
public static class MixOfPublicAndPrivateConstructors {
private MixOfPublicAndPrivateConstructors() {
}
public MixOfPublicAndPrivateConstructors(int i) {
}
public static void foo() {
}
}
public static class FailToInstantiate {
private FailToInstantiate() {
throw new IllegalArgumentException();
}
}
}
| 2,047 | 27.444444 | 104 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.i18n;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.SortedMap;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.TestCase.fail;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class BundleSynchronizedMatcherTest {
BundleSynchronizedMatcher matcher;
@Before
public void init() {
matcher = new BundleSynchronizedMatcher();
}
@Test
public void shouldMatch() {
assertThat("myPlugin_fr_CA.properties", matcher);
assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists());
}
@Test
public void shouldMatchEvenWithAdditionalKeys() {
assertThat("myPlugin_fr_QB.properties", matcher);
assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists());
}
@Test
public void shouldNotMatch() {
try {
assertThat("myPlugin_fr.properties", matcher);
assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists());
} catch (AssertionError e) {
assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop"));
assertThat(e.getMessage(), containsString("The following translations do not exist in the reference bundle:\nfourth.prop"));
}
}
@Test
public void shouldNotMatchIfNotString() {
assertThat(matcher.matches(3), is(false));
}
@Test
public void testGetBundleFileFromClasspath() {
// OK
assertThat(BundleSynchronizedMatcher.getBundleFileInputStream("myPlugin_fr.properties"), notNullValue());
// KO
try {
BundleSynchronizedMatcher.getBundleFileInputStream("unexistingBundle.properties");
fail();
} catch (AssertionError e) {
assertThat(e.getMessage(), startsWith("File 'unexistingBundle.properties' does not exist in '/org/sonar/l10n/'."));
}
}
@Test
public void testGetDefaultBundleFileFromClasspath() {
try {
BundleSynchronizedMatcher.getDefaultBundleFileInputStream("unexistingBundle_fr.properties");
fail();
} catch (AssertionError e) {
assertThat(e.getMessage(), startsWith("Default bundle 'unexistingBundle.properties' could not be found: add a dependency to the corresponding plugin in your POM."));
}
}
@Test
public void testExtractDefaultBundleName() {
// OK
assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr.properties"), is("myPlugin.properties"));
assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr_QB.properties"), is("myPlugin.properties"));
// KO
try {
BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin.properties");
fail();
} catch (AssertionError e) {
assertThat(e.getMessage(), startsWith("The bundle 'myPlugin.properties' is a default bundle (without locale), so it can't be compared."));
}
}
@Test
public void testRetrieveMissingKeys() throws Exception {
InputStream defaultBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin.properties");
InputStream frBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr.properties");
InputStream qbBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr_QB.properties");
try {
SortedMap<String, String> diffs = BundleSynchronizedMatcher.retrieveMissingTranslations(frBundleIS, defaultBundleIS);
assertThat(diffs.size(), is(1));
assertThat(diffs.keySet(), hasItem("second.prop"));
diffs = BundleSynchronizedMatcher.retrieveMissingTranslations(qbBundleIS, defaultBundleIS);
assertThat(diffs.size(), is(0));
} finally {
IOUtils.closeQuietly(defaultBundleIS);
IOUtils.closeQuietly(frBundleIS);
IOUtils.closeQuietly(qbBundleIS);
}
}
@Test
public void shouldFailToLoadUnexistingPropertiesFile() throws Exception {
assertThatThrownBy(() -> BundleSynchronizedMatcher.loadProperties(new FileInputStream("foo.blabla")))
.isInstanceOf(IOException.class);
}
}
| 5,423 | 36.150685 | 171 | java |
sonarqube | sonarqube-master/sonar-testing-harness/src/test/java/org/sonar/test/i18n/I18nMatchersTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.test.i18n;
import org.junit.Test;
import java.io.File;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.sonar.test.i18n.I18nMatchers.isBundleUpToDate;
public class I18nMatchersTest {
@Test
public void testBundlesInsideSonarPlugin() {
// synchronized bundle
assertThat("myPlugin_fr_CA.properties", isBundleUpToDate());
assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists());
// missing keys
try {
assertThat("myPlugin_fr.properties", isBundleUpToDate());
assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists());
} catch (AssertionError e) {
assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop"));
}
}
@Test
public void shouldNotFailIfNoMissingKeysButAdditionalKeys() {
assertThat("noMissingKeys_fr.properties", isBundleUpToDate());
}
}
| 1,900 | 34.867925 | 91 | java |
sonarqube | sonarqube-master/sonar-testing-ldap/src/main/java/org/sonar/ldap/ApacheDS.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.ldap;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.DefaultModification;
import org.apache.directory.api.ldap.model.entry.ModificationOperation;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
import org.apache.directory.api.ldap.model.ldif.ChangeType;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.util.FileUtils;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.InstanceLayout;
import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
import org.apache.directory.server.core.kerberos.KeyDerivationInterceptor;
import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
import org.apache.directory.server.kerberos.KerberosConfig;
import org.apache.directory.server.kerberos.kdc.KdcServer;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.ldap.handlers.sasl.MechanismHandler;
import org.apache.directory.server.ldap.handlers.sasl.cramMD5.CramMd5MechanismHandler;
import org.apache.directory.server.ldap.handlers.sasl.digestMD5.DigestMd5MechanismHandler;
import org.apache.directory.server.ldap.handlers.sasl.gssapi.GssapiMechanismHandler;
import org.apache.directory.server.ldap.handlers.sasl.plain.PlainMechanismHandler;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
import org.apache.directory.server.protocol.shared.transport.UdpTransport;
import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
import org.apache.mina.util.AvailablePortFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ApacheDS {
private static final Logger LOG = LoggerFactory.getLogger(ApacheDS.class);
private final String realm;
private final String baseDn;
private DirectoryService directoryService;
private LdapServer ldapServer;
private KdcServer kdcServer;
private ApacheDS(String realm, String baseDn) {
this.realm = realm;
this.baseDn = baseDn;
ldapServer = new LdapServer();
}
public static ApacheDS start(String realm, String baseDn, String workDir, Integer port) throws Exception {
return new ApacheDS(realm, baseDn)
.startDirectoryService(workDir)
.startKdcServer()
.startLdapServer(port == null ? AvailablePortFinder.getNextAvailable(1024) : port)
.activateNis();
}
public static ApacheDS start(String realm, String baseDn, String workDir) throws Exception {
return start(realm, baseDn, workDir + realm, null);
}
public static ApacheDS start(String realm, String baseDn) throws Exception {
return start(realm, baseDn, "target/ldap-work/" + realm, null);
}
public void stop() {
try {
kdcServer.stop();
kdcServer = null;
ldapServer.stop();
ldapServer = null;
directoryService.shutdown();
directoryService = null;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public String getUrl() {
return "ldap://localhost:" + ldapServer.getPort();
}
/**
* Stream will be closed automatically.
*/
public void importLdif(InputStream is) throws Exception {
try (LdifReader reader = new LdifReader(is)) {
CoreSession coreSession = directoryService.getAdminSession();
// see LdifFileLoader
for (LdifEntry ldifEntry : reader) {
String ldif = ldifEntry.toString();
LOG.info(ldif);
if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */ ChangeType.None == ldifEntry.getChangeType()) {
coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry()));
} else if (ChangeType.Modify == ldifEntry.getChangeType()) {
coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications());
} else if (ChangeType.Delete == ldifEntry.getChangeType()) {
coreSession.delete(ldifEntry.getDn());
} else {
throw new IllegalStateException();
}
}
}
}
public void disableAnonymousAccess() {
directoryService.setAllowAnonymousAccess(false);
}
public void enableAnonymousAccess() {
directoryService.setAllowAnonymousAccess(true);
}
private ApacheDS startDirectoryService(String workDirStr) throws Exception {
DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
factory.init(realm);
directoryService = factory.getDirectoryService();
directoryService.getChangeLog().setEnabled(false);
directoryService.setShutdownHookEnabled(false);
directoryService.setAllowAnonymousAccess(true);
File workDir = new File(workDirStr);
if (workDir.exists()) {
FileUtils.deleteDirectory(workDir);
}
InstanceLayout instanceLayout = new InstanceLayout(workDir);
directoryService.setInstanceLayout(instanceLayout);
AvlPartition partition = new AvlPartition(directoryService.getSchemaManager());
partition.setId("Test");
partition.setSuffixDn(new Dn(directoryService.getSchemaManager(), baseDn));
partition.addIndexedAttributes(
new AvlIndex<>("ou"),
new AvlIndex<>("uid"),
new AvlIndex<>("dc"),
new AvlIndex<>("objectClass"));
partition.initialize();
directoryService.addPartition(partition);
directoryService.addLast(new KeyDerivationInterceptor());
directoryService.shutdown();
directoryService.startup();
return this;
}
private ApacheDS startLdapServer(int port) throws Exception {
ldapServer.setTransports(new TcpTransport(port));
ldapServer.setDirectoryService(directoryService);
// Setup SASL mechanisms
Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<>();
mechanismHandlerMap.put(SupportedSaslMechanisms.PLAIN, new PlainMechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.CRAM_MD5, new CramMd5MechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.DIGEST_MD5, new DigestMd5MechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.GSSAPI, new GssapiMechanismHandler());
ldapServer.setSaslMechanismHandlers(mechanismHandlerMap);
ldapServer.setSaslHost("localhost");
ldapServer.setSaslRealms(Collections.singletonList(realm));
// TODO ldapServer.setSaslPrincipal();
// The base DN containing users that can be SASL authenticated.
ldapServer.setSearchBaseDn(baseDn);
ldapServer.start();
return this;
}
private ApacheDS startKdcServer() throws IOException, LdapOperationException {
int port = AvailablePortFinder.getNextAvailable(6088);
KerberosConfig kdcConfig = new KerberosConfig();
kdcConfig.setServicePrincipal("krbtgt/EXAMPLE.ORG@EXAMPLE.ORG");
kdcConfig.setPrimaryRealm("EXAMPLE.ORG");
kdcConfig.setPaEncTimestampRequired(false);
kdcServer = new KdcServer(kdcConfig);
kdcServer.setSearchBaseDn("dc=example,dc=org");
kdcServer.addTransports(new UdpTransport("localhost", port));
kdcServer.setDirectoryService(directoryService);
kdcServer.start();
FileUtils.writeStringToFile(new File("target/krb5.conf"), ""
+ "[libdefaults]\n"
+ " default_realm = EXAMPLE.ORG\n"
+ "\n"
+ "[realms]\n"
+ " EXAMPLE.ORG = {\n"
+ " kdc = localhost:" + port + "\n"
+ " }\n"
+ "\n"
+ "[domain_realm]\n"
+ " .example.org = EXAMPLE.ORG\n"
+ " example.org = EXAMPLE.ORG\n",
StandardCharsets.UTF_8.name());
return this;
}
/**
* This seems to be required for objectClass posixGroup.
*/
private ApacheDS activateNis() throws Exception {
directoryService.getAdminSession().modify(
new Dn("cn=nis,ou=schema"),
new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE"));
return this;
}
}
| 9,225 | 37.441667 | 136 | java |
sonarqube | sonarqube-master/sonar-testing-ldap/src/main/java/org/sonar/ldap/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.ldap;
| 867 | 40.333333 | 75 | java |
sonarqube | sonarqube-master/sonar-testing-ldap/src/test/java/org/sonar/ldap/ApacheDSTest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.ldap;
import org.junit.Test;
public class ApacheDSTest {
@Test
public void start_and_stop_apache_server() throws Exception {
ApacheDS apacheDS = ApacheDS.start("example.org", "dc=example,dc=org");
apacheDS.importLdif(ApacheDS.class.getResourceAsStream("/init.ldif"));
apacheDS.importLdif(ApacheDS.class.getResourceAsStream("/change.ldif"));
apacheDS.importLdif(ApacheDS.class.getResourceAsStream("/delete.ldif"));
apacheDS.disableAnonymousAccess();
apacheDS.enableAnonymousAccess();
apacheDS.stop();
}
}
| 1,403 | 35.947368 | 76 | java |
sonarqube | sonarqube-master/sonar-ws-generator/src/main/java/org/sonarqube/wsgenerator/ApiDefinitionDownloader.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.wsgenerator;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.http.HttpCall;
import com.sonar.orchestrator.http.HttpResponse;
import com.sonar.orchestrator.locator.FileLocation;
import java.io.File;
import static com.sonar.orchestrator.container.Edition.COMMUNITY;
public class ApiDefinitionDownloader {
public static void main(String[] args) {
System.out.println(downloadApiDefinition());
}
public static String downloadApiDefinition() {
OrchestratorBuilder builder = Orchestrator.builderEnv()
.defaultForceAuthentication();
builder.setEdition(COMMUNITY);
builder.setZipFile(FileLocation.byWildcardMavenFilename(new File("../sonar-application/build/distributions"), "sonar-application-*.zip").getFile())
.setOrchestratorProperty("orchestrator.workspaceDir", "build");
Orchestrator orchestrator = builder.setServerProperty("sonar.forceAuthentication", "false")
.build();
orchestrator.start();
try {
HttpCall httpCall = orchestrator.getServer().newHttpCall("api/webservices/list").setParam("include_internals", "true");
HttpResponse response = httpCall.execute();
return response.getBodyAsString();
} finally {
orchestrator.stop();
}
}
}
| 2,170 | 37.767857 | 151 | java |
sonarqube | sonarqube-master/sonar-ws-generator/src/main/java/org/sonarqube/wsgenerator/CodeFormatter.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.wsgenerator;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.sonarqube.wsgenerator.Helper.PATH_EXCLUSIONS;
public class CodeFormatter {
public static void format(String json) {
JsonObject jsonElement = new Gson().fromJson(json, JsonObject.class);
JsonArray webServices = (JsonArray) jsonElement.get("webServices");
Helper helper = new Helper();
VelocityContext globalContext = new VelocityContext();
globalContext.put("webServices", webServices);
globalContext.put("helper", helper);
String defaultWsClientCode = applyTemplate("defaultWsClient.vm", globalContext);
writeSourceFile(helper.defaultWsClientFile(), defaultWsClientCode);
String wsClientCode = applyTemplate("wsClient.vm", globalContext);
writeSourceFile(helper.wsClientFile(), wsClientCode);
writeSourceFile(helper.packageInfoFile(), applyTemplate("package-info.vm", globalContext));
for (JsonElement webServiceElement : webServices) {
JsonObject webService = (JsonObject) webServiceElement;
String webServicePath = webService.get("path").getAsString();
if (PATH_EXCLUSIONS.contains(webServicePath)) {
System.out.println("Excluding WS " + webServicePath + " from code generation");
continue;
}
VelocityContext webServiceContext = new VelocityContext();
webServiceContext.put("webService", webServiceElement);
webServiceContext.put("helper", helper);
String webServiceCode = applyTemplate("webService.vm", webServiceContext);
writeSourceFile(helper.file(webServicePath), webServiceCode);
writeSourceFile(helper.packageInfoFile(webServicePath), applyTemplate("package-info.vm", webServiceContext));
for (JsonElement actionElement : (JsonArray) webService.get("actions")) {
JsonObject action = (JsonObject) actionElement;
JsonArray params = (JsonArray) action.get("params");
if (params == null || params.size() < 1) {
continue;
}
VelocityContext actionContext = new VelocityContext();
actionContext.put("webService", webServiceElement);
actionContext.put("action", actionElement);
actionContext.put("helper", helper);
String requestCode = applyTemplate("request.vm", actionContext);
writeSourceFile(helper.requestFile(webServicePath, action.get("key").getAsString()), requestCode);
}
}
}
private static void writeSourceFile(String file, String code) {
try {
FileUtils.writeStringToFile(new File(file), code, UTF_8);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private static String applyTemplate(String templateName, VelocityContext context) {
VelocityEngine velocity = new VelocityEngine();
Properties properties = new Properties();
properties.setProperty("resource.loader", "class");
properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
velocity.init(properties);
Writer writer = new StringWriter();
velocity.mergeTemplate(templateName, "UTF-8", context, writer);
try {
writer.flush();
} catch (IOException e) {
throw new IllegalStateException(e);
}
return writer.toString();
}
public static void main(String[] args) {
String json = readFromInputStream(Generator.class.getResourceAsStream("/snapshot-of-api.json"));
format(json);
}
private static String readFromInputStream(InputStream inputStream) {
StringBuilder resultStringBuilder = new StringBuilder();
try {
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = br.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
return resultStringBuilder.toString();
}
}
| 5,323 | 37.028571 | 129 | java |
sonarqube | sonarqube-master/sonar-ws-generator/src/main/java/org/sonarqube/wsgenerator/Generator.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.wsgenerator;
public class Generator {
public static void main(String[] args) {
String json = ApiDefinitionDownloader.downloadApiDefinition();
CodeFormatter.format(json);
}
}
| 1,053 | 35.344828 | 75 | java |
sonarqube | sonarqube-master/sonar-ws-generator/src/main/java/org/sonarqube/wsgenerator/Helper.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.wsgenerator;
import com.google.common.base.CaseFormat;
import com.google.gson.JsonPrimitive;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.Arrays.asList;
public class Helper {
static final Set<String> PATH_EXCLUSIONS = new HashSet<>(asList("api/orchestrator"));
private static final String OUTPUT_DIR = "build/generated-sources/results";
private final Map<String, List<String[]>> responseTypes;
public Helper() {
InputStream inputStream = Helper.class.getResourceAsStream("/responseClasses.config");
responseTypes = new BufferedReader(new InputStreamReader(inputStream))
.lines()
.map(line -> line.split("\\s+"))
.collect(Collectors.groupingBy(arr -> arr[0]));
}
public boolean isIncluded(String path) {
return !PATH_EXCLUSIONS.contains(path);
}
public String packageName() {
return "org.sonarqube.ws.client";
}
public String packageName(String path) {
return packageName() + "." + rawName(path).toLowerCase();
}
private String rawName(String path) {
String x = path.replaceFirst("^api\\/", "");
if (x.contains("_")) {
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, x.toLowerCase());
}
return capitalizeFirstLetter(x);
}
public String className(String path) {
String name = rawName(path);
return capitalizeFirstLetter(name) + "Service";
}
public String defaultWsClientFieldName(String path) {
String name = rawName(path);
return lowercaseFirstLetter(name) + "Service";
}
public String defaultWsClientMethodName(String path) {
String name = rawName(path);
return lowercaseFirstLetter(name);
}
public String webserviceTypeImport(String path) {
return "import " + packageName(path) + "." + className(path) + ";";
}
private String capitalizeFirstLetter(String name) {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
private String lowercaseFirstLetter(String name) {
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
public String responseType(String path, String action) {
return responseTypeFullyQualified(path, action).replaceFirst("^.*\\.", "");
}
private String responseTypeFullyQualified(String path, String action) {
String fullPath = path + "/" + action;
List<String[]> responseTypesConfig = responseTypes.get(fullPath);
String fullyQualified;
if (responseTypesConfig == null) {
fullyQualified = guessResponseType(path, action);
responseTypes.put(fullPath, Collections.singletonList(new String[] {fullPath, fullyQualified}));
} else {
fullyQualified = responseTypesConfig.get(0)[1];
}
return fullyQualified;
}
private String guessResponseType(String path, String action) {
return guessResponseOuterClassName(path).flatMap(
potentialClassName -> guessResponseInnerClassName(action).flatMap(potentialInnerClassName -> {
try {
String guess = "org.sonarqube.ws." + potentialClassName + "$" + potentialInnerClassName;
Helper.class.forName(guess);
return Stream.of(guess.replaceFirst("\\$", "."));
} catch (ClassNotFoundException e) {
}
return Stream.empty();
})).findFirst().orElseGet(() -> "String");
}
private Stream<String> guessResponseInnerClassName(String action) {
return Stream.of(
rawName(action) + "Response",
rawName(action) + "WsResponse",
"Ws" + rawName(action) + "Response");
}
private Stream<String> guessResponseOuterClassName(String path) {
return Stream.of(
rawName(path),
"Ws" + rawName(path),
rawName(path) + "Ws");
}
public String responseTypeImport(String path, String action) {
String fullyQualified = responseTypeFullyQualified(path, action);
if ("String".equals(fullyQualified)) {
return null;
}
return "import " + fullyQualified + ";";
}
public String methodName(String path, String action) {
return lowercaseFirstLetter(rawName(action));
}
public String requestType(String path, String action) {
return rawName(action) + "Request";
}
public String parameterGetter(String parameter) {
return "get" + rawName(parameter);
}
public String parameterSetter(String parameter) {
return "set" + rawName(parameter);
}
public String setterParameter(String parameter) {
return lowercaseFirstLetter(rawName(parameter));
}
public String setterParameterType(String parameter, JsonPrimitive parameterDescription) {
if (parameter.equals("values") || parameter.equals("fieldValues") || parameter.equals("keys")) {
return "List<String>";
}
if (parameterDescription != null && parameterDescription.getAsString().matches(".*[Cc]omma.?separated.*|.*[Ll]ist of.*")) {
return "List<String>";
}
return "String";
}
public String apiDocUrl(String path) {
return "https://next.sonarqube.com/sonarqube/web_api/" + path;
}
public String apiDocUrl(String path, String action) {
return apiDocUrl(path) + "/" + action;
}
public String file(String path) {
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/" + className(path) + ".java";
}
public String defaultWsClientFile() {
return OUTPUT_DIR + "/org/sonarqube/ws/client/DefaultWsClient.java";
}
public String wsClientFile() {
return OUTPUT_DIR + "/org/sonarqube/ws/client/WsClient.java";
}
public String packageInfoFile() {
return OUTPUT_DIR + "/org/sonarqube/ws/client/package-info.java";
}
public String packageInfoFile(String path) {
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/package-info.java";
}
public String requestFile(String path, String action) {
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/" + requestType(path, action) + ".java";
}
}
| 7,013 | 32.241706 | 127 | java |
sonarqube | sonarqube-master/sonar-ws-generator/src/main/java/org/sonarqube/wsgenerator/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonarqube.wsgenerator;
import javax.annotation.ParametersAreNonnullByDefault;
| 966 | 37.68 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/FilenameUtils.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws;
import static java.util.Objects.requireNonNull;
/**
* Extracted from org.apache.commons.io.FilenameUtils
*/
public class FilenameUtils {
private static final int NOT_FOUND = -1;
private static final char EXTENSION_SEPARATOR = '.';
/**
* The Unix separator character.
*/
private static final char UNIX_SEPARATOR = '/';
/**
* The Windows separator character.
*/
private static final char WINDOWS_SEPARATOR = '\\';
private FilenameUtils() {
// Only static methods here
}
public static String getExtension(String filename) {
requireNonNull(filename);
final int index = indexOfExtension(filename);
if (index == NOT_FOUND) {
return "";
} else {
return filename.substring(index + 1);
}
}
private static int indexOfExtension(String filename) {
final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
final int lastSeparator = indexOfLastSeparator(filename);
return lastSeparator > extensionPos ? NOT_FOUND : extensionPos;
}
private static int indexOfLastSeparator(String filename) {
final int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
final int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
return Math.max(lastUnixPos, lastWindowsPos);
}
}
| 2,147 | 30.588235 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/MediaTypes.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import static org.sonarqube.ws.WsUtils.isNullOrEmpty;
/**
* @since 5.3
*/
public final class MediaTypes {
public static final String CSV = "text/csv";
public static final String DEFAULT = "application/octet-stream";
public static final String HTML = "text/html";
public static final String JAVASCRIPT = "text/javascript";
public static final String JSON = "application/json";
public static final String PROTOBUF = "application/x-protobuf";
public static final String SVG = "image/svg+xml";
public static final String TXT = "text/plain";
public static final String XML = "application/xml";
public static final String ZIP = "application/zip";
private static final String BMP = "image/bmp";
private static final String CSS = "text/css";
private static final String DTD = "application/xml-dtd";
private static final String GIF = "image/gif";
private static final String ICO = "image/x-icon";
private static final String JAR = "application/java-archive";
private static final String JNLP = "application/jnlp";
private static final String JPEG = "image/jpeg";
private static final String JPG = "image/jpeg";
private static final String PNG = "image/png";
private static final String POSTSCRIPT = "application/postscript";
private static final String PPT = "application/vnd.ms-powerpoint";
private static final String RTF = "text/rtf";
private static final String TAR = "application/x-tar";
private static final String TIFF = "image/tiff";
private static final String TGZ = "application/tgz";
private static final String TSV = "text/tab-separated-values";
private static final String WOFF2 = "application/font-woff2";
private static final String XLS = "application/vnd.ms-excel";
private static final String XSLT = "application/xslt+xml";
private static final Map<String, String> MAP;
static {
MAP = new HashMap<>(27);
MAP.put("js", JAVASCRIPT);
MAP.put("json", JSON);
MAP.put("zip", ZIP);
MAP.put("tgz", TGZ);
MAP.put("ps", POSTSCRIPT);
MAP.put("jnlp", JNLP);
MAP.put("jar", JAR);
MAP.put("xls", XLS);
MAP.put("ppt", PPT);
MAP.put("tar", TAR);
MAP.put("xml", XML);
MAP.put("dtd", DTD);
MAP.put("xslt", XSLT);
MAP.put("bmp", BMP);
MAP.put("gif", GIF);
MAP.put("jpg", JPG);
MAP.put("jpeg", JPEG);
MAP.put("tiff", TIFF);
MAP.put("png", PNG);
MAP.put("svg", SVG);
MAP.put("ico", ICO);
MAP.put("txt", TXT);
MAP.put("csv", CSV);
MAP.put("properties", TXT);
MAP.put("rtf", RTF);
MAP.put("html", HTML);
MAP.put("css", CSS);
MAP.put("tsv", TSV);
MAP.put("woff2", WOFF2);
}
private MediaTypes() {
// only static methods
}
public static String getByFilename(String filename) {
String extension = FilenameUtils.getExtension(filename);
String mime = null;
if (!isNullOrEmpty(extension)) {
mime = MAP.get(extension.toLowerCase(Locale.ENGLISH));
}
return mime != null ? mime : DEFAULT;
}
}
| 3,943 | 34.854545 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/WsUtils.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws;
import javax.annotation.Nullable;
import static java.lang.String.format;
public class WsUtils {
private WsUtils() {
// Only static methods here
}
public static void checkArgument(boolean expression) {
if (!expression) {
throw new IllegalArgumentException();
}
}
public static void checkArgument(boolean expression, String message, Object... args) {
if (!expression) {
throw new IllegalArgumentException(format(message, args));
}
}
public static boolean isNullOrEmpty(@Nullable String string) {
return string == null || string.length() == 0;
}
public static String nullToEmpty(@Nullable String string) {
return string == null ? "" : string;
}
}
| 1,582 | 28.867925 | 88 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonarqube.ws;
import javax.annotation.ParametersAreNonnullByDefault;
| 957 | 37.32 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonarqube.ws.MediaTypes;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableSet;
import static java.util.Objects.requireNonNull;
import static org.sonarqube.ws.WsUtils.checkArgument;
import static org.sonarqube.ws.WsUtils.isNullOrEmpty;
abstract class BaseRequest<SELF extends BaseRequest<SELF>> implements WsRequest {
private final String path;
private String mediaType = MediaTypes.JSON;
private final DefaultParameters parameters = new DefaultParameters();
private final DefaultHeaders headers = new DefaultHeaders();
private OptionalInt timeOutInMs = OptionalInt.empty();
private OptionalInt writeTimeOutInMs = OptionalInt.empty();
BaseRequest(String path) {
this.path = path;
}
@Override
public String getPath() {
return path;
}
@Override
public String getMediaType() {
return mediaType;
}
@Override
public OptionalInt getTimeOutInMs() {
return timeOutInMs;
}
public <T extends SELF> T setTimeOutInMs(int timeOutInMs) {
this.timeOutInMs = OptionalInt.of(timeOutInMs);
return (T) this;
}
@Override
public OptionalInt getWriteTimeOutInMs() {
return writeTimeOutInMs;
}
public <T extends SELF> T setWriteTimeOutInMs(int writeTimeOutInMs) {
this.writeTimeOutInMs = OptionalInt.of(writeTimeOutInMs);
return (T) this;
}
/**
* Expected media type of response. Default is {@link MediaTypes#JSON}.
*/
@SuppressWarnings("unchecked")
public <T extends SELF> T setMediaType(String s) {
requireNonNull(s, "media type of response cannot be null");
this.mediaType = s;
return (T) this;
}
public <T extends SELF> T setParam(String key, @Nullable String value) {
return (T) setSingleValueParam(key, value);
}
public <T extends SELF> T setParam(String key, @Nullable Integer value) {
return setSingleValueParam(key, value);
}
public <T extends SELF> T setParam(String key, @Nullable Long value) {
return setSingleValueParam(key, value);
}
public <T extends SELF> T setParam(String key, @Nullable Float value) {
return setSingleValueParam(key, value);
}
public <T extends SELF> T setParam(String key, @Nullable Boolean value) {
return setSingleValueParam(key, value);
}
@SuppressWarnings("unchecked")
private <T extends SELF> T setSingleValueParam(String key, @Nullable Object value) {
checkArgument(!isNullOrEmpty(key), "a WS parameter key cannot be null");
if (value == null) {
return (T) this;
}
parameters.setValue(key, value.toString());
return (T) this;
}
@SuppressWarnings("unchecked")
public <T extends SELF> T setParam(String key, @Nullable Collection<? extends Object> values) {
checkArgument(!isNullOrEmpty(key), "a WS parameter key cannot be null");
if (values == null || values.isEmpty()) {
return (T) this;
}
parameters.setValues(key, values.stream()
.filter(Objects::nonNull)
.map(Object::toString)
.collect(Collectors.toList()));
return (T) this;
}
@Override
public Map<String, String> getParams() {
return parameters.keyValues.keySet().stream()
.collect(Collectors.toMap(
Function.identity(),
key -> parameters.keyValues.get(key).get(0),
(v1, v2) -> {
throw new IllegalStateException(String.format("Duplicate key '%s' in request", v1));
},
LinkedHashMap::new));
}
@Override
public Parameters getParameters() {
return parameters;
}
@Override
public Headers getHeaders() {
return headers;
}
@SuppressWarnings("unchecked")
public <T extends SELF> T setHeader(String name, @Nullable String value) {
requireNonNull(name, "Header name can't be null");
headers.setValue(name, value);
return (T) this;
}
private static class DefaultParameters implements Parameters {
// preserve insertion order
private final Map<String, List<String>> keyValues = new LinkedHashMap<>();
@Override
@CheckForNull
public String getValue(String key) {
return keyValues.containsKey(key) ? keyValues.get(key).get(0) : null;
}
@Override
public List<String> getValues(String key) {
return keyValues.containsKey(key) ? keyValues.get(key) : emptyList();
}
@Override
public Set<String> getKeys() {
return keyValues.keySet();
}
private DefaultParameters setValue(String key, String value) {
checkArgument(!isNullOrEmpty(key));
checkArgument(value != null);
keyValues.computeIfAbsent(key, k -> new ArrayList<>()).add(value);
return this;
}
private DefaultParameters setValues(String key, Collection<String> values) {
checkArgument(!isNullOrEmpty(key));
checkArgument(values != null && !values.isEmpty());
keyValues.computeIfAbsent(key, k -> new ArrayList<>()).addAll(values.stream().map(Object::toString).filter(Objects::nonNull).collect(Collectors.toList()));
return this;
}
}
private static class DefaultHeaders implements Headers {
private final Map<String, String> keyValues = new HashMap<>();
@Override
public Optional<String> getValue(String name) {
return Optional.ofNullable(keyValues.get(name));
}
private DefaultHeaders setValue(String name, @Nullable String value) {
checkArgument(!isNullOrEmpty(name));
if (value == null) {
keyValues.remove(name);
} else {
keyValues.put(name, value);
}
return this;
}
@Override
public Set<String> getNames() {
return unmodifiableSet(keyValues.keySet());
}
}
}
| 6,922 | 28.334746 | 161 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
abstract class BaseResponse implements WsResponse {
@Override
public boolean isSuccessful() {
return code() >= 200 && code() < 300;
}
@Override
public WsResponse failIfNotSuccessful() {
if (!isSuccessful()) {
String content = content();
close();
throw new HttpException(requestUrl(), code(), content);
}
return this;
}
@Override
public boolean hasContent() {
return code() != HTTP_NO_CONTENT;
}
@Override
public void close() {
// override if needed
}
}
| 1,459 | 27.627451 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import com.google.protobuf.Message;
import com.google.protobuf.Parser;
import java.io.InputStream;
import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonarqube.ws.MediaTypes;
import static org.sonarqube.ws.WsUtils.checkArgument;
import static org.sonarqube.ws.WsUtils.isNullOrEmpty;
public abstract class BaseService {
private final WsConnector wsConnector;
protected final String controller;
public BaseService(WsConnector wsConnector, String controllerPath) {
checkArgument(!isNullOrEmpty(controllerPath), "Controller path cannot be empty");
this.wsConnector = wsConnector;
this.controller = controllerPath;
}
protected <T extends Message> T call(BaseRequest request, Parser<T> parser) {
return call(request, parser, MediaTypes.PROTOBUF);
}
protected <T extends Message> T call(BaseRequest request, Parser<T> parser, String mediaType) {
request.setMediaType(mediaType);
WsResponse response = call(request);
return convert(response, parser);
}
protected WsResponse call(WsRequest request) {
return wsConnector.call(request).failIfNotSuccessful();
}
public static <T extends Message> T convert(WsResponse response, Parser<T> parser) {
try (InputStream byteStream = response.contentStream()) {
// HTTP header "Content-Type" is not verified. It may be different than protobuf.
return parser.parseFrom(byteStream);
} catch (Exception e) {
throw new IllegalStateException("Fail to parse protobuf response of " + response.requestUrl(), e);
}
}
protected String path(String action) {
return String.format("%s/%s", controller, action);
}
@CheckForNull
protected static String inlineMultipleParamValue(@Nullable Collection<String> values) {
return values == null ? null : String.join(",", values);
}
}
| 2,746 | 35.144737 | 104 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import javax.annotation.Generated;
import org.sonarqube.ws.client.almintegrations.AlmIntegrationsService;
import org.sonarqube.ws.client.almsettings.AlmSettingsService;
import org.sonarqube.ws.client.analysiscache.AnalysisCacheService;
import org.sonarqube.ws.client.analysisreports.AnalysisReportsService;
import org.sonarqube.ws.client.applications.ApplicationsService;
import org.sonarqube.ws.client.authentication.AuthenticationService;
import org.sonarqube.ws.client.batch.BatchService;
import org.sonarqube.ws.client.ce.CeService;
import org.sonarqube.ws.client.components.ComponentsService;
import org.sonarqube.ws.client.developers.DevelopersService;
import org.sonarqube.ws.client.duplications.DuplicationsService;
import org.sonarqube.ws.client.editions.EditionsService;
import org.sonarqube.ws.client.emails.EmailsService;
import org.sonarqube.ws.client.favorites.FavoritesService;
import org.sonarqube.ws.client.githubprovisioning.GithubProvisioningService;
import org.sonarqube.ws.client.governancereports.GovernanceReportsService;
import org.sonarqube.ws.client.hotspots.HotspotsService;
import org.sonarqube.ws.client.issues.IssuesService;
import org.sonarqube.ws.client.l10n.L10nService;
import org.sonarqube.ws.client.languages.LanguagesService;
import org.sonarqube.ws.client.measures.MeasuresService;
import org.sonarqube.ws.client.metrics.MetricsService;
import org.sonarqube.ws.client.monitoring.MonitoringService;
import org.sonarqube.ws.client.navigation.NavigationService;
import org.sonarqube.ws.client.newcodeperiods.NewCodePeriodsService;
import org.sonarqube.ws.client.notifications.NotificationsService;
import org.sonarqube.ws.client.permissions.PermissionsService;
import org.sonarqube.ws.client.plugins.PluginsService;
import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService;
import org.sonarqube.ws.client.projectbadges.ProjectBadgesService;
import org.sonarqube.ws.client.projectbranches.ProjectBranchesService;
import org.sonarqube.ws.client.projectdump.ProjectDumpService;
import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.projectpullrequests.ProjectPullRequestsService;
import org.sonarqube.ws.client.projects.ProjectsService;
import org.sonarqube.ws.client.projecttags.ProjectTagsService;
import org.sonarqube.ws.client.push.SonarLintServerPushService;
import org.sonarqube.ws.client.qualitygates.QualitygatesService;
import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService;
import org.sonarqube.ws.client.regulatoryreports.RegulatoryReportsService;
import org.sonarqube.ws.client.roots.RootsService;
import org.sonarqube.ws.client.rules.RulesService;
import org.sonarqube.ws.client.securityreports.SecurityReportsService;
import org.sonarqube.ws.client.server.ServerService;
import org.sonarqube.ws.client.settings.SettingsService;
import org.sonarqube.ws.client.sources.SourcesService;
import org.sonarqube.ws.client.support.SupportService;
import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.updatecenter.UpdatecenterService;
import org.sonarqube.ws.client.usergroups.UserGroupsService;
import org.sonarqube.ws.client.users.UsersService;
import org.sonarqube.ws.client.usertokens.UserTokensService;
import org.sonarqube.ws.client.views.ViewsService;
import org.sonarqube.ws.client.webhooks.WebhooksService;
import org.sonarqube.ws.client.webservices.WebservicesService;
/**
* This class is not public anymore since version 5.5. It is
* created by {@link WsClientFactory}
*
* @since 5.3
*/
@Generated("sonar-ws-generator")
class DefaultWsClient implements WsClient {
private final WsConnector wsConnector;
private final AlmIntegrationsService almIntegrationsService;
private final AlmSettingsService almSettingsService;
private final AnalysisCacheService analysisCacheService;
private final AnalysisReportsService analysisReportsService;
private final ApplicationsService applicationsService;
private final AuthenticationService authenticationService;
private final CeService ceService;
private final ComponentsService componentsService;
private final DevelopersService developersService;
private final DuplicationsService duplicationsService;
private final EditionsService editionsService;
private final EmailsService emailsService;
private final FavoritesService favoritesService;
private final GovernanceReportsService governanceReportsService;
private final HotspotsService hotspotsService;
private final IssuesService issuesService;
private final L10nService l10nService;
private final LanguagesService languagesService;
private final MeasuresService measuresService;
private final MetricsService metricsService;
private final MonitoringService monitoringService;
private final NavigationService navigationService;
private final NewCodePeriodsService newCodePeriodsService;
private final NotificationsService notificationsService;
private final PermissionsService permissionsService;
private final PluginsService pluginsService;
private final ProjectAnalysesService projectAnalysesService;
private final ProjectBadgesService projectBadgesService;
private final ProjectBranchesService projectBranchesService;
private final ProjectDumpService projectDumpService;
private final ProjectLinksService projectLinksService;
private final ProjectPullRequestsService projectPullRequestsService;
private final ProjectTagsService projectTagsService;
private final ProjectsService projectsService;
private final QualitygatesService qualitygatesService;
private final QualityprofilesService qualityprofilesService;
private final RootsService rootsService;
private final RulesService rulesService;
private final ServerService serverService;
private final SettingsService settingsService;
private final SourcesService sourcesService;
private final SupportService supportService;
private final SystemService systemService;
private final UpdatecenterService updatecenterService;
private final UserGroupsService userGroupsService;
private final UserTokensService userTokensService;
private final UsersService usersService;
private final ViewsService viewsService;
private final WebhooksService webhooksService;
private final WebservicesService webservicesService;
private final BatchService batchService;
private final SecurityReportsService securityReportsService;
private final RegulatoryReportsService regulatoryReportsService;
private final SonarLintServerPushService sonarLintPushService;
private final GithubProvisioningService githubProvisioningService;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
this.almIntegrationsService = new AlmIntegrationsService(wsConnector);
this.almSettingsService = new AlmSettingsService(wsConnector);
this.analysisCacheService = new AnalysisCacheService(wsConnector);
this.analysisReportsService = new AnalysisReportsService(wsConnector);
this.applicationsService = new ApplicationsService(wsConnector);
this.authenticationService = new AuthenticationService(wsConnector);
this.ceService = new CeService(wsConnector);
this.componentsService = new ComponentsService(wsConnector);
this.developersService = new DevelopersService(wsConnector);
this.duplicationsService = new DuplicationsService(wsConnector);
this.editionsService = new EditionsService(wsConnector);
this.emailsService = new EmailsService(wsConnector);
this.favoritesService = new FavoritesService(wsConnector);
this.governanceReportsService = new GovernanceReportsService(wsConnector);
this.hotspotsService = new HotspotsService(wsConnector);
this.issuesService = new IssuesService(wsConnector);
this.l10nService = new L10nService(wsConnector);
this.languagesService = new LanguagesService(wsConnector);
this.measuresService = new MeasuresService(wsConnector);
this.metricsService = new MetricsService(wsConnector);
this.monitoringService = new MonitoringService(wsConnector);
this.navigationService = new NavigationService(wsConnector);
this.newCodePeriodsService = new NewCodePeriodsService(wsConnector);
this.notificationsService = new NotificationsService(wsConnector);
this.permissionsService = new PermissionsService(wsConnector);
this.pluginsService = new PluginsService(wsConnector);
this.projectAnalysesService = new ProjectAnalysesService(wsConnector);
this.projectBadgesService = new ProjectBadgesService(wsConnector);
this.projectBranchesService = new ProjectBranchesService(wsConnector);
this.projectDumpService = new ProjectDumpService(wsConnector);
this.projectLinksService = new ProjectLinksService(wsConnector);
this.projectPullRequestsService = new ProjectPullRequestsService(wsConnector);
this.projectTagsService = new ProjectTagsService(wsConnector);
this.projectsService = new ProjectsService(wsConnector);
this.qualitygatesService = new QualitygatesService(wsConnector);
this.qualityprofilesService = new QualityprofilesService(wsConnector);
this.rootsService = new RootsService(wsConnector);
this.rulesService = new RulesService(wsConnector);
this.serverService = new ServerService(wsConnector);
this.settingsService = new SettingsService(wsConnector);
this.sourcesService = new SourcesService(wsConnector);
this.supportService = new SupportService(wsConnector);
this.systemService = new SystemService(wsConnector);
this.updatecenterService = new UpdatecenterService(wsConnector);
this.userGroupsService = new UserGroupsService(wsConnector);
this.userTokensService = new UserTokensService(wsConnector);
this.usersService = new UsersService(wsConnector);
this.viewsService = new ViewsService(wsConnector);
this.webhooksService = new WebhooksService(wsConnector);
this.webservicesService = new WebservicesService(wsConnector);
this.batchService = new BatchService(wsConnector);
this.securityReportsService = new SecurityReportsService(wsConnector);
this.sonarLintPushService = new SonarLintServerPushService(wsConnector);
this.regulatoryReportsService = new RegulatoryReportsService(wsConnector);
this.githubProvisioningService = new GithubProvisioningService(wsConnector);
}
@Override
@Deprecated
public WsConnector wsConnector() {
return wsConnector;
}
@Override
public AlmIntegrationsService almIntegrations() {
return almIntegrationsService;
}
@Override
public AlmSettingsService almSettings() {
return almSettingsService;
}
@Override
public AnalysisCacheService analysisCache() {
return analysisCacheService;
}
@Override
public AnalysisReportsService analysisReports() {
return analysisReportsService;
}
@Override
public ApplicationsService applications() {
return applicationsService;
}
@Override
public AuthenticationService authentication() {
return authenticationService;
}
@Override
public CeService ce() {
return ceService;
}
@Override
public ComponentsService components() {
return componentsService;
}
@Override
public DevelopersService developers() {
return developersService;
}
@Override
public RegulatoryReportsService regulatoryReports() {
return regulatoryReportsService;
}
@Override
public DuplicationsService duplications() {
return duplicationsService;
}
@Override
public EditionsService editions() {
return editionsService;
}
@Override
public EmailsService emails() {
return emailsService;
}
@Override
public FavoritesService favorites() {
return favoritesService;
}
@Override
public GovernanceReportsService governanceReports() {
return governanceReportsService;
}
@Override
public HotspotsService hotspots() {
return hotspotsService;
}
@Override
public IssuesService issues() {
return issuesService;
}
@Override
public L10nService l10n() {
return l10nService;
}
@Override
public LanguagesService languages() {
return languagesService;
}
@Override
public MeasuresService measures() {
return measuresService;
}
@Override
public MetricsService metrics() {
return metricsService;
}
@Override
public MonitoringService monitoring() {
return monitoringService;
}
@Override
public SonarLintServerPushService sonarLintPush() {
return sonarLintPushService;
}
@Override
public NavigationService navigation() {
return navigationService;
}
@Override
public NewCodePeriodsService newCodePeriods() {
return newCodePeriodsService;
}
@Override
public NotificationsService notifications() {
return notificationsService;
}
@Override
public PermissionsService permissions() {
return permissionsService;
}
@Override
public PluginsService plugins() {
return pluginsService;
}
@Override
public ProjectAnalysesService projectAnalyses() {
return projectAnalysesService;
}
@Override
public ProjectBadgesService projectBadges() {
return projectBadgesService;
}
@Override
public ProjectBranchesService projectBranches() {
return projectBranchesService;
}
@Override
public ProjectDumpService projectDump() {
return projectDumpService;
}
@Override
public ProjectLinksService projectLinks() {
return projectLinksService;
}
@Override
public ProjectPullRequestsService projectPullRequests() {
return projectPullRequestsService;
}
@Override
public ProjectTagsService projectTags() {
return projectTagsService;
}
@Override
public ProjectsService projects() {
return projectsService;
}
@Override
public QualitygatesService qualitygates() {
return qualitygatesService;
}
@Override
public QualityprofilesService qualityprofiles() {
return qualityprofilesService;
}
@Override
public RootsService roots() {
return rootsService;
}
@Override
public RulesService rules() {
return rulesService;
}
@Override
public ServerService server() {
return serverService;
}
@Override
public SettingsService settings() {
return settingsService;
}
@Override
public GithubProvisioningService githubProvisioning() {
return githubProvisioningService;
}
@Override
public SourcesService sources() {
return sourcesService;
}
@Override
public SupportService support() {
return supportService;
}
@Override
public SystemService system() {
return systemService;
}
@Override
public UpdatecenterService updatecenter() {
return updatecenterService;
}
@Override
public UserGroupsService userGroups() {
return userGroupsService;
}
@Override
public UserTokensService userTokens() {
return userTokensService;
}
@Override
public UsersService users() {
return usersService;
}
@Override
public ViewsService views() {
return viewsService;
}
@Override
public WebhooksService webhooks() {
return webhooksService;
}
@Override
public WebservicesService webservices() {
return webservicesService;
}
@Override
public BatchService batch() {
return batchService;
}
@Override
public SecurityReportsService securityReports() {
return securityReportsService;
}
}
| 16,229 | 32.258197 | 82 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/DeleteRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
/**
* @since 5.3
*/
public class DeleteRequest extends RequestWithoutPayload<DeleteRequest> {
public DeleteRequest(String path) {
super(path);
}
@Override
public Method getMethod() {
return Method.DELETE;
}
@Override
Function<Request.Builder, Request.Builder> addVerbToBuilder() {
return Request.Builder::delete;
}
}
| 1,287 | 28.953488 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/GetRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
/**
* @since 5.3
*/
public class GetRequest extends RequestWithoutPayload<GetRequest> {
public GetRequest(String path) {
super(path);
}
@Override
public Method getMethod() {
return Method.GET;
}
@Override
Function<Request.Builder, Request.Builder> addVerbToBuilder() {
return Request.Builder::get;
}
}
| 1,272 | 28.604651 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/Headers.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.Optional;
import java.util.Set;
/**
* HTTP headers
*
* @since 6.6
*/
public interface Headers {
Optional<String> getValue(String name);
Set<String> getNames();
}
| 1,068 | 27.891892 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.IOException;
import java.net.Proxy;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.Call;
import okhttp3.Credentials;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.sonarqube.ws.client.RequestWithPayload.Part;
import static java.lang.String.format;
import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
import static java.nio.charset.StandardCharsets.UTF_8;
import static okhttp3.internal.http.StatusLine.HTTP_PERM_REDIRECT;
import static okhttp3.internal.http.StatusLine.HTTP_TEMP_REDIRECT;
import static org.sonarqube.ws.WsUtils.checkArgument;
import static org.sonarqube.ws.WsUtils.isNullOrEmpty;
import static org.sonarqube.ws.WsUtils.nullToEmpty;
/**
* Connect to any SonarQube server available through HTTP or HTTPS.
* <p>The JVM system proxies are used.</p>
*/
public class HttpConnector implements WsConnector {
public static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30_000;
public static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60_000;
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
/**
* Base URL with trailing slash, for instance "https://localhost/sonarqube/".
* It is required for further usage of {@link HttpUrl#resolve(String)}.
*/
private final HttpUrl baseUrl;
private final String systemPassCode;
private final OkHttpClient okHttpClient;
private final OkHttpClient noRedirectOkHttpClient;
private HttpConnector(Builder builder) {
this.baseUrl = HttpUrl.parse(builder.url.endsWith("/") ? builder.url : format("%s/", builder.url));
checkArgument(this.baseUrl != null, "Malformed URL: '%s'", builder.url);
OkHttpClientBuilder okHttpClientBuilder = new OkHttpClientBuilder();
okHttpClientBuilder.setUserAgent(builder.userAgent);
if (!isNullOrEmpty(builder.login)) {
// password is null when login represents an access token. In this case
// the Basic credentials consider an empty password.
okHttpClientBuilder.setCredentials(Credentials.basic(builder.login, nullToEmpty(builder.password), UTF_8));
}
this.systemPassCode = builder.systemPassCode;
okHttpClientBuilder.setProxy(builder.proxy);
okHttpClientBuilder.setProxyLogin(builder.proxyLogin);
okHttpClientBuilder.setProxyPassword(builder.proxyPassword);
okHttpClientBuilder.setConnectTimeoutMs(builder.connectTimeoutMs);
okHttpClientBuilder.setReadTimeoutMs(builder.readTimeoutMs);
okHttpClientBuilder.setSSLSocketFactory(builder.sslSocketFactory);
okHttpClientBuilder.setTrustManager(builder.sslTrustManager);
this.okHttpClient = okHttpClientBuilder.build();
this.noRedirectOkHttpClient = newClientWithoutRedirect(this.okHttpClient);
}
private static OkHttpClient newClientWithoutRedirect(OkHttpClient client) {
return client.newBuilder()
.followRedirects(false)
.followSslRedirects(false)
.build();
}
@Override
public String baseUrl() {
return baseUrl.url().toExternalForm();
}
public OkHttpClient okHttpClient() {
return okHttpClient;
}
@Override
public WsResponse call(WsRequest httpRequest) {
if (httpRequest instanceof RequestWithoutPayload) {
return executeRequest((RequestWithoutPayload) httpRequest);
}
if (httpRequest instanceof RequestWithPayload) {
return executeRequest((RequestWithPayload) httpRequest);
}
throw new IllegalArgumentException(format("Unsupported implementation: %s", httpRequest.getClass()));
}
private WsResponse executeRequest(RequestWithoutPayload<?> request) {
HttpUrl.Builder urlBuilder = prepareUrlBuilder(request);
completeUrlQueryParameters(request, urlBuilder);
Request.Builder okRequestBuilder = prepareOkRequestBuilder(request, urlBuilder);
okRequestBuilder = request.addVerbToBuilder().apply(okRequestBuilder);
return new OkHttpResponse(doCall(prepareOkHttpClient(okHttpClient, request), okRequestBuilder.build()));
}
private WsResponse executeRequest(RequestWithPayload<?> request) {
HttpUrl.Builder urlBuilder = prepareUrlBuilder(request);
RequestBody body;
Map<String, Part> parts = request.getParts();
if (request.hasBody()) {
body = RequestBody.create(JSON, request.getBody());
} else if (parts.isEmpty()) {
// parameters are defined in the body (application/x-www-form-urlencoded)
FormBody.Builder formBody = new FormBody.Builder();
request.getParameters().getKeys()
.forEach(key -> request.getParameters().getValues(key)
.forEach(value -> formBody.add(key, value)));
body = formBody.build();
} else {
// parameters are defined in the URL (as GET)
completeUrlQueryParameters(request, urlBuilder);
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
parts.entrySet().forEach(param -> {
Part part = param.getValue();
bodyBuilder.addFormDataPart(
param.getKey(),
part.getFile().getName(),
RequestBody.create(MediaType.parse(part.getMediaType()), part.getFile()));
});
body = bodyBuilder.build();
}
Request.Builder okRequestBuilder = prepareOkRequestBuilder(request, urlBuilder);
okRequestBuilder = request.addVerbToBuilder(body).apply(okRequestBuilder);
Response response = doCall(prepareOkHttpClient(noRedirectOkHttpClient, request), okRequestBuilder.build());
response = checkRedirect(response, request);
return new OkHttpResponse(response);
}
private HttpUrl.Builder prepareUrlBuilder(WsRequest wsRequest) {
String path = wsRequest.getPath();
return baseUrl
.resolve(path.startsWith("/") ? path.replaceAll("^(/)+", "") : path)
.newBuilder();
}
static OkHttpClient prepareOkHttpClient(OkHttpClient okHttpClient, WsRequest wsRequest) {
if (!wsRequest.getTimeOutInMs().isPresent() && !wsRequest.getWriteTimeOutInMs().isPresent()) {
return okHttpClient;
}
OkHttpClient.Builder builder = okHttpClient.newBuilder();
if (wsRequest.getTimeOutInMs().isPresent()) {
builder.readTimeout(wsRequest.getTimeOutInMs().getAsInt(), TimeUnit.MILLISECONDS);
}
if (wsRequest.getWriteTimeOutInMs().isPresent()) {
builder.writeTimeout(wsRequest.getWriteTimeOutInMs().getAsInt(), TimeUnit.MILLISECONDS);
}
return builder.build();
}
private static void completeUrlQueryParameters(BaseRequest<?> request, HttpUrl.Builder urlBuilder) {
request.getParameters().getKeys()
.forEach(key -> request.getParameters().getValues(key)
.forEach(value -> urlBuilder.addQueryParameter(key, value)));
}
private Request.Builder prepareOkRequestBuilder(WsRequest getRequest, HttpUrl.Builder urlBuilder) {
Request.Builder okHttpRequestBuilder = new Request.Builder()
.url(urlBuilder.build())
.header("Accept", getRequest.getMediaType())
.header("Accept-Charset", "UTF-8");
if (systemPassCode != null) {
okHttpRequestBuilder.header("X-Sonar-Passcode", systemPassCode);
}
getRequest.getHeaders().getNames().forEach(name -> okHttpRequestBuilder.header(name, getRequest.getHeaders().getValue(name).get()));
return okHttpRequestBuilder;
}
private static Response doCall(OkHttpClient client, Request okRequest) {
Call call = client.newCall(okRequest);
try {
return call.execute();
} catch (IOException e) {
throw new IllegalStateException("Fail to request url: " + okRequest.url(), e);
}
}
private Response checkRedirect(Response response, RequestWithPayload<?> postRequest) {
switch (response.code()) {
case HTTP_MOVED_PERM:
case HTTP_MOVED_TEMP:
case HTTP_TEMP_REDIRECT:
case HTTP_PERM_REDIRECT:
// OkHttpClient does not follow the redirect with the same HTTP method. A POST is
// redirected to a GET. Because of that the redirect must be manually implemented.
// See:
// https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316
// https://github.com/square/okhttp/issues/936#issuecomment-266430151
return followPostRedirect(response, postRequest);
default:
return response;
}
}
private Response followPostRedirect(Response response, RequestWithPayload<?> postRequest) {
String location = response.header("Location");
if (location == null) {
throw new IllegalStateException(format("Missing HTTP header 'Location' in redirect of %s", response.request().url()));
}
HttpUrl url = response.request().url().resolve(location);
// Don't follow redirects to unsupported protocols.
if (url == null) {
throw new IllegalStateException(format("Unsupported protocol in redirect of %s to %s", response.request().url(), location));
}
Request.Builder redirectRequest = response.request().newBuilder();
redirectRequest.post(response.request().body());
response.body().close();
return doCall(prepareOkHttpClient(noRedirectOkHttpClient, postRequest), redirectRequest.url(url).build());
}
/**
* @since 5.5
*/
public static Builder newBuilder() {
return new Builder();
}
public static class Builder {
private String url;
private String userAgent;
private String login;
private String password;
private Proxy proxy;
private String proxyLogin;
private String proxyPassword;
private String systemPassCode;
private int connectTimeoutMs = DEFAULT_CONNECT_TIMEOUT_MILLISECONDS;
private int readTimeoutMs = DEFAULT_READ_TIMEOUT_MILLISECONDS;
private SSLSocketFactory sslSocketFactory = null;
private X509TrustManager sslTrustManager = null;
/**
* Private since 5.5.
*
* @see HttpConnector#newBuilder()
*/
private Builder() {
}
/**
* Optional User Agent
*/
public Builder userAgent(@Nullable String userAgent) {
this.userAgent = userAgent;
return this;
}
/**
* Mandatory HTTP server URL, eg "http://localhost:9000"
*/
public Builder url(String url) {
this.url = url;
return this;
}
/**
* Optional login/password, for example "admin"
*/
public Builder credentials(@Nullable String login, @Nullable String password) {
this.login = login;
this.password = password;
return this;
}
/**
* Optional access token, for example {@code "ABCDE"}. Alternative to {@link #credentials(String, String)}
*/
public Builder token(@Nullable String token) {
this.login = token;
this.password = null;
return this;
}
/**
* Sets a specified timeout value, in milliseconds, to be used when opening HTTP connection.
* A timeout of zero is interpreted as an infinite timeout. Default value is {@link #DEFAULT_CONNECT_TIMEOUT_MILLISECONDS}
*/
public Builder connectTimeoutMilliseconds(int i) {
this.connectTimeoutMs = i;
return this;
}
/**
* Optional SSL socket factory with which SSL sockets will be created to establish SSL connections.
* If not set, a default SSL socket factory will be used, base d on the JVM's default key store.
*/
public Builder setSSLSocketFactory(@Nullable SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}
/**
* Optional SSL trust manager used to validate certificates.
* If not set, a default system trust manager will be used, based on the JVM's default truststore.
*/
public Builder setTrustManager(@Nullable X509TrustManager sslTrustManager) {
this.sslTrustManager = sslTrustManager;
return this;
}
/**
* Sets the read timeout to a specified timeout, in milliseconds.
* A timeout of zero is interpreted as an infinite timeout. Default value is {@link #DEFAULT_READ_TIMEOUT_MILLISECONDS}
*/
public Builder readTimeoutMilliseconds(int i) {
this.readTimeoutMs = i;
return this;
}
public Builder proxy(@Nullable Proxy proxy) {
this.proxy = proxy;
return this;
}
public Builder proxyCredentials(@Nullable String proxyLogin, @Nullable String proxyPassword) {
this.proxyLogin = proxyLogin;
this.proxyPassword = proxyPassword;
return this;
}
public Builder systemPassCode(@Nullable String systemPassCode) {
this.systemPassCode = systemPassCode;
return this;
}
public HttpConnector build() {
checkArgument(!isNullOrEmpty(url), "Server URL is not defined");
return new HttpConnector(this);
}
}
}
| 13,915 | 36.408602 | 170 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
/**
* @since 5.3
*/
public class HttpException extends RuntimeException {
private final String url;
private final int code;
private final String content;
public HttpException(String url, int code, String content) {
super(String.format("Error %d on %s : %s", code, url, content));
this.url = url;
this.code = code;
this.content = content;
}
public String content() {
return content;
}
public String url() {
return url;
}
/**
* @see java.net.HttpURLConnection constants
*/
public int code() {
return code;
}
}
| 1,452 | 26.415094 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsClientFactory.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import org.sonar.api.server.ServerSide;
import org.sonar.api.server.ws.LocalConnector;
@ServerSide
public interface LocalWsClientFactory extends WsClientFactory {
WsClient newClient(LocalConnector localConnector);
}
| 1,098 | 34.451613 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.sonar.api.server.ws.LocalConnector;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.function.Function.identity;
class LocalWsConnector implements WsConnector {
private final LocalConnector localConnector;
LocalWsConnector(LocalConnector localConnector) {
this.localConnector = localConnector;
}
LocalConnector localConnector() {
return localConnector;
}
@Override
public String baseUrl() {
return "/";
}
@Override
public WsResponse call(WsRequest wsRequest) {
DefaultLocalRequest localRequest = new DefaultLocalRequest(wsRequest);
LocalConnector.LocalResponse localResponse = localConnector.call(localRequest);
return new ByteArrayResponse(wsRequest.getPath(), localResponse);
}
private static class DefaultLocalRequest implements LocalConnector.LocalRequest {
private final WsRequest wsRequest;
public DefaultLocalRequest(WsRequest wsRequest) {
this.wsRequest = wsRequest;
}
@Override
public String getPath() {
return wsRequest.getPath();
}
@Override
public String getMediaType() {
return wsRequest.getMediaType();
}
@Override
public String getMethod() {
return wsRequest.getMethod().name();
}
@Override
public boolean hasParam(String key) {
return !wsRequest.getParameters().getValues(key).isEmpty();
}
@Override
public String getParam(String key) {
return wsRequest.getParameters().getValue(key);
}
@Override
public List<String> getMultiParam(String key) {
return wsRequest.getParameters().getValues(key);
}
@Override
public Optional<String> getHeader(String name) {
return wsRequest.getHeaders().getValue(name);
}
@Override
public Map<String, String[]> getParameterMap() {
return wsRequest.getParameters()
.getKeys()
.stream()
.collect(Collectors.toMap(
identity(),
k -> wsRequest.getParameters().getValues(k).toArray(new String[0])));
}
}
private static class ByteArrayResponse extends BaseResponse {
private final String path;
private final byte[] bytes;
private final String contentType;
private final int code;
ByteArrayResponse(String path, LocalConnector.LocalResponse localResponse) {
this.path = path;
this.bytes = localResponse.getBytes();
this.contentType = localResponse.getMediaType();
this.code = localResponse.getStatus();
}
@Override
public String requestUrl() {
return path;
}
@Override
public int code() {
return code;
}
@Override
public String contentType() {
return contentType;
}
@Override
public InputStream contentStream() {
return new ByteArrayInputStream(bytes);
}
@Override
public Reader contentReader() {
return new InputStreamReader(new ByteArrayInputStream(bytes), UTF_8);
}
@Override
public String content() {
return new String(bytes, UTF_8);
}
/**
* Not implemented yet
*/
@Override
public Optional<String> header(String name) {
return Optional.empty();
}
@Override
public Map<String, List<String>> headers() {
return new HashMap<>();
}
}
}
| 4,457 | 25.223529 | 83 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.sonarqube.ws.MediaTypes;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.*;
public class MockWsResponse extends BaseResponse {
private static final String CONTENT_TYPE_HEADER = "Content-Type";
private static final String SQ_TOKEN_EXPIRATION_HEADER = "SonarQube-Authentication-Token-Expiration";
private int code = HttpURLConnection.HTTP_OK;
private String requestUrl;
private byte[] content;
private final Map<String, String> headers = new HashMap<>();
@Override
public int code() {
return code;
}
public MockWsResponse setCode(int code) {
this.code = code;
return this;
}
@Override
public String contentType() {
return requireNonNull(headers.get(CONTENT_TYPE_HEADER));
}
@Override
public Optional<String> header(String name) {
return Optional.ofNullable(headers.get(name));
}
@Override
public Map<String, List<String>> headers() {
return headers.entrySet()
.stream()
.collect(toMap(Map.Entry::getKey, e -> Collections.singletonList(e.getValue())));
}
public MockWsResponse setContentType(String contentType) {
headers.put(CONTENT_TYPE_HEADER, contentType);
return this;
}
public MockWsResponse setExpirationDate(String expirationDate) {
headers.put(SQ_TOKEN_EXPIRATION_HEADER, expirationDate);
return this;
}
public MockWsResponse setRequestUrl(String requestUrl) {
this.requestUrl = requestUrl;
return this;
}
public MockWsResponse setContent(byte[] b) {
this.content = b;
return this;
}
public MockWsResponse setContent(String s) {
this.content = s.getBytes(StandardCharsets.UTF_8);
return this;
}
public MockWsResponse setHeader(String key, String value) {
this.headers.put(key, value);
return this;
}
@Override
public boolean hasContent() {
return content != null;
}
@Override
public String requestUrl() {
requireNonNull(requestUrl);
return requestUrl;
}
@Override
public InputStream contentStream() {
requireNonNull(content);
return new ByteArrayInputStream(content);
}
@Override
public Reader contentReader() {
requireNonNull(content);
return new StringReader(new String(content, StandardCharsets.UTF_8));
}
@Override
public String content() {
requireNonNull(content);
return new String(content, StandardCharsets.UTF_8);
}
public static MockWsResponse createJson(String json) {
return new MockWsResponse()
.setContentType(MediaTypes.JSON)
.setContentType(json);
}
}
| 3,780 | 26.007143 | 103 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.ConnectionSpec;
import okhttp3.Credentials;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.sonarqube.ws.WsUtils.nullToEmpty;
/**
* Helper to build an instance of {@link okhttp3.OkHttpClient} that
* correctly supports HTTPS and proxy authentication. It also handles
* sending of User-Agent header.
*/
public class OkHttpClientBuilder {
private static final String NONE = "NONE";
private static final String P11KEYSTORE = "PKCS11";
private static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
private String userAgent;
private Proxy proxy;
private String credentials;
private String proxyLogin;
private String proxyPassword;
private Boolean followRedirects;
private long connectTimeoutMs = -1;
private long readTimeoutMs = -1;
private SSLSocketFactory sslSocketFactory = null;
private X509TrustManager sslTrustManager = null;
/**
* Optional User-Agent. If set, then all the requests sent by the
* {@link OkHttpClient} will include the header "User-Agent".
*/
public OkHttpClientBuilder setUserAgent(@Nullable String s) {
this.userAgent = s;
return this;
}
/**
* Optional SSL socket factory with which SSL sockets will be created to establish SSL connections.
* If not set, a default SSL socket factory will be used, base d on the JVM's default key store.
*/
public OkHttpClientBuilder setSSLSocketFactory(@Nullable SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}
/**
* Optional SSL trust manager used to validate certificates.
* If not set, a default system trust manager will be used, based on the JVM's default truststore.
*/
public OkHttpClientBuilder setTrustManager(@Nullable X509TrustManager sslTrustManager) {
this.sslTrustManager = sslTrustManager;
return this;
}
/**
* Optional proxy. If set, then all the requests sent by the
* {@link OkHttpClient} will reach the proxy. If not set,
* then the system-wide proxy is used.
*/
public OkHttpClientBuilder setProxy(@Nullable Proxy proxy) {
this.proxy = proxy;
return this;
}
/**
* Login required for proxy authentication.
*/
public OkHttpClientBuilder setProxyLogin(@Nullable String s) {
this.proxyLogin = s;
return this;
}
/**
* Password used for proxy authentication. It is ignored if
* proxy login is not defined (see {@link #setProxyLogin(String)}).
* It can be null or empty when login is defined.
*/
public OkHttpClientBuilder setProxyPassword(@Nullable String s) {
this.proxyPassword = s;
return this;
}
/**
* Sets the default connect timeout for new connections. A value of 0 means no timeout.
* Default is defined by OkHttp (10 seconds in OkHttp 3.3).
*/
public OkHttpClientBuilder setConnectTimeoutMs(long l) {
if (l < 0) {
throw new IllegalArgumentException("Connect timeout must be positive. Got " + l);
}
this.connectTimeoutMs = l;
return this;
}
/**
* Set credentials that will be passed on every request
*/
public OkHttpClientBuilder setCredentials(String credentials) {
this.credentials = credentials;
return this;
}
/**
* Sets the default read timeout for new connections. A value of 0 means no timeout.
* Default is defined by OkHttp (10 seconds in OkHttp 3.3).
*/
public OkHttpClientBuilder setReadTimeoutMs(long l) {
if (l < 0) {
throw new IllegalArgumentException("Read timeout must be positive. Got " + l);
}
this.readTimeoutMs = l;
return this;
}
/**
* Set if redirects should be followed or not.
* Default is defined by OkHttp (true, follow redirects).
*/
public OkHttpClientBuilder setFollowRedirects(Boolean followRedirects) {
this.followRedirects = followRedirects;
return this;
}
public OkHttpClient build() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.proxy(proxy);
if (connectTimeoutMs >= 0) {
builder.connectTimeout(connectTimeoutMs, TimeUnit.MILLISECONDS);
}
if (readTimeoutMs >= 0) {
builder.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS);
}
builder.addNetworkInterceptor(this::addHeaders);
if (proxyLogin != null) {
builder.proxyAuthenticator((route, response) -> {
if (response.request().header(PROXY_AUTHORIZATION) != null) {
// Give up, we've already attempted to authenticate.
return null;
}
if (HttpURLConnection.HTTP_PROXY_AUTH == response.code()) {
String credential = Credentials.basic(proxyLogin, nullToEmpty(proxyPassword), UTF_8);
return response.request().newBuilder().header(PROXY_AUTHORIZATION, credential).build();
}
return null;
});
}
if (followRedirects != null) {
builder.followRedirects(followRedirects);
builder.followSslRedirects(followRedirects);
}
ConnectionSpec tls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.allEnabledTlsVersions()
.allEnabledCipherSuites()
.supportsTlsExtensions(true)
.build();
builder.connectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
X509TrustManager trustManager = sslTrustManager != null ? sslTrustManager : systemDefaultTrustManager();
SSLSocketFactory sslFactory = sslSocketFactory != null ? sslSocketFactory : systemDefaultSslSocketFactory(trustManager);
builder.sslSocketFactory(sslFactory, trustManager);
return builder.build();
}
private Response addHeaders(Interceptor.Chain chain) throws IOException {
Request.Builder newRequest = chain.request().newBuilder();
if (userAgent != null) {
newRequest.header("User-Agent", userAgent);
}
if (credentials != null) {
newRequest.header("Authorization", credentials);
}
return chain.proceed(newRequest.build());
}
private static X509TrustManager systemDefaultTrustManager() {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
}
return (X509TrustManager) trustManagers[0];
} catch (GeneralSecurityException e) {
// The system has no TLS. Just give up.
throw new AssertionError(e);
}
}
private static SSLSocketFactory systemDefaultSslSocketFactory(X509TrustManager trustManager) {
KeyManager[] defaultKeyManager;
try {
defaultKeyManager = getDefaultKeyManager();
} catch (Exception e) {
throw new IllegalStateException("Unable to get default key manager", e);
}
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(defaultKeyManager, new TrustManager[] {trustManager}, null);
return sslContext.getSocketFactory();
} catch (GeneralSecurityException e) {
// The system has no TLS. Just give up.
throw new AssertionError(e);
}
}
private static void logDebug(String msg) {
boolean debugEnabled = "all".equals(System.getProperty("javax.net.debug"));
if (debugEnabled) {
System.out.println(msg);
}
}
/**
* Inspired from sun.security.ssl.SSLContextImpl#getDefaultKeyManager()
*/
private static synchronized KeyManager[] getDefaultKeyManager() throws KeyStoreException, NoSuchProviderException,
IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException {
final String defaultKeyStore = System.getProperty("javax.net.ssl.keyStore", "");
String defaultKeyStoreType = System.getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType());
String defaultKeyStoreProvider = System.getProperty("javax.net.ssl.keyStoreProvider", "");
logDebug("keyStore is : " + defaultKeyStore);
logDebug("keyStore type is : " + defaultKeyStoreType);
logDebug("keyStore provider is : " + defaultKeyStoreProvider);
if (P11KEYSTORE.equals(defaultKeyStoreType) && !NONE.equals(defaultKeyStore)) {
throw new IllegalArgumentException("if keyStoreType is " + P11KEYSTORE + ", then keyStore must be " + NONE);
}
KeyStore ks = null;
String defaultKeyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword", "");
char[] passwd = defaultKeyStorePassword.isEmpty() ? null : defaultKeyStorePassword.toCharArray();
// Try to initialize key store.
if (!defaultKeyStoreType.isEmpty()) {
logDebug("init keystore");
if (defaultKeyStoreProvider.isEmpty()) {
ks = KeyStore.getInstance(defaultKeyStoreType);
} else {
ks = KeyStore.getInstance(defaultKeyStoreType, defaultKeyStoreProvider);
}
if (!defaultKeyStore.isEmpty() && !NONE.equals(defaultKeyStore)) {
try (FileInputStream fs = new FileInputStream(defaultKeyStore)) {
ks.load(fs, passwd);
}
} else {
ks.load(null, passwd);
}
}
// Try to initialize key manager.
logDebug("init keymanager of type " + KeyManagerFactory.getDefaultAlgorithm());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
if (P11KEYSTORE.equals(defaultKeyStoreType)) {
// do not pass key passwd if using token
kmf.init(ks, null);
} else {
kmf.init(ks, passwd);
}
return kmf.getKeyManagers();
}
}
| 11,451 | 35.126183 | 124 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import okhttp3.Response;
import okhttp3.ResponseBody;
class OkHttpResponse extends BaseResponse {
private final Response okResponse;
OkHttpResponse(Response okResponse) {
this.okResponse = okResponse;
}
@Override
public int code() {
return okResponse.code();
}
@Override
public String requestUrl() {
return okResponse.request().url().toString();
}
@Override
public String contentType() {
return okResponse.header("Content-Type");
}
@Override
public Optional<String> header(String name) {
return Optional.ofNullable(okResponse.header(name));
}
@Override
public Map<String, List<String>> headers() {
return okResponse.headers().toMultimap();
}
/**
* Get stream of bytes
*/
@Override
public InputStream contentStream() {
return okResponse.body().byteStream();
}
/**
* Get stream of characters, decoded with the charset
* of the Content-Type header. If that header is either absent or lacks a
* charset, this will attempt to decode the response body as UTF-8.
*/
@Override
public Reader contentReader() {
return okResponse.body().charStream();
}
/**
* Get body content as a String. This response will be automatically closed.
*/
@Override
public String content() {
try (ResponseBody body = okResponse.body()) {
return body.string();
} catch (IOException e) {
throw fail(e);
}
}
private RuntimeException fail(Exception e) {
throw new IllegalStateException("Fail to read response of " + requestUrl(), e);
}
/**
* Equivalent to closing contentReader or contentStream.
*/
@Override
public void close() {
okResponse.close();
}
}
| 2,727 | 24.735849 | 83 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/Parameters.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
public interface Parameters {
/**
* In the case of a multi value parameter, returns the first element
*/
@CheckForNull
String getValue(String key);
List<String> getValues(String key);
Set<String> getKeys();
}
| 1,188 | 31.135135 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/PatchRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @since 10.0
*/
public class PatchRequest extends RequestWithPayload<PatchRequest> {
public PatchRequest(String path) {
super(path);
}
@Override
Function<Request.Builder, Request.Builder> addVerbToBuilder(RequestBody body) {
return builder -> builder.patch(body);
}
@Override
public Method getMethod() {
return Method.PATCH;
}
}
| 1,334 | 28.021739 | 81 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/PostRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @since 5.3
*/
public class PostRequest extends RequestWithPayload<PostRequest> {
public PostRequest(String path) {
super(path);
}
@Override
Function<Request.Builder, Request.Builder> addVerbToBuilder(RequestBody body) {
return builder -> builder.post(body);
}
@Override
public Method getMethod() {
return Method.POST;
}
}
| 1,328 | 27.891304 | 81 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/PutRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @since 5.3
*/
public class PutRequest extends RequestWithPayload<PutRequest> {
public PutRequest(String path) {
super(path);
}
@Override
Function<Request.Builder, Request.Builder> addVerbToBuilder(RequestBody body) {
return builder -> builder.put(body);
}
@Override
public Method getMethod() {
return Method.PUT;
}
}
| 1,323 | 27.782609 | 81 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/RequestWithPayload.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @since 5.3
*/
public abstract class RequestWithPayload<T extends RequestWithPayload<T>> extends BaseRequest<RequestWithPayload<T>> {
private String body;
private final Map<String, Part> parts = new LinkedHashMap<>();
protected RequestWithPayload(String path) {
super(path);
}
public T setBody(String body) {
this.body = body;
return (T) this;
}
public String getBody() {
return body;
}
public boolean hasBody() {
return this.body != null;
}
public T setPart(String name, Part part) {
this.parts.put(name, part);
return (T) this;
}
abstract Function<Request.Builder, Request.Builder> addVerbToBuilder(RequestBody body);
public Map<String, Part> getParts() {
return parts;
}
public static class Part {
private final String mediaType;
private final File file;
public Part(String mediaType, File file) {
this.mediaType = mediaType;
this.file = file;
}
public String getMediaType() {
return mediaType;
}
public File getFile() {
return file;
}
}
}
| 2,126 | 24.321429 | 118 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/RequestWithoutPayload.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.function.Function;
import okhttp3.Request;
/**
* @since 5.3
*/
public abstract class RequestWithoutPayload<T extends BaseRequest<RequestWithoutPayload<T>>> extends BaseRequest<RequestWithoutPayload<T>> {
protected RequestWithoutPayload(String path) {
super(path);
}
abstract Function<Request.Builder, Request.Builder> addVerbToBuilder();
}
| 1,250 | 32.810811 | 140 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import javax.annotation.Generated;
import org.sonarqube.ws.client.almintegrations.AlmIntegrationsService;
import org.sonarqube.ws.client.almsettings.AlmSettingsService;
import org.sonarqube.ws.client.analysiscache.AnalysisCacheService;
import org.sonarqube.ws.client.analysisreports.AnalysisReportsService;
import org.sonarqube.ws.client.applications.ApplicationsService;
import org.sonarqube.ws.client.authentication.AuthenticationService;
import org.sonarqube.ws.client.batch.BatchService;
import org.sonarqube.ws.client.ce.CeService;
import org.sonarqube.ws.client.components.ComponentsService;
import org.sonarqube.ws.client.developers.DevelopersService;
import org.sonarqube.ws.client.duplications.DuplicationsService;
import org.sonarqube.ws.client.editions.EditionsService;
import org.sonarqube.ws.client.emails.EmailsService;
import org.sonarqube.ws.client.favorites.FavoritesService;
import org.sonarqube.ws.client.githubprovisioning.GithubProvisioningService;
import org.sonarqube.ws.client.governancereports.GovernanceReportsService;
import org.sonarqube.ws.client.hotspots.HotspotsService;
import org.sonarqube.ws.client.issues.IssuesService;
import org.sonarqube.ws.client.l10n.L10nService;
import org.sonarqube.ws.client.languages.LanguagesService;
import org.sonarqube.ws.client.measures.MeasuresService;
import org.sonarqube.ws.client.metrics.MetricsService;
import org.sonarqube.ws.client.monitoring.MonitoringService;
import org.sonarqube.ws.client.navigation.NavigationService;
import org.sonarqube.ws.client.newcodeperiods.NewCodePeriodsService;
import org.sonarqube.ws.client.notifications.NotificationsService;
import org.sonarqube.ws.client.permissions.PermissionsService;
import org.sonarqube.ws.client.plugins.PluginsService;
import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService;
import org.sonarqube.ws.client.projectbadges.ProjectBadgesService;
import org.sonarqube.ws.client.projectbranches.ProjectBranchesService;
import org.sonarqube.ws.client.projectdump.ProjectDumpService;
import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.projectpullrequests.ProjectPullRequestsService;
import org.sonarqube.ws.client.projects.ProjectsService;
import org.sonarqube.ws.client.projecttags.ProjectTagsService;
import org.sonarqube.ws.client.push.SonarLintServerPushService;
import org.sonarqube.ws.client.qualitygates.QualitygatesService;
import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService;
import org.sonarqube.ws.client.regulatoryreports.RegulatoryReportsService;
import org.sonarqube.ws.client.roots.RootsService;
import org.sonarqube.ws.client.rules.RulesService;
import org.sonarqube.ws.client.securityreports.SecurityReportsService;
import org.sonarqube.ws.client.server.ServerService;
import org.sonarqube.ws.client.settings.SettingsService;
import org.sonarqube.ws.client.sources.SourcesService;
import org.sonarqube.ws.client.support.SupportService;
import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.updatecenter.UpdatecenterService;
import org.sonarqube.ws.client.usergroups.UserGroupsService;
import org.sonarqube.ws.client.users.UsersService;
import org.sonarqube.ws.client.usertokens.UserTokensService;
import org.sonarqube.ws.client.views.ViewsService;
import org.sonarqube.ws.client.webhooks.WebhooksService;
import org.sonarqube.ws.client.webservices.WebservicesService;
/**
* Allows to request the web services of SonarQube server. Instance is provided by
* {@link WsClientFactory}.
*
* <p>
* Usage:
* <pre>
* HttpConnector httpConnector = HttpConnector.newBuilder()
* .url("http://localhost:9000")
* .credentials("admin", "admin")
* .build();
* WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
* wsClient.issues().search(issueRequest);
* </pre>
* </p>
*
* @since 5.3
*/
@Generated("https://github.com/SonarSource/sonar-ws-generator")
public interface WsClient {
WsConnector wsConnector();
AlmIntegrationsService almIntegrations();
AlmSettingsService almSettings();
AnalysisCacheService analysisCache();
AnalysisReportsService analysisReports();
ApplicationsService applications();
AuthenticationService authentication();
CeService ce();
ComponentsService components();
DevelopersService developers();
DuplicationsService duplications();
EditionsService editions();
EmailsService emails();
FavoritesService favorites();
GovernanceReportsService governanceReports();
HotspotsService hotspots();
IssuesService issues();
L10nService l10n();
LanguagesService languages();
MeasuresService measures();
MetricsService metrics();
NavigationService navigation();
NewCodePeriodsService newCodePeriods();
NotificationsService notifications();
PermissionsService permissions();
PluginsService plugins();
ProjectAnalysesService projectAnalyses();
ProjectBadgesService projectBadges();
ProjectBranchesService projectBranches();
ProjectDumpService projectDump();
ProjectLinksService projectLinks();
ProjectPullRequestsService projectPullRequests();
ProjectTagsService projectTags();
ProjectsService projects();
QualitygatesService qualitygates();
QualityprofilesService qualityprofiles();
RootsService roots();
RulesService rules();
ServerService server();
SettingsService settings();
GithubProvisioningService githubProvisioning();
SourcesService sources();
SupportService support();
SystemService system();
UpdatecenterService updatecenter();
UserGroupsService userGroups();
UserTokensService userTokens();
UsersService users();
ViewsService views();
WebhooksService webhooks();
WebservicesService webservices();
BatchService batch();
SecurityReportsService securityReports();
RegulatoryReportsService regulatoryReports();
MonitoringService monitoring();
SonarLintServerPushService sonarLintPush();
}
| 6,844 | 31.287736 | 82 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClientFactories.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import org.sonar.api.server.ws.LocalConnector;
/**
* All provided implementations of {@link WsClientFactory}.
*/
public class WsClientFactories {
private WsClientFactories() {
// prevent instantiation
}
/**
* Factory to be used when connecting to a remote SonarQube web server.
*/
public static WsClientFactory getDefault() {
return DefaultWsClientFactory.INSTANCE;
}
/**
* Factory that allows a SonarQube web service to interact
* with other web services, without using the HTTP stack.
* @see org.sonar.api.server.ws.LocalConnector
*/
public static LocalWsClientFactory getLocal() {
return DefaultLocalWsClientFactory.INSTANCE;
}
private enum DefaultWsClientFactory implements WsClientFactory {
INSTANCE;
@Override
public WsClient newClient(WsConnector connector) {
return new DefaultWsClient(connector);
}
}
private enum DefaultLocalWsClientFactory implements LocalWsClientFactory {
INSTANCE;
@Override
public WsClient newClient(WsConnector connector) {
return DefaultWsClientFactory.INSTANCE.newClient(connector);
}
@Override
public WsClient newClient(LocalConnector localConnector) {
return new DefaultWsClient(new LocalWsConnector(localConnector));
}
}
}
| 2,164 | 29.069444 | 76 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClientFactory.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
/**
* Creates {@link WsClient}. Implementations are provided by {@link WsClientFactories}.
*
* @since 5.5
*/
public interface WsClientFactory {
WsClient newClient(WsConnector connector);
}
| 1,074 | 32.59375 | 87 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsConnector.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
/**
* @since 5.3
*/
public interface WsConnector {
/**
* Server base URL, always with trailing slash, for instance "http://localhost:9000/"
*/
String baseUrl();
/**
* @throws IllegalStateException if the request could not be executed due to
* a connectivity problem or timeout. Because networks can
* fail during an exchange, it is possible that the remote server
* accepted the request before the failure
*/
WsResponse call(WsRequest wsRequest);
}
| 1,372 | 32.487805 | 87 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.util.Map;
import java.util.OptionalInt;
/**
* @since 5.3
*/
public interface WsRequest {
Method getMethod();
String getPath();
String getMediaType();
OptionalInt getTimeOutInMs();
OptionalInt getWriteTimeOutInMs();
/**
*
* In case of multi value parameters, returns the first value
*
* @deprecated since 6.1. Use {@link #getParameters()} instead
*/
@Deprecated
Map<String, String> getParams();
Parameters getParameters();
Headers getHeaders();
enum Method {
GET, POST, PATCH, DELETE, PUT
}
}
| 1,436 | 24.210526 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client;
import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @since 5.3
*/
public interface WsResponse extends Closeable {
/**
* The absolute requested URL
*/
String requestUrl();
/**
* HTTP status code
*/
int code();
/**
* Returns true if the code is in [200..300), which means the request was
* successfully received, understood, and accepted.
*/
boolean isSuccessful() ;
/**
* Throws a {@link HttpException} if {@link #isSuccessful()} is false.
*/
WsResponse failIfNotSuccessful();
String contentType();
Optional<String> header(String name);
Map<String, List<String>> headers();
boolean hasContent();
InputStream contentStream();
Reader contentReader();
String content();
@Override
void close();
}
| 1,751 | 23 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
@Generated("sonar-ws-generator")
package org.sonarqube.ws.client;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Generated;
| 1,032 | 37.259259 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/AlmIntegrationsService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
import org.sonarqube.ws.AlmIntegrations;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.Projects;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
/**
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations">Further information about this web service online</a>
*/
@Generated("sonar-ws-generator")
public class AlmIntegrationsService extends BaseService {
public AlmIntegrationsService(WsConnector wsConnector) {
super(wsConnector, "api/alm_integrations");
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/check_pat">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public void checkPat(CheckPatRequest request) {
call(
new GetRequest(path("check_pat"))
.setParam("almSetting", request.getAlmSetting())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_bitbucketserver_project">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public Projects.CreateWsResponse importBitbucketserverProject(ImportBitbucketserverProjectRequest request) {
return call(
new PostRequest(path("import_bitbucketserver_project"))
.setParam("almSetting", request.getAlmSetting())
.setParam("projectKey", request.getProjectKey())
.setParam("repositorySlug", request.getRepositorySlug())
.setMediaType(MediaTypes.JSON),
Projects.CreateWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_bitbucketcloud_project">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public Projects.CreateWsResponse importBitbucketcloudProject(ImportBitbucketcloudRepoRequest request) {
return call(
new PostRequest(path("import_bitbucketcloud_repo"))
.setParam("almSetting", request.getAlmSetting())
.setParam("repositorySlug", request.getRepositorySlug())
.setMediaType(MediaTypes.JSON),
Projects.CreateWsResponse.parser());
}
/**
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_gitlab_project">Further information about this action online (including a response example)</a>
* @since 8.5
*/
public Projects.CreateWsResponse importGitLabProject(ImportGitLabProjectRequest request) {
return call(
new PostRequest(path("import_gitlab_project"))
.setParam("almSetting", request.getAlmSetting())
.setParam("gitlabProjectId", request.getGitlabProjectId())
.setMediaType(MediaTypes.JSON),
Projects.CreateWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_azure_project">Further information about this action online (including a response example)</a>
* @since 8.6
*/
public Projects.CreateWsResponse importAzureProject(ImportAzureProjectRequest request) {
return call(
new PostRequest(path("import_azure_project"))
.setParam("almSetting", request.getAlmSetting())
.setParam("projectName", request.getProjectName())
.setParam("repositoryName", request.getRepositoryName())
.setMediaType(MediaTypes.JSON),
Projects.CreateWsResponse.parser()
);
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_gitlab_repos">Further information about this action online (including a response example)</a>
* @since 8.5
*/
public AlmIntegrations.SearchGitlabReposWsResponse searchGitlabRepos(SearchGitlabReposRequest request) {
return call(
new GetRequest(path("search_gitlab_repos"))
.setParam("almSetting", request.getAlmSetting())
.setParam("projectName", request.getProjectName())
.setMediaType(MediaTypes.JSON),
AlmIntegrations.SearchGitlabReposWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/list_azure_projects">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public AlmIntegrations.ListAzureProjectsWsResponse listAzureProjects(ListAzureProjectsRequest request) {
return call(
new GetRequest(path("list_azure_projects"))
.setParam("almSetting", request.getAlmSetting())
.setMediaType(MediaTypes.JSON),
AlmIntegrations.ListAzureProjectsWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/list_bitbucketserver_projects">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public AlmIntegrations.ListBitbucketserverProjectsWsResponse listBitbucketserverProjects(ListBitbucketserverProjectsRequest request) {
return call(
new GetRequest(path("list_bitbucketserver_projects"))
.setParam("almSetting", request.getAlmSetting())
.setMediaType(MediaTypes.JSON),
AlmIntegrations.ListBitbucketserverProjectsWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_bitbucketserver_repos">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public AlmIntegrations.SearchBitbucketserverReposWsResponse searchBitbucketserverRepos(SearchBitbucketserverReposRequest request) {
return call(
new GetRequest(path("search_bitbucketserver_repos"))
.setParam("almSetting", request.getAlmSetting())
.setParam("projectName", request.getProjectName())
.setParam("repositoryName", request.getRepositoryName())
.setMediaType(MediaTypes.JSON),
AlmIntegrations.SearchBitbucketserverReposWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_bitbucketcloud_repos">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public AlmIntegrations.SearchBitbucketcloudReposWsResponse searchBitbucketcloudRepos(SearchBitbucketcloudReposRequest request) {
return call(
new GetRequest(path("search_bitbucketcloud_repos"))
.setParam("almSetting", request.getAlmSetting())
.setMediaType(MediaTypes.JSON),
AlmIntegrations.SearchBitbucketcloudReposWsResponse.parser());
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/webhook_github">Further information about this action online (including a response example)</a>
* @since 9.7
*/
public void sendGitubCodeScanningAlertWebhookPayload(SendGithubCodeScanningAlertWebhookPayloadRequest request) {
call(
new PostRequest(path("webhook_github"))
.setHeader("X-GitHub-Event", request.getGithubEventHeader())
.setHeader("X-Hub-Signature", request.getGithubSignatureHeader())
.setHeader("X-Hub-Signature-256", request.getGithubSignature256Header())
.setBody(request.getPayload())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/set_pat">Further information about this action online (including a response example)</a>
* @since 8.2
*/
public void setPat(SetPatRequest request) {
call(
new PostRequest(path("set_pat"))
.setParam("almSetting", request.getAlmSetting())
.setParam("pat", request.getPat())
.setParam("username", request.getUsername())
.setMediaType(MediaTypes.JSON)
).content();
}
}
| 9,671 | 40.157447 | 196 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/CheckPatRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/check_pat">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class CheckPatRequest {
private String almSetting;
/**
* This is a mandatory parameter.
*/
public CheckPatRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
}
| 1,511 | 31.170213 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ImportAzureProjectRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_azure_project">Further information about this action online (including a response example)</a>
* @since 8.6
*/
@Generated("sonar-ws-generator")
public class ImportAzureProjectRequest {
private String almSetting;
private String projectName;
private String repositoryName;
/**
* This is a mandatory parameter.
*/
public ImportAzureProjectRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public ImportAzureProjectRequest setProjectName(String projectName) {
this.projectName = projectName;
return this;
}
public String getProjectName() {
return projectName;
}
/**
* This is a mandatory parameter.
*/
public ImportAzureProjectRequest setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
return this;
}
public String getRepositoryName() {
return repositoryName;
}
}
| 2,107 | 27.876712 | 184 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ImportBitbucketcloudRepoRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_bitbucketcloud_repo">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class ImportBitbucketcloudRepoRequest {
private String almSetting;
private String repositorySlug;
/**
* This is a mandatory parameter.
*/
public ImportBitbucketcloudRepoRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public ImportBitbucketcloudRepoRequest setRepositorySlug(String repositorySlug) {
this.repositorySlug = repositorySlug;
return this;
}
public String getRepositorySlug() {
return repositorySlug;
}
}
| 1,859 | 30 | 190 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ImportBitbucketserverProjectRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_bitbucketserver_project">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class ImportBitbucketserverProjectRequest {
private String almSetting;
private String projectKey;
private String repositorySlug;
/**
* This is a mandatory parameter.
*/
public ImportBitbucketserverProjectRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public ImportBitbucketserverProjectRequest setProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}
public String getProjectKey() {
return projectKey;
}
/**
* This is a mandatory parameter.
*/
public ImportBitbucketserverProjectRequest setRepositorySlug(String repositorySlug) {
this.repositorySlug = repositorySlug;
return this;
}
public String getRepositorySlug() {
return repositorySlug;
}
}
| 2,150 | 28.465753 | 194 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ImportGitLabProjectRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/import_gitlab_project">Further information about this action online (including a response example)</a>
* @since 8.5
*/
@Generated("sonar-ws-generator")
public class ImportGitLabProjectRequest {
private String almSetting;
private String gitlabProjectId;
/**
* This is a mandatory parameter.
*/
public ImportGitLabProjectRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public ImportGitLabProjectRequest setGitlabProjectId(String gitlabProjectId) {
this.gitlabProjectId = gitlabProjectId;
return this;
}
public String getGitlabProjectId() {
return gitlabProjectId;
}
}
| 1,846 | 29.783333 | 185 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ListAzureProjectsRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/list_azure_projects">Further information about this action online (including a response example)</a>
* @since 8.6
*/
public class ListAzureProjectsRequest {
private String almSetting;
/**
* This is a mandatory parameter.
*/
public ListAzureProjectsRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
}
| 1,470 | 32.431818 | 183 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ListBitbucketserverProjectsRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/list_bitbucketserver_projects">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class ListBitbucketserverProjectsRequest {
private String almSetting;
/**
* This is a mandatory parameter.
*/
public ListBitbucketserverProjectsRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
}
| 1,569 | 32.404255 | 193 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/SearchBitbucketcloudReposRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_bitbucketserver_repos">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class SearchBitbucketcloudReposRequest {
private String almSetting;
private String projectName;
private String repositoryName;
/**
* This is a mandatory parameter.
*/
public SearchBitbucketcloudReposRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
*/
public SearchBitbucketcloudReposRequest setProjectName(String projectName) {
this.projectName = projectName;
return this;
}
public String getProjectName() {
return projectName;
}
/**
*/
public SearchBitbucketcloudReposRequest setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
return this;
}
public String getRepositoryName() {
return repositoryName;
}
}
| 2,071 | 28.183099 | 192 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/SearchBitbucketserverReposRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_bitbucketserver_repos">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class SearchBitbucketserverReposRequest {
private String almSetting;
private String projectName;
private String repositoryName;
/**
* This is a mandatory parameter.
*/
public SearchBitbucketserverReposRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
*/
public SearchBitbucketserverReposRequest setProjectName(String projectName) {
this.projectName = projectName;
return this;
}
public String getProjectName() {
return projectName;
}
/**
*/
public SearchBitbucketserverReposRequest setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
return this;
}
public String getRepositoryName() {
return repositoryName;
}
}
| 2,075 | 28.239437 | 192 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/SearchGitlabReposRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/search_gitlab_repos">Further information about this action online (including a response example)</a>
* @since 8.5
*/
@Generated("sonar-ws-generator")
public class SearchGitlabReposRequest {
private String almSetting;
private String projectName;
/**
* This is a mandatory parameter.
*/
public SearchGitlabReposRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
*/
public SearchGitlabReposRequest setProjectName(String projectName) {
this.projectName = projectName;
return this;
}
public String getProjectName() {
return projectName;
}
}
| 1,774 | 28.583333 | 183 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/SendGithubCodeScanningAlertWebhookPayloadRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/webhook_github">Further information about this action online (including a response example)</a>
* @since 9.7
*/
@Generated("sonar-ws-generator")
public class SendGithubCodeScanningAlertWebhookPayloadRequest {
private String payload;
private String githubEventHeader;
private String githubSignatureHeader;
private String githubSignature256Header;
/**
* This is a mandatory parameter.
*/
public SendGithubCodeScanningAlertWebhookPayloadRequest setPayload(String payload) {
this.payload = payload;
return this;
}
public String getPayload() {
return payload;
}
/**
* This is a mandatory parameter.
*/
public SendGithubCodeScanningAlertWebhookPayloadRequest setGithubEventHeader(String header) {
this.githubEventHeader = header;
return this;
}
public String getGithubEventHeader() {
return githubEventHeader;
}
/**
* This is a mandatory parameter.
*/
public SendGithubCodeScanningAlertWebhookPayloadRequest setGithubSignatureHeader(String header) {
this.githubSignatureHeader = header;
return this;
}
public String getGithubSignatureHeader() {
return this.githubSignatureHeader;
}
/**
* This is a mandatory parameter.
*/
public SendGithubCodeScanningAlertWebhookPayloadRequest setGithubSignature256Header(String header) {
this.githubSignature256Header = header;
return this;
}
public String getGithubSignature256Header() {
return githubSignature256Header;
}
}
| 2,565 | 29.188235 | 178 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/SetPatRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_integrations/set_pat">Further information about this action online (including a response example)</a>
* @since 8.2
*/
@Generated("sonar-ws-generator")
public class SetPatRequest {
private String almSetting;
private String pat;
private String username;
/**
* This is a mandatory parameter.
*/
public SetPatRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetPatRequest setPat(String pat) {
this.pat = pat;
return this;
}
public String getPat() {
return pat;
}
public SetPatRequest setUsername(String username) {
this.username = username;
return this;
}
public String getUsername() {
return username;
}
}
| 1,900 | 26.157143 | 171 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
@Generated("sonar-ws-generator")
package org.sonarqube.ws.client.almintegrations;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
| 1,048 | 37.851852 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/AlmSettingsService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
import org.sonarqube.ws.AlmSettings;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
/**
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings">Further information about this web service online</a>
*/
@Generated("sonar-ws-generator")
public class AlmSettingsService extends BaseService {
public AlmSettingsService(WsConnector wsConnector) {
super(wsConnector, "api/alm_settings");
}
/**
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/count_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public AlmSettings.CountBindingWsResponse countBinding(CountBindingRequest request) {
return call(
new GetRequest(path("count_binding"))
.setParam("almSetting", request.getAlmSetting())
.setMediaType(MediaTypes.JSON),
AlmSettings.CountBindingWsResponse.parser());
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_azure">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void createAzure(CreateAzureRequest request) {
call(
new PostRequest(path("create_azure"))
.setParam("key", request.getKey())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setParam("url", request.getUrl())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_gitlab">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void createGitlab(CreateGitlabRequest request) {
call(
new PostRequest(path("create_gitlab"))
.setParam("key", request.getKey())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setParam("url", request.getUrl())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_bitbucket">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void createBitbucket(CreateBitbucketRequest request) {
call(
new PostRequest(path("create_bitbucket"))
.setParam("key", request.getKey())
.setParam("url", request.getUrl())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_bitbucket_cloud">Further information about this action online (including a response example)</a>
* @since 8.7
*/
public void createBitbucketCloud(CreateBitbucketCloudRequest request) {
call(
new PostRequest(path("create_bitbucketcloud"))
.setParam("key", request.getKey())
.setParam("clientId", request.getClientId())
.setParam("clientSecret", request.getClientSecret())
.setParam("workspace", request.getWorkspace())
.setMediaType(MediaTypes.JSON)).content();
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_github">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void createGithub(CreateGithubRequest request) {
call(
new PostRequest(path("create_github"))
.setParam("appId", request.getAppId())
.setParam("key", request.getKey())
.setParam("privateKey", request.getPrivateKey())
.setParam("url", request.getUrl())
.setParam("clientId", request.getClientId())
.setParam("clientSecret", request.getClientSecret())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/delete">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void delete(DeleteRequest request) {
call(
new PostRequest(path("delete"))
.setParam("key", request.getKey())
.setMediaType(MediaTypes.JSON)).content();
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/delete_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void deleteBinding(DeleteBindingRequest request) {
call(
new PostRequest(path("delete_binding"))
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON)).content();
}
/**
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/get_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public AlmSettings.GetBindingWsResponse getBinding(GetBindingRequest request) {
return call(
new GetRequest(path("get_binding"))
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON),
AlmSettings.GetBindingWsResponse.parser());
}
/**
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/list">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public AlmSettings.ListWsResponse list(ListRequest request) {
return call(
new GetRequest(path("list"))
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON),
AlmSettings.ListWsResponse.parser());
}
/**
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/validate">Further information about this action online (including a response example)</a>
* @since 8.6
*/
public void validate(ValidateRequest request) {
call(
new GetRequest(path("validate"))
.setParam("key", request.getKey()));
}
/**
*
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/list_definitions">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public AlmSettings.ListDefinitionsWsResponse listDefinitions() {
return call(
new GetRequest(path("list_definitions")),
AlmSettings.ListDefinitionsWsResponse.parser());
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_azure_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void setAzureBinding(SetAzureBindingRequest request) {
call(
new PostRequest(path("set_azure_binding"))
.setParam("almSetting", request.getAlmSetting())
.setParam("project", request.getProject())
.setParam("projectName", request.getProjectName())
.setParam("repositoryName", request.getRepositoryName())
.setParam("monorepo", request.getMonorepo())
.setMediaType(MediaTypes.JSON)).content();
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_gitlab_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void setGitlabBinding(SetGitlabBindingRequest request) {
call(
new PostRequest(path("set_gitlab_binding"))
.setParam("almSetting", request.getAlmSetting())
.setParam("project", request.getProject())
.setParam("repository", request.getRepository())
.setParam("monorepo", request.getMonorepo())
.setMediaType(MediaTypes.JSON)).content();
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_bitbucket_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void setBitbucketBinding(SetBitbucketBindingRequest request) {
call(
new PostRequest(path("set_bitbucket_binding"))
.setParam("almSetting", request.getAlmSetting())
.setParam("project", request.getProject())
.setParam("repository", request.getRepositoryKey())
.setParam("slug", request.getRepositorySlug())
.setParam("monorepo", request.getMonorepo())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_bitbucketcloud_binding">Further information about this action online (including a response example)</a>
* @since 8.7
*/
public void setBitbucketcloudBinding(SetBitbucketCloudBindingRequest request) {
call(
new PostRequest(path("set_bitbucketcloud_binding"))
.setParam("almSetting", request.getAlmSetting())
.setParam("monorepo", request.getMonorepo())
.setParam("project", request.getProject())
.setParam("repository", request.getRepository())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_github_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void setGithubBinding(SetGithubBindingRequest request) {
call(
new PostRequest(path("set_github_binding"))
.setParam("almSetting", request.getAlmSetting())
.setParam("project", request.getProject())
.setParam("repository", request.getRepository())
.setParam("summaryCommentEnabled", request.getSummaryCommentEnabled())
.setParam("monorepo", request.getMonorepo())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_azure">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void updateAzure(UpdateAzureRequest request) {
call(
new PostRequest(path("update_azure"))
.setParam("key", request.getKey())
.setParam("newKey", request.getNewKey())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setParam("url", request.getUrl())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_gitlab">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void updateGitlab(UpdateGitlabRequest request) {
call(
new PostRequest(path("update_gitlab"))
.setParam("key", request.getKey())
.setParam("newKey", request.getNewKey())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setParam("url", request.getUrl())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_bitbucket">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void updateBitbucket(UpdateBitbucketRequest request) {
call(
new PostRequest(path("update_bitbucket"))
.setParam("key", request.getKey())
.setParam("newKey", request.getNewKey())
.setParam("url", request.getUrl())
.setParam("personalAccessToken", request.getPersonalAccessToken())
.setMediaType(MediaTypes.JSON)).content();
}
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_github">Further information about this action online (including a response example)</a>
* @since 8.1
*/
public void updateGithub(UpdateGithubRequest request) {
call(
new PostRequest(path("update_github"))
.setParam("appId", request.getAppId())
.setParam("key", request.getKey())
.setParam("newKey", request.getNewKey())
.setParam("privateKey", request.getPrivateKey())
.setParam("url", request.getUrl())
.setParam("clientId", request.getClientId())
.setParam("clientSecret", request.getClientSecret())
.setMediaType(MediaTypes.JSON)).content();
}
}
| 13,900 | 38.379603 | 188 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CountBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/count_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class CountBindingRequest {
private String almSetting;
/**
* This is a mandatory parameter.
*/
public CountBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
}
| 1,515 | 31.255319 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CreateAzureRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_azure">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class CreateAzureRequest {
private String key;
private String personalAccessToken;
private String url;
public CreateAzureRequest setKey(String key) {
this.key = key;
return this;
}
public CreateAzureRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public CreateAzureRequest setUrl(String url) {
this.url = url;
return this;
}
public String getKey() {
return key;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
public String getUrl() {
return url;
}
}
| 1,813 | 27.34375 | 172 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CreateBitbucketCloudRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
*
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_bitbucket_cloud">Further information about this action online (including a response example)</a>
* @since 8.7
*/
@Generated("sonar-ws-generator")
public class CreateBitbucketCloudRequest {
private String key;
private String clientId;
private String clientSecret;
private String workspace;
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketCloudRequest setKey(String key) {
this.key = key;
return this;
}
public String getClientId() {
return clientId;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketCloudRequest setClientId(String clientId) {
this.clientId = clientId;
return this;
}
public String getClientSecret() {
return clientSecret;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketCloudRequest setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
return this;
}
public String getWorkspace() {
return workspace;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketCloudRequest setWorkspace(String workspace) {
this.workspace = workspace;
return this;
}
}
| 2,251 | 25.186047 | 182 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CreateBitbucketRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_bitbucket">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class CreateBitbucketRequest {
private String key;
private String url;
private String personalAccessToken;
/**
* This is a mandatory parameter.
*/
public CreateBitbucketRequest setKey(String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
/**
* This is a mandatory parameter.
*/
public CreateBitbucketRequest setUrl(String url) {
this.url = url;
return this;
}
public String getUrl() {
return url;
}
}
| 1,976 | 26.458333 | 176 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CreateGithubRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.CheckForNull;
import javax.annotation.Generated;
import javax.annotation.Nullable;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_github">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class CreateGithubRequest {
private String appId;
private String key;
private String privateKey;
private String url;
private String clientId;
private String clientSecret;
/**
* This is a mandatory parameter.
*/
public CreateGithubRequest setAppId(String appId) {
this.appId = appId;
return this;
}
public String getAppId() {
return appId;
}
/**
* This is a mandatory parameter.
*/
public CreateGithubRequest setKey(String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public CreateGithubRequest setPrivateKey(String privateKey) {
this.privateKey = privateKey;
return this;
}
public String getPrivateKey() {
return privateKey;
}
/**
* This is a mandatory parameter.
*/
public CreateGithubRequest setUrl(String url) {
this.url = url;
return this;
}
public String getUrl() {
return url;
}
public CreateGithubRequest setClientId(@Nullable String clientId) {
this.clientId = clientId;
return this;
}
@CheckForNull
public String getClientId() {
return clientId;
}
public CreateGithubRequest setClientSecret(@Nullable String clientSecret) {
this.clientSecret = clientSecret;
return this;
}
@CheckForNull
public String getClientSecret() {
return clientSecret;
}
}
| 2,668 | 23.486239 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/CreateGitlabRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/create_gitlab">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class CreateGitlabRequest {
private String key;
private String personalAccessToken;
private String url;
public String getUrl() {
return url;
}
public CreateGitlabRequest setUrl(String url) {
this.url = url;
return this;
}
/**
* This is a mandatory parameter.
*/
public CreateGitlabRequest setKey(String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public CreateGitlabRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
}
| 1,914 | 26.357143 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/DeleteBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/delete_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class DeleteBindingRequest {
private String project;
/**
* This is a mandatory parameter.
*/
public DeleteBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
}
| 1,497 | 30.87234 | 174 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/DeleteRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/delete">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class DeleteRequest {
private static String key;
public DeleteRequest(String key) {
this.key = key;
}
public String getKey() {
return key;
}
}
| 1,346 | 30.325581 | 166 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/get_github_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class GetBindingRequest {
private String project;
/**
* This is a mandatory parameter.
*/
public GetBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
}
| 1,495 | 30.829787 | 178 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/ListRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/list">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class ListRequest {
private String project;
/**
* This is a mandatory parameter.
*/
public ListRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
}
| 1,469 | 30.276596 | 164 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetAzureBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_azure_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class SetAzureBindingRequest {
private String almSetting;
private String project;
private String repositoryName;
private String projectName;
private String monorepo;
/**
* This is a mandatory parameter.
*/
public SetAzureBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetAzureBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
public String getRepositoryName() {
return repositoryName;
}
/**
* This is a mandatory parameter.
* @return
*/
public SetAzureBindingRequest setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
return this;
}
public String getProjectName() {
return projectName;
}
/**
* This is a mandatory parameter.
* @return
*/
public SetAzureBindingRequest setProjectName(String projectName) {
this.projectName = projectName;
return this;
}
public String getMonorepo() {
return monorepo;
}
public SetAzureBindingRequest setMonorepo(String monorepo) {
this.monorepo = monorepo;
return this;
}
}
| 2,514 | 24.927835 | 177 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_bitbucket_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class SetBitbucketBindingRequest {
private String almSetting;
private String project;
private String repositoryKey;
private String repositorySlug;
private Boolean monorepo;
/**
* This is a mandatory parameter.
*/
public SetBitbucketBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketBindingRequest setRepository(String repository) {
this.repositoryKey = repository;
return this;
}
public String getRepositoryKey() {
return repositoryKey;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketBindingRequest setSlug(String slug) {
this.repositorySlug = slug;
return this;
}
public String getRepositorySlug() {
return repositorySlug;
}
public Boolean getMonorepo() {
return monorepo;
}
public SetBitbucketBindingRequest setMonorepo(Boolean monorepo) {
this.monorepo = monorepo;
return this;
}
}
| 2,494 | 25.263158 | 181 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketCloudBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_bitbucketcloud_binding">Further information about this action online (including a response example)</a>
* @since 8.7
*/
@Generated("sonar-ws-generator")
public class SetBitbucketCloudBindingRequest {
private String almSetting;
private String monorepo;
private String project;
private String repository;
/**
* This is a mandatory parameter.
*/
public SetBitbucketCloudBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketCloudBindingRequest setMonorepo(String monorepo) {
this.monorepo = monorepo;
return this;
}
public String getMonorepo() {
return monorepo;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketCloudBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
/**
* This is a mandatory parameter.
*/
public SetBitbucketCloudBindingRequest setRepository(String repository) {
this.repository = repository;
return this;
}
public String getRepository() {
return repository;
}
}
| 2,330 | 26.104651 | 186 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetGithubBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_github_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class SetGithubBindingRequest {
private String almSetting;
private String project;
private String repository;
private String summaryCommentEnabled;
private String monorepo;
/**
* This is a mandatory parameter.
*/
public SetGithubBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetGithubBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
/**
* This is a mandatory parameter.
*/
public SetGithubBindingRequest setRepository(String repository) {
this.repository = repository;
return this;
}
public String getRepository() {
return repository;
}
public String getSummaryCommentEnabled() {
return summaryCommentEnabled;
}
public SetGithubBindingRequest setSummaryCommentEnabled(String summaryCommentEnabled) {
this.summaryCommentEnabled = summaryCommentEnabled;
return this;
}
public String getMonorepo() {
return monorepo;
}
public SetGithubBindingRequest setMonorepo(String monorepo) {
this.monorepo = monorepo;
return this;
}
}
| 2,526 | 26.172043 | 178 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetGitlabBindingRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/set_gitlab_binding">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class SetGitlabBindingRequest {
private String almSetting;
private String project;
private String repository;
private String monorepo;
public String getRepository() {
return repository;
}
public SetGitlabBindingRequest setRepository(String repository) {
this.repository = repository;
return this;
}
/**
* This is a mandatory parameter.
*/
public SetGitlabBindingRequest setAlmSetting(String almSetting) {
this.almSetting = almSetting;
return this;
}
public String getAlmSetting() {
return almSetting;
}
/**
* This is a mandatory parameter.
*/
public SetGitlabBindingRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
public String getMonorepo() {
return monorepo;
}
public SetGitlabBindingRequest setMonorepo(String monorepo) {
this.monorepo = monorepo;
return this;
}
}
| 2,150 | 25.8875 | 178 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/UpdateAzureRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_azure">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class UpdateAzureRequest {
private String key;
private String newKey;
private String personalAccessToken;
private String url;
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public UpdateAzureRequest setKey(String key) {
this.key = key;
return this;
}
public String getNewKey() {
return newKey;
}
/**
*/
public UpdateAzureRequest setNewKey(String newKey) {
this.newKey = newKey;
return this;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
/**
* This is a mandatory parameter.
*/
public UpdateAzureRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public String getUrl() {
return url;
}
/**
* This is a mandatory parameter.
*/
public UpdateAzureRequest setUrl(String url) {
this.url = url;
return this;
}
}
| 2,151 | 24.317647 | 172 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/UpdateBitbucketRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_bitbucket">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class UpdateBitbucketRequest {
private String key;
private String newKey;
private String personalAccessToken;
private String url;
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public UpdateBitbucketRequest setKey(String key) {
this.key = key;
return this;
}
public String getNewKey() {
return newKey;
}
/**
*/
public UpdateBitbucketRequest setNewKey(String newKey) {
this.newKey = newKey;
return this;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
/**
* This is a mandatory parameter.
*/
public UpdateBitbucketRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public String getUrl() {
return url;
}
/**
* This is a mandatory parameter.
*/
public UpdateBitbucketRequest setUrl(String url) {
this.url = url;
return this;
}
}
| 2,175 | 24.6 | 176 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/UpdateGithubRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.CheckForNull;
import javax.annotation.Generated;
import javax.annotation.Nullable;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_github">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class UpdateGithubRequest {
private String appId;
private String key;
private String newKey;
private String privateKey;
private String url;
private String clientId;
private String clientSecret;
public String getAppId() {
return appId;
}
/**
* This is a mandatory parameter.
*/
public UpdateGithubRequest setAppId(String appId) {
this.appId = appId;
return this;
}
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public UpdateGithubRequest setKey(String key) {
this.key = key;
return this;
}
public String getNewKey() {
return newKey;
}
/**
*/
public UpdateGithubRequest setNewKey(String newKey) {
this.newKey = newKey;
return this;
}
public String getPrivateKey() {
return privateKey;
}
/**
* This is a mandatory parameter.
*/
public UpdateGithubRequest setPrivateKey(String privateKey) {
this.privateKey = privateKey;
return this;
}
public String getUrl() {
return url;
}
/**
* This is a mandatory parameter.
*/
public UpdateGithubRequest setUrl(String url) {
this.url = url;
return this;
}
public UpdateGithubRequest setClientId(@Nullable String clientId) {
this.clientId = clientId;
return this;
}
@CheckForNull
public String getClientId() {
return clientId;
}
public UpdateGithubRequest setClientSecret(@Nullable String clientSecret) {
this.clientSecret = clientSecret;
return this;
}
@CheckForNull
public String getClientSecret() {
return clientSecret;
}
}
| 2,863 | 22.669421 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/UpdateGitlabRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/update_gitlab">Further information about this action online (including a response example)</a>
* @since 8.1
*/
@Generated("sonar-ws-generator")
public class UpdateGitlabRequest {
private String key;
private String newKey;
private String personalAccessToken;
private String url;
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public UpdateGitlabRequest setKey(String key) {
this.key = key;
return this;
}
public String getNewKey() {
return newKey;
}
/**
*/
public UpdateGitlabRequest setNewKey(String newKey) {
this.newKey = newKey;
return this;
}
public String getPersonalAccessToken() {
return personalAccessToken;
}
/**
* This is a mandatory parameter.
*/
public UpdateGitlabRequest setPersonalAccessToken(String personalAccessToken) {
this.personalAccessToken = personalAccessToken;
return this;
}
public String getUrl() {
return url;
}
/**
* This is a mandatory parameter.
*/
public UpdateGitlabRequest setUrl(String url) {
this.url = url;
return this;
}
}
| 2,157 | 24.388235 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/ValidateRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/alm_settings/validate">Further information about this action online (including a response example)</a>
* @since 8.6
*/
@Generated("sonar-ws-generator")
public class ValidateRequest {
private String key;
public String getKey() {
return key;
}
public ValidateRequest setKey(String key) {
this.key = key;
return this;
}
}
| 1,405 | 30.954545 | 168 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
@Generated("sonar-ws-generator")
package org.sonarqube.ws.client.almsettings;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
| 1,043 | 39.153846 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/analysiscache/AnalysisCacheService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.analysiscache;
import java.io.InputStream;
import javax.annotation.Generated;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
/**
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_cache">Further information about this web service online</a>
*/
@Generated("sonar-ws-generator")
public class AnalysisCacheService extends BaseService {
public AnalysisCacheService(WsConnector wsConnector) {
super(wsConnector, "api/analysis_cache");
}
/**
* This is part of the internal API.
* This is a POST request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_cache/clear">Further information about this action online (including a response example)</a>
* @since 9.4
*/
public void clear() {
call(
new PostRequest(path("clear"))
.setMediaType(MediaTypes.JSON)
).content();
}
/**
* This is part of the internal API.
* This is a GET request.
*
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_cache/get">Further information about this action online (including a response example)</a>
* @since 9.4
*/
public InputStream get(GetRequest request) {
return call(
new org.sonarqube.ws.client.GetRequest(path("get"))
.setParam("branch", request.getBranch())
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON)
).contentStream();
}
}
| 2,426 | 34.173913 | 169 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/analysiscache/GetRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.analysiscache;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_cache/get">Further information about this action online (including a response example)</a>
* @since 9.4
*/
@Generated("sonar-ws-generator")
public class GetRequest {
private String branch;
private String project;
/**
* Example value: "feature/my_branch"
*/
public GetRequest setBranch(String branch) {
this.branch = branch;
return this;
}
public String getBranch() {
return branch;
}
/**
* This is a mandatory parameter.
* Example value: "my_project"
*/
public GetRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
}
| 1,729 | 27.360656 | 165 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/analysiscache/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
@Generated("sonar-ws-generator")
package org.sonarqube.ws.client.analysiscache;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Generated;
| 1,046 | 37.777778 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/analysisreports/AnalysisReportsService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.analysisreports;
import javax.annotation.Generated;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsConnector;
/**
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_reports">Further information about this web service online</a>
*/
@Generated("sonar-ws-generator")
public class AnalysisReportsService extends BaseService {
public AnalysisReportsService(WsConnector wsConnector) {
super(wsConnector, "api/analysis_reports");
}
/**
*
* This is part of the internal API.
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/analysis_reports/is_queue_empty">Further information about this action online (including a response example)</a>
* @since 5.1
*/
public String isQueueEmpty() {
return call(
new GetRequest(path("is_queue_empty"))
.setMediaType(MediaTypes.JSON)
).content();
}
}
| 1,886 | 35.288462 | 180 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/analysisreports/package-info.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
@Generated("sonar-ws-generator")
package org.sonarqube.ws.client.analysisreports;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Generated;
| 1,048 | 37.851852 | 75 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/applications/AddProjectRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.applications;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/add_project">Further information about this action online (including a response example)</a>
* @since 7.3
*/
@Generated("sonar-ws-generator")
public class AddProjectRequest {
private String application;
private String project;
/**
* This is a mandatory parameter.
*/
public AddProjectRequest setApplication(String application) {
this.application = application;
return this;
}
public String getApplication() {
return application;
}
/**
* This is a mandatory parameter.
* Example value: "my_project"
*/
public AddProjectRequest setProject(String project) {
this.project = project;
return this;
}
public String getProject() {
return project;
}
}
| 1,786 | 28.295082 | 171 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/applications/ApplicationsService.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.applications;
import javax.annotation.Generated;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
/**
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications">Further information about this web service online</a>
*/
@Generated("sonar-ws-generator")
public class ApplicationsService extends BaseService {
public ApplicationsService(WsConnector wsConnector) {
super(wsConnector, "api/applications");
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/add_project">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void addProject(AddProjectRequest request) {
call(
new PostRequest(path("add_project"))
.setParam("application", request.getApplication())
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/create">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public String create(CreateRequest request) {
return call(
new PostRequest(path("create"))
.setParam("description", request.getDescription())
.setParam("key", request.getKey())
.setParam("name", request.getName())
.setParam("visibility", request.getVisibility())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/create_branch">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void createBranch(CreateBranchRequest request) {
call(
new PostRequest(path("create_branch"))
.setParam("application", request.getApplication())
.setParam("branch", request.getBranch())
.setParam("project", request.getProject())
.setParam("projectBranch", request.getProjectBranch())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/delete">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void delete(DeleteRequest request) {
call(
new PostRequest(path("delete"))
.setParam("application", request.getApplication())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/delete_branch">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void deleteBranch(DeleteBranchRequest request) {
call(
new PostRequest(path("delete_branch"))
.setParam("application", request.getApplication())
.setParam("branch", request.getBranch())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/remove_project">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void removeProject(RemoveProjectRequest request) {
call(
new PostRequest(path("remove_project"))
.setParam("application", request.getApplication())
.setParam("project", request.getProject())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/search_projects">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public String searchProjects(SearchProjectsRequest request) {
return call(
new GetRequest(path("search_projects"))
.setParam("application", request.getApplication())
.setParam("p", request.getP())
.setParam("ps", request.getPs())
.setParam("q", request.getQ())
.setParam("selected", request.getSelected())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/show">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public String show(ShowRequest request) {
return call(
new GetRequest(path("show"))
.setParam("application", request.getApplication())
.setParam("branch", request.getBranch())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a GET request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/show_leak">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public String showLeak(ShowLeakRequest request) {
return call(
new GetRequest(path("show_leak"))
.setParam("application", request.getApplication())
.setParam("branch", request.getBranch())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/update">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void update(UpdateRequest request) {
call(
new PostRequest(path("update"))
.setParam("application", request.getApplication())
.setParam("description", request.getDescription())
.setParam("name", request.getName())
.setMediaType(MediaTypes.JSON)
).content();
}
/**
*
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/update_branch">Further information about this action online (including a response example)</a>
* @since 7.3
*/
public void updateBranch(UpdateBranchRequest request) {
call(
new PostRequest(path("update_branch"))
.setParam("application", request.getApplication())
.setParam("branch", request.getBranch())
.setParam("name", request.getName())
.setParam("project", request.getProject())
.setParam("projectBranch", request.getProjectBranch())
.setMediaType(MediaTypes.JSON)
).content();
}
}
| 8,053 | 34.795556 | 177 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/applications/CreateBranchRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.applications;
import java.util.List;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/create_branch">Further information about this action online (including a response example)</a>
* @since 7.3
*/
@Generated("sonar-ws-generator")
public class CreateBranchRequest {
private String application;
private String branch;
private List<String> projects;
private List<String> projectBranches;
/**
* This is a mandatory parameter.
*/
public CreateBranchRequest setApplication(String application) {
this.application = application;
return this;
}
public String getApplication() {
return application;
}
/**
* This is a mandatory parameter.
*/
public CreateBranchRequest setBranch(String branch) {
this.branch = branch;
return this;
}
public String getBranch() {
return branch;
}
/**
* This is a mandatory parameter.
* Example value: "project=firstProjectKey&project=secondProjectKey&project=thirdProjectKey"
*/
public CreateBranchRequest setProject(List<String> projects) {
this.projects = projects;
return this;
}
public List<String> getProject() {
return projects;
}
/**
* This is a mandatory parameter.
* Example value: "projectBranch=&projectBranch=branch-2.0&projectBranch=branch-2.1"
*/
public CreateBranchRequest setProjectBranch(List<String> projectBranches) {
this.projectBranches = projectBranches;
return this;
}
public List<String> getProjectBranch() {
return projectBranches;
}
}
| 2,528 | 27.41573 | 173 | java |
sonarqube | sonarqube-master/sonar-ws/src/main/java/org/sonarqube/ws/client/applications/CreateRequest.java | /*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.ws.client.applications;
import javax.annotation.Generated;
/**
* This is part of the internal API.
* This is a POST request.
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/applications/create">Further information about this action online (including a response example)</a>
* @since 7.3
*/
@Generated("sonar-ws-generator")
public class CreateRequest {
private String description;
private String key;
private String name;
private String visibility;
/**
*/
public CreateRequest setDescription(String description) {
this.description = description;
return this;
}
public String getDescription() {
return description;
}
/**
*/
public CreateRequest setKey(String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
/**
* This is a mandatory parameter.
*/
public CreateRequest setName(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
/**
* Possible values:
* <ul>
* <li>"private"</li>
* <li>"public"</li>
* </ul>
*/
public CreateRequest setVisibility(String visibility) {
this.visibility = visibility;
return this;
}
public String getVisibility() {
return visibility;
}
}
| 2,158 | 23.534091 | 166 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.