<commit_before>package com.ulisesbocchio.jasyptmavenplugin.mojo;

import com.ulisesbocchio.jasyptmavenplugin.encrypt.EncryptionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.Banner;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

/**
 * A mojo that spins up a Spring Boot application for any encrypt/decrypt function.
 *
 * @author <NAME>
 */
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"})
@Slf4j
public abstract class AbstractJasyptMojo extends AbstractMojo {

    /**
     * The encrypted property prefix
     */
    @Parameter(property = "jasypt.plugin.encrypt.prefix", defaultValue = "ENC(")
    private String encryptPrefix = "ENC(";

    /**
     * The encrypted property suffix
     */
    @Parameter(property = "jasypt.plugin.encrypt.suffix", defaultValue = ")")
    private String encryptSuffix = ")";

    /**
     * The decrypted property prefix
     */
    @Parameter(property = "jasypt.plugin.decrypt.prefix", defaultValue = "DEC(")
    private String decryptPrefix = "DEC(";

    /**
     * The decrypted property suffix
     */
    @Parameter(property = "jasypt.plugin.decrypt.suffix", defaultValue = ")")
    private String decryptSuffix = ")";

    private Environment environment;

    protected Environment getEnvironment() {
        return environment;
    }

    @Override
    public void execute() throws MojoExecutionException {
        ConfigurableApplicationContext context = new SpringApplicationBuilder()
                .sources(Application.class)
                .bannerMode(Banner.Mode.OFF)
                .run();

        this.environment = context.getEnvironment();

        String[] activeProfiles = context.getEnvironment().getActiveProfiles();
        String profiles = activeProfiles.length != 0 ? String.join(",", activeProfiles) : "Default";
        log.info("Active Profiles: {}", profiles);
        StringEncryptor encryptor = context.getBean(StringEncryptor.class);
        run(new EncryptionService(encryptor), context, encryptPrefix, encryptSuffix, decryptPrefix, decryptSuffix);
    }
<commit_msg>Add application resources to plugin Spring configuration locations by default.<commit_after>package com.ulisesbocchio.jasyptmavenplugin.mojo;

import com.ulisesbocchio.jasyptmavenplugin.encrypt.EncryptionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.Banner;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.util.HashMap;
import java.util.Map;

/**
 * A mojo that spins up a Spring Boot application for any encrypt/decrypt function.
 *
 * @author <NAME>
 */
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"})
@Slf4j
public abstract class AbstractJasyptMojo extends AbstractMojo {

    /**
     * The encrypted property prefix
     */
    @Parameter(property = "jasypt.plugin.encrypt.prefix", defaultValue = "ENC(")
    private String encryptPrefix = "ENC(";

    /**
     * The encrypted property suffix
     */
    @Parameter(property = "jasypt.plugin.encrypt.suffix", defaultValue = ")")
    private String encryptSuffix = ")";

    /**
     * The decrypted property prefix
     */
    @Parameter(property = "jasypt.plugin.decrypt.prefix", defaultValue = "DEC(")
    private String decryptPrefix = "DEC(";

    /**
     * The decrypted property suffix
     */
    @Parameter(property = "jasypt.plugin.decrypt.suffix", defaultValue = ")")
    private String decryptSuffix = ")";

    private Environment environment;

    protected Environment getEnvironment() {
        return environment;
    }

    @Override
    public void execute() throws MojoExecutionException {
        Map<String, Object> defaultProperties = new HashMap<>();
        defaultProperties.put("spring.config.location", "file:./src/main/resources/");

        ConfigurableApplicationContext context = new SpringApplicationBuilder()
                .sources(Application.class)
                .bannerMode(Banner.Mode.OFF)
                .properties(defaultProperties)
                .run();

        this.environment = context.getEnvironment();

        String[] activeProfiles = context.getEnvironment().getActiveProfiles();
        String profiles = activeProfiles.length != 0 ? String.join(",", activeProfiles) : "Default";
        log.info("Active Profiles: {}", profiles);
        StringEncryptor encryptor = context.getBean(StringEncryptor.class);
        run(new EncryptionService(encryptor), context, encryptPrefix, encryptSuffix, decryptPrefix, decryptSuffix);
    }

{'fraction_non_alphanumeric': 0.10955710955710955, 'fraction_numerical': 0.001554001554001554, 'mean_word_length': 3.798695246971109, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6351368', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1381, 'n_words': 293}