Search in sources :

Example 71 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class BatchUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    user = userFactory.create(userId);
    project = new Project.NameKey("test");
    InMemoryRepository inMemoryRepo = repoManager.createRepository(project);
    repo = new TestRepository<>(inMemoryRepo);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) Provider(com.google.inject.Provider) Project(com.google.gerrit.reviewdb.client.Project) Injector(com.google.inject.Injector) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Before(org.junit.Before)

Example 72 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    Config cfg = InMemoryModule.newDefaultConfig();
    cfg.setInt("receive", null, "maxTrustDepth", 2);
    cfg.setStringList("receive", null, "trustedKey", ImmutableList.of(Fingerprint.toString(keyB().getPublicKey().getFingerprint()), Fingerprint.toString(keyD().getPublicKey().getFingerprint())));
    Injector injector = Guice.createInjector(new InMemoryModule(cfg, new TestNotesMigration()));
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    injector.injectMembers(this);
    lifecycle.start();
    db = schemaFactory.open();
    schemaCreator.create(db);
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    Account userAccount = db.accounts().get(userId);
    // Note: does not match any key in TestKeys.
    userAccount.setPreferredEmail("user@example.com");
    db.accounts().update(ImmutableList.of(userAccount));
    user = reloadUser();
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    storeRepo = new InMemoryRepository(new DfsRepositoryDescription("repo"));
    store = new PublicKeyStore(storeRepo);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) Config(org.eclipse.jgit.lib.Config) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) Provider(com.google.inject.Provider) Injector(com.google.inject.Injector) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RequestContext(com.google.gerrit.server.util.RequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) Before(org.junit.Before)

Example 73 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class LabelNormalizerTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    db = schemaFactory.open();
    schemaCreator.create(db);
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    user = userFactory.create(userId);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    configureProject();
    setUpChange();
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) Provider(com.google.inject.Provider) Before(org.junit.Before)

Example 74 with Provider

use of com.google.inject.Provider in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method findVisibleFeatures.

/**
 * looks up the static final fields which are accessible in unqualified form for the given expression.
 * That essentially includes static imports and the fields declared in the containing types
 */
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
    HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
    {
        Resource _eResource = expression.eResource();
        final Resource res = _eResource;
        boolean _matched = false;
        if (res instanceof StorageAwareResource) {
            boolean _isLoadedFromStorage = ((StorageAwareResource) res).isLoadedFromStorage();
            if (_isLoadedFromStorage) {
                _matched = true;
                return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
            }
        }
        JvmDeclaredType _switchResult_1 = null;
        JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
        final JvmIdentifiableElement cont = _nearestLogicalContainer;
        boolean _matched_1 = false;
        if (cont instanceof JvmGenericType) {
            _matched_1 = true;
            _switchResult_1 = ((JvmGenericType) cont);
        }
        if (!_matched_1) {
            if (cont instanceof JvmMember) {
                _matched_1 = true;
                _switchResult_1 = ((JvmMember) cont).getDeclaringType();
            }
        }
        final JvmDeclaredType container = _switchResult_1;
        Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
        final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
            final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
            Resource _eResource_1 = expression.eResource();
            final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
            if ((section != null)) {
                EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
                for (final XImportDeclaration imp : _importDeclarations) {
                    boolean _isStatic = imp.isStatic();
                    if (_isStatic) {
                        final String importedTypeName = imp.getImportedTypeName();
                        if ((importedTypeName != null)) {
                            final JvmType type = this.findTypeByName(imp, importedTypeName);
                            boolean _matched_2 = false;
                            if (type instanceof JvmGenericType) {
                                _matched_2 = true;
                                this.collectAllVisibleFields(((JvmDeclaredType) type), result);
                            }
                            if (!_matched_2) {
                                if (type instanceof JvmEnumerationType) {
                                    _matched_2 = true;
                                    EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType) type).getLiterals();
                                    for (final JvmEnumerationLiteral feature : _literals) {
                                        result.put(feature.getSimpleName(), feature);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.collectAllVisibleFields(container, result);
            return result;
        };
        _xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
    }
    return _xblockexpression;
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XImportSection(org.eclipse.xtext.xtype.XImportSection) HashMap(java.util.HashMap) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtextResource(org.eclipse.xtext.resource.XtextResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmType(org.eclipse.xtext.common.types.JvmType) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration) ProcessorInstanceForJvmTypeProvider(org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider) ILogicalContainerProvider(org.eclipse.xtext.xbase.jvmmodel.ILogicalContainerProvider) Provider(com.google.inject.Provider) IScopeProvider(org.eclipse.xtext.scoping.IScopeProvider) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Pair(org.eclipse.xtext.xbase.lib.Pair) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair)

Example 75 with Provider

use of com.google.inject.Provider in project cdap by caskdata.

the class LogPipelineLoader method validate.

/**
   * Validates the log pipeline configurations.
   *
   * @throws InvalidPipelineException if any of the pipeline configuration is invalid.
   */
public void validate() throws InvalidPipelineException {
    Provider<LoggerContext> contextProvider = new Provider<LoggerContext>() {

        @Override
        public LoggerContext get() {
            LoggerContext context = new LoggerContext();
            context.putObject(Constants.Logging.PIPELINE_VALIDATION, Boolean.TRUE);
            return context;
        }
    };
    doLoad(contextProvider, false);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Provider(com.google.inject.Provider)

Aggregations

Provider (com.google.inject.Provider)133 Injector (com.google.inject.Injector)72 AbstractModule (com.google.inject.AbstractModule)63 Module (com.google.inject.Module)44 Key (com.google.inject.Key)17 TypeLiteral (com.google.inject.TypeLiteral)10 ArrayList (java.util.ArrayList)10 ProvisionException (com.google.inject.ProvisionException)9 Dependency (com.google.inject.spi.Dependency)9 Map (java.util.Map)8 Before (org.junit.Before)7 CurrentUser (com.google.gerrit.server.CurrentUser)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 PrivateModule (com.google.inject.PrivateModule)6 Scope (com.google.inject.Scope)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Annotation (java.lang.annotation.Annotation)5