use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class GerritServer method createTestInjector.
private static Injector createTestInjector(Daemon daemon) throws Exception {
Injector sysInjector = getInjector(daemon, "sysInjector");
Module module = new FactoryModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(SshEnabled.class).to(daemon.getEnableSshd());
bind(AccountCreator.class);
bind(AccountOperations.class).to(AccountOperationsImpl.class);
bind(GroupOperations.class).to(GroupOperationsImpl.class);
bind(ProjectOperations.class).to(ProjectOperationsImpl.class);
bind(RequestScopeOperations.class).to(RequestScopeOperationsImpl.class);
bind(ChangeOperations.class).to(ChangeOperationsImpl.class);
factory(PerPatchsetOperationsImpl.Factory.class);
factory(PerCommentOperationsImpl.Factory.class);
factory(PerDraftCommentOperationsImpl.Factory.class);
factory(PerRobotCommentOperationsImpl.Factory.class);
factory(PushOneCommit.Factory.class);
install(InProcessProtocol.module());
install(new NoSshModule());
install(new AsyncReceiveCommitsModule());
factory(ProjectResetter.Builder.Factory.class);
}
@Provides
@Singleton
@Nullable
@TestSshServerAddress
InetSocketAddress getSshAddress(@GerritServerConfig Config cfg) {
String addr = cfg.getString("sshd", null, "listenAddress");
// We do not use InitSshd.isOff to avoid coupling GerritServer to the SSH code.
return !"off".equalsIgnoreCase(addr) ? SocketUtil.resolve(cfg.getString("sshd", null, "listenAddress"), 0) : null;
}
};
return sysInjector.createChildInjector(module);
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class LocalUsernamesToLowerCase method run.
@Override
public int run() throws Exception {
Injector dbInjector = createDbInjector();
manager.add(dbInjector, dbInjector.createChildInjector(NoteDbSchemaVersionCheck.module()));
manager.start();
dbInjector.createChildInjector(new FactoryModule() {
@Override
protected void configure() {
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
factory(MetaDataUpdate.InternalFactory.class);
// The LocalUsernamesToLowerCase program needs to access all external IDs only
// once to update them. After the update they are not accessed again. Hence the
// LocalUsernamesToLowerCase program doesn't benefit from caching external IDs and
// the external ID cache can be disabled.
install(DisabledExternalIdCache.module());
}
}).injectMembers(this);
Collection<ExternalId> todo = externalIds.all();
monitor.beginTask("Converting local usernames", todo.size());
try (Repository repo = repoManager.openRepository(allUsersName)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
for (ExternalId extId : todo) {
convertLocalUserToLowerCase(extIdNotes, extId);
monitor.update(1);
}
try (MetaDataUpdate metaDataUpdate = metaDataUpdateServerFactory.get().create(allUsersName)) {
metaDataUpdate.setMessage("Convert local usernames to lower case");
extIdNotes.commit(metaDataUpdate);
}
}
monitor.endTask();
int exitCode = reindexAccounts();
manager.stop();
return exitCode;
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class Rulec method run.
@Override
public int run() throws Exception {
dbInjector = createDbInjector();
manager.add(dbInjector);
manager.start();
dbInjector.createChildInjector(new FactoryModule() {
@Override
protected void configure() {
factory(PrologCompiler.Factory.class);
}
}).injectMembers(this);
LinkedHashSet<Project.NameKey> names = new LinkedHashSet<>();
for (String name : projectNames) {
names.add(Project.nameKey(name));
}
if (all) {
names.addAll(gitManager.list());
}
boolean error = false;
for (Project.NameKey project : names) {
try (Repository git = gitManager.openRepository(project)) {
switch(jarFactory.create(git).call()) {
case NO_RULES:
if (!all || projectNames.contains(project.get())) {
System.err.println("error: No rules.pl in " + project.get());
error = true;
}
break;
case COMPILED:
if (!quiet) {
System.out.format("Compiled %-60s ... SUCCESS", project.get());
System.out.println();
}
break;
}
} catch (CompileException err) {
if (showStackTrace) {
err.printStackTrace();
} else {
System.err.println("fatal: " + err.getMessage());
}
error = true;
}
}
return !error ? 0 : 1;
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method createModule.
@Override
public Module createModule() {
return new FactoryModule() {
@Override
public void configure() {
CommentValidator mockCommentValidator = mock(CommentValidator.class);
bind(CommentValidator.class).annotatedWith(Exports.named(mockCommentValidator.getClass())).toInstance(mockCommentValidator);
bind(CommentValidator.class).toInstance(mockCommentValidator);
}
};
}
Aggregations