use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class SchemaUpdaterTest method update.
@Test
public void update() throws OrmException, FileNotFoundException, IOException {
db.create();
final Path site = Paths.get(UUID.randomUUID().toString());
final SitePaths paths = new SitePaths(site);
SchemaUpdater u = Guice.createInjector(new FactoryModule() {
@Override
protected void configure() {
TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
};
bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
bind(Key.get(schemaFactory, ReviewDbFactory.class)).toInstance(db);
bind(SitePaths.class).toInstance(paths);
Config cfg = new Config();
cfg.setString("user", null, "name", "Gerrit Code Review");
cfg.setString("user", null, "email", "gerrit@localhost");
//
bind(Config.class).annotatedWith(//
GerritServerConfig.class).toInstance(cfg);
//
bind(PersonIdent.class).annotatedWith(//
GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
//
bind(String.class).annotatedWith(//
AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(DataSourceType.class).to(InMemoryH2Type.class);
bind(SystemGroupBackend.class);
install(new ConfigNotesMigration.Module());
}
}).getInstance(SchemaUpdater.class);
for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
try {
assertThat(s.getPrior().getVersionNbr()).named("schema %s has prior version %s. Not true that", s.getVersionNbr(), s.getPrior().getVersionNbr()).isEqualTo(s.getVersionNbr() - 1);
} catch (ProvisionException e) {
// version.
break;
}
}
u.update(new UpdateUI() {
@Override
public void message(String msg) {
}
@Override
public boolean yesno(boolean def, String msg) {
return def;
}
@Override
public boolean isBatch() {
return true;
}
@Override
public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
for (String sql : pruneList) {
e.execute(sql);
}
}
});
db.assertSchemaVersion();
final SystemConfig sc = db.getSystemConfig();
assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class Passwd method getSysInjector.
private Injector getSysInjector() {
List<Module> modules = new ArrayList<>();
modules.add(new FactoryModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
bind(ConsoleUI.class).toInstance(ConsoleUI.getInstance(password != null));
factory(Section.Factory.class);
bind(Boolean.class).annotatedWith(InstallAllPlugins.class).toInstance(Boolean.FALSE);
bind(new TypeLiteral<List<String>>() {
}).annotatedWith(InstallPlugins.class).toInstance(new ArrayList<>());
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
}
});
modules.add(new GerritServerConfigModule());
return Guice.createInjector(modules);
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class Reindex method createSysInjector.
private Injector createSysInjector() {
Map<String, Integer> versions = new HashMap<>();
if (changesVersion != null) {
versions.put(ChangeSchemaDefinitions.INSTANCE.getName(), changesVersion);
}
boolean replica = ReplicaUtil.isReplica(globalConfig);
List<Module> modules = new ArrayList<>();
Module indexModule;
IndexType indexType = IndexModule.getIndexType(dbInjector);
if (indexType.isLucene()) {
indexModule = LuceneIndexModule.singleVersionWithExplicitVersions(versions, threads, replica, AutoFlush.DISABLED);
} else if (indexType.isFake()) {
// compile the component in.
try {
Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
Method m = clazz.getMethod("singleVersionWithExplicitVersions", Map.class, int.class, boolean.class);
indexModule = (Module) m.invoke(null, versions, threads, replica);
} catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("can't create index", e);
}
} else {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
modules.add(indexModule);
modules.add(new AbstractModule() {
@Override
protected void configure() {
super.configure();
OptionalBinder.newOptionalBinder(binder(), IsFirstInsertForEntry.class).setBinding().toInstance(IsFirstInsertForEntry.YES);
}
});
modules.add(new BatchProgramModule(dbInjector));
modules.add(new FactoryModule() {
@Override
protected void configure() {
factory(ChangeResource.Factory.class);
}
});
return dbInjector.createChildInjector(ModuleOverloader.override(modules, LibModuleLoader.loadReindexModules(cfgInjector, versions, threads, replica)));
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class ChangeExternalIdCaseSensitivity method run.
@Override
public int run() throws Exception {
mustHaveValidSite();
ui = ConsoleUI.getInstance(batch);
Injector dbInjector = createDbInjector();
manager.add(dbInjector, dbInjector.createChildInjector(NoteDbSchemaVersionCheck.module()));
dbInjector.createChildInjector(new FactoryModule() {
@Override
protected void configure() {
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
install(new FactoryModuleBuilder().build(ExternalIdCaseSensitivityMigrator.Factory.class));
factory(MetaDataUpdate.InternalFactory.class);
DynamicMap.mapOf(binder(), ExternalIdUpsertPreprocessor.class);
// The ChangeExternalIdCaseSensitivity 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);
globalConfig = dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
this.isUserNameCaseInsensitive = globalConfig.getBoolean("auth", "userNameCaseInsensitive", false);
String message = "auth.userNameCaseInsensitive is set to %b. " + "External IDs will be migrated to be case %ssensitive. Continue?";
if (!ui.yesno(true, message, isUserNameCaseInsensitive, isUserNameCaseInsensitive ? "" : "in")) {
return 0;
}
Collection<ExternalId> todo = externalIds.all();
monitor.beginTask("Converting external ID note names", todo.size());
manager.start();
try {
migratorFactory.create(!isUserNameCaseInsensitive, dryrun).migrate(todo, () -> monitor.update(1));
} finally {
manager.stop();
monitor.endTask();
}
int exitCode;
if (!dryrun) {
updateGerritConfig();
exitCode = reindexAccounts();
} else {
exitCode = 0;
}
return exitCode;
}
use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.
the class AbstractChangeNotesTest method setUpTestEnvironment.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Before
public void setUpTestEnvironment() throws Exception {
setTimeForTesting();
serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", Date.from(TimeUtil.now()), TZ);
project = Project.nameKey("test-project");
repoManager = new InMemoryRepositoryManager();
repo = repoManager.createRepository(project);
tr = new TestRepository<>(repo);
rw = tr.getRevWalk();
accountCache = new FakeAccountCache();
Account.Builder co = Account.builder(Account.id(1), TimeUtil.now());
co.setFullName("Change Owner");
co.setPreferredEmail("change@owner.com");
accountCache.put(co.build());
Account.Builder ou = Account.builder(Account.id(2), TimeUtil.now());
ou.setFullName("Other Account");
ou.setPreferredEmail("other@account.com");
accountCache.put(ou.build());
assertableFanOutExecutor = new AssertableExecutorService();
injector = Guice.createInjector(new FactoryModule() {
@Override
public void configure() {
install(new GitModule());
install(new DefaultUrlFormatterModule());
install(NoteDbModule.forTest());
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
bind(GitRepositoryManager.class).toInstance(repoManager);
bind(ProjectCache.class).to(NullProjectCache.class);
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(EnablePeerIPInReflogRecord.class).toInstance(Boolean.FALSE);
bind(Realm.class).to(FakeRealm.class);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);
bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
bind(MetricMaker.class).to(DisabledMetricMaker.class);
bind(ExecutorService.class).annotatedWith(FanOutExecutor.class).toInstance(assertableFanOutExecutor);
bind(ServiceUserClassifier.class).to(ServiceUserClassifier.NoOp.class);
bind(InternalChangeQuery.class).toProvider(() -> {
throw new UnsupportedOperationException();
});
bind(PatchSetApprovalUuidGenerator.class).to(TestPatchSetApprovalUuidGenerator.class);
}
});
injector.injectMembers(this);
repoManager.createRepository(allUsers);
changeOwner = userFactory.create(co.id());
otherUser = userFactory.create(ou.id());
otherUserId = otherUser.getAccountId();
internalUser = new InternalUser();
}
Aggregations