org.pf4j.PluginManager Java Examples

The following examples show how to use org.pf4j.PluginManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdditionalOptionsCmdLineParser.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new command line owner that parses arguments/options and set them into the given
 * object.
 *
 * @param bean instance of a class annotated by {@link Option}, {@link Argument} and {@link
 *     AdditionalOptions}. This object will receive values. If this is null, the processing will
 *     be skipped, which is useful if you'd like to feed metadata from other sources.
 * @throws IllegalAnnotationError if the option bean class is using args4j annotations
 *     incorrectly.
 * @see CmdLineParser#CmdLineParser(Object)
 */
public AdditionalOptionsCmdLineParser(PluginManager pluginManager, Object bean) {
  /**
   * Disable '@' syntax. We convert this ourselves in {@link BuckArgsMethods#expandAtFiles}, so
   * options passed to parseArgument() should already be properly expanded. This allows us to have
   * things like `buck run @file //:script -- @this_goes_to_the_script`, as @file is expanded
   * before hitting this method.
   */
  super(null, ParserProperties.defaults().withAtSyntax(false));
  this.pluginManager = pluginManager;

  // This is copied in simplified form from CmdLineParser constructor and put here to save the
  // reference to the plugin manager before doing the parsing of options.
  new ClassParser().parse(bean, this);
  getOptions().sort(DEFAULT_COMPARATOR);

  Set<Class<?>> visited = new HashSet<>();
  parseAnnotations(new ClassParser(), bean, visited);
}
 
Example #2
Source File: NonModuleClassTest.java    From buck with Apache License 2.0 6 votes vote down vote up
private static void testBuckModuleHashProvider() {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  BuckModuleJarHashProvider hashProvider = new BuckModuleJarHashProvider();
  BuckModuleManager moduleManager = new DefaultBuckModuleManager(pluginManager, hashProvider);

  try {
    moduleManager.getModuleHash(NonModuleClassTest.class);
    fail("Should throw IllegalStateException");
  } catch (IllegalStateException e) {
    assertEquals(
        "Requested module hash for class "
            + "com.facebook.buck.core.module.impl.nonmoduleclass.NonModuleClassTest but "
            + "its class loader is not PluginClassCloader",
        e.getMessage());
  }

  assertFalse(moduleManager.isClassInModule(NonModuleClassTest.class));
}
 
Example #3
Source File: KnownBuildRuleDescriptionsFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
static ImmutableList<Description<?>> createBuildDescriptions(
    BuckConfig config,
    ProcessExecutor processExecutor,
    ToolchainProvider toolchainProvider,
    PluginManager pluginManager,
    SandboxExecutionStrategyFactory sandboxExecutionStrategyFactory) {

  ImmutableList.Builder<Description<?>> builder = ImmutableList.builder();

  SandboxExecutionStrategy sandboxExecutionStrategy =
      sandboxExecutionStrategyFactory.create(processExecutor, config);

  DescriptionCreationContext descriptionCreationContext =
      DescriptionCreationContext.of(
          config, toolchainProvider, sandboxExecutionStrategy, pluginManager);
  List<DescriptionProvider> descriptionProviders =
      pluginManager.getExtensions(DescriptionProvider.class);
  for (DescriptionProvider provider : descriptionProviders) {
    builder.addAll(provider.getDescriptions(descriptionCreationContext));
  }

  return builder.build();
}
 
Example #4
Source File: Hive3StoragePlugin.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name) {
  super(context, name);
  this.isCoordinator = context.isCoordinator();
  this.hiveConf = hiveConf;
  this.pf4jManager = pf4jManager;
  this.sabotConfig = context.getConfig();
  this.hiveSettings = new HiveSettings(context.getOptionManager());
  this.optionManager = context.getOptionManager();
  this.dremioConfig = context.getDremioConfig();

  storageImpersonationEnabled = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS);

  // Hive Metastore impersonation is enabled if:
  // - "hive.security.authorization.enabled" is set to true,
  // - "hive.metastore.execute.setugi" is set to true (in SASL disabled scenarios) or
  // - "hive.metastore.sasl.enabled" is set to true in which case all metastore calls are impersonated as
  //     the authenticated user.
  this.metastoreImpersonationEnabled =
    hiveConf.getBoolVar(ConfVars.HIVE_AUTHORIZATION_ENABLED) ||
      hiveConf.getBoolVar(ConfVars.METASTORE_EXECUTE_SET_UGI) ||
      hiveConf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_SASL);
}
 
Example #5
Source File: Boot.java    From pf4j-spring with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // print logo
    printLogo();

    // retrieves the spring application context
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);

    // retrieves automatically the extensions for the Greeting.class extension point
    Greetings greetings = applicationContext.getBean(Greetings.class);
    greetings.printGreetings();

    // stop plugins
    PluginManager pluginManager = applicationContext.getBean(PluginManager.class);
    /*
    // retrieves manually the extensions for the Greeting.class extension point
    List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
    System.out.println("greetings.size() = " + greetings.size());
    */
    pluginManager.stopPlugins();
}
 
Example #6
Source File: TestKnownRuleTypesFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
public static KnownNativeRuleTypes create(
    BuckConfig config, ToolchainProvider toolchainProvider, ProcessExecutor processExecutor) {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();

  SandboxExecutionStrategyFactory sandboxExecutionStrategyFactory =
      new TestSandboxExecutionStrategyFactory();
  return KnownNativeRuleTypes.of(
      KnownBuildRuleDescriptionsFactory.createBuildDescriptions(
          config,
          processExecutor,
          toolchainProvider,
          pluginManager,
          sandboxExecutionStrategyFactory),
      ImmutableList.of(),
      KnownBuildRuleDescriptionsFactory.createBuiltInProviders(pluginManager));
}
 
Example #7
Source File: HiveStoragePlugin.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name) {
  super(context, name);
  this.isCoordinator = context.isCoordinator();
  this.hiveConf = hiveConf;
  this.pf4jManager = pf4jManager;
  this.sabotConfig = context.getConfig();
  this.hiveSettings = new HiveSettings(context.getOptionManager());
  this.optionManager = context.getOptionManager();
  this.dremioConfig = context.getDremioConfig();

  storageImpersonationEnabled = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS);

  // Hive Metastore impersonation is enabled if:
  // - "hive.security.authorization.enabled" is set to true,
  // - "hive.metastore.execute.setugi" is set to true (in SASL disabled scenarios) or
  // - "hive.metastore.sasl.enabled" is set to true in which case all metastore calls are impersonated as
  //     the authenticated user.
  this.metastoreImpersonationEnabled =
    hiveConf.getBoolVar(ConfVars.HIVE_AUTHORIZATION_ENABLED) ||
      hiveConf.getBoolVar(ConfVars.METASTORE_EXECUTE_SET_UGI) ||
      hiveConf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_SASL);
}
 
Example #8
Source File: ModuleClassTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private static PluginWrapper getPluginWrapperForClass(PluginManager pluginManager, Class<?> cls)
    throws Exception {
  Field pluginDescriptorField = PluginClassLoader.class.getDeclaredField("pluginDescriptor");
  pluginDescriptorField.setAccessible(true);
  PluginDescriptor pluginDescriptor =
      (PluginDescriptor) pluginDescriptorField.get(cls.getClassLoader());

  return pluginManager.getPlugin(pluginDescriptor.getPluginId());
}
 
Example #9
Source File: DefaultKnownNativeRuleTypesFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
public DefaultKnownNativeRuleTypesFactory(
    ProcessExecutor executor,
    PluginManager pluginManager,
    SandboxExecutionStrategyFactory sandboxExecutionStrategyFactory,
    ImmutableList<ConfigurationRuleDescription<?, ?>> knownConfigurationDescriptions) {
  this.executor = executor;
  this.pluginManager = pluginManager;
  this.sandboxExecutionStrategyFactory = sandboxExecutionStrategyFactory;
  this.knownConfigurationDescriptions = knownConfigurationDescriptions;
}
 
Example #10
Source File: PluginBasedKnownConfigurationDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Create rule descriptors using provided plugin manager */
public static ImmutableList<ConfigurationRuleDescription<?, ?>> createFromPlugins(
    PluginManager pluginManager) {

  List<ConfigurationRuleDescriptionProvider> descriptionProviders =
      pluginManager.getExtensions(ConfigurationRuleDescriptionProvider.class);

  return descriptionProviders.stream()
      .map(ConfigurationRuleDescriptionProvider::getDescriptions)
      .flatMap(Collection::stream)
      .collect(ImmutableList.toImmutableList());
}
 
Example #11
Source File: DefaultToolchainProviderFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
public DefaultToolchainProviderFactory(
    PluginManager pluginManager,
    ImmutableMap<String, String> environment,
    ProcessExecutor processExecutor,
    ExecutableFinder executableFinder) {
  this.pluginManager = pluginManager;
  this.environment = environment;
  this.processExecutor = processExecutor;
  this.executableFinder = executableFinder;
}
 
Example #12
Source File: CommandRunnerParamsForTesting.java    From buck with Apache License 2.0 5 votes vote down vote up
public CommandRunnerParams build() {
  TestCellBuilder cellBuilder = new TestCellBuilder();
  if (toolchainProvider != null) {
    cellBuilder.setToolchainProvider(toolchainProvider);
  }
  Cells cell = cellBuilder.build();
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  KnownRuleTypesProvider knownRuleTypesProvider =
      TestKnownRuleTypesProvider.create(pluginManager);
  Parser parser =
      TestParserFactory.create(executor, cell.getRootCell(), knownRuleTypesProvider);

  return createCommandRunnerParamsForTesting(
      executor,
      console,
      cell,
      artifactCache,
      eventBus,
      config,
      platform,
      environment,
      javaPackageFinder,
      webServer,
      pluginManager,
      knownRuleTypesProvider,
      parser);
}
 
Example #13
Source File: SkylarkPackageFileParserTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
  skylarkFilesystem = SkylarkFilesystem.using(projectFilesystem);
  cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  knownRuleTypesProvider = TestKnownRuleTypesProvider.create(pluginManager);

  eventCollector = new EventCollector(EnumSet.allOf(EventKind.class));

  ProjectBuildFileParserOptions options =
      ProjectBuildFileParserOptions.builder()
          .setProjectRoot(cell.getRootCell().getRoot())
          .setAllowEmptyGlobs(false)
          .setIgnorePaths(ImmutableSet.of())
          .setBuildFileName("PACKAGE")
          .setRawConfig(
              ImmutableMap.of("dummy_section", ImmutableMap.of("dummy_key", "dummy_value")))
          .setDescriptions(ImmutableSet.of())
          .setPerFeatureProviders(ImmutableList.of())
          .setBuildFileImportWhitelist(ImmutableList.of())
          .setPythonInterpreter("skylark")
          .build();

  parser =
      SkylarkPackageFileParser.using(
          options,
          BuckEventBusForTests.newInstance(),
          skylarkFilesystem,
          BuckGlobals.of(
              SkylarkPackageModule.PACKAGE_MODULE,
              options.getDescriptions(),
              options.getUserDefinedRulesState(),
              options.getImplicitNativeRulesState(),
              new RuleFunctionFactory(new DefaultTypeCoercerFactory()),
              LabelCache.newLabelCache(),
              knownRuleTypesProvider.getUserDefinedRuleTypes(cell.getRootCell()),
              options.getPerFeatureProviders()),
          eventCollector);
}
 
Example #14
Source File: BuildCommandTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private CommandRunnerParams createTestParams(ImmutableSet<String> buildTargetNames) {
  CloseableResource<DepsAwareExecutor<? super ComputeResult, ?>> executor =
      CloseableResource.of(() -> DefaultDepsAwareExecutor.of(4));
  Cells cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
  ArtifactCache artifactCache = new NoopArtifactCache();
  BuckEventBus eventBus = BuckEventBusForTests.newInstance();
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  KnownRuleTypesProvider knownRuleTypesProvider =
      TestKnownRuleTypesProvider.create(pluginManager);

  return CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(
      executor.get(),
      console,
      cell,
      artifactCache,
      eventBus,
      FakeBuckConfig.builder().build(),
      Platform.detect(),
      EnvVariablesProvider.getSystemEnv(),
      new FakeJavaPackageFinder(),
      Optional.empty(),
      pluginManager,
      knownRuleTypesProvider,
      new TestParser(
          TestParserFactory.create(executor.get(), cell.getRootCell(), knownRuleTypesProvider),
          TargetGraphCreationResult.of(
              TargetGraph.EMPTY,
              buildTargetNames.stream()
                  .map(BuildTargetFactory::newInstance)
                  .collect(ImmutableSet.toImmutableSet()))));
}
 
Example #15
Source File: PluginConfig.java    From pf4j-spring-tutorial with MIT License 5 votes vote down vote up
private void registerMvcEndpoints(PluginManager pm) {
    pm.getExtensions(PluginInterface.class).stream()
            .flatMap(g -> g.mvcControllers().stream())
            .forEach(r -> ((ConfigurableBeanFactory) beanFactory)
                    .registerSingleton(r.getClass().getName(), r));
    applicationContext
            .getBeansOfType(RequestMappingHandlerMapping.class)
            .forEach((k, v) -> v.afterPropertiesSet());
}
 
Example #16
Source File: PluginConfig.java    From pf4j-spring-tutorial with MIT License 5 votes vote down vote up
private String pluginNamesMono(PluginManager pm) {
    List<String> identityList = pm.getExtensions(PluginInterface.class).stream()
            .map(g-> g.getClass().getName() + ": " + g.identify())
            .collect(Collectors.toList());
    try {
        return objectMapper.writeValueAsString(identityList);
    } catch (JsonProcessingException e) {
        return "[]";
    }
}
 
Example #17
Source File: ModuleClassTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private static void testBuckModuleHashProvider(TestExtension testExtension) {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  BuckModuleJarHashProvider hashProvider = new BuckModuleJarHashProvider();
  BuckModuleManager moduleManager = new DefaultBuckModuleManager(pluginManager, hashProvider);
  Hasher hasher = Hashing.murmur3_128().newHasher();
  hasher.putUnencodedChars("some content that never changes");
  assertEquals(hasher.hash().toString(), moduleManager.getModuleHash(testExtension.getClass()));

  assertTrue(moduleManager.isClassInModule(testExtension.getClass()));
  assertFalse(moduleManager.isClassInModule(ModuleClassTest.class));
}
 
Example #18
Source File: MainRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor allows integration tests to add/remove/modify known build rules (aka
 * descriptions).
 *
 * @param console the {@link Console} to print to for this command
 * @param stdIn the input stream to the command being ran
 * @param knownRuleTypesFactoryFactory the known rule types for this command
 * @param buildId the {@link BuildId} for this command
 * @param clientEnvironment the environment variable map for this command
 * @param platform the current running {@link Platform}
 * @param projectRoot the project root of the current command
 * @param pluginManager the {@link PluginManager} for this command
 * @param moduleManager the {@link BuckModuleManager} for this command
 * @param context the {@link NGContext} from nailgun for this command
 */
@VisibleForTesting
public MainRunner(
    Console console,
    InputStream stdIn,
    KnownRuleTypesFactoryFactory knownRuleTypesFactoryFactory,
    BuildId buildId,
    ImmutableMap<String, String> clientEnvironment,
    Platform platform,
    Path projectRoot,
    PluginManager pluginManager,
    BuckModuleManager moduleManager,
    BackgroundTaskManager bgTaskManager,
    CommandMode commandMode,
    Optional<NGContext> context) {
  this.printConsole = new DuplicatingConsole(console);
  this.stdIn = stdIn;
  this.knownRuleTypesFactoryFactory = knownRuleTypesFactoryFactory;
  this.projectRoot = projectRoot;
  this.pluginManager = pluginManager;
  this.moduleManager = moduleManager;
  this.bgTaskManager = bgTaskManager;
  this.architecture = Architecture.detect();
  this.buildId = buildId;
  this.clientEnvironment = clientEnvironment;
  this.platform = platform;
  this.context = context;
  this.commandMode = commandMode;
}
 
Example #19
Source File: KnownBuildRuleDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
static ImmutableList<BuiltInProvider<?>> createBuiltInProviders(PluginManager pluginManager) {
  ImmutableList.Builder<BuiltInProvider<?>> builder = ImmutableList.builder();
  List<BuiltInProviderProvider> providerProviders =
      pluginManager.getExtensions(BuiltInProviderProvider.class);
  for (BuiltInProviderProvider provider : providerProviders) {
    builder.addAll(provider.getBuiltInProviders());
  }
  return builder.build();
}
 
Example #20
Source File: Hive3StoragePluginConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public StoragePlugin newPlugin(SabotContext context, String name, Provider<StoragePluginId> pluginIdProvider) {
  final PluginManager manager = new NativeLibPluginManager();

  manager.loadPlugins();
  manager.startPlugin(getPf4jPluginId());
  final StoragePluginCreator pluginCreator =
    manager.getExtensions(StoragePluginCreator.class, getPf4jPluginId()).get(0);

  return pluginCreator.createStoragePlugin(manager, this, context, name, pluginIdProvider);
}
 
Example #21
Source File: Hive2StoragePluginConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public StoragePlugin newPlugin(SabotContext context, String name, Provider<StoragePluginId> pluginIdProvider) {
  final PluginManager manager = new NativeLibPluginManager();

  manager.loadPlugins();
  manager.startPlugin(getPf4jPluginId());
  final StoragePluginCreator pluginCreator =
    manager.getExtensions(StoragePluginCreator.class, getPf4jPluginId()).get(0);

  return pluginCreator.createStoragePlugin(manager, this, context, name, pluginIdProvider);
}
 
Example #22
Source File: ExpressionsSupport.java    From kork with Apache License 2.0 5 votes vote down vote up
public ExpressionsSupport(
    Class<?>[] extraAllowedReturnTypes,
    List<ExpressionFunctionProvider> extraExpressionFunctionProviders,
    PluginManager pluginManager) {

  allowedReturnTypes =
      new HashSet<>(
          Arrays.asList(
              Collection.class,
              Map.class,
              SortedMap.class,
              List.class,
              Set.class,
              SortedSet.class,
              ArrayList.class,
              LinkedList.class,
              HashSet.class,
              LinkedHashSet.class,
              HashMap.class,
              LinkedHashMap.class,
              TreeMap.class,
              TreeSet.class));
  Collections.addAll(allowedReturnTypes, extraAllowedReturnTypes);

  expressionFunctionProviders =
      new ArrayList<>(
          Arrays.asList(
              new JsonExpressionFunctionProvider(), new StringExpressionFunctionProvider()));
  if (extraExpressionFunctionProviders != null) {
    expressionFunctionProviders.addAll(extraExpressionFunctionProviders);
  }

  // TODO(rz): Once plugins are no longer an incubating feature, extraExpressionFunctionProviders
  //  var could be removed
  if (pluginManager != null) {
    expressionFunctionProviders.addAll(
        pluginManager.getExtensions(ExpressionFunctionProvider.class));
  }
}
 
Example #23
Source File: SkylarkProjectBuildFileParserTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
  skylarkFilesystem = SkylarkFilesystem.using(projectFilesystem);
  cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  knownRuleTypesProvider = TestKnownRuleTypesProvider.create(pluginManager);
  parser = createParser(new PrintingEventHandler(EventKind.ALL_EVENTS));
}
 
Example #24
Source File: DefaultBuckModuleManager.java    From buck with Apache License 2.0 5 votes vote down vote up
public DefaultBuckModuleManager(
    PluginManager pluginManager, BuckModuleJarHashProvider moduleJarHashProvider) {
  this.pluginManager = pluginManager;
  this.moduleJarHashProvider = moduleJarHashProvider;

  try {
    pluginDescriptorField = PluginClassLoader.class.getDeclaredField("pluginDescriptor");
    pluginDescriptorField.setAccessible(true);
  } catch (NoSuchFieldException e) {
    throw new RuntimeException(
        "Cannot find pluginDescriptor field in " + PluginClassLoader.class.getName());
  }
}
 
Example #25
Source File: RootCellFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
public static Cell create(
    ImmutableSortedSet<AbsPath> knownRoots,
    CellProvider cellProvider,
    NewCellPathResolver newCellPathResolver,
    CellPathResolver rootCellCellPathResolver,
    ProjectFilesystem rootFilesystem,
    BuckModuleManager moduleManager,
    PluginManager pluginManager,
    BuckConfig rootConfig,
    ImmutableMap<String, String> environment,
    ProcessExecutor processExecutor,
    ExecutableFinder executableFinder) {
  Preconditions.checkState(
      !rootCellCellPathResolver.getCanonicalCellName(rootFilesystem.getRootPath()).isPresent(),
      "Root cell should be nameless");
  RuleKeyConfiguration ruleKeyConfiguration =
      ConfigRuleKeyConfigurationFactory.create(rootConfig, moduleManager);
  ToolchainProvider toolchainProvider =
      new DefaultToolchainProvider(
          pluginManager,
          environment,
          rootConfig,
          rootFilesystem,
          processExecutor,
          executableFinder,
          ruleKeyConfiguration);

  return ImmutableCellImpl.of(
      knownRoots,
      CanonicalCellName.rootCell(),
      rootFilesystem,
      rootConfig,
      cellProvider,
      toolchainProvider,
      rootCellCellPathResolver,
      newCellPathResolver,
      rootCellCellPathResolver.getCellNameResolver());
}
 
Example #26
Source File: SkylarkUserDefinedRulesParserTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private void setupWorkspace(String scenario) throws IOException {
  workspace = TestDataHelper.createProjectWorkspaceForScenario(this, scenario, tmp.getRoot());
  workspace.setUp();
  projectFilesystem = new FakeProjectFilesystem(CanonicalCellName.rootCell(), tmp.getRoot());
  skylarkFilesystem = SkylarkFilesystem.using(projectFilesystem);
  cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  knownRuleTypesProvider = TestKnownRuleTypesProvider.create(pluginManager);
  parser = createParser(new PrintingEventHandler(EventKind.ALL_EVENTS));
}
 
Example #27
Source File: BuckPluginManagerFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Creates a {@link PluginManager} and loads plugins. */
public static PluginManager createPluginManager() {
  PluginManager pluginManager = new DefaultBuckPluginManager();
  pluginManager.loadPlugins();
  pluginManager.startPlugins();

  return pluginManager;
}
 
Example #28
Source File: TestCellBuilder.java    From buck with Apache License 2.0 5 votes vote down vote up
public Cells build() {
  ProjectFilesystem filesystem =
      this.filesystem != null ? this.filesystem : new FakeProjectFilesystem();

  BuckConfig config =
      buckConfig == null
          ? FakeBuckConfig.builder().setFilesystem(filesystem).build()
          : buckConfig;

  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  ProcessExecutor processExecutor = new DefaultProcessExecutor(new TestConsole());
  ExecutableFinder executableFinder = new ExecutableFinder();

  ImmutableMap<String, String> environmentCopy = ImmutableMap.copyOf(environment);

  ToolchainProviderFactory toolchainProviderFactory =
      toolchainProvider == null
          ? new DefaultToolchainProviderFactory(
              pluginManager, environmentCopy, processExecutor, executableFinder)
          : (buckConfig, filesystemIgnore, ruleKeyConfiguration) -> toolchainProvider;

  DefaultCellPathResolver rootCellCellPathResolver =
      DefaultCellPathResolver.create(filesystem.getRootPath(), config.getConfig());

  return new Cells(
      LocalCellProviderFactory.create(
              filesystem,
              config,
              cellConfig,
              rootCellCellPathResolver.getPathMapping(),
              rootCellCellPathResolver,
              TestBuckModuleManagerFactory.create(pluginManager),
              toolchainProviderFactory,
              new DefaultProjectFilesystemFactory(),
              new ParsingUnconfiguredBuildTargetViewFactory())
          .getCellByPath(filesystem.getRootPath()));
}
 
Example #29
Source File: ModuleWithExternalDependenciesTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private static void testBuckModuleHashProvider(List<TestExtension> testExtensions) {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  BuckModuleJarHashProvider hashProvider = new BuckModuleJarHashProvider();
  BuckModuleManager moduleManager = new DefaultBuckModuleManager(pluginManager, hashProvider);

  TestExtension testExtension1 = testExtensions.get(0);
  TestExtension testExtension2 = testExtensions.get(1);

  String hash1 = moduleManager.getModuleHash(testExtension1.getClass());
  String hash2 = moduleManager.getModuleHash(testExtension2.getClass());

  assertNotEquals(hash1, hash2);

  TestExtension extensionFromDependentModule;
  TestExtension extensionFromIndependentModule;

  if (testExtension1 instanceof Serializable) {
    extensionFromDependentModule = testExtension2;
    extensionFromIndependentModule = testExtension1;
  } else {
    extensionFromDependentModule = testExtension1;
    extensionFromIndependentModule = testExtension2;
  }

  assertEquals(
      hash(HASH), moduleManager.getModuleHash(extensionFromIndependentModule.getClass()));
  assertEquals(
      hash(hash(HASH), HASH),
      moduleManager.getModuleHash(extensionFromDependentModule.getClass()));
}
 
Example #30
Source File: XCodeDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
public static XCodeDescriptions create(PluginManager pluginManager) {
  List<XCodeDescriptionClassSupplier> xcodeDescriptionClassSuppliers =
      pluginManager.getExtensions(XCodeDescriptionClassSupplier.class);

  return new XCodeDescriptions(
      xcodeDescriptionClassSuppliers.stream()
          .flatMap(supplier -> supplier.getXCodeDescriptions().stream())
          .collect(ImmutableSet.toImmutableSet()));
}