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

net.jhorstmann.i18n.mojo.GettextMojo Maven / Gradle / Ivy

package net.jhorstmann.i18n.mojo;

import java.text.MessageFormat;

import net.jhorstmann.i18n.tools.MessageBundle;
import net.jhorstmann.i18n.tools.xgettext.MessageExtractor;
import net.jhorstmann.i18n.xgettext.asm.AsmMessageExtractor;
import net.jhorstmann.i18n.xgettext.web.WebMessageExtractor;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * @goal gettext
 * @phase process-classes
 */
public class GettextMojo extends AbstractGettextMojo {

    /**
     * Relativize the path for source-references to the project-root.
     *
     * @parameter expression="${relativizeSrcRefPaths}" default-value="false"
     */
    protected boolean relativizeSrcRefPaths;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        if (skip) {
            getLog().info("Skipping gettext.");
            return;
        }
        MessageBundle bundle = loadMessageBundle();
        int errorCount = 0;

        if (!poDirectory.exists() || !poDirectory.canWrite()) {
            getLog().warn(MessageFormat.format("Target-Directory <{0}> does not exist or is unwritable, skipping", poDirectory.getAbsolutePath()));
            return;
        }

        if (classesDirectory.exists()) {
            MessageExtractor extractor = new AsmMessageExtractor(bundle, getJavaFunctions());
            errorCount += extractMessages(extractor, classesDirectory, new String[] { "**/*.class" }, new String[] {});
        }

        if (webappDirectory.exists()) {
            MessageExtractor extractor = new WebMessageExtractor(bundle, getELFunctions(), projectRoot, relativizeSrcRefPaths);
            errorCount += extractMessages(extractor, webappDirectory, getWebappIncludes(), getWebappExcludes());
        }

        if (errorCount > 0) {
            throw new MojoExecutionException("Encountered " + errorCount + " error(s) while extracting messages from classes");
        } else {
            saveMessageBundle(bundle);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy