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

org.nuiton.i18n.plugin.I18nMojoWithI18nModuleSupport Maven / Gradle / Ivy

package org.nuiton.i18n.plugin;

/*-
 * #%L
 * I18n :: Maven Plugin
 * %%
 * Copyright (C) 2007 - 2018 Code Lutin, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import io.ultreia.java4all.i18n.spi.builder.I18nModule;
import io.ultreia.java4all.i18n.spi.builder.I18nModuleConfiguration;

import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.Set;

/**
 * Created by tchemit on 30/10/2018.
 *
 * @author Tony Chemit - [email protected]
 */
public abstract class I18nMojoWithI18nModuleSupport extends I18nMojoSupport {

    private I18nModule i18nModule;

    @Override
    public void init() throws Exception {
        super.init();
        URLClassLoader classLoader = initClassLoader(getProject(), null, false, false, false, true, true);
        i18nModule = I18nModule.builder(getProject().getProperties())
                .loadDependencies(classLoader)
                .loadKeySets(true)
                .loadTranslations()
                .loadTemplates()
                .build();
    }

    @Override
    protected boolean checkSkip() {
        boolean result = super.checkSkip();
        if (result && i18nModule.isEmpty()) {
            getLog().info("Skip - No getters, nor translations, nor templates  detected in module and dependencies.");
            result = false;
        }
        if (result && !needInvoke(true, false, I18nMojoSupport.getProjectCacheKey(this))) {
            getLog().info("Skip - already executed.");
            result = false;
        }
        return result;
    }

    protected I18nModule getI18nModule() {
        return i18nModule;
    }

    protected Charset getEncoding() {
        return getI18nModuleConfiguration().getEncoding();
    }

    protected I18nModuleConfiguration getI18nModuleConfiguration() {
        return i18nModule.getConfiguration();
    }

    protected Set getLocales() {
        return getI18nModuleConfiguration().getLocales();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy