Search in sources :

Example 11 with Multibinder

use of com.google.inject.multibindings.Multibinder in project intellij-plugins by JetBrains.

the class TestRunner method runTests.

@SuppressWarnings("deprecation")
private void runTests(@NotNull final File configFile, @NotNull String[] extraArgs, final boolean dryRun) throws ConfigurationException {
    JsTestDriverBuilder builder = new JsTestDriverBuilder();
    final ParsedConfiguration parsedConfiguration;
    try {
        parsedConfiguration = JstdConfigParsingUtils.parseConfiguration(configFile);
    } catch (Exception e) {
        throw new ConfigurationException("Configuration file parsing failed.\n" + "See http://code.google.com/p/js-test-driver/wiki/ConfigurationFile for clarification.\n\n" + "Details:", e);
    }
    final File singleBasePath = JstdConfigParsingUtils.getSingleBasePath(parsedConfiguration.getBasePaths(), configFile);
    myTreeManager.setCurrentBasePath(singleBasePath.getAbsolutePath());
    JstdConfigParsingUtils.wipeCoveragePlugin(parsedConfiguration);
    builder.setDefaultConfiguration(parsedConfiguration);
    builder.withPluginInitializer(new PluginInitializer() {

        @Override
        public Module initializeModule(Flags flags, Configuration config) {
            return new AbstractModule() {

                @Override
                public void configure() {
                    Multibinder<TestListener> testListeners = Multibinder.newSetBinder(binder(), TestListener.class);
                    testListeners.addBinding().to(TestResultHolder.class);
                    testListeners.addBinding().toInstance(new IdeaTestListener(myTreeManager, configFile, singleBasePath, dryRun, mySettings.getTestFileScope()));
                }
            };
        }
    });
    builder.setRunnerMode(RunnerMode.QUIET);
    builder.setServer(mySettings.getServerUrl());
    List<String> flagArgs = Lists.newArrayList("--captureConsole", "--server", mySettings.getServerUrl());
    ResolvedConfiguration resolvedConfiguration = JstdConfigParsingUtils.resolveConfiguration(parsedConfiguration);
    if (dryRun && JstdUtils.isJasmineTests(resolvedConfiguration)) {
        // https://github.com/ibolmo/jasmine-jstd-adapter/pull/21
        flagArgs.add("--reset");
    }
    flagArgs.addAll(Arrays.asList(extraArgs));
    List<String> coverageExcludedFiles = null;
    File emptyOutputDir = null;
    boolean runCoverage = false;
    if (myCoverageSession != null && !dryRun) {
        emptyOutputDir = createTempDir();
        if (emptyOutputDir != null) {
            flagArgs.add("--testOutput");
            flagArgs.add(emptyOutputDir.getAbsolutePath());
            List<String> testPaths = getTestFilePaths(resolvedConfiguration);
            coverageExcludedFiles = Lists.newArrayList(testPaths);
            coverageExcludedFiles.addAll(mySettings.getFilesExcludedFromCoverageRec());
            PluginInitializer coverageInitializer = getCoverageInitializer(coverageExcludedFiles);
            if (coverageInitializer != null) {
                builder.withPluginInitializer(coverageInitializer);
                builder.withPluginInitializer(new DependenciesTouchFix());
                runCoverage = true;
            }
        }
    }
    builder.setFlags(toStringArray(flagArgs));
    builder.setFlagsParser(new IntelliJFlagParser(mySettings, dryRun));
    JsTestDriver jstd = builder.build();
    jstd.runConfiguration();
    if (runCoverage) {
        File[] coverageReportFiles = emptyOutputDir.listFiles((dir, name) -> name.endsWith("-coverage.dat"));
        if (coverageReportFiles != null && coverageReportFiles.length == 1) {
            try {
                CoverageReport coverageReport = CoverageSerializationUtils.readLCOV(coverageReportFiles[0]);
                for (String excludedPath : coverageExcludedFiles) {
                    coverageReport.clearReportByFilePath(excludedPath);
                }
                myCoverageSession.mergeReport(coverageReport);
            } catch (Exception e) {
                myTreeManager.printThrowable(e);
            }
        }
    }
}
Also used : PluginInitializer(com.google.jstestdriver.hooks.PluginInitializer) Configuration(com.google.jstestdriver.config.Configuration) ResolvedConfiguration(com.google.jstestdriver.config.ResolvedConfiguration) ParsedConfiguration(com.google.jstestdriver.config.ParsedConfiguration) Multibinder(com.google.inject.multibindings.Multibinder) CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport) TestResultHolder(com.google.jstestdriver.output.TestResultHolder) JsTestDriverBuilder(com.google.jstestdriver.embedded.JsTestDriverBuilder) ConfigurationException(com.google.jstestdriver.config.ConfigurationException) AbstractModule(com.google.inject.AbstractModule) ResolvedConfiguration(com.google.jstestdriver.config.ResolvedConfiguration) ParsedConfiguration(com.google.jstestdriver.config.ParsedConfiguration) ConfigurationException(com.google.jstestdriver.config.ConfigurationException) TestListener(com.google.jstestdriver.hooks.TestListener) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule)

Example 12 with Multibinder

use of com.google.inject.multibindings.Multibinder in project cdap by caskdata.

the class DataSetServiceModules method getInMemoryModules.

@Override
public Module getInMemoryModules() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            // Add the system dataset runtime module as public binding so that adding bindings could be added
            install(new SystemDatasetRuntimeModule().getInMemoryModules());
            install(new PrivateModule() {

                @Override
                protected void configure() {
                    install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
                    bind(DatasetFramework.class).annotatedWith(Names.named("datasetMDS")).toProvider(DatasetMdsProvider.class).in(Singleton.class);
                    expose(DatasetFramework.class).annotatedWith(Names.named("datasetMDS"));
                    bind(DatasetService.class);
                    expose(DatasetService.class);
                    Named datasetUserName = Names.named(Constants.Service.DATASET_EXECUTOR);
                    Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, datasetUserName);
                    CommonHandlers.add(handlerBinder);
                    handlerBinder.addBinding().to(DatasetAdminOpHTTPHandler.class);
                    Multibinder.newSetBinder(binder(), DatasetMetricsReporter.class);
                    bind(DatasetOpExecutorService.class).in(Scopes.SINGLETON);
                    expose(DatasetOpExecutorService.class);
                    bind(DatasetOpExecutor.class).to(LocalDatasetOpExecutor.class);
                    expose(DatasetOpExecutor.class);
                }
            });
        }
    };
}
Also used : Named(com.google.inject.name.Named) HttpHandler(co.cask.http.HttpHandler) DatasetAdminOpHTTPHandler(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler) Multibinder(com.google.inject.multibindings.Multibinder) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) AbstractModule(com.google.inject.AbstractModule) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) Singleton(com.google.inject.Singleton) DatasetOpExecutorService(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) LevelDBDatasetMetricsReporter(co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter) DatasetMetricsReporter(co.cask.cdap.data2.metrics.DatasetMetricsReporter) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) PrivateModule(com.google.inject.PrivateModule)

Aggregations

AbstractModule (com.google.inject.AbstractModule)12 Multibinder (com.google.inject.multibindings.Multibinder)12 Injector (com.google.inject.Injector)6 HttpHandler (co.cask.http.HttpHandler)5 Singleton (com.google.inject.Singleton)4 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)3 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)3 DatasetAdminOpHTTPHandler (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler)3 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)3 DatasetOpExecutorService (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)3 LocalDatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor)3 YarnDatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor)3 DefaultDatasetDefinitionRegistry (co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry)3 DatasetMetricsReporter (co.cask.cdap.data2.metrics.DatasetMetricsReporter)3 HBaseDatasetMetricsReporter (co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter)3 LevelDBDatasetMetricsReporter (co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 PrivateModule (com.google.inject.PrivateModule)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3