text:
package com.streamsets.datacollector.creation;

import com.google.common.collect.ImmutableList;
import com.streamsets.datacollector.config.ConfigDefinition;
import com.streamsets.datacollector.config.ConnectionConfiguration;
import com.streamsets.datacollector.config.InterceptorDefinition;
import com.streamsets.datacollector.config.PipelineConfiguration;
import com.streamsets.datacollector.config.PipelineFragmentConfiguration;
import com.streamsets.datacollector.config.PipelineGroups;
import com.streamsets.datacollector.config.PipelineWebhookConfig;
import com.streamsets.datacollector.config.RuleDefinitions;
import com.streamsets.datacollector.config.ServiceConfiguration;
import com.streamsets.datacollector.config.ServiceDefinition;
import com.streamsets.datacollector.config.SparkClusterType;
import com.streamsets.datacollector.config.StageConfiguration;
import com.streamsets.datacollector.config.StageDefinition;
import com.streamsets.datacollector.config.StageLibraryDefinition;
import com.streamsets.datacollector.definition.StageDefinitionExtractor;
import com.streamsets.datacollector.main.RuntimeInfo;
import com.streamsets.datacollector.runner.InterceptorCreatorContextBuilder;
import com.streamsets.datacollector.stagelibrary.ClassLoaderReleaser;
import com.streamsets.datacollector.stagelibrary.StageLibraryTask;
import com.streamsets.datacollector.util.Configuration;
import com.streamsets.datacollector.validation.Issue;
import com.streamsets.datacollector.validation.IssueCreator;
import com.streamsets.pipeline.api.Config;
import com.streamsets.pipeline.api.ExecutionMode;
import com.streamsets.pipeline.api.Stage;
import com.streamsets.pipeline.api.impl.Utils;
import com.streamsets.pipeline.api.interceptor.Interceptor;
import com.streamsets.pipeline.api.interceptor.InterceptorCreator;
import com.streamsets.pipeline.api.service.Service;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;

public abstract class PipelineBeanCreator {
  private static final Logger LOG = LoggerFactory.getLogger(PipelineBeanCreator.class);

  public static final String PIPELINE_LIB_DEFINITION = "Pipeline";
  public static final String FRAGMENT_LIB_DEFINITION = "Fragment";
  private static final String RULE_DEFINITIONS_LIB_DEFINITION = "RuleDefinitions";
  private static final String PARAMETERS = "constants";

  private static final PipelineBeanCreator CREATOR = new PipelineBeanCreator() {
  };

  public static PipelineBeanCreator get() {
    return CREATOR;
  }

  public static void prepareForConnections(Configuration configuration, RuntimeInfo runtimeInfo) {
    ConfigInjector.prepareForConnections(configuration, runtimeInfo);
  }

  public static final StageDefinition PIPELINE_DEFINITION = getPipelineDefinition();

  static private StageDefinition getPipelineDefinition() {
    StageLibraryDefinition libraryDef = new StageLibraryDefinition(
        Thread.currentThread().getContextClassLoader(),
        PIPELINE_LIB_DEFINITION,
        PIPELINE_LIB_DEFINITION,
        new Properties(),
        null,
        null,
        null
    );
    return StageDefinitionExtractor.get()
        .extract(libraryDef, PipelineConfigBean.class, "Pipeline Config Definitions");
  }

  public static final StageDefinition RULES_DEFINITION = getRulesDefinition();

  static private StageDefinition getRulesDefinition() {
    StageLibraryDefinition libraryDef = new StageLibraryDefinition(
        Thread.currentThread().getContextClassLoader(),
        RULE_DEFINITIONS_LIB_DEFINITION,
        RULE_DEFINITIONS_LIB_DEFINITION,
        new Properties(),
        null,
        null,
        null
    );
    return StageDefinitionExtractor.get().extract(
        libraryDef,
        RuleDefinitionsConfigBean.class,
        "Rules Definitions Config Definitions"
    );
  }

  public static final StageDefinition FRAGMENT_DEFINITION = getFragmentDefinition();

  static private StageDefinition getFragmentDefinition() {
    StageLibraryDefinition libraryDef = new StageLibraryDefinition(
        Thread.currentThread().getContextClassLoader(),
        FRAGMENT_LIB_DEFINITION,
        FRAGMENT_LIB_DEFINITION,
        new Properties(),
        null,
        null,
        null
    );
    return StageDefinitionExtractor.get()
        .extract(libraryDef, PipelineFragmentConfigBean.class, "Fragment Config Definitions");
  }

  public PipelineConfigBean create(
      PipelineConfiguration pipelineConf,
      List<Issue> errors,
      Map<String, Object> runtimeParameters,
      String user,
      Map<String, ConnectionConfiguration> connections
  ) {
    int priorErrors = errors.size();
    PipelineConfigBean pipelineConfigBean = createPipelineConfigs(
        pipelineConf,
        errors,
        runtimeParameters,
        user,
        connections
    );
    return (errors.size() == priorErrors) ? pipelineConfigBean : null;
  }

  public RuleDefinitionsConfigBean createRuleDefinitionsConfigBean(
      RuleDefinitions ruleDefinitions,
      List<Issue> errors,
      Map<String, Object> runtimeParameters
  ) {
    RuleDefinitionsConfigBean ruleDefinitionsConfigBean = new RuleDefinitionsConfigBean();
    ConfigInjector.get().injectStage(
        ruleDefinitionsConfigBean,
        RULES_DEFINITION,
        getRulesConfAsStageConf(ruleDefinitions),
        runtimeParameters,
        null,
        null,
        errors
    );
    return ruleDefinitionsConfigBean;
  }

  public PipelineBean create(
      boolean forExecution,
      StageLibraryTask library,
      PipelineConfiguration pipelineConf,
      InterceptorCreatorContextBuilder interceptorContextBuilder,
      String user,
      Map<String, ConnectionConfiguration> connections,
      List<Issue> errors
  ) {
    return create(forExecution, library, pipelineConf, interceptorContextBuilder, errors, null, user, connections);
  }

  /**
   * Create PipelineBean which means instantiating all stages for the pipeline.
   *
   * For multi-threaded pipelines this method will *NOT* create all required instances since the number of required
   * instances is not known at the time of creation - for that the origin has to be initialized which is not at this
   * point. Hence this method will create only one instance of the whole pipeline and it's up to the caller to call
   * createPipelineStageBeans to instantiate remaining source-less pipelines later in the execution.
   */
  public PipelineBean create(
      boolean forExecution,
      StageLibraryTask library,
      PipelineConfiguration pipelineConf,
      InterceptorCreatorContextBuilder interceptorContextBuilder,
      List<Issue> errors,
      Map<String, Object> runtimeParameters,
      String user,
      Map<String, ConnectionConfiguration> connections
  ) {
    int priorErrors = errors.size();
    PipelineConfigBean pipelineConfigBean = create(pipelineConf, errors, runtimeParameters, user, connections);
    StageBean errorStageBean = null;
    StageBean statsStageBean = null;
    StageBean origin = null;
    PipelineStageBeans stages = null;
    PipelineStageBeans startEventBeans = null;
    PipelineStageBeans stopEventBeans = null;
    if (pipelineConfigBean != null && pipelineConfigBean.constants != null) {
      Map<String, Object> resolvedConstants = pipelineConfigBean.constants;
      if(interceptorContextBuilder != null) {
        interceptorContextBuilder
          .withExecutionMode(pipelineConfigBean.executionMode)
          .withDeliveryGuarantee(pipelineConfigBean.deliveryGuarantee)
        ;
      }

      // Instantiate usual stages
      if(!pipelineConf.getStages().isEmpty()) {
        origin = createStageBean(
            forExecution,
            library,
            pipelineConf.getStages().get(0),
            true,
            false,
            false,
            resolvedConstants,
            interceptorContextBuilder,
            user,
            connections,
            errors
        );

        stages = createPipelineStageBeans(
            forExecution,
            library,
            pipelineConf.getStages().subList(1, pipelineConf.getStages().size()),
            interceptorContextBuilder,
            resolvedConstants,
            user,
            connections,
            errors
        );
      }

      // It is not mandatory to have a stats aggregating target configured
      StageConfiguration statsStageConf = pipelineConf.getStatsAggregatorStage();
      if (statsStageConf != null) {
        statsStageBean = createStageBean(
            forExecution,
            library,
            statsStageConf,
            true,
            false,
            false,
            resolvedConstants,
            interceptorContextBuilder,
            user,
            connections,
            errors
        );
      }

      // Error stage is mandatory
      StageConfiguration errorStageConf = pipelineConf.getErrorStage();
      if (errorStageConf != null) {
        errorStageBean = createStageBean(
            forExecution,
            library,
            errorStageConf,
            true,
            true,
            false,
            resolvedConstants,
            interceptorContextBuilder,
            user,
            connections,
            errors
        );
      } else if (!(pipelineConfigBean.executionMode.equals(ExecutionMode.BATCH) ||
          pipelineConfigBean.executionMode.equals(ExecutionMode.STREAMING))) {
        errors.add(IssueCreator.getPipeline().create(
            PipelineGroups.BAD_RECORDS.name(),
            "badRecordsHandling",
            CreationError.CREATION_009
        ));
      }

      // Pipeline Lifecycle event handlers
      StageBean startBean = null;
      if(CollectionUtils.isNotEmpty(pipelineConf.getStartEventStages())) {
         startBean = createStageBean(
            forExecution,
            library,
            pipelineConf.getStartEventStages().get(0),
            true,
            false,
            true,
            resolvedConstants,
            interceptorContextBuilder,
            user,
            connections,
            errors
        );
      }
      startEventBeans = new PipelineStageBeans(startBean == null ? Collections.emptyList() : ImmutableList.of(startBean));
      StageBean stopBean = null;
      if(CollectionUtils.isNotEmpty(pipelineConf.getStopEventStages())) {
         stopBean = createStageBean(
            forExecution,
            library,
            pipelineConf.getStopEventStages().get(0),
            true,
            false,
            true,
            resolvedConstants,
            interceptorContextBuilder,
            user,
            connections,
            errors
        );
      }
      stopEventBeans = new PipelineStageBeans(stopBean == null ? Collections.emptyList() : ImmutableList.of(stopBean));

      // Validate Webhook Configs
      if (pipelineConfigBean.webhookConfigs != null && !pipelineConfigBean.webhookConfigs.isEmpty()) {
        int index = 0;
        for (PipelineWebhookConfig webhookConfig: pipelineConfigBean.webhookConfigs) {
          if (StringUtils.isEmpty(webhookConfig.webhookUrl)) {
            Issue issue = IssueCreator.getPipeline().create(
                PipelineGroups.NOTIFICATIONS.name(),
                "webhookUrl",
                CreationError.CREATION_080
            );
            issue.setAdditionalInfo("index", index);
            errors.add(issue);
            break;
          }
          index++;
        }
      }
    }

    // Something went wrong
    if(errors.size() != priorErrors) {
      return  null;
    }

    return new PipelineBean(
        pipelineConfigBean,
        origin,
        stages,
        errorStageBean,
        statsStageBean,
        startEventBeans,
        stopEventBeans
    );
  }

  private PipelineStageBeans createPipelineStageBeans(
    boolean forExecution,
    StageLibraryTask library,
    List<StageConfiguration> stageConfigurations,
    InterceptorCreatorContextBuilder interceptorContextBuilder,
    Map<String, Object> constants,
    String user,
    Map<String, ConnectionConfiguration> connections,
    List<Issue> errors
  ) {
    List<StageBean> stageBeans = new ArrayList<>(stageConfigurations.size());

    for (StageConfiguration stageConf : stageConfigurations) {
      StageBean stageBean = createStageBean(
          forExecution,
          library,
          stageConf,
          true,
          false,
          false,
          constants,
          interceptorContextBuilder,
          user,
          connections,
          errors
      );

      if (stageBean != null) {
        stageBeans.add(stageBean);
      }
    }

    return new PipelineStageBeans(stageBeans);
  }

  /**
   * Creates additional PipelineStageBeans for additional runners. Stages will share stage definition and thus
   * class loader with the first given runner. That includes stages with private class loader as well.
   *
   * @param pipelineStageBeans First runner that should be duplicated.
   * @param interceptorCreatorContextBuilder Builder for interceptor context
   * @param constants Pipeline constants
   * @param errors Any generated errors will be stored in this list
   *
   * @return PipelineStageBeans with new instances of the given stages
   */
  public PipelineStageBeans duplicatePipelineStageBeans(
    StageLibraryTask stageLib,
    PipelineStageBeans pipelineStageBeans,
    InterceptorCreatorContextBuilder interceptorCreatorContextBuilder,
    Map<String, Object> constants,
    String user,
    Map<String, ConnectionConfiguration> connections,
    List<Issue> errors
  ) {
    List<StageBean> stageBeans = new ArrayList<>(pipelineStageBeans.size());

    for(StageBean original: pipelineStageBeans.getStages()) {

      // Create StageDefinition map for this stage
      Map<Class, ServiceDefinition> services = original.getServices().stream()
        .collect(Collectors.toMap(c -> c.getDefinition().getProvides(), ServiceBean::getDefinition));

      StageBean stageBean = createStage(
          stageLib,
          original.getDefinition(),
          ClassLoaderReleaser.NOOP_RELEASER,
          original.getConfiguration(),
          services::get,
          interceptorCreatorContextBuilder,
          constants,
          user,
          connections,
          errors
      );

      if (stageBean != null) {
        stageBeans.add(stageBean);
      }
    }

    return new PipelineStageBeans(stageBeans);
  }

  public ExecutionMode getExecutionMode(PipelineFragmentConfiguration pipelineConf, List<Issue> errors) {
    ExecutionMode mode = null;
    String value = null;
    if (pipelineConf.getConfiguration("executionMode") != null) {
      if (pipelineConf.getConfiguration("executionMode").getValue() != null) {
        value = pipelineConf.getConfiguration("executionMode").getValue().toString();
      }
    }
    if (value != null) {
      try {
        mode = ExecutionMode.valueOf(value);
      } catch (IllegalArgumentException ex) {
        errors.add(IssueCreator.getPipeline().create("", "executionMode", CreationError.CREATION_070, value));
      }
    } else {
      errors.add(IssueCreator.getPipeline().create("", "executionMode", CreationError.CREATION_071));
    }
    return mode;
  }

  public SparkClusterType getClusterType(PipelineFragmentConfiguration pipelineConf, List<Issue> errors) {
    SparkClusterType clusterType = SparkClusterType.LOCAL;
    String value = null;
    if (pipelineConf.getConfiguration("clusterConfig.clusterType") != null) {
      if (pipelineConf.getConfiguration("clusterConfig.clusterType").getValue() != null) {
        value = pipelineConf.getConfiguration("clusterConfig.clusterType").getValue().toString();
      }
    }
    if (value != null) {
      try {
        clusterType = SparkClusterType.valueOf(value);
      } catch (IllegalArgumentException ex) {
        errors.add(IssueCreator.getPipeline().create(
            PipelineGroups.CLUSTER.name(),
            "clusterConfig.clusterType",
            CreationError.CREATION_1000,
            value
        ));
      }
    }
    return clusterType;
  }

  public String getMesosDispatcherURL(PipelineConfiguration pipelineConf) {
    String value = null;
    if (pipelineConf.getConfiguration("mesosDispatcherURL") != null) {
      value = pipelineConf.getConfiguration("mesosDispatcherURL").getValue().toString();
    }
    return value;
  }

  public String getHdfsS3ConfDirectory(PipelineConfiguration pipelineConf) {
    String value = null;
    if (pipelineConf.getConfiguration("hdfsS3ConfDir") != null) {
      value = pipelineConf.getConfiguration("hdfsS3ConfDir").getValue().toString();
    }
    return value;
  }

  /**
   * Create new instance of StageBean.
   *
   * This method can be used outside of pipeline context (for example for detached stage).
   *
   * @param forExecution If the instance is going to be used for execution (and for example private classloaders must be respected)
   * @param library Stage Library from which a definition will be loaded
   * @param stageConf Stage configuration
   * @param errorStage True if the stage needs to be declared as error stage
   * @param pipelineLifecycleStage True if the stage needs to be declared as pipeline lifecycle stage
   * @param constants Pipeline constants (runtime parameters)
   * @param user The user who is creating the pipeline
   * @param connections A map of Connections
   * @param errors List where all errors will be persisted
   * @return New StageBean instance or null on any error
   */
  public StageBean createStageBean(
      boolean forExecution,
      StageLibraryTask library,
      StageConfiguration stageConf,
      boolean validateAnnotations,
      boolean errorStage,
      boolean pipelineLifecycleStage,
      Map<String, Object> constants,
      InterceptorCreatorContextBuilder interceptorContextBuilder,
      String user,
      Map<String, ConnectionConfiguration> connections,
      List<Issue> errors
  ) {
    IssueCreator issueCreator = IssueCreator.getStage(stageConf.getInstanceName());
    StageBean bean = null;
    StageDefinition stageDef = library.getStage(stageConf.getLibrary(), stageConf.getStageName(),
                                                forExecution);
    if (stageDef != null) {
      // Pipeline lifecycle events validation must match, whether it's also marked as error stage does not matter
      if(validateAnnotations) {
        if (pipelineLifecycleStage) {
          if (!stageDef.isPipelineLifecycleStage()) {
            errors.add(issueCreator.create(
              CreationError.CREATION_018,
              stageDef.getLibraryLabel(),
              stageDef.getLabel(),
              stageConf.getStageVersion())
            );
          }
          // For non pipeline lifecycle stages, the error stage annotation must match
        } else if (stageDef.isErrorStage() != errorStage) {
          if (stageDef.isErrorStage()) {
            errors.add(issueCreator.create(CreationError.CREATION_007, stageDef.getLibraryLabel(), stageDef.getLabel(),
              stageConf.getStageVersion()));
          } else {
            errors.add(issueCreator.create(CreationError.CREATION_008, stageDef.getLibraryLabel(), stageDef.getLabel(),
              stageConf.getStageVersion()));
          }
        }
      }

      bean = createStage(
        library,
        stageDef,
        library,
        stageConf,
        serviceClass -> library.getServiceDefinition(serviceClass, true),
        interceptorContextBuilder,
        constants,
        user,
        connections,
        errors
      );
    } else {
      if(library.getLegacyStageLibs().contains(stageConf.getLibrary())) {
        errors.add(issueCreator.create(
          CreationError.CREATION_072,
          stageConf.getLibrary()
        ));
      } else {
        errors.add(issueCreator.create(
          CreationError.CREATION_006,
          stageConf.getLibrary(),
          stageConf.getStageName(),
          stageConf.getStageVersion()
        ));
      }
    }
    return bean;
  }

  @SuppressWarnings("unchecked")
  public static StageConfiguration getPipelineConfAsStageConf(PipelineFragmentConfiguration pipelineConf) {
    return new StageConfiguration(
        null,
        "none",
        "pipeline",
        pipelineConf.getVersion(),
        pipelineConf.getConfiguration(),
        Collections.emptyMap(),
        Collections.emptyList(),
        Collections.emptyList(),
        Collections.emptyList(),
        Collections.emptyList()
    );
  }

  @SuppressWarnings("unchecked")
  public static StageConfiguration getRulesConfAsStageConf(RuleDefinitions ruleDefinitions) {
    return new StageConfiguration(
        null,
        "none",
        "pipeline",
        ruleDefinitions.getVersion(),
        ruleDefinitions.getConfiguration() != null ? ruleDefinitions.getConfiguration() : Collections.emptyList(),
        Collections.emptyMap(),
        Collections.emptyList(),
        Collections.emptyList(),
        Collections.emptyList(),
        Collections.emptyList()
    );
  }

  @SuppressWarnings("unchecked")
  private PipelineConfigBean createPipelineConfigs(
      PipelineConfiguration pipelineConf,
      List<Issue> errors,
      Map<String, Object> runtimeParameters,
      String user,
      Map<String, ConnectionConfiguration> connections
  ) {
    PipelineConfigBean pipelineConfigBean = new PipelineConfigBean();
    StageConfiguration stageConf = getPipelineConfAsStageConf(pipelineConf);
    ConfigInjector.StageInjectorContext context = new ConfigInjector.StageInjectorContext(PIPELINE_DEFINITION,
        stageConf, runtimeParameters, user, connections, errors);
    if (ConfigInjector.get().createConfigBeans(
        pipelineConfigBean,
        "",
        context
    )) {

      // To support parameters in Pipeline Configuration inject "parameters" (constants) field first
      Config parametersConfigConf = stageConf.getConfig(PARAMETERS);
      ConfigDefinition parametersConfigDef = PIPELINE_DEFINITION.getConfigDefinitionsMap().get(PARAMETERS);
      if (parametersConfigConf != null) {
        try {
          ConfigInjector.get().injectConfigValue(
              pipelineConfigBean,
              PipelineConfigBean.class.getField(PARAMETERS),
              parametersConfigConf.getValue(),
              parametersConfigDef,
              new ConfigInjector.StageInjectorContext(context, Collections.EMPTY_MAP)
          );
        } catch (NoSuchFieldException ex) {
          IssueCreator issueCreator = IssueCreator.getStage(stageConf.getStageName());
          errors.add(issueCreator.create(CreationError.CREATION_000, "pipeline", parametersConfigDef.getLabel(), ex.toString()));
          pipelineConfigBean.constants = Collections.EMPTY_MAP;
        }
      }

      Map<String, Object> resolvedConstants = pipelineConfigBean.constants;

      if (pipelineConfigBean.constants == null) {
        pipelineConfigBean.constants = Collections.emptyMap();
        resolvedConstants = Collections.emptyMap();
      } else {
        // Merge constant and runtime Constants
        if (runtimeParameters != null) {
          for (String key: runtimeParameters.keySet()) {
            if (resolvedConstants.containsKey(key)) {
              resolvedConstants.put(key, runtimeParameters.get(key));
            }
          }
        }
      }

      ConfigInjector.get().injectConfigs(
          pipelineConfigBean,
          "",
          new ConfigInjector.StageInjectorContext(context, pipelineConfigBean.constants)
      );

      if (runtimeParameters != null) {
        pipelineConfigBean.constants = resolvedConstants;
      }
    }
    return pipelineConfigBean;
  }

  StageBean createStage(
      StageLibraryTask stageLib,
      StageDefinition stageDef,
      ClassLoaderReleaser classLoaderReleaser,
      StageConfiguration stageConf,
      Function<Class, ServiceDefinition> serviceDefinitionResolver,
      InterceptorCreatorContextBuilder interceptorContextBuilder,
      Map<String, Object> pipelineConstants,
      String user,
      Map<String, ConnectionConfiguration> connections,
      List<Issue> errors
  ) {
    Stage stage;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(stageDef.getStageClassLoader());
      stage = createStageInstance(stageDef, stageConf.getInstanceName(), errors);
      if (stage != null) {
        ConfigInjector.get().injectStage(stage,stageDef, stageConf, pipelineConstants, user, connections, errors);
      }
    } finally {
      Thread.currentThread().setContextClassLoader(classLoader);
    }
    StageConfigBean stageConfigBean = new StageConfigBean();
    ConfigInjector.get().injectStage(stageConfigBean, stageDef, stageConf, pipelineConstants, user, connections, errors);

    // Create services
    List<ServiceBean> services = new ArrayList<>();
    for(ServiceConfiguration serviceConf : stageConf.getServices()) {
      ServiceDefinition serviceDef = serviceDefinitionResolver.apply(serviceConf.getService());

      ServiceBean serviceBean = createService(
        stageConf.getInstanceName(),
        serviceDef,
        classLoaderReleaser,
        serviceConf,
        pipelineConstants,
        user,
        connections,
        errors
      );

      if(serviceBean != null) {
        services.add(serviceBean);
      }
    }

    if(!errors.isEmpty()) {
      return null;
    }

    return new StageBean(
      stageDef,
      stageConf,
      stageConfigBean,
      stage,
      classLoaderReleaser,
      services,
      createInterceptors(stageLib, stageConf, stageDef, interceptorContextBuilder, InterceptorCreator.InterceptorType.PRE_STAGE, errors),
      createInterceptors(stageLib, stageConf, stageDef, interceptorContextBuilder, InterceptorCreator.InterceptorType.POST_STAGE, errors)
    );
  }

  private Stage createStageInstance(StageDefinition stageDef, String stageName, List<Issue> errors) {
    Stage stage = null;
    try {
      stage = stageDef.getStageClass().newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
      IssueCreator issueCreator = IssueCreator.getStage(stageName);
      errors.add(issueCreator.create(CreationError.CREATION_000, "stage", stageDef.getLabel(), ex.toString()));
    }
    return stage;
  }

  ServiceBean createService(
      String stageName,
      ServiceDefinition serviceDef,
      ClassLoaderReleaser classLoaderReleaser,
      ServiceConfiguration serviceConf,
      Map<String, Object> pipelineConstants,
      String user,
      Map<String, ConnectionConfiguration> connections,
      List<Issue> errors
  ) {
    Utils.checkNotNull(serviceDef, "ServiceDefinition for " + serviceConf.getService().getName());
    Service service;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(serviceDef.getStageClassLoader());
      service = createServiceInstance(stageName, serviceDef, errors);
      if (service != null) {
        ConfigInjector.get().injectService(
            service,
            stageName,
            serviceDef,
            serviceConf,
            pipelineConstants,
            user,
            connections,
            errors
        );
      }
    } finally {
      Thread.currentThread().setContextClassLoader(classLoader);
    }
    return (errors.isEmpty()) ? new ServiceBean(serviceDef, serviceConf, service, classLoaderReleaser) : null;
  }

  private Service createServiceInstance(String stageName, ServiceDefinition serviceDef, List<Issue> errors) {
    Service service = null;
    try {
      service = serviceDef.getKlass().newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
      IssueCreator issueCreator = IssueCreator.getService(stageName, serviceDef.getKlass().getName());
      errors.add(issueCreator.create(CreationError.CREATION_000, "service", serviceDef.getKlass().getName(), ex.toString()));
    }
    return service;
  }

  /**
   * Create interceptors for given stage.
   */
  public List<InterceptorBean> createInterceptors(
    StageLibraryTask stageLib,
    StageConfiguration stageConfiguration,
    StageDefinition stageDefinition,
    InterceptorCreatorContextBuilder contextBuilder,
    InterceptorCreator.InterceptorType interceptorType,
    List<Issue> issues
  ) {
    List<InterceptorBean> beans = new ArrayList<>();
    if(contextBuilder == null) {
      return beans;
    }

    for(InterceptorDefinition definition : stageLib.getInterceptorDefinitions()) {
      InterceptorBean bean = createInterceptor(stageLib, definition, stageConfiguration, stageDefinition, contextBuilder, interceptorType, issues);
      if (bean != null) {
        beans.add(bean);
      }
    }

    return beans;
  }

  /**
   * Create a default interceptor for given InterceptorDefinition. This method might
   * return null as the underlying interface for default creation allows it as well -
   * in such case no interceptor is needed.
   */
  public InterceptorBean createInterceptor(
    StageLibraryTask stageLib,
    InterceptorDefinition definition,
    StageConfiguration stageConfiguration,
    StageDefinition stageDefinition,
    InterceptorCreatorContextBuilder contextBuilder,
    InterceptorCreator.InterceptorType interceptorType,
    List<Issue> issues
  ) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InterceptorCreator.Context context = contextBuilder.buildFor(
      definition.getLibraryDefinition().getName(),
      definition.getKlass().getName(),
      stageConfiguration,
      stageDefinition,
      interceptorType
    );

    try {
      Thread.currentThread().setContextClassLoader(definition.getStageClassLoader());
      InterceptorCreator creator = definition.getDefaultCreator().newInstance();
      Interceptor interceptor = creator.create(context);

      if(interceptor == null) {
        return null;
      }

      return new InterceptorBean(
        definition,
        interceptor,
        stageLib
      );
    } catch (IllegalAccessException|InstantiationException e) {
      LOG.debug("Can't instantiate interceptor: {}", e.toString(), e);
      IssueCreator issueCreator = IssueCreator.getStage(stageDefinition.getName());
      issues.add(issueCreator.create(
        CreationError.CREATION_000, "interceptor", definition.getKlass().getName(), e.toString()
      ));
    } finally {
      Thread.currentThread().setContextClassLoader(classLoader);
    }

    return null;
  }

}


text:
use bitflags::bitflags;

// Checks for possible errors caused by overriding names used by `bitflags!` internally.

mod core {}
mod _core {}

bitflags! {
    struct Test: u8 {
        const A = 1;
    }
}

fn main() {}

redpajama_set_name: RedPajamaGithub


text:
<?php
/**
 * TOP API: taobao.sp.content.detail.get request
 *
 * @author auto create
 * @since 1.0, 2014-09-13 16:51:05
 */
class SpContentDetailGetRequest
{
	/**
	 * 内容的主键ID
	 **/
	private $id;

	/**
	 * 站长Key
 支持最大长度为:32
 支持的最大列表长度为:32
	 **/
	private $siteKey;

	private $apiParas = array();

	public function setId($id)
	{
		$this->id = $id;
		$this->apiParas["id"] = $id;
	}

	public function getId()
	{
		return $this->id;
	}

	public function setSiteKey($siteKey)
	{
		$this->siteKey = $siteKey;
		$this->apiParas["site_key"] = $siteKey;
	}

	public function getSiteKey()
	{
		return $this->siteKey;
	}

	public function getApiMethodName()
	{
		return "taobao.sp.content.detail.get";
	}

	public function getApiParas()
	{
		return $this->apiParas;
	}

	public function check()
	{

		RequestCheckUtil::checkNotNull($this->id,"id");
		RequestCheckUtil::checkNotNull($this->siteKey,"siteKey");
		RequestCheckUtil::checkMaxLength($this->siteKey,32,"siteKey");
	}

	public function putOtherTextParam($key, $value) {
		$this->apiParas[$key] = $value;
		$this->$key = $value;
	}
}


text:
module Paperclip
  module Meta
    if defined? ::Rails::Railtie
      class Railtie < ::Rails::Railtie
        initializer :paperclip_meta do
          ActiveSupport.on_load :active_record do
            Paperclip::Meta::Railtie.insert
          end
        end
      end
    end

    class Railtie
      def self.insert
        Paperclip::Attachment.prepend Paperclip::Meta::Attachment
      end
    end
  end
end


text:
title: Michael Colombo
summary: Writer, fabricator, musician
date: 2016-12-09
categories:
- artist
- designer
- hacker
- musician
- writer
---

### Who are you, and what do you do?

I'm Michael Colombo. I'm a writer, fabricator, and musician. I was a full-time blogger for MAKE Magazine, have done technical writing and documentation, and instructional design work. I also do construction, carpentry, home renovation, physical electronic interfaces, interactive art installations, and one-off musical instruments. I find myself performing music in unexpected situations, and doing some sound design work. I'm also an occasional visual artist and designer.

### What hardware do you use?

[15" MacBook Pro][macbook-pro], Uniball pens, Leuchterm notebooks. Makita circular saw, Milwaukee drills and drivers, Bosch jigsaw, Weller soldering station, ['64 Gibson EB-O bass][eb-0] (think Jack Bruce from Cream), Bach Omega Bb trumpet, [Roland VS-1680 digital recorder][vs-1680], [Epiphone PR5-E acoustic guitar][pr5-e] (the same one Courtney Love plays on Hole Unplugged).

### And what software?

[Arduino][arduino-ide], [Google Docs][google-docs], [Audacity][], [Long Exposure Camera][long-exposure-camera-android] (seriously the best weirdo low-rent app I've ever used), [GIMP][], [Switch][], [Handbrake][], [Serato][serato-dj], [Storyline][storyline-360], [SketchUp][], [Logic Pro][logic-pro] and [Final Cut Pro][final-cut-pro].

### What would be your dream setup?

I'm content with my writing setup already, but I'd like a full workshop for woodworking, plus a TIG welding station, CNC, laser cutter, 3D printer, lathes, and an electronics lab with oscilloscope, bench power supply, and every component imaginable on hand.

Oh, and a bangin' recording studio with tons of instruments, amps, mics, and an old Neotek mixing desk.

[arduino-ide]: https://www.arduino.cc/en/Main/Software "A development environment for Arduino hardware."
[audacity]: https://sourceforge.net/projects/audacity/ "An open-source, cross-platform audio editor."
[eb-0]: https://en.wikipedia.org/wiki/Gibson_EB-0 "A bass guitar."
[final-cut-pro]: https://en.wikipedia.org/wiki/Final_Cut_Pro "A nonlinear video editor."
[gimp]: https://www.gimp.org/ "An open-source image editor."
[google-docs]: https://en.wikipedia.org/wiki/Google_Docs "A web-based office suite."
[handbrake]: https://handbrake.fr/ "Cross-platform, open source video encoding software."
[logic-pro]: https://www.apple.com/logic-pro/ "A professional audio application for the Mac."
[long-exposure-camera-android]: https://play.google.com/store/apps/details?id=com.longexposure2 "An app for taking long exposure photos."
[macbook-pro]: https://www.apple.com/macbook-pro/ "A laptop."
[pr5-e]: http://www.epiphone.com/Products/Acoustic-Electric/PR-5E.aspx "An acoustic guitar."
[serato-dj]: https://serato.com/dj "DJing software."
[sketchup]: https://www.sketchup.com/ "3D modeling software."
[storyline-360]: https://articulate.com/360/storyline "Course publishing software."
[switch]: https://www.nch.com.au/switch/mp3.html "MP3 conversion software."
[vs-1680]: https://www.roland.com/us/products/vs-1680/ "A 16-track audio workstation."


text:
package controller;

import domain.Artista;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import service.ArtistaService;

import java.util.ArrayList;
import java.util.Collection;

@Controller
public class ArtistaController {

	@Autowired
	ArtistaService artistaService;

	@RequestMapping(value = "/artista", method = RequestMethod.POST)
	String savePerson(@ModelAttribute Artista person, ModelMap model) {
		System.out.println("savving: " + person.getId());
		System.out.println("nombre "+ person.getName());
		artistaService.save(person);
		return showPerson(person.getName(), model);
	}
	@RequestMapping(value = "/add-artista", method = RequestMethod.GET)
	String addNewPerson(@RequestParam(required = false) Long id, ModelMap model) {
		Artista person = id == null ? new Artista() : artistaService.get(id);
		model.addAttribute("artista", person);
		return "add-artista";
	}

	@RequestMapping(value = "/artista", method = RequestMethod.GET)
	String showPerson(@RequestParam(required = false) String filter, ModelMap model) {
		Collection<Artista> artistas;
		if (filter != null) {
			artistas = new ArrayList<>();
			artistas.add(artistaService.searchByName(filter));
		} else {
			artistas = artistaService.getAll();
		}
			model.addAttribute("Artista", artistas);
			return "artista";
	}
	@RequestMapping(value = "/", method = RequestMethod.GET)
	String home(ModelMap model) {
		return "home";
	}

	@RequestMapping(value = "/search-artista", method = RequestMethod.GET)
	String searchNewartistIndex(String name, ModelMap model) {
		return "search-artista";
	}

	@RequestMapping(value = "/update-artista", method = RequestMethod.GET)
	String updateArtist(Long id, ModelMap model) {
		Artista artista = artistaService.get(id);
		model.addAttribute("id", artista.getId());
		model.addAttribute("name", artista.getName());
		model.addAttribute("genero", artista.getGenero());
		model.addAttribute("ciudad", artista.getCiudad());
		model.addAttribute("pais", artista.getPais());

		return "update-artista";
	}

	@RequestMapping(value = "/update-artista", method = RequestMethod.POST)
	String updateArtistaAction(Long id, String name, String genero, String ciudad, String pais, ModelMap model) {
		Artista artista = artistaService.get(id);
		artista.setName(name);
		artista.setCiudad(ciudad);
		artista.setPais(pais);
		artista.setGenero(genero);

		return "artista";
	}

	@RequestMapping(value = "/search-artista", method = RequestMethod.POST)
	String searchNewartist(String name, ModelMap model) {
		Collection<Artista> artistas;
		artistas = new ArrayList<>();
		artistas.add(artistaService.searchByName(name));
		model.addAttribute("Artista", artistas);
		return "artista";
	}

}


text: Startup Weekend Cedar Rapids 2015


text:
using namespace Coffee;

bool sysinfo_printing()
{
    cDebug("Device name: {0}", SysInfo::DeviceName());

    cDebug("System memory: {0:1}MB", SysInfo::MemTotal() / CMath::pow(1024, 2));
    cDebug(
        "Available system memory: {0:1}MB",
        SysInfo::MemAvailable() / CMath::pow(1024, 2));

    cDebug("Processor info: {0}", SysInfo::Processor());
    cDebug("Frequency: {0:2}GHz", SysInfo::ProcessorFrequency());
    cDebug("Hyper-threading: {0}", SysInfo::HasHyperThreading());
    cDebug("FPU: {0}", SysInfo::HasFPU());
    cDebug("CPUs: {0}", SysInfo::CpuCount());
    cDebug("Cores: {0}", SysInfo::CoreCount());
    cDebug("Threads: {0}", SysInfo::ThreadCount());
    cDebug("Processor cache: {0}", SysInfo::ProcessorCacheSize());

    cDebug("CPU temperature: {0}", PowerInfo::CpuTemperature().current);

    Profiler::Profile("Get system data");

    return true;
}

COFFEE_TESTS_BEGIN(1)

    {sysinfo_printing, "Basic SysInfo information"}

COFFEE_TESTS_END()


text:
package io.cdep.cdep.io;

import static io.cdep.cdep.utils.StringUtils.safeFormat;
import static org.fusesource.jansi.Ansi.Attribute.INTENSITY_FAINT;
import static org.fusesource.jansi.Ansi.Color.GREEN;
import static org.fusesource.jansi.Ansi.Color.RED;
import static org.fusesource.jansi.Ansi.Color.WHITE;
import static org.fusesource.jansi.Ansi.ansi;

import io.cdep.annotations.NotNull;
import io.cdep.cdep.utils.HashUtils;
import java.io.IOException;
import java.io.PrintStream;
import java.security.NoSuchAlgorithmException;
import org.fusesource.jansi.AnsiConsole;

/**
 * Methods for dealing with command-line IO, messages, errors, etc.
 */
public class IO {
  final private static IO io = new IO();
  private PrintStream out = AnsiConsole.out;
  private PrintStream err = AnsiConsole.err;
  private boolean ansi = true;

  /**
   * Set the out stream and return the prior out stream.
   */
  public static PrintStream setOut(PrintStream out) {
    PrintStream original = io.out;
    io.out = out;
    return original;
  }

  /**
   * Set the error stream and return the prior out stream.
   */
  public static PrintStream setErr(PrintStream err) {
    PrintStream original = io.err;
    io.err = err;
    return original;
  }

  /**
   * Whether or not streams support ansi codes
   */
  public static void setAnsi(boolean ansi) {
    io.ansi = ansi;
  }

  /**
   * Print an info message.
   */
  public static void info(@NotNull String format, Object... args) {
    io.infoImpl(format, args);
  }

  /**
   * Print an info message.
   */
  public static void infogreen(@NotNull String format, Object... args) {
    io.infogreenImpl(format, args);
  }
  /**
   * Print an info message with a line-feed.
   */
  public static void infoln(Object format, Object... args) {
    io.infoImpl(format + "\n", args);
  }

  /**
   * Print an info message with a line-feed.
   */
  public static void errorln(String format, Object... args) {
    io.errorImpl(format, args);
  }

  private void infoImpl(@NotNull String format, Object... args) {
    if (ansi) {
      out.print(ansi().a(INTENSITY_FAINT).fg(WHITE).a(safeFormat(format, args)).reset());
    } else {
      out.print(safeFormat(format, args));
    }
  }

  private void errorImpl(String format, Object... args) {
    // Create a code that is fairly unique for this error message
    String code;
    try {
      code = HashUtils.getSHA256OfString(format).substring(0, 7);
    } catch (NoSuchAlgorithmException e) {
      code = "no-algo";
    } catch (IOException e) {
      code = "io-failed";
    }
    String prefix = String.format("FAILURE (%s): ", code);
    if (ansi) {
      err.print(ansi().fg(RED).a(prefix).a(safeFormat(format, args)).a("\n").reset());
    } else {
      err.printf(prefix);
      err.print(safeFormat(format, args));
      err.printf("\n");
    }
  }

  private void infogreenImpl(@NotNull String format, Object... args) {
    if (ansi) {
      out.print(ansi().a(INTENSITY_FAINT).fg(GREEN).a(safeFormat(format, args)).reset());
    } else {
      out.print(safeFormat(format, args));
    }
  }
}


text:
require 'rubygems'

require 'simplecov'
require 'coveralls'
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
SimpleCov.start do
  add_filter 'spec'
end

require 'vcr'
VCR.configure do |c|
  c.cassette_library_dir = 'spec/cassettes'
  c.hook_into :faraday
  c.configure_rspec_metadata!
end

require 'rspec'
require 'faraday'

Dir['./spec/support/**/*.rb'].sort.each { |f| require f}
require File.dirname(__FILE__) + '/../lib/whos_got_dirt'


text:
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SignatureCapture.Demo
{
	public partial class SignatureCaptureViewController : UIViewController
	{
		static bool UserInterfaceIdiomIsPhone {
			get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
		}

		public SignatureCaptureViewController ()
			: base (UserInterfaceIdiomIsPhone ? "SignatureCaptureViewController_iPhone" : "SignatureCaptureViewController_iPad", null)
		{
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var signature = new UISignatureView (this.SignatureView.Frame);
			signature.StrokeWidth = 2;
			signature.BackgroundColor = UIColor.Gray;

			this.View.AddSubview (signature);

			// clears the signature
			this.ClearButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				signature.ClearSignature();
			};

			// shows/hides shadow
			this.ShowShadowButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.ShowShadowButton.CurrentTitle.Contains("Hide"))
				{
					signature.ShowShadow = false;
					SetButtonText(this.ShowShadowButton, "Show Shadow");
				}
				else
				{
					signature.ShowShadow = true;
					SetButtonText(this.ShowShadowButton, "Hide Shadow");
				}
			};

			// sets shadow color
			this.SetShadowColorButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.SetShadowColorButton.CurrentTitle.Contains("Green"))
				{
					signature.ShadowColor = UIColor.Green;
					SetButtonText(this.SetShadowColorButton, "Set Shadow Color To Black");
				}
				else
				{
					signature.ShadowColor = UIColor.Black;
					SetButtonText(this.SetShadowColorButton, "Set Shadow Color To Green");
				}
			};

			// sets stroke color of the signature
			this.SetStrokeColorButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.SetStrokeColorButton.CurrentTitle.Contains("Red"))
				{
					signature.StrokeColor = UIColor.Red;
					SetButtonText(this.SetStrokeColorButton, "Set Stroke Color To Black");
				}
				else
				{
					signature.StrokeColor = UIColor.Black;
					SetButtonText(this.SetStrokeColorButton, "Set Stroke Color To Red");
				}
			};

			// sets stroke width of the signature lines
			this.SetStrokeWidthButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.SetStrokeWidthButton.CurrentTitle.Contains("10"))
				{
					signature.StrokeWidth = 10;
					SetButtonText(this.SetStrokeWidthButton, "Set Stroke Width to 2");
				}
				else
				{
					signature.StrokeWidth = 2;
					SetButtonText(this.SetStrokeWidthButton, "Set Stroke Width to 10");
				}
			};

			// sets background color of the signature view
			this.SetBackgroundColorButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.SetBackgroundColorButton.CurrentTitle.Contains("Black"))
				{
					signature.ViewBackgroundColor = UIColor.Black;
					SetButtonText(this.SetBackgroundColorButton, "Set View Background To Grey");
				}
				else
				{
					signature.ViewBackgroundColor = UIColor.Gray;
					SetButtonText(this.SetBackgroundColorButton, "Set View Background To Black");
				}
			};

			// sets the color of the text of the UI elements on the signature view
			this.SetTextColorButton.TouchUpInside += (object sender, EventArgs e) =>
			{
				if (this.SetTextColorButton.CurrentTitle.Contains("Blue"))
				{
					signature.TextColor = UIColor.Blue;
					SetButtonText(this.SetTextColorButton, "Set Text Color To Black");
				}
				else
				{
					signature.TextColor = UIColor.Black;
					SetButtonText(this.SetTextColorButton, "Set Text Color To Blue");
				}
			};
		}

		private void SetButtonText(UIButton button, string text)
		{
			button.SetTitle (text, UIControlState.Normal);
		}
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Module: PowerVMTools</title>

  <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />

          Home
          Classes
          Methods

In Files

lib/nim.rb

lib/hmc.rb

lib/error.rb

lib/common.rb

lib/lpar.rb

lib/vios.rb

lib/frame.rb

Namespace

MODULE PowerVMTools::Common

MODULE PowerVMTools::Error

CLASS PowerVMTools::Frame

CLASS PowerVMTools::HMC

CLASS PowerVMTools::Lpar

CLASS PowerVMTools::NIM

CLASS PowerVMTools::Vios

Files

LICENSE

Class/Module Index

        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

PowerVMTools

PowerVMTools::Common

PowerVMTools::Error

PowerVMTools::Error::CustomError

PowerVMTools::Error::PowerStateError

PowerVMTools::Frame

PowerVMTools::HMC

PowerVMTools::Lpar

PowerVMTools::NIM

PowerVMTools::Vios

No matching classes.

PowerVMTools

[Validate]

Generated with the Darkfish
      Rdoc Generator 2.


text:
<!DOCTYPE html>
<meta charset="utf-8">

<link rel="stylesheet" type="text/css" href="year.css" media="screen" />

TripAdvisor Annual Mean Rating (Zoom on y-axis)

Local Reviewers

<button id="button_ratings_tripadvisor_year" onclick="update_data_tripadvisor()">Click to Change Local vs. Non-local</button>


text:
"""
dropbox/__init__.py

Created by Maximillian Dornseif on 2011-02-06.
Copyright (c) 2011 HUDORA. All rights reserved.
BSD-licensed
"""

def get_dropbox_client(consumer_key, consumer_secret, access_token_key, access_token_secret):
    """Gibt ein vorkonfiguriertes Dropbox Client Object zurück.

        db_client = dropbox.get_dropbox_client(consumer_key='wj123',
                                               consumer_secret='ph123',
                                               access_token='oauth_token_secret=xe123&oauth_token=1w123')
    """
    # Lazy Import
    from dropbox import session
    from dropbox import client

    session = session.DropboxSession(consumer_key, consumer_secret, 'dropbox')
    session.set_token(access_token_key, access_token_secret)
    return client.DropboxClient(session)


text:
require 'test_helper'

class VacationRequestTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
end


text:
import copy
from mock import Mock
from tests.unit import unittest

from boto.auth import QueryAuthHandler
from boto.connection import HTTPRequest

class TestQueryAuthHandler(unittest.TestCase):
    def setUp(self):
        self.provider = Mock()
        self.provider.access_key = 'access_key'
        self.provider.secret_key = 'secret_key'
        self.request = HTTPRequest(
            method='GET',
            protocol='https',
            host='sts.amazonaws.com',
            port=443,
            path='/',
            auth_path=None,
            params={
                'Action': 'AssumeRoleWithWebIdentity',
                'Version': '2011-06-15',
                'RoleSessionName': 'web-identity-federation',
                'ProviderId': '2012-06-01',
                'WebIdentityToken': 'Atza|IQEBLjAsAhRkcxQ',
            },
            headers={},
            body=''
        )

    def test_escape_value(self):
        auth = QueryAuthHandler('sts.amazonaws.com',
                                 Mock(), self.provider)
        # This should **NOT** get escaped.
        value = auth._escape_value('Atza|IQEBLjAsAhRkcxQ')
        self.assertEqual(value, 'Atza|IQEBLjAsAhRkcxQ')

    def test_build_query_string(self):
        auth = QueryAuthHandler('sts.amazonaws.com',
                                 Mock(), self.provider)
        query_string = auth._build_query_string(self.request.params)
        self.assertEqual(query_string, 'Action=AssumeRoleWithWebIdentity' + \
            '&ProviderId=2012-06-01&RoleSessionName=web-identity-federation' + \
            '&Version=2011-06-15&WebIdentityToken=Atza|IQEBLjAsAhRkcxQ')

    def test_add_auth(self):
        auth = QueryAuthHandler('sts.amazonaws.com',
                                 Mock(), self.provider)
        req = copy.copy(self.request)
        auth.add_auth(req)
        self.assertEqual(req.path,
            '/?Action=AssumeRoleWithWebIdentity' + \
            '&ProviderId=2012-06-01&RoleSessionName=web-identity-federation' + \
            '&Version=2011-06-15&WebIdentityToken=Atza|IQEBLjAsAhRkcxQ')


text:
import React from 'react';
import { isNil } from 'lodash';
import { styled, t } from '@superset-ui/core';
import { css } from '@emotion/react';
import {
  Modal as AntdModal,
  ModalProps as AntdModalProps,
} from 'src/common/components';
import Button from 'src/components/Button';

export interface ModalProps {
  className?: string;
  children: React.ReactNode;
  disablePrimaryButton?: boolean;
  onHide: () => void;
  onHandledPrimaryAction?: () => void;
  primaryButtonName?: string;
  primaryButtonType?: 'primary' | 'danger';
  show: boolean;
  name?: string;
  title: React.ReactNode;
  width?: string;
  maxWidth?: string;
  responsive?: boolean;
  hideFooter?: boolean;
  centered?: boolean;
  footer?: React.ReactNode;
  wrapProps?: object;
  height?: string;
  closable?: boolean;
}

interface StyledModalProps {
  maxWidth?: string;
  responsive?: boolean;
  height?: string;
  hideFooter?: boolean;
}

const BaseModal = (props: AntdModalProps) => (
  // Removes mask animation. Fixed in 4.6.0.
  // https://github.com/ant-design/ant-design/issues/27192
  <AntdModal {...props} maskTransitionName="" />
);

export const StyledModal = styled(BaseModal)<StyledModalProps>`
  ${({ theme, responsive, maxWidth }) =>
    responsive &&
    css`
      max-width: ${maxWidth ?? '900px'};
      padding-left: ${theme.gridUnit * 3}px;
      padding-right: ${theme.gridUnit * 3}px;
    `}

  .ant-modal-header {
    background-color: ${({ theme }) => theme.colors.grayscale.light4};
    border-radius: ${({ theme }) => theme.borderRadius}px
      ${({ theme }) => theme.borderRadius}px 0 0;
    padding-left: ${({ theme }) => theme.gridUnit * 4}px;
    padding-right: ${({ theme }) => theme.gridUnit * 4}px;

    .ant-modal-title h4 {
      display: flex;
      margin: 0;
      align-items: center;
    }
  }

  .ant-modal-close-x {
    display: flex;
    align-items: center;

    .close {
      flex: 1 1 auto;
      margin-bottom: ${({ theme }) => theme.gridUnit}px;
      color: ${({ theme }) => theme.colors.secondary.dark1};
      font-size: 32px;
      font-weight: ${({ theme }) => theme.typography.weights.light};
    }
  }

  .ant-modal-body {
    padding: ${({ theme }) => theme.gridUnit * 4}px;
    overflow: auto;
    ${({ height }) => height && `height: ${height};`}
  }

  .ant-modal-footer {
    border-top: ${({ theme }) => theme.gridUnit / 4}px solid
      ${({ theme }) => theme.colors.grayscale.light2};
    padding: ${({ theme }) => theme.gridUnit * 4}px;

    .btn {
      font-size: 12px;
      text-transform: uppercase;
    }

    .btn + .btn {
      margin-left: ${({ theme }) => theme.gridUnit * 2}px;
    }
  }

  // styling for Tabs component
  // Aaron note 20-11-19: this seems to be exclusively here for the Edit Database modal.
  // TODO: remove this as it is a special case.
  .ant-tabs-top {
    margin-top: -${({ theme }) => theme.gridUnit * 4}px;
  }

  &.no-content-padding .ant-modal-body {
    padding: 0;
  }
`;

const CustomModal = ({
  children,
  disablePrimaryButton = false,
  onHide,
  onHandledPrimaryAction,
  primaryButtonName = t('OK'),
  primaryButtonType = 'primary',
  show,
  name,
  title,
  width,
  maxWidth,
  responsive = false,
  centered,
  footer,
  hideFooter,
  wrapProps,
  ...rest
}: ModalProps) => {
  const modalFooter = isNil(footer)
    ? [
        <Button key="back" onClick={onHide} cta data-test="modal-cancel-button">
          {t('Cancel')}
        </Button>,
        <Button
          key="submit"
          buttonStyle={primaryButtonType}
          disabled={disablePrimaryButton}
          onClick={onHandledPrimaryAction}
          cta
          data-test="modal-confirm-button"
        >
          {primaryButtonName}
        </Button>,
      ]
    : footer;

  const modalWidth = width || (responsive ? '100vw' : '600px');
  return (
    <StyledModal
      centered={!!centered}
      onOk={onHandledPrimaryAction}
      onCancel={onHide}
      width={modalWidth}
      maxWidth={maxWidth}
      responsive={responsive}
      visible={show}
      title={title}
      closeIcon={
        <span className="close" aria-hidden="true">
          ×
        </span>
      }
      footer={!hideFooter ? modalFooter : null}
      wrapProps={{ 'data-test': `${name || title}-modal`, ...wrapProps }}
      {...rest}
    >
      {children}
    </StyledModal>
  );
};
CustomModal.displayName = 'Modal';

// TODO: in another PR, rename this to CompatabilityModal
// and demote it as the default export.
// We should start using AntD component interfaces going forward.
const Modal = Object.assign(CustomModal, {
  error: AntdModal.error,
  warning: AntdModal.warning,
  confirm: AntdModal.confirm,
  useModal: AntdModal.useModal,
});

export default Modal;


text:
<?php

/**
 * Fixture class for the default session configuration
 *
 * @package       Cake.Test.Fixture
 */
class CakeSessionFixture extends CakeTestFixture {

/**
 * name property
 *
 * @var string
 */
	public $name = 'CakeSession';

/**
 * fields property
 *
 * @var array
 */
	public $fields = array(
		'id' => array('type' => 'string', 'length' => 128, 'key' => 'primary'),
		'data' => array('type' => 'text', 'null' => true),
		'expires' => array('type' => 'integer', 'length' => 11, 'null' => true)
	);

/**
 * records property
 *
 * @var array
 */
	public $records = array();
}


text:
import keyOf from '../src/keyOf';
import {isChainableAndUndefinedOK} from './helpers.js';

describe('keyOf', function() {
  const obj = {'foo': 1};
  function validate(prop) {
    return keyOf(obj)({p: prop}, 'p', 'Component');
  }

  isChainableAndUndefinedOK(keyOf(obj));

  it('Should return error with non-key values', function() {
    const err = validate('bar');
    assert.instanceOf(err, Error);
    assert.include(err.message, 'expected one of ["foo"]');
  });

  it('Should validate OK with key values', function() {
    assert.isUndefined(validate('foo'));
    obj.bar = 2;
    assert.isUndefined(validate('bar'));
  });
});


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">

<meta name="generator" content="JDiff v1.0.9">

<meta name="description" content="JDiff is a Javadoc doclet which generates an HTML report of all the packages, classes, constructors, methods, and fields which have been removed, added or changed in any way, including their documentation, when two APIs are compared.">
<meta name="keywords" content="diff, jdiff, javadiff, java diff, java difference, API difference, difference between two APIs, API diff, Javadoc, doclet">
<TITLE>
org.apache.hadoop.mapred.OutputCommitter
</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="../stylesheet-jdiff.css" TITLE="Style">

       <tt>hadoop 0.20.2-cdh3u4</tt>
       Overview
       Package
        Class
       Statistics
       Help

  Generated by
JDiff

 PREV CLASS
 NEXT CLASS

  FRAMES
   NO FRAMES
   DETAIL:
CONSTRUCTORS |
METHODS |
FIELDS

Class org.apache.hadoop.mapred.<tt>OutputCommitter</tt>

The superclass changed from java.lang.Object to org.apache.hadoop.mapreduce.OutputCommitter.

  Added Methods

  <nobr>void <tt>abortJob</tt>(JobContext,</nobr> int<nobr><nobr>)</nobr>

  For cleaning up the job's output after job failure.

  <nobr>void <tt>abortJob</tt>(JobContext,</nobr> State<nobr><nobr>)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>abortTask</tt>(TaskAttemptContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>cleanupJob</tt>(JobContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>commitJob</tt>(JobContext)</nobr>

  For committing job's output after successful job completion.

  <nobr>void <tt>commitJob</tt>(JobContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>commitTask</tt>(TaskAttemptContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>boolean <tt>needsTaskCommit</tt>(TaskAttemptContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>setupJob</tt>(JobContext)</nobr>

  This method implements the new interface by calling the old method.

  <nobr>void <tt>setupTask</tt>(TaskAttemptContext)</nobr>

  This method implements the new interface by calling the old method.

  Changed Methods

  <nobr>void <tt>cleanupJob</tt>(JobContext)  </nobr>

Changed from abstract to non-abstract. Now deprecated.

  use {@link #commitJob(JobContext)} or                  {@link #abortJob(JobContext, int)} instead

       <tt>hadoop 0.20.2-cdh3u4</tt>
       Overview
       Package
        Class
       Statistics
       Help

 PREV CLASS
 NEXT CLASS

  FRAMES
   NO FRAMES