use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.
the class RefControlTest method add.
private InMemoryRepository add(ProjectConfig pc) {
PrologEnvironment.Factory envFactory = null;
ProjectControl.AssistedFactory projectControlFactory = null;
RulesCache rulesCache = null;
SitePaths sitePaths = null;
List<CommentLinkInfo> commentLinks = null;
InMemoryRepository repo;
try {
repo = repoManager.createRepository(pc.getName());
if (pc.getProject() == null) {
pc.load(repo);
}
} catch (IOException | ConfigInvalidException e) {
throw new RuntimeException(e);
}
all.put(pc.getName(), new ProjectState(sitePaths, projectCache, allProjectsName, allUsersName, projectControlFactory, envFactory, repoManager, rulesCache, commentLinks, capabilityCollectionFactory, pc));
return repo;
}
use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.
the class MigrateAccountPatchReviewDb method run.
@Override
public int run() throws Exception {
SitePaths sitePaths = new SitePaths(getSitePath());
Config fakeCfg = new Config();
if (!Strings.isNullOrEmpty(sourceUrl)) {
fakeCfg.setString("accountPatchReviewDb", null, "url", sourceUrl);
}
JdbcAccountPatchReviewStore sourceJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(fakeCfg, sitePaths);
Injector dbInjector = createDbInjector(DataSourceProvider.Context.SINGLE_USER);
Config cfg = dbInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
String targetUrl = cfg.getString("accountPatchReviewDb", null, "url");
if (targetUrl == null) {
System.err.println("accountPatchReviewDb.url is null in gerrit.config");
return 1;
}
System.out.println("target Url: " + targetUrl);
JdbcAccountPatchReviewStore targetJdbcAccountPatchReviewStore = JdbcAccountPatchReviewStore.createAccountPatchReviewStore(cfg, sitePaths);
targetJdbcAccountPatchReviewStore.createTableIfNotExists();
if (!isTargetTableEmpty(targetJdbcAccountPatchReviewStore)) {
System.err.println("target table is not empty, cannot proceed");
return 1;
}
try (Connection sourceCon = sourceJdbcAccountPatchReviewStore.getConnection();
Connection targetCon = targetJdbcAccountPatchReviewStore.getConnection();
PreparedStatement sourceStmt = sourceCon.prepareStatement("SELECT account_id, change_id, patch_set_id, file_name " + "FROM account_patch_reviews " + "LIMIT ? " + "OFFSET ?");
PreparedStatement targetStmt = targetCon.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
targetCon.setAutoCommit(false);
long offset = 0;
List<Row> rows = selectRows(sourceStmt, offset);
while (!rows.isEmpty()) {
insertRows(targetCon, targetStmt, rows);
offset += rows.size();
rows = selectRows(sourceStmt, offset);
}
}
return 0;
}
use of com.google.gerrit.server.config.SitePaths in project gerrit by GerritCodeReview.
the class SwitchSecureStore method run.
@Override
public int run() throws Exception {
SitePaths sitePaths = new SitePaths(getSitePath());
Path newSecureStorePath = Paths.get(newSecureStoreLib);
if (!Files.exists(newSecureStorePath)) {
log.error(String.format("File %s doesn't exist", newSecureStorePath.toAbsolutePath()));
return -1;
}
String newSecureStore = getNewSecureStoreClassName(newSecureStorePath);
String currentSecureStoreName = getCurrentSecureStoreClassName(sitePaths);
if (currentSecureStoreName.equals(newSecureStore)) {
log.error("Old and new SecureStore implementation names " + "are the same. Migration will not work");
return -1;
}
IoUtil.loadJARs(newSecureStorePath);
SiteLibraryLoaderUtil.loadSiteLib(sitePaths.lib_dir);
log.info("Current secureStoreClass property ({}) will be replaced with {}", currentSecureStoreName, newSecureStore);
Injector dbInjector = createDbInjector(SINGLE_USER);
SecureStore currentStore = getSecureStore(currentSecureStoreName, dbInjector);
SecureStore newStore = getSecureStore(newSecureStore, dbInjector);
migrateProperties(currentStore, newStore);
removeOldLib(sitePaths, currentSecureStoreName);
copyNewLib(sitePaths, newSecureStorePath);
updateGerritConfig(sitePaths, newSecureStore);
return 0;
}
use of com.google.gerrit.server.config.SitePaths 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.server.config.SitePaths in project gerrit by GerritCodeReview.
the class LocalDiskRepositoryManagerTest method setUp.
@Before
public void setUp() throws Exception {
site = new SitePaths(TempFileUtil.createTempDirectory().toPath());
site.resolve("git").toFile().mkdir();
cfg = new Config();
cfg.setString("gerrit", null, "basePath", "git");
repoManager = new LocalDiskRepositoryManager(site, cfg);
}
Aggregations