All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.buschmais.jqassistant.commandline.task.AbstractTask Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.buschmais.jqassistant.commandline.task;

import com.buschmais.jqassistant.commandline.CliExecutionException;
import com.buschmais.jqassistant.commandline.Task;
import com.buschmais.jqassistant.core.plugin.api.PluginRepository;
import com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException;
import com.buschmais.jqassistant.core.report.api.ReportHelper;
import com.buschmais.jqassistant.core.splittingsupport.scm.RuleHelper;
import com.buschmais.jqassistant.core.store.api.Store;
import com.buschmais.jqassistant.core.store.impl.EmbeddedGraphStore;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author jn4, Kontext E GmbH, 24.01.14
 */
public abstract class AbstractTask implements Task {

    protected static final String CMDLINE_OPTION_S = "s";
    protected static final String CMDLINE_OPTION_STOREDIRECTORY = "storeDirectory";
    protected static final String CMDLINE_OPTION_REPORTDIR = "reportDirectory";

    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTask.class);

    protected String storeDirectory;
    protected PluginRepository pluginRepository;
    protected RuleHelper ruleHelper;
    protected ReportHelper reportHelper;
    protected Map pluginProperties;

    @Override
    public void initialize(PluginRepository pluginRepository, Map pluginProperties) throws CliExecutionException {
        this.pluginRepository = pluginRepository;
        this.pluginProperties = pluginProperties;
        this.ruleHelper = new RuleHelper(LOGGER);
        this.reportHelper = new ReportHelper(LOGGER);
    }

    @Override
    public void run() throws CliExecutionException {
        List> descriptorTypes;
        final Store store = getStore();
        try {
            descriptorTypes = pluginRepository.getModelPluginRepository().getDescriptorTypes();
        } catch (PluginRepositoryException e) {
            throw new CliExecutionException("Cannot get model.", e);
        }
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(pluginRepository.getClassLoader());
        try {
            store.start(descriptorTypes);
            executeTask(store);
        } finally {
            store.stop();
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }

    @Override
    public void withStandardOptions(CommandLine options) {
        storeDirectory = getOptionValue(options, CMDLINE_OPTION_S, DEFAULT_STORE_DIRECTORY);
    }

    @Override
    public List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy