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

fr.ird.observe.maven.plugins.toolbox.GenerateValidatorsDescriptorMojo Maven / Gradle / Ivy

There is a newer version: 4.34
Show newest version
package fr.ird.observe.maven.plugins.toolbox;

/*-
 * #%L
 * ObServe Toolkit :: Maven plugin
 * %%
 * Copyright (C) 2017 - 2019 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import fr.ird.observe.validation.ValidatorDto;
import fr.ird.observe.validation.ValidatorsManager;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * Pour générer les clefs i18n des champs utilisés dans les validateurs.
 * 

* Created on 31/08/16. * * @author Tony Chemit - [email protected] * @since 5.0 */ @Mojo(name = "generate-validators-descriptor", threadSafe = true, defaultPhase = LifecyclePhase.GENERATE_RESOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) class GenerateValidatorsDescriptorMojo extends GenerateValidatorMojoSupport { /** * The root directory where to generated. */ @Parameter(property = "generateValidatorsDescriptor.outputFile", defaultValue = "${project.build.directory}/generated-sources/java/META-INF/validators/${project.artifactId}.json", required = true) private File outputFile; /** * Un flag pour activer le mode verbeux. * * @since 1.0.0 */ @Parameter(property = "generateValidatorsDescriptor.verbose", defaultValue = "${maven.verbose}") private boolean verbose; /** * A flag to skip the goal. * * @since 1.0.0 */ @Parameter(property = "generateValidatorsDescriptor.skip", defaultValue = "false") private boolean skip; @Override protected Path createOutputFile() throws IOException { Files.createDirectories(outputFile.getParentFile().toPath()); return outputFile.toPath(); } @Override protected boolean isSkip() { return skip; } @Override public void doAction() throws Exception { if (isVerbose()) { getLog().info("project = " + getProject()); } getLog().info("Generate to " + getOutputFile()); Set fields = new TreeSet<>(); for (ValidatorsCache.ValidatorInfo validator : getValidators()) { fields.addAll(validator.getFields()); } getLog().info(fields.size() + " validator files(s) detected."); List validatorList = new ArrayList<>(getValidators()); List validators = validatorList.stream().sorted(Comparator.comparing(ValidatorsCache.ValidatorInfo::getOrderKey)).map(ValidatorsCache.ValidatorInfo::toValidatorDto).collect(Collectors.toList()); new ValidatorsManager(validators).store(outputFile.toPath()); } @Override public boolean isVerbose() { return verbose; } @Override public void setVerbose(boolean verbose) { this.verbose = verbose; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy