本文整理汇总了Java中com.google.gerrit.extensions.api.GerritApi类的典型用法代码示例。如果您正苦于以下问题:Java GerritApi类的具体用法?Java GerritApi怎么用?Java GerritApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GerritApi类属于com.google.gerrit.extensions.api包,在下文中一共展示了GerritApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServerContext
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
private ServerContext(GerritServer server) throws Exception {
this.server = server;
Injector i = server.getTestInjector();
if (adminId == null) {
adminId = i.getInstance(AccountCreator.class).admin().getId();
}
ctx = i.getInstance(OneOffRequestContext.class).openAs(adminId);
GerritApi gApi = i.getInstance(GerritApi.class);
try {
// ServerContext ctor is called multiple times but the group can be only created once
gApi.groups().id("Group");
} catch (ResourceNotFoundException e) {
GroupInput in = new GroupInput();
in.members = Collections.singletonList("admin");
in.name = "Group";
gApi.groups().create(in);
}
}
示例2: setUpChange
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
private void setUpChange() throws Exception {
project = new Project.NameKey("project");
try (ServerContext ctx = startServer()) {
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
gApi.projects().create(project.get());
ChangeInput in = new ChangeInput(project.get(), "master", "Test change");
in.newBranch = true;
changeId = gApi.changes().create(in).info().changeId;
}
}
示例3: configure
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Override
protected void configure() {
bind(GerritApi.class).to(GerritApiImpl.class);
install(new com.google.gerrit.server.api.accounts.Module());
install(new com.google.gerrit.server.api.changes.Module());
install(new com.google.gerrit.server.api.config.Module());
install(new com.google.gerrit.server.api.groups.Module());
install(new com.google.gerrit.server.api.projects.Module());
}
示例4: reindexFromScratch
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test
public void reindexFromScratch() throws Exception {
setUpChange();
MoreFiles.deleteRecursively(sitePaths.index_dir, RecursiveDeleteOption.ALLOW_INSECURE);
Files.createDirectory(sitePaths.index_dir);
assertServerStartupFails();
runGerrit("reindex", "-d", sitePaths.site_path.toString(), "--show-stack-trace");
assertReady(ChangeSchemaDefinitions.INSTANCE.getLatest().getVersion());
try (ServerContext ctx = startServer()) {
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
// Query change index
assertThat(gApi.changes().query("message:Test").get().stream().map(c -> c.changeId))
.containsExactly(changeId);
// Query account index
assertThat(gApi.accounts().query("admin").get().stream().map(a -> a._accountId))
.containsExactly(adminId.get());
// Query group index
assertThat(
gApi.groups()
.query("Group")
.withOption(MEMBERS)
.get()
.stream()
.flatMap(g -> g.members.stream())
.map(a -> a._accountId))
.containsExactly(adminId.get());
}
}
示例5: migrateOneChange
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test
public void migrateOneChange() throws Exception {
assertNoAutoMigrateConfig(gerritConfig);
assertNoAutoMigrateConfig(noteDbConfig);
assertNotesMigrationState(NotesMigrationState.REVIEW_DB);
setUpOneChange();
migrate();
assertNotesMigrationState(NotesMigrationState.NOTE_DB);
try (ServerContext ctx = startServer()) {
GitRepositoryManager repoManager = ctx.getInjector().getInstance(GitRepositoryManager.class);
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.exactRef(RefNames.changeMetaRef(changeId))).isNotNull();
}
try (ReviewDb db = openUnderlyingReviewDb(ctx)) {
Change c = db.changes().get(changeId);
assertThat(c).isNotNull();
NoteDbChangeState state = NoteDbChangeState.parse(c);
assertThat(state).isNotNull();
assertThat(state.getPrimaryStorage()).isEqualTo(PrimaryStorage.NOTE_DB);
assertThat(state.getRefState()).isEmpty();
ChangeInput in = new ChangeInput(project.get(), "master", "NoteDb-only change");
in.newBranch = true;
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
Change.Id id2 = new Change.Id(gApi.changes().create(in).info()._number);
assertThat(db.changes().get(id2)).isNull();
}
}
assertNoAutoMigrateConfig(gerritConfig);
assertAutoMigrateConfig(noteDbConfig, false);
}
示例6: setUpOneChange
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
private void setUpOneChange() throws Exception {
project = new Project.NameKey("project");
try (ServerContext ctx = startServer()) {
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
gApi.projects().create("project");
ChangeInput in = new ChangeInput(project.get(), "master", "Test change");
in.newBranch = true;
changeId = new Change.Id(gApi.changes().create(in).info()._number);
}
}
示例7: testInvalidHost
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test(expectedExceptions = RestApiException.class)
public void testInvalidHost() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritAuthData.Basic authData = new GerritAuthData.Basic("http://averyinvaliddomainforgerritresttest.com:8089");
GerritApi gerritClient = gerritRestApiFactory.create(authData);
gerritClient.changes().query().get();
}
示例8: testUserAuth
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
/**
* Tests authentication with a login which us handled by HTTP auth (preemptive authentication is assumed)
* (path: "/a/changes/" isn't mapped -> status 404).
*/
@Test
public void testUserAuth() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic(jettyUrl, "foo", "bar"));
boolean catched = false;
try {
gerritClient.changes().query().get();
} catch (HttpStatusException e) {
catched = true;
// 404 because this url does not provide a valid response (not set up in this test case)
Truth.assertThat(e.getStatusCode()).isEqualTo(404);
}
Truth.assertThat(catched).isTrue();
}
示例9: testInvalidUserAuth
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
/**
* Tests authentication with an invalid HTTP login (preemptive authentication is assumed). Status 401 expected.
*/
@Test
public void testInvalidUserAuth() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic(jettyUrl, "foox", "bar"));
boolean catched = false;
try {
gerritClient.changes().query().get();
} catch (HttpStatusException e) {
catched = true;
Truth.assertThat(e.getStatusCode()).isEqualTo(401);
Truth.assertThat(e.getStatusText().toLowerCase()).contains("unauthorized");
}
Truth.assertThat(catched).isTrue();
}
示例10: testVersion
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test
public void testVersion() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic(jettyUrl));
String version = gerritClient.config().server().getVersion();
Truth.assertThat(version).isEqualTo("2.10");
}
示例11: testBasicRestCallToLocalhost
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test(enabled = false) // requires running Gerrit instance
public void testBasicRestCallToLocalhost() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic("http://localhost:8080"));
List<ChangeInfo> changes = gerritClient.changes().query().get();
System.out.println(String.format("Got %s changes.", changes.size()));
System.out.println(changes);
}
示例12: testBasicRestCallToLocalhostProjects
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test(enabled = false) // requires running Gerrit instance
public void testBasicRestCallToLocalhostProjects() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic("http://localhost:8080"));
List<ProjectInfo> projects = gerritClient.projects().list().get();
System.out.println(String.format("Got %s projects.", projects.size()));
System.out.println(projects);
}
示例13: testBasicRestCallToLocalhostProjectsQuery
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Test(enabled = false) // requires running Gerrit instance
public void testBasicRestCallToLocalhostProjectsQuery() throws Exception {
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritApi gerritClient = gerritRestApiFactory.create(new GerritAuthData.Basic("http://localhost:8080"));
List<ProjectInfo> projects = gerritClient.projects().list().withLimit(1).withDescription(true).get();
System.out.println(String.format("Got %s projects.", projects.size()));
System.out.println(projects);
}
示例14: DefaultReviewers
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Inject
DefaultReviewers(
GerritApi gApi,
@Assisted Change change,
@Assisted Set<Account> reviewers) {
this.gApi = gApi;
this.change = change;
this.reviewers = reviewers;
}
示例15: perform
import com.google.gerrit.extensions.api.GerritApi; //导入依赖的package包/类
@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
List<ReportInfo> issueInfos = readSonarReports(listener, filePath);
if (issueInfos == null) {
throw new AbortException(getLocalized("jenkins.plugin.validation.path.no.project.config.available"));
}
Multimap<String, Issue> file2issues = generateFilenameToIssuesMapFilteredByPredicates(issueInfos);
// Step 3 - Prepare Gerrit REST API client
// Check Gerrit configuration is available
String gerritNameEnvVar = getEnvVar(run, listener, GERRIT_NAME_ENV_VAR_NAME);
GerritTrigger trigger = GerritTrigger.getTrigger(run.getParent());
String gerritServerName = gerritNameEnvVar != null ? gerritNameEnvVar : trigger != null ? trigger.getServerName() : null;
if (gerritServerName == null) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.server.empty"));
}
IGerritHudsonTriggerConfig gerritConfig = GerritManagement.getConfig(gerritServerName);
if (gerritConfig == null) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.config.empty"));
}
if (!gerritConfig.isUseRestApi()) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.restapi.off"));
}
if (gerritConfig.getGerritHttpUserName() == null) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.user.empty"));
}
GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
GerritAuthData.Basic authData = new GerritAuthData.Basic(
gerritConfig.getGerritFrontEndUrl(),
isOverrideCredentials() ? httpUsername : gerritConfig.getGerritHttpUserName(),
isOverrideCredentials() ? httpPassword : gerritConfig.getGerritHttpPassword(),
gerritConfig.isUseRestApi());
GerritApi gerritApi = gerritRestApiFactory.create(authData);
try {
String changeNStr = getEnvVar(run, listener, GERRIT_CHANGE_NUMBER_ENV_VAR_NAME);
if (changeNStr == null) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.change.number.empty"));
}
int changeNumber = Integer.parseInt(changeNStr);
String patchsetNStr = getEnvVar(run, listener, GERRIT_PATCHSET_NUMBER_ENV_VAR_NAME);
if (patchsetNStr == null) {
throw new AbortException(getLocalized("jenkins.plugin.error.gerrit.patchset.number.empty"));
}
int patchSetNumber = Integer.parseInt(patchsetNStr);
RevisionApi revision = gerritApi.changes().id(changeNumber).revision(patchSetNumber);
logMessage(listener, "jenkins.plugin.connected.to.gerrit", Level.INFO, new Object[]{gerritServerName, changeNumber, patchSetNumber});
// Step 4 - Filter issues by changed files
final Map<String, FileInfo> files = revision.files();
file2issues = Multimaps.filterKeys(file2issues, new Predicate<String>() {
@Override
public boolean apply(@Nullable String input) {
return input != null && files.keySet().contains(input);
}
});
// logResultMap(file2issues, "Filter issues by changed files: {0} elements");
if (isChangedLinesOnly()) {
// Step 4a - Filter issues by changed lines in file only
filterIssuesByChangedLines(file2issues, revision);
// logResultMap(file2issues, "Filter issues by changed lines: {0} elements");
}
// Step 6 - Send review to Gerrit
ReviewInput reviewInput = getReviewResult(file2issues);
// Step 7 - Post review
revision.review(reviewInput);
logMessage(listener, "jenkins.plugin.review.sent", Level.INFO);
} catch (RestApiException e) {
LOGGER.log(Level.SEVERE, "Unable to post review: " + e.getMessage(), e);
throw new AbortException("Unable to post review: " + e.getMessage());
}
}