Search in sources :

Example 1 with CliConfigurationException

use of com.buschmais.jqassistant.commandline.CliConfigurationException in project jqa-commandline-tool by jQAssistant.

the class AbstractStoreTask method withStandardOptions.

@Override
public final void withStandardOptions(CommandLine options, PropertiesConfigBuilder propertiesConfigBuilder) throws CliConfigurationException {
    StoreConfiguration.StoreConfigurationBuilder builder = StoreConfiguration.builder();
    String storeUri = getOptionValue(options, CMDLINE_OPTION_STORE_URI);
    String storeDirectory = getOptionValue(options, CMDLINE_OPTION_S);
    if (storeUri != null && storeDirectory != null) {
        throw new CliConfigurationException("Expecting either parameter '" + CMDLINE_OPTION_STORE_DIRECTORY + "' or '" + CMDLINE_OPTION_STORE_URI + "'.");
    }
    if (storeUri != null) {
        try {
            builder.uri(new URI(storeUri));
        } catch (URISyntaxException e) {
            throw new CliConfigurationException("Cannot parse URI " + storeUri, e);
        }
        builder.username(getOptionValue(options, CMDLINE_OPTION_STORE_USERNAME));
        builder.password(getOptionValue(options, CMDLINE_OPTION_STORE_PASSWORD));
        builder.encryption(getOptionValue(options, CMDLINE_OPTION_STORE_ENCRYPTION));
        builder.trustStrategy(getOptionValue(options, CMDLINE_OPTION_STORE_TRUST_STRATEGY));
        builder.trustCertificate(getOptionValue(options, CMDLINE_OPTION_STORE_TRUST_CERITFICATE));
    } else {
        String directoryName = OptionHelper.coalesce(storeDirectory, DEFAULT_STORE_DIRECTORY);
        File directory = new File(directoryName);
        directory.getParentFile().mkdirs();
        builder.uri(directory.toURI());
    }
    builder.embedded(getEmbeddedNeo4jConfiguration(options));
    this.storeConfiguration = builder.build();
}
Also used : StoreConfiguration(com.buschmais.jqassistant.core.store.api.StoreConfiguration) CliConfigurationException(com.buschmais.jqassistant.commandline.CliConfigurationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File)

Example 2 with CliConfigurationException

use of com.buschmais.jqassistant.commandline.CliConfigurationException in project jqa-commandline-tool by jQAssistant.

the class AbstractAnalyzeTask method withOptions.

@Override
public void withOptions(CommandLine options, PropertiesConfigBuilder propertiesConfigBuilder) throws CliConfigurationException {
    String rulesUrl = getOptionValue(options, CMDLINE_OPTION_RULESURL, null);
    if (rulesUrl != null) {
        try {
            this.rulesUrl = new URL(rulesUrl);
        } catch (MalformedURLException e) {
            throw new CliConfigurationException("'" + rulesUrl + "' is not a valid URL.", e);
        }
    }
    ruleDirectory = getOptionValue(options, CMDLINE_OPTION_R, Task.DEFAULT_RULE_DIRECTORY);
    groupIds = getOptionValues(options, CMDLINE_OPTION_GROUPS, Collections.<String>emptyList());
    constraintIds = getOptionValues(options, CMDLINE_OPTION_CONSTRAINTS, Collections.<String>emptyList());
    conceptIds = getOptionValues(options, CMDLINE_OPTION_CONCEPTS, Collections.<String>emptyList());
    RuleConfiguration.RuleConfigurationBuilder ruleConfigurationBuilder = RuleConfiguration.builder();
    String defaultGroupSeverityValue = getOptionValue(options, CMDLINE_OPTION_DEFAULT_GROUP_SEVERITY);
    if (defaultGroupSeverityValue != null) {
        ruleConfigurationBuilder.defaultGroupSeverity(getSeverity(defaultGroupSeverityValue));
    }
    String defaultConceptSeverityValue = getOptionValue(options, CMDLINE_OPTION_DEFAULT_CONCEPT_SEVERITY);
    if (defaultConceptSeverityValue != null) {
        ruleConfigurationBuilder.defaultConceptSeverity(getSeverity(defaultConceptSeverityValue));
    }
    String defaultConstraintSeverityValue = getOptionValue(options, CMDLINE_OPTION_DEFAULT_CONSTRAINT_SEVERITY);
    if (defaultConstraintSeverityValue != null) {
        ruleConfigurationBuilder.defaultConstraintSeverity(getSeverity(defaultConstraintSeverityValue));
    }
    ruleConfiguration = ruleConfigurationBuilder.build();
}
Also used : MalformedURLException(java.net.MalformedURLException) CliConfigurationException(com.buschmais.jqassistant.commandline.CliConfigurationException) RuleConfiguration(com.buschmais.jqassistant.core.rule.api.reader.RuleConfiguration) URL(java.net.URL)

Example 3 with CliConfigurationException

use of com.buschmais.jqassistant.commandline.CliConfigurationException in project jqa-commandline-tool by jQAssistant.

the class ScanTask method executeTask.

@Override
protected void executeTask(Configuration configuration, Store store) throws CliExecutionException {
    ScannerContext scannerContext = new ScannerContextImpl(store, new File(DEFAULT_OUTPUT_DIRECTORY));
    if (configuration.scan().reset()) {
        store.reset();
    }
    for (ScopeHelper.ScopedResource scopedResource : files) {
        String fileName = scopedResource.getResource();
        String scopeName = scopedResource.getScopeName();
        File file = new File(fileName);
        String absolutePath = file.getAbsolutePath();
        if (!file.exists()) {
            LOGGER.info(absolutePath + "' does not exist, skipping scan.");
        } else {
            scan(configuration, scannerContext, file, file.getAbsolutePath(), scopeName);
        }
    }
    for (ScopeHelper.ScopedResource scopedResource : urls) {
        String uri = scopedResource.getResource();
        String scopeName = scopedResource.getScopeName();
        try {
            scan(configuration, scannerContext, new URI(uri), uri, scopeName);
        } catch (URISyntaxException e) {
            throw new CliConfigurationException("Cannot parse URI " + uri, e);
        }
    }
}
Also used : ScopeHelper(com.buschmais.jqassistant.core.scanner.api.ScopeHelper) ScannerContextImpl(com.buschmais.jqassistant.core.scanner.impl.ScannerContextImpl) CliConfigurationException(com.buschmais.jqassistant.commandline.CliConfigurationException) URISyntaxException(java.net.URISyntaxException) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) File(java.io.File) URI(java.net.URI)

Example 4 with CliConfigurationException

use of com.buschmais.jqassistant.commandline.CliConfigurationException in project jqa-commandline-tool by jQAssistant.

the class AbstractAnalyzeTask method configure.

@Override
public void configure(CommandLine options, ConfigurationBuilder configurationBuilder) throws CliConfigurationException {
    super.configure(options, configurationBuilder);
    String rulesUrl = getOptionValue(options, CMDLINE_OPTION_RULESURL, null);
    if (rulesUrl != null) {
        try {
            this.rulesUrl = new URL(rulesUrl);
        } catch (MalformedURLException e) {
            throw new CliConfigurationException("'" + rulesUrl + "' is not a valid URL.", e);
        }
    }
    ruleDirectory = getOptionValue(options, CMDLINE_OPTION_R, Task.DEFAULT_RULE_DIRECTORY);
    configurationBuilder.with(Analyze.class, Analyze.GROUPS, getOptionValues(options, CMDLINE_OPTION_GROUPS, Collections.<String>emptyList()));
    configurationBuilder.with(Analyze.class, Analyze.CONSTRAINTS, getOptionValues(options, CMDLINE_OPTION_CONSTRAINTS, Collections.<String>emptyList()));
    configurationBuilder.with(Analyze.class, Analyze.CONCEPTS, getOptionValues(options, CMDLINE_OPTION_CONCEPTS, Collections.<String>emptyList()));
    try {
        configurationBuilder.with(Rule.class, Rule.DEFAULT_CONCEPT_SEVERITY, Severity.fromValue(getOptionValue(options, CMDLINE_OPTION_DEFAULT_CONCEPT_SEVERITY)));
        configurationBuilder.with(Rule.class, Rule.DEFAULT_CONSTRAINT_SEVERITY, Severity.fromValue(getOptionValue(options, CMDLINE_OPTION_DEFAULT_CONSTRAINT_SEVERITY)));
        configurationBuilder.with(Rule.class, Rule.DEFAULT_GROUP_SEVERITY, Severity.fromValue(getOptionValue(options, CMDLINE_OPTION_DEFAULT_GROUP_SEVERITY)));
    } catch (RuleException e) {
        throw new CliConfigurationException("Cannot convert severity.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) CliConfigurationException(com.buschmais.jqassistant.commandline.CliConfigurationException) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) URL(java.net.URL)

Example 5 with CliConfigurationException

use of com.buschmais.jqassistant.commandline.CliConfigurationException in project jqa-commandline-tool by jQAssistant.

the class AbstractStoreTask method configure.

@Override
public void configure(CommandLine options, ConfigurationBuilder configurationBuilder) throws CliConfigurationException {
    String storeUri = getOptionValue(options, CMDLINE_OPTION_STORE_URI);
    String storeDirectory = getOptionValue(options, CMDLINE_OPTION_S);
    if (storeUri != null && storeDirectory != null) {
        throw new CliConfigurationException("Expecting either parameter '" + CMDLINE_OPTION_STORE_DIRECTORY + "' or '" + CMDLINE_OPTION_STORE_URI + "'.");
    }
    if (storeUri != null) {
        URI uri;
        try {
            uri = new URI(storeUri);
        } catch (URISyntaxException e) {
            throw new CliConfigurationException("Cannot parse URI " + storeUri, e);
        }
        configurationBuilder.with(com.buschmais.jqassistant.core.store.api.configuration.Store.class, com.buschmais.jqassistant.core.store.api.configuration.Store.URI, uri);
        configurationBuilder.with(Remote.class, Remote.USERNAME, getOptionValue(options, CMDLINE_OPTION_STORE_USERNAME));
        configurationBuilder.with(Remote.class, Remote.PASSWORD, getOptionValue(options, CMDLINE_OPTION_STORE_PASSWORD));
        configurationBuilder.with(Remote.class, Remote.ENCRYPTION, getOptionValue(options, CMDLINE_OPTION_STORE_ENCRYPTION));
        configurationBuilder.with(Remote.class, Remote.TRUST_STRATEGY, getOptionValue(options, CMDLINE_OPTION_STORE_TRUST_STRATEGY));
        configurationBuilder.with(Remote.class, Remote.TRUST_CERTIFICATE, getOptionValue(options, CMDLINE_OPTION_STORE_TRUST_CERITFICATE));
    } else if (storeDirectory != null) {
        File directory = new File(storeDirectory);
        directory.getParentFile().mkdirs();
        configurationBuilder.with(com.buschmais.jqassistant.core.store.api.configuration.Store.class, com.buschmais.jqassistant.core.store.api.configuration.Store.URI, directory.toURI());
    }
    configurationBuilder.with(Embedded.class, Embedded.CONNECTOR_ENABLED, isConnectorRequired());
    configurationBuilder.with(Embedded.class, Embedded.LISTEN_ADDRESS, getOptionValue(options, CMDLINE_OPTION_EMBEDDED_LISTEN_ADDRESS));
    configurationBuilder.with(Embedded.class, Embedded.HTTP_PORT, getOptionValue(options, CMDLINE_OPTION_EMBEDDED_HTTP_PORT));
    configurationBuilder.with(Embedded.class, Embedded.BOLT_PORT, getOptionValue(options, CMDLINE_OPTION_EMBEDDED_BOLT_PORT));
}
Also used : CliConfigurationException(com.buschmais.jqassistant.commandline.CliConfigurationException) Store(com.buschmais.jqassistant.core.store.api.Store) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File)

Aggregations

CliConfigurationException (com.buschmais.jqassistant.commandline.CliConfigurationException)9 File (java.io.File)6 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)2 ScopeHelper (com.buschmais.jqassistant.core.scanner.api.ScopeHelper)2 ScannerContextImpl (com.buschmais.jqassistant.core.scanner.impl.ScannerContextImpl)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ReportException (com.buschmais.jqassistant.core.report.api.ReportException)1 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)1 RuleConfiguration (com.buschmais.jqassistant.core.rule.api.reader.RuleConfiguration)1 Store (com.buschmais.jqassistant.core.store.api.Store)1 StoreConfiguration (com.buschmais.jqassistant.core.store.api.StoreConfiguration)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1