Example usage for org.eclipse.jgit.lib Config getBoolean

List of usage examples for org.eclipse.jgit.lib Config getBoolean

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Config getBoolean.

Prototype

public boolean getBoolean(final String section, String subsection, final String name,
        final boolean defaultValue) 

Source Link

Document

Get a boolean value from the git config

Usage

From source file:com.google.gerrit.elasticsearch.ElasticConfiguration.java

License:Apache License

@Inject
ElasticConfiguration(@GerritServerConfig Config cfg) {
    this.username = cfg.getString("elasticsearch", null, "username");
    this.password = cfg.getString("elasticsearch", null, "password");
    this.requestCompression = cfg.getBoolean("elasticsearch", null, "requestCompression", false);
    this.connectionTimeout = cfg.getTimeUnit("elasticsearch", null, "connectionTimeout", 3000,
            TimeUnit.MILLISECONDS);
    this.maxConnectionIdleTime = cfg.getTimeUnit("elasticsearch", null, "maxConnectionIdleTime", 3000,
            TimeUnit.MILLISECONDS);
    this.maxTotalConnection = cfg.getInt("elasticsearch", null, "maxTotalConnection", 1);
    this.readTimeout = (int) cfg.getTimeUnit("elasticsearch", null, "readTimeout", 3000, TimeUnit.MICROSECONDS);

    Set<String> subsections = cfg.getSubsections("elasticsearch");
    if (subsections.isEmpty()) {
        this.urls = Arrays.asList(buildUrl(DEFAULT_PROTOCOL, DEFAULT_HOST, DEFAULT_PORT));
    } else {//from w w w . j a  v a  2  s.  co  m
        this.urls = new ArrayList<>(subsections.size());
        for (String subsection : subsections) {
            String port = getString(cfg, subsection, "port", DEFAULT_PORT);
            String host = getString(cfg, subsection, "hostname", DEFAULT_HOST);
            String protocol = getString(cfg, subsection, "protocol", DEFAULT_PROTOCOL);
            this.urls.add(buildUrl(protocol, host, port));
        }
    }
}

From source file:com.google.gerrit.httpd.GerritOptions.java

License:Apache License

public GerritOptions(Config cfg, boolean headless, boolean slave, boolean forcePolyGerritDev) {
    this.headless = headless;
    this.slave = slave;
    this.enablePolyGerrit = forcePolyGerritDev || cfg.getBoolean("gerrit", null, "enablePolyGerrit", false);
    this.forcePolyGerritDev = forcePolyGerritDev;
}

From source file:com.google.gerrit.httpd.GitWebConfig.java

License:Apache License

@Inject
GitWebConfig(final SitePaths sitePaths, @GerritServerConfig final Config cfg) {
    final String cfgUrl = cfg.getString("gitweb", null, "url");
    final String cfgCgi = cfg.getString("gitweb", null, "cgi");

    type = GitWebType.fromName(cfg.getString("gitweb", null, "type"));
    if (type == null) {
        url = null;//from   w w  w.java  2 s . c o m
        gitweb_cgi = null;
        gitweb_css = null;
        gitweb_js = null;
        git_logo_png = null;
        return;
    }

    type.setLinkName(cfg.getString("gitweb", null, "linkname"));
    type.setBranch(cfg.getString("gitweb", null, "branch"));
    type.setProject(cfg.getString("gitweb", null, "project"));
    type.setRevision(cfg.getString("gitweb", null, "revision"));
    type.setRootTree(cfg.getString("gitweb", null, "roottree"));
    type.setFile(cfg.getString("gitweb", null, "file"));
    type.setFileHistory(cfg.getString("gitweb", null, "filehistory"));
    type.setLinkDrafts(cfg.getBoolean("gitweb", null, "linkdrafts", true));
    type.setUrlEncode(cfg.getBoolean("gitweb", null, "urlencode", true));
    String pathSeparator = cfg.getString("gitweb", null, "pathSeparator");
    if (pathSeparator != null) {
        if (pathSeparator.length() == 1) {
            char c = pathSeparator.charAt(0);
            if (isValidPathSeparator(c)) {
                type.setPathSeparator(c);
            } else {
                log.warn("Invalid value specified for gitweb.pathSeparator: " + c);
            }
        } else {
            log.warn("Value specified for gitweb.pathSeparator is not a single character:" + pathSeparator);
        }
    }

    if (type.getBranch() == null) {
        log.warn("No Pattern specified for gitweb.branch, disabling.");
        type = null;
    } else if (type.getProject() == null) {
        log.warn("No Pattern specified for gitweb.project, disabling.");
        type = null;
    } else if (type.getRevision() == null) {
        log.warn("No Pattern specified for gitweb.revision, disabling.");
        type = null;
    } else if (type.getRootTree() == null) {
        log.warn("No Pattern specified for gitweb.roottree, disabling.");
        type = null;
    } else if (type.getFile() == null) {
        log.warn("No Pattern specified for gitweb.file, disabling.");
        type = null;
    } else if (type.getFileHistory() == null) {
        log.warn("No Pattern specified for gitweb.filehistory, disabling.");
        type = null;
    }

    if ((cfgUrl != null && cfgUrl.isEmpty()) || (cfgCgi != null && cfgCgi.isEmpty())) {
        // Either setting was explicitly set to the empty string disabling
        // gitweb for this server. Disable the configuration.
        //
        url = null;
        gitweb_cgi = null;
        gitweb_css = null;
        gitweb_js = null;
        git_logo_png = null;
        return;
    }

    if ((cfgUrl != null) && (cfgCgi == null || cfgCgi.isEmpty())) {
        // Use an externally managed gitweb instance, and not an internal one.
        //
        url = cfgUrl;
        gitweb_cgi = null;
        gitweb_css = null;
        gitweb_js = null;
        git_logo_png = null;
        return;
    }

    final File pkgCgi = new File("/usr/lib/cgi-bin/gitweb.cgi");
    String[] resourcePaths = { "/usr/share/gitweb/static", "/usr/share/gitweb", "/var/www/static", "/var/www" };
    File cgi;

    if (cfgCgi != null) {
        // Use the CGI script configured by the administrator, failing if it
        // cannot be used as specified.
        //
        cgi = sitePaths.resolve(cfgCgi);
        if (!cgi.isFile()) {
            throw new IllegalStateException("Cannot find gitweb.cgi: " + cgi);
        }
        if (!cgi.canExecute()) {
            throw new IllegalStateException("Cannot execute gitweb.cgi: " + cgi);
        }

        if (!cgi.equals(pkgCgi)) {
            // Assume the administrator pointed us to the distribution,
            // which also has the corresponding CSS and logo file.
            //
            String absPath = cgi.getParentFile().getAbsolutePath();
            resourcePaths = new String[] { absPath + "/static", absPath };
        }

    } else if (pkgCgi.isFile() && pkgCgi.canExecute()) {
        // Use the OS packaged CGI.
        //
        log.debug("Assuming gitweb at " + pkgCgi);
        cgi = pkgCgi;

    } else {
        log.warn("gitweb not installed (no " + pkgCgi + " found)");
        cgi = null;
        resourcePaths = new String[] {};
    }

    File css = null, js = null, logo = null;
    for (String path : resourcePaths) {
        File dir = new File(path);
        css = new File(dir, "gitweb.css");
        js = new File(dir, "gitweb.js");
        logo = new File(dir, "git-logo.png");
        if (css.isFile() && logo.isFile()) {
            break;
        }
    }

    if (cfgUrl == null || cfgUrl.isEmpty()) {
        url = cgi != null ? "gitweb" : null;
    } else {
        url = cgi != null ? cfgUrl : null;
    }
    gitweb_cgi = cgi;
    gitweb_css = css;
    gitweb_js = js;
    git_logo_png = logo;
}

From source file:com.google.gerrit.httpd.ProjectOAuthFilter.java

License:Apache License

@Inject
ProjectOAuthFilter(DynamicItem<WebSession> session, DynamicMap<OAuthLoginProvider> pluginsProvider,
        AccountCache accountCache, AccountManager accountManager, @GerritServerConfig Config gerritConfig) {
    this.session = session;
    this.loginProviders = pluginsProvider;
    this.accountCache = accountCache;
    this.accountManager = accountManager;
    this.gitOAuthProvider = gerritConfig.getString("auth", null, "gitOAuthProvider");
    this.userNameToLowerCase = gerritConfig.getBoolean("auth", null, "userNameToLowerCase", false);
}

From source file:com.google.gerrit.lucene.LuceneChangeIndex.java

License:Apache License

@AssistedInject
LuceneChangeIndex(@GerritServerConfig Config cfg, SitePaths sitePaths,
        @IndexExecutor(INTERACTIVE) ListeningExecutorService executor, Provider<ReviewDb> db,
        ChangeData.Factory changeDataFactory, FillArgs fillArgs, @Assisted Schema<ChangeData> schema,
        @Assisted @Nullable String base) throws IOException {
    this.sitePaths = sitePaths;
    this.fillArgs = fillArgs;
    this.executor = executor;
    this.db = db;
    this.changeDataFactory = changeDataFactory;
    this.schema = schema;
    this.useDocValuesForSorting = schema.getVersion() >= 15;
    this.idSortField = sortFieldName(LegacyChangeIdPredicate.idField(schema));

    CustomMappingAnalyzer analyzer = new CustomMappingAnalyzer(new StandardAnalyzer(CharArraySet.EMPTY_SET),
            CUSTOM_CHAR_MAPPING);//from w w  w .jav  a2  s  .  c  o m
    queryBuilder = new QueryBuilder(analyzer);

    BooleanQuery
            .setMaxClauseCount(cfg.getInt("index", "defaultMaxClauseCount", BooleanQuery.getMaxClauseCount()));

    GerritIndexWriterConfig openConfig = new GerritIndexWriterConfig(cfg, "changes_open");
    GerritIndexWriterConfig closedConfig = new GerritIndexWriterConfig(cfg, "changes_closed");

    SearcherFactory searcherFactory = newSearcherFactory();
    if (cfg.getBoolean("index", "lucene", "testInmemory", false)) {
        openIndex = new SubIndex(new RAMDirectory(), "ramOpen", openConfig, searcherFactory);
        closedIndex = new SubIndex(new RAMDirectory(), "ramClosed", closedConfig, searcherFactory);
    } else {
        Path dir = base != null ? Paths.get(base) : LuceneVersionManager.getDir(sitePaths, schema);
        openIndex = new SubIndex(dir.resolve(CHANGES_OPEN), openConfig, searcherFactory);
        closedIndex = new SubIndex(dir.resolve(CHANGES_CLOSED), closedConfig, searcherFactory);
    }
}

From source file:com.google.gerrit.lucene.LuceneVersionManager.java

License:Apache License

private static boolean getReady(Config cfg, int version) {
    return cfg.getBoolean("index", Integer.toString(version), "ready", false);
}

From source file:com.google.gerrit.lucene.LuceneVersionManager.java

License:Apache License

@Inject
LuceneVersionManager(@GerritServerConfig Config cfg, SitePaths sitePaths,
        LuceneChangeIndex.Factory indexFactory, IndexCollection indexes,
        OnlineReindexer.Factory reindexerFactory) {
    this.sitePaths = sitePaths;
    this.indexFactory = indexFactory;
    this.indexes = indexes;
    this.reindexerFactory = reindexerFactory;
    this.onlineUpgrade = cfg.getBoolean("index", null, "onlineUpgrade", true);
}

From source file:com.google.gerrit.rules.RulesCache.java

License:Apache License

@Inject
protected RulesCache(@GerritServerConfig Config config, SitePaths site, GitRepositoryManager gm,
        DynamicSet<PredicateProvider> predicateProviders) {
    enableProjectRules = config.getBoolean("rules", null, "enable", true);
    cacheDir = site.resolve(config.getString("cache", null, "directory"));
    rulesDir = cacheDir != null ? cacheDir.resolve("rules") : null;
    gitMgr = gm;//from   w w w .  jav a2  s .c om
    this.predicateProviders = predicateProviders;

    systemLoader = getClass().getClassLoader();
    defaultMachine = save(newEmptyMachine(systemLoader));
}

From source file:com.google.gerrit.server.account.externalids.ExternalIdReader.java

License:Apache License

@Inject
ExternalIdReader(@GerritServerConfig Config cfg, GitRepositoryManager repoManager, AllUsersName allUsersName,
        MetricMaker metricMaker) {/*  w ww . ja  va  2s.  co  m*/
    this.readFromGit = cfg.getBoolean("user", null, "readExternalIdsFromGit", false);
    this.repoManager = repoManager;
    this.allUsersName = allUsersName;
    this.readAllLatency = metricMaker.newTimer("notedb/read_all_external_ids_latency",
            new Description("Latency for reading all external IDs from NoteDb.").setCumulative()
                    .setUnit(Units.MILLISECONDS));
}

From source file:com.google.gerrit.server.account.QueryAccounts.java

License:Apache License

@Inject
QueryAccounts(AccountControl.Factory accountControlFactory, AccountLoader.Factory accountLoaderFactory,
        AccountCache accountCache, AccountIndexCollection indexes, AccountQueryBuilder queryBuilder,
        AccountQueryProcessor queryProcessor, ReviewDb db, @GerritServerConfig Config cfg) {
    this.accountControl = accountControlFactory.get();
    this.accountLoaderFactory = accountLoaderFactory;
    this.accountCache = accountCache;
    this.indexes = indexes;
    this.queryBuilder = queryBuilder;
    this.queryProcessor = queryProcessor;
    this.db = db;
    this.suggestFrom = cfg.getInt("suggest", null, "from", 0);
    this.options = EnumSet.noneOf(ListAccountsOption.class);

    if ("off".equalsIgnoreCase(cfg.getString("suggest", null, "accounts"))) {
        suggestConfig = false;/*from  w  w  w  .j a v a 2 s.  com*/
    } else {
        boolean suggest;
        try {
            AccountVisibility av = cfg.getEnum("suggest", null, "accounts", AccountVisibility.ALL);
            suggest = (av != AccountVisibility.NONE);
        } catch (IllegalArgumentException err) {
            suggest = cfg.getBoolean("suggest", null, "accounts", true);
        }
        this.suggestConfig = suggest;
    }
}