Пример #1
0
 public void run() {
   while (status != Status.Dead) {
     if (thisS != null) {
       thisS.run();
     }
     update();
   }
 }
    public void apply(final Object target) {
      DefaultServiceRegistry services = new DefaultServiceRegistry();
      services.add(ScriptPluginFactory.class, DefaultScriptPluginFactory.this);
      services.add(ScriptHandlerFactory.class, scriptHandlerFactory);
      services.add(ClassLoaderScope.class, targetScope);
      services.add(LoggingManagerInternal.class, loggingManagerFactory.create());
      services.add(Instantiator.class, instantiator);
      services.add(ScriptHandler.class, scriptHandler);
      services.add(FileLookup.class, fileLookup);
      services.add(ModelRuleSourceDetector.class, modelRuleSourceDetector);

      ScriptSource withImports = importsReader.withImports(scriptSource);

      PluginDependenciesService pluginDependenciesService =
          new PluginDependenciesService(getSource());
      services.add(PluginDependenciesService.class, pluginDependenciesService);

      ScriptCompiler compiler = scriptCompilerFactory.createCompiler(withImports);
      compiler.setClassloader(baseScope.getExportClassLoader());

      boolean supportsPluginsBlock = ProjectScript.class.isAssignableFrom(scriptType);
      String onPluginBlockError =
          supportsPluginsBlock ? null : "Only Project build scripts can contain plugins {} blocks";

      PluginsAndBuildscriptTransformer scriptBlockTransformer =
          new PluginsAndBuildscriptTransformer(
              classpathClosureName, onPluginBlockError, documentationRegistry);

      StatementExtractingScriptTransformer classpathScriptTransformer =
          new StatementExtractingScriptTransformer(classpathClosureName, scriptBlockTransformer);

      compiler.setTransformer(classpathScriptTransformer);

      ScriptRunner<? extends BasicScript> classPathScriptRunner = compiler.compile(scriptType);
      classPathScriptRunner.getScript().init(target, services);
      classPathScriptRunner.run();

      List<PluginRequest> pluginRequests = pluginDependenciesService.getRequests();
      PluginAwareInternal pluginAware =
          target instanceof PluginAwareInternal ? (PluginAwareInternal) target : null;
      pluginRequestApplicator.applyPlugins(pluginRequests, scriptHandler, pluginAware, targetScope);

      compiler.setClassloader(targetScope.getLocalClassLoader());

      BuildScriptTransformer transformer =
          new BuildScriptTransformer(
              "no_" + classpathScriptTransformer.getId(),
              classpathScriptTransformer.invert(),
              scriptSource);
      compiler.setTransformer(transformer);

      // TODO - find a less tangled way of getting this in here, see the verifier impl for why it's
      // needed
      compiler.setVerifier(new ClosureCreationInterceptingVerifier());

      ScriptRunner<? extends BasicScript> runner = compiler.compile(scriptType);

      BasicScript script = runner.getScript();
      script.init(target, services);
      if (ownerScript && target instanceof ScriptAware) {
        ((ScriptAware) target).setScript(script);
      }
      runner.run();
    }