<commit_before>/*******************************************************************************
 * Copyright (c) 2013 GigaSpaces Technologies Ltd. All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package org.cloudifysource.cosmo.manager.config;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Charsets;
import com.google.common.collect.Maps;
import com.google.common.io.Resources;
import org.cloudifysource.cosmo.orchestrator.workflow.RuoteRuntime;
import org.cloudifysource.cosmo.orchestrator.workflow.ruote.RuoteRadialVariable;
import org.cloudifysource.cosmo.statecache.StateCache;
import org.cloudifysource.cosmo.statecache.config.StateCacheConfig;
import org.cloudifysource.cosmo.tasks.TaskExecutor;
import org.cloudifysource.cosmo.tasks.config.TaskExecutorConfig;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import javax.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.util.Map;

/**
 * Creates a new {@link org.cloudifysource.cosmo.orchestrator.workflow.RuoteRuntime}.
 *
 * @author <NAME>
 * @since 0.1
 */
@Configuration
@Import({
        StateCacheConfig.class,
        TaskExecutorConfig.class
})
@PropertySource("org/cloudifysource/cosmo/manager/ruote/ruote.properties")
public class RuoteRuntimeConfig {

    @NotEmpty
    @Value("${cosmo.ruote.workflows:ruote/workflows.yaml}")
    private String workflows;

    @Inject
    private StateCache stateCache;

    @Inject
    private TaskExecutor taskExecutor;

    @Bean
    public RuoteRuntime ruoteRuntime() throws IOException {
        Map<String, Object> runtimeProperties = Maps.newHashMap();
        runtimeProperties.put("state_cache", stateCache);
        runtimeProperties.put("executor", taskExecutor);

        final Map<String, Object> variables = Maps.newHashMap();
        variables.putAll(loadInitialWorkflows());

        return RuoteRuntime.createRuntime(runtimeProperties, variables);
    }

    private static String getContent(String resource) throws IOException {
        final URL url = Resources.getResource(resource);
        return Resources.toString(url, Charsets.UTF_8);
    }<commit_msg>CLOUDIFY-1911 added capability for creating ruote runtime using a custom class loader. this is needed to load the ruby file<commit_after>/*******************************************************************************
 * Copyright (c) 2013 GigaSpaces Technologies Ltd. All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package org.cloudifysource.cosmo.manager.config;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Charsets;
import com.google.common.collect.Maps;
import com.google.common.io.Resources;
import org.cloudifysource.cosmo.orchestrator.workflow.RuoteRuntime;
import org.cloudifysource.cosmo.orchestrator.workflow.ruote.RuoteRadialVariable;
import org.cloudifysource.cosmo.statecache.StateCache;
import org.cloudifysource.cosmo.statecache.config.StateCacheConfig;
import org.cloudifysource.cosmo.tasks.TaskExecutor;
import org.cloudifysource.cosmo.tasks.config.TaskExecutorConfig;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import javax.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;

/**
 * Creates a new {@link org.cloudifysource.cosmo.orchestrator.workflow.RuoteRuntime}.
 *
 * @author <NAME>
 * @since 0.1
 */
@Configuration
@Import({
        StateCacheConfig.class,
        TaskExecutorConfig.class
})
@PropertySource("org/cloudifysource/cosmo/manager/ruote/ruote.properties")
public class RuoteRuntimeConfig {

    @NotEmpty
    @Value("${cosmo.ruote.workflows:ruote/workflows.yaml}")
    private String workflows;

    @Inject
    private StateCache stateCache;

    @Inject
    private TaskExecutor taskExecutor;

    @Inject
    private URLClassLoader rubyResourcesClassLoader;

    @Bean
    public RuoteRuntime ruoteRuntime() throws IOException {
        Map<String, Object> runtimeProperties = Maps.newHashMap();
        runtimeProperties.put("state_cache", stateCache);
        runtimeProperties.put("executor", taskExecutor);

        final Map<String, Object> variables = Maps.newHashMap();
        variables.putAll(loadInitialWorkflows());

        return RuoteRuntime.createRuntime(runtimeProperties, variables, rubyResourcesClassLoader);
    }

    private static String getContent(String resource) throws IOException {
        final URL url = Resources.getResource(resource);
        return Resources.toString(url, Charsets.UTF_8);
    }
{'fraction_non_alphanumeric': 0.13464991023339318, 'fraction_numerical': 0.0038898862956313583, 'mean_word_length': 5.011690647482014, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6725080', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1750, 'n_words': 432}