Search in sources :

Example 1 with ConsoleUI

use of com.google.gerrit.pgm.init.api.ConsoleUI in project gerrit by GerritCodeReview.

the class Init method beforeInit.

@Override
protected boolean beforeInit(SiteInit init) throws Exception {
    indexStatus = new GerritIndexStatus(init.site);
    ErrorLogFile.errorOnlyConsole();
    if (!skipPlugins) {
        final List<PluginData> plugins = InitPlugins.listPluginsAndRemoveTempFiles(init.site, pluginsDistribution);
        ConsoleUI ui = ConsoleUI.getInstance(false);
        if (installAllPlugins && !nullOrEmpty(installPlugins)) {
            ui.message("Cannot use --install-plugin together with --install-all-plugins.\n");
            return true;
        }
        verifyInstallPluginList(ui, plugins);
        if (listPlugins) {
            if (!plugins.isEmpty()) {
                ui.message("Available plugins:\n");
                for (PluginData plugin : plugins) {
                    ui.message(" * %s version %s\n", plugin.name, plugin.version);
                }
            } else {
                ui.message("No plugins found.\n");
            }
            return true;
        }
    }
    return false;
}
Also used : PluginData(com.google.gerrit.common.PluginData) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) GerritIndexStatus(com.google.gerrit.server.index.GerritIndexStatus)

Example 2 with ConsoleUI

use of com.google.gerrit.pgm.init.api.ConsoleUI in project gerrit by GerritCodeReview.

the class BaseInit method createSiteInit.

private SiteInit createSiteInit() {
    final ConsoleUI ui = getConsoleUI();
    final Path sitePath = getSitePath();
    final List<Module> m = new ArrayList<>();
    final SecureStoreInitData secureStoreInitData = discoverSecureStoreClass();
    final String currentSecureStoreClassName = getConfiguredSecureStoreClass();
    if (secureStoreInitData != null && currentSecureStoreClassName != null && !currentSecureStoreClassName.equals(secureStoreInitData.className)) {
        String err = String.format("Different secure store was previously configured: %s. " + "Use SwitchSecureStore program to switch between implementations.", currentSecureStoreClassName);
        throw die(err);
    }
    m.add(new GerritServerConfigModule());
    m.add(new InitModule(standalone));
    m.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(ConsoleUI.class).toInstance(ui);
            bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
            List<String> plugins = MoreObjects.firstNonNull(getInstallPlugins(), new ArrayList<>());
            bind(new TypeLiteral<List<String>>() {
            }).annotatedWith(InstallPlugins.class).toInstance(plugins);
            bind(new TypeLiteral<Boolean>() {
            }).annotatedWith(InstallAllPlugins.class).toInstance(installAllPlugins());
            bind(PluginsDistribution.class).toInstance(pluginsDistribution);
            String secureStoreClassName;
            if (secureStoreInitData != null) {
                secureStoreClassName = secureStoreInitData.className;
            } else {
                secureStoreClassName = currentSecureStoreClassName;
            }
            if (secureStoreClassName != null) {
                ui.message("Using secure store: %s\n", secureStoreClassName);
            }
            bind(SecureStoreInitData.class).toProvider(Providers.of(secureStoreInitData));
            bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(secureStoreClassName));
            bind(SecureStore.class).toProvider(SecureStoreProvider.class).in(SINGLETON);
            bind(new TypeLiteral<List<String>>() {
            }).annotatedWith(LibraryDownload.class).toInstance(getSkippedDownloads());
            bind(Boolean.class).annotatedWith(LibraryDownload.class).toInstance(skipAllDownloads());
            bind(MetricMaker.class).to(DisabledMetricMaker.class);
        }
    });
    try {
        return Guice.createInjector(PRODUCTION, m).getInstance(SiteInit.class);
    } catch (CreationException ce) {
        final Message first = ce.getErrorMessages().iterator().next();
        Throwable why = first.getCause();
        if (why instanceof Die) {
            throw (Die) why;
        }
        final StringBuilder buf = new StringBuilder(ce.getMessage());
        while (why != null) {
            buf.append("\n");
            buf.append(why.getMessage());
            why = why.getCause();
            if (why != null) {
                buf.append("\n  caused by ");
            }
        }
        throw die(buf.toString(), new RuntimeException("InitInjector failed", ce));
    }
}
Also used : Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) Die(com.google.gerrit.common.Die) Message(com.google.inject.spi.Message) ArrayList(java.util.ArrayList) CreationException(com.google.inject.CreationException) SecureStore(com.google.gerrit.server.securestore.SecureStore) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) AbstractModule(com.google.inject.AbstractModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) TypeLiteral(com.google.inject.TypeLiteral) List(java.util.List) ArrayList(java.util.ArrayList) Module(com.google.inject.Module) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) IndexModule(com.google.gerrit.server.index.IndexModule) AbstractModule(com.google.inject.AbstractModule) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker)

Example 3 with ConsoleUI

use of com.google.gerrit.pgm.init.api.ConsoleUI in project gerrit by GerritCodeReview.

the class LibrariesTest method create.

@Test
public void create() throws Exception {
    final SitePaths site = new SitePaths(Paths.get("."));
    final ConsoleUI ui = createStrictMock(ConsoleUI.class);
    final StaleLibraryRemover remover = createStrictMock(StaleLibraryRemover.class);
    replay(ui);
    Libraries lib = new Libraries(new Provider<LibraryDownloader>() {

        @Override
        public LibraryDownloader get() {
            return new LibraryDownloader(ui, site, remover);
        }
    }, Collections.<String>emptyList(), false);
    assertNotNull(lib.mysqlDriver);
    verify(ui);
}
Also used : SitePaths(com.google.gerrit.server.config.SitePaths) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Test(org.junit.Test)

Example 4 with ConsoleUI

use of com.google.gerrit.pgm.init.api.ConsoleUI in project gerrit by GerritCodeReview.

the class UpgradeFrom2_0_xTest method upgrade.

@Test
public void upgrade() throws IOException, ConfigInvalidException {
    final Path p = newSitePath();
    final SitePaths site = new SitePaths(p);
    assertTrue(site.isNew);
    FileUtil.mkdirsOrDie(site.etc_dir, "Failed to create");
    for (String n : UpgradeFrom2_0_x.etcFiles) {
        Files.write(p.resolve(n), ("# " + n + "\n").getBytes(UTF_8));
    }
    FileBasedConfig old = new FileBasedConfig(p.resolve("gerrit.config").toFile(), FS.DETECTED);
    old.setString("ldap", null, "username", "ldap.user");
    old.setString("ldap", null, "password", "ldap.s3kr3t");
    old.setString("sendemail", null, "smtpUser", "email.user");
    old.setString("sendemail", null, "smtpPass", "email.s3kr3t");
    old.save();
    final InMemorySecureStore secureStore = new InMemorySecureStore();
    final InitFlags flags = new InitFlags(site, secureStore, Collections.<String>emptyList(), false);
    final ConsoleUI ui = createStrictMock(ConsoleUI.class);
    Section.Factory sections = new Section.Factory() {

        @Override
        public Section get(String name, String subsection) {
            return new Section(flags, site, secureStore, ui, name, subsection);
        }
    };
    expect(ui.yesno(eq(true), eq("Upgrade '%s'"), eq(p.toAbsolutePath().normalize()))).andReturn(true);
    replay(ui);
    UpgradeFrom2_0_x u = new UpgradeFrom2_0_x(site, flags, ui, sections);
    assertTrue(u.isNeedUpgrade());
    u.run();
    assertFalse(u.isNeedUpgrade());
    verify(ui);
    for (String n : UpgradeFrom2_0_x.etcFiles) {
        if ("gerrit.config".equals(n) || "secure.config".equals(n)) {
            continue;
        }
        try (InputStream in = Files.newInputStream(site.etc_dir.resolve(n))) {
            assertEquals("# " + n + "\n", new String(ByteStreams.toByteArray(in), UTF_8));
        }
    }
    FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
    cfg.load();
    assertEquals("email.user", cfg.getString("sendemail", null, "smtpUser"));
    assertNull(cfg.getString("sendemail", null, "smtpPass"));
    assertEquals("email.s3kr3t", secureStore.get("sendemail", null, "smtpPass"));
    assertEquals("ldap.user", cfg.getString("ldap", null, "username"));
    assertNull(cfg.getString("ldap", null, "password"));
    assertEquals("ldap.s3kr3t", secureStore.get("ldap", null, "password"));
    u.run();
}
Also used : Path(java.nio.file.Path) InitFlags(com.google.gerrit.pgm.init.api.InitFlags) InputStream(java.io.InputStream) SitePaths(com.google.gerrit.server.config.SitePaths) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Section(com.google.gerrit.pgm.init.api.Section) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Test(org.junit.Test)

Aggregations

ConsoleUI (com.google.gerrit.pgm.init.api.ConsoleUI)4 SitePaths (com.google.gerrit.server.config.SitePaths)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 Die (com.google.gerrit.common.Die)1 PluginData (com.google.gerrit.common.PluginData)1 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)1 InitFlags (com.google.gerrit.pgm.init.api.InitFlags)1 Section (com.google.gerrit.pgm.init.api.Section)1 GerritServerConfigModule (com.google.gerrit.server.config.GerritServerConfigModule)1 SitePath (com.google.gerrit.server.config.SitePath)1 GerritIndexStatus (com.google.gerrit.server.index.GerritIndexStatus)1 IndexModule (com.google.gerrit.server.index.IndexModule)1 SecureStore (com.google.gerrit.server.securestore.SecureStore)1 AbstractModule (com.google.inject.AbstractModule)1 CreationException (com.google.inject.CreationException)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 Message (com.google.inject.spi.Message)1 InputStream (java.io.InputStream)1