Search in sources :

Example 6 with Exposed

use of com.google.inject.Exposed in project LanternServer by LanternPowered.

the class LanternModule method provideAssetManager.

@Exposed
@Provides
@Singleton
private LanternAssetManager provideAssetManager(@Option({ "asset-repository-config", "asset-repo-config" }) @Nullable Path repoConfig, LanternPluginManager pluginManager) {
    final Gson gson = new GsonBuilder().registerTypeAdapter(AssetRepository.class, new AssetRepositoryJsonDeserializer(pluginManager)).create();
    try {
        URL url;
        if (repoConfig != null) {
            url = PathUtils.toURL(repoConfig);
        } else {
            url = getClass().getClassLoader().getResource("assets_repo.json");
            checkNotNull(url);
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
            return new LanternAssetManager(gson.fromJson(reader, AssetRepository.class));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LanternAssetManager(org.lanternpowered.server.asset.LanternAssetManager) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) AssetRepository(org.lanternpowered.server.asset.AssetRepository) IOException(java.io.IOException) AssetRepositoryJsonDeserializer(org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer) URL(java.net.URL) Exposed(com.google.inject.Exposed) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 7 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method privateModuleInheritScanner_usingPrivateModule.

@Test
public void privateModuleInheritScanner_usingPrivateModule() {
    Injector injector = Guice.createInjector(scannerModule(new NamedMunger()), new PrivateModule() {

        @Override
        protected void configure() {
        }

        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Exposed(com.google.inject.Exposed) Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule) Test(org.junit.Test)

Aggregations

Exposed (com.google.inject.Exposed)7 Injector (com.google.inject.Injector)6 PrivateModule (com.google.inject.PrivateModule)6 Named (com.google.inject.name.Named)5 Test (org.junit.Test)4 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 ProviderMethodsModule (com.google.inject.internal.ProviderMethodsModule)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 AssetRepository (org.lanternpowered.server.asset.AssetRepository)1 LanternAssetManager (org.lanternpowered.server.asset.LanternAssetManager)1 AssetRepositoryJsonDeserializer (org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer)1