This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 3623cf7374ddac0b2f41d373f3e9ed85dc705e91 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Sep 3 20:30:25 2016 +0200 Rename module otherwise maven cries... + add new i18n generator for type and their plurals :) --- application-swing-validation/pom.xml | 2 +- application-web/pom.xml | 2 +- pom.xml | 9 +- services-topia-validation/pom.xml | 2 +- {maven-plugin => toolbox-maven-plugin}/LICENSE.txt | 0 {maven-plugin => toolbox-maven-plugin}/README.md | 0 {maven-plugin => toolbox-maven-plugin}/pom.xml | 23 ++- .../src/license/THIRD-PARTY.properties | 0 .../maven/plugins/toolbox}/CheckApiMojo.java | 2 +- .../plugins/toolbox/GenerateI18nTypesMojo.java | 226 +++++++++++++++++++++ .../toolbox}/GenerateI18nValidatorFieldsMojo.java | 30 +-- .../toolbox}/GenerateValidatorMojoSupport.java | 45 +--- .../toolbox}/GenerateValidatorsDescriptorMojo.java | 10 +- .../MismatchMethodParameterNameException.java | 2 +- .../plugins/toolbox}/MissingClassException.java | 2 +- .../plugins/toolbox}/MissingMethodException.java | 2 +- .../maven/plugins/toolbox/ToolboxMojoSupport.java | 79 ++++--- .../plugins/toolbox}/ValidatorCacheRequest.java | 2 +- .../maven/plugins/toolbox}/ValidatorsCache.java | 2 +- .../src/main/resources/log4j.properties | 0 20 files changed, 313 insertions(+), 127 deletions(-) diff --git a/application-swing-validation/pom.xml b/application-swing-validation/pom.xml index 21ac964..418327f 100644 --- a/application-swing-validation/pom.xml +++ b/application-swing-validation/pom.xml @@ -106,7 +106,7 @@ <plugin> <groupId>${project.groupId}</groupId> - <artifactId>maven-plugin</artifactId> + <artifactId>toolbox-maven-plugin</artifactId> <version>${project.version}</version> <configuration> <validatorsFile>${project.basedir}/src/test/resources/validators.xml</validatorsFile> diff --git a/application-web/pom.xml b/application-web/pom.xml index f131e0e..0f3f5ff 100644 --- a/application-web/pom.xml +++ b/application-web/pom.xml @@ -219,7 +219,7 @@ <plugin> <groupId>${project.groupId}</groupId> - <artifactId>maven-plugin</artifactId> + <artifactId>toolbox-maven-plugin</artifactId> <version>${project.version}</version> <executions> <execution> diff --git a/pom.xml b/pom.xml index e7b44e3..94fae9d 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ </developers> <modules> - <module>maven-plugin</module> + <module>toolbox-maven-plugin</module> <module>topia-extension</module> <module>topia-templates-extension</module> <module>services-configuration-api</module> @@ -519,6 +519,13 @@ <version>2.3.23</version> </dependency> + <!-- Pluralize --> + <dependency> + <groupId>org.atteo</groupId> + <artifactId>evo-inflector</artifactId> + <version>1.2</version> + </dependency> + <!-- db --> <dependency> <groupId>com.h2database</groupId> diff --git a/services-topia-validation/pom.xml b/services-topia-validation/pom.xml index 105b701..1432eb0 100644 --- a/services-topia-validation/pom.xml +++ b/services-topia-validation/pom.xml @@ -121,7 +121,7 @@ <plugin> <groupId>${project.groupId}</groupId> - <artifactId>maven-plugin</artifactId> + <artifactId>toolbox-maven-plugin</artifactId> <version>${project.version}</version> <configuration> <validatorsFile>${project.basedir}/src/test/resources/validators.xml</validatorsFile> diff --git a/maven-plugin/LICENSE.txt b/toolbox-maven-plugin/LICENSE.txt similarity index 100% rename from maven-plugin/LICENSE.txt rename to toolbox-maven-plugin/LICENSE.txt diff --git a/maven-plugin/README.md b/toolbox-maven-plugin/README.md similarity index 100% rename from maven-plugin/README.md rename to toolbox-maven-plugin/README.md diff --git a/maven-plugin/pom.xml b/toolbox-maven-plugin/pom.xml similarity index 86% rename from maven-plugin/pom.xml rename to toolbox-maven-plugin/pom.xml index 6802617..d33b794 100644 --- a/maven-plugin/pom.xml +++ b/toolbox-maven-plugin/pom.xml @@ -31,13 +31,21 @@ <version>5.0-SNAPSHOT</version> </parent> - <artifactId>maven-plugin</artifactId> + <artifactId>toolbox-maven-plugin</artifactId> - <name>ObServe :: Maven plugin</name> - <description>ObServe Maven plugin module</description> + <name>ObServe :: Toolbox Maven plugin</name> + <description>ObServe Toolbox Maven plugin module</description> <packaging>maven-plugin</packaging> <dependencies> + <!-- sibling dependencies --> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>services-model</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.nuiton</groupId> <artifactId>helper-maven-plugin-api</artifactId> @@ -51,6 +59,15 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> + <dependency> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + </dependency> + + <dependency> + <groupId>org.atteo</groupId> + <artifactId>evo-inflector</artifactId> + </dependency> <!-- provided dependencies --> diff --git a/maven-plugin/src/license/THIRD-PARTY.properties b/toolbox-maven-plugin/src/license/THIRD-PARTY.properties similarity index 100% rename from maven-plugin/src/license/THIRD-PARTY.properties rename to toolbox-maven-plugin/src/license/THIRD-PARTY.properties diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/CheckApiMojo.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/CheckApiMojo.java similarity index 99% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/CheckApiMojo.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/CheckApiMojo.java index af2c646..c3a2992 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/CheckApiMojo.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/CheckApiMojo.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /* * #%L diff --git a/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nTypesMojo.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nTypesMojo.java new file mode 100644 index 0000000..331e483 --- /dev/null +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nTypesMojo.java @@ -0,0 +1,226 @@ +package fr.ird.observe.maven.plugins.toolbox; + +/*- + * #%L + * ObServe :: Maven plugin + * %% + * Copyright (C) 2008 - 2016 IRD, Codelutin, Tony Chemit + * %% + * 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 + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.services.dto.IdDto; +import org.apache.commons.lang3.StringUtils; +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 org.atteo.evo.inflector.English; +import org.nuiton.plugin.PluginHelper; +import org.reflections.Reflections; + +import java.beans.Introspector; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +/** + * Pour générer les clefs i18n des différents types de dto utilisés dans l'application. + * + * Created on 31/08/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.0 + */ +@Mojo(name = "generate-i18n-types", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) +class GenerateI18nTypesMojo extends ToolboxMojoSupport { + + /** + * Un flag pour activer le mode verbeux. + * + * @since 1.0.0 + */ + @Parameter(property = "generateI18nTypes.verbose", defaultValue = "${maven.verbose}") + private boolean verbose; + + /** + * A flag to skip the goal. + * + * @since 1.0.0 + */ + @Parameter(property = "generateI18nTypes.skip", defaultValue = "false") + private boolean skip; + + /** + * To set the package fully qualified name of the generated class. + * + * By default, will use groupId.artifactId (with {@code -} replaced by {@code .}). + */ + @Parameter(property = "generateI18nTypes.packageName") + private String packageName; + + /** + * Name of the generated class. + */ + @Parameter(property = "generateI18nTypes.className", defaultValue = "I18nTypeHelper", required = true) + private String className; + + /** + * Prefix to add to generated i18n keys. + */ + @Parameter(property = "generateI18nTypes.prefix") + private String prefix; + + /** + * Possible suffix to remove to detected class. Can contains multiple values separated by a comma. + */ + @Parameter(property = "generateI18nTypes.removeSuffix") + private String removeSuffix; + + /** + * Possible suffix to skip some detected classes. Can contains multiple values separated by a comma. + */ + @Parameter(property = "generateI18nTypes.skipSuffix") + private String skipSuffix; + + /** + * The root directory where to generated. + */ + @Parameter(property = "generateI18nTypes.outputDirectory", defaultValue = "${basedir}/target/generated-sources/java", required = true) + private File outputDirectory; + + private Set<String> typeNames; + + @Override + protected Path createOutputFile() throws IOException { + + if (packageName == null) { + + packageName = getProject().getGroupId() + "." + getProject().getArtifactId().replaceAll("-", "."); + + } + Path directory = PluginHelper.getFile(outputDirectory, packageName.trim().split("\\.")).toPath(); + + Files.createDirectories(directory); + + return directory.resolve(className + ".java"); + } + + @Override + protected boolean isSkip() { + return skip; + } + + @Override + public void doAction() throws Exception { + + if (isVerbose()) { + getLog().info("project = " + getProject()); + } + + getLog().info("Generate to " + getOutputFile()); + + List<String> compileSourceRoots = getProject().getCompileSourceRoots(); + + if (!compileSourceRoots.contains(outputDirectory.getAbsolutePath())) { + + getLog().info("Add to compile source root: " + outputDirectory); + getProject().addCompileSourceRoot(outputDirectory.getAbsolutePath()); + + } + + generate(packageName, className, prefix, typeNames, getOutputFile()); + + } + + @Override + protected void init() throws Exception { + super.init(); + + typeNames = new TreeSet<>(); + + List<String> removeSuffixes = Arrays.asList(removeSuffix.split("\\s*,\\s*")); + List<String> skipSuffixes = Arrays.asList(skipSuffix.split("\\s*,\\s*")); + Collections.sort(removeSuffixes); + Collections.reverse(removeSuffixes); + for (Class<? extends IdDto> aClass : new Reflections("fr.ird.observe.services.dto").getSubTypesOf(IdDto.class)) { + + if (Modifier.isAbstract(aClass.getModifiers())) { + continue; + } + + String simpleName = aClass.getSimpleName(); + + boolean skip = false; + for (String skipSuffix : skipSuffixes) { + if (simpleName.endsWith(skipSuffix)) { + + skip = true; + break; + } + } + + if (skip) { + continue; + } + + for (String suffix : removeSuffixes) { + if (simpleName.endsWith(suffix)) { + String typeName = Introspector.decapitalize(StringUtils.removeEnd(simpleName, suffix)); + typeNames.add(typeName); + typeNames.add(English.plural(typeName)); + break; + } + } + + } + + getLog().info(typeNames.size() + " types(s) detected."); + + } + + @Override + protected boolean checkSkip() { + + if (isSkip()) { + getLog().info("Skipping goal (skip flag is on)."); + return false; + } + if (typeNames.isEmpty()) { + getLog().info("Skipping goal (no type detected)."); + return false; + } + return true; + } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + +} diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateI18nValidatorFieldsMojo.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nValidatorFieldsMojo.java similarity index 80% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateI18nValidatorFieldsMojo.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nValidatorFieldsMojo.java index cacafe9..3c7377b 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateI18nValidatorFieldsMojo.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateI18nValidatorFieldsMojo.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L @@ -28,13 +28,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.nuiton.plugin.PluginHelper; -import java.io.BufferedWriter; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Date; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -135,31 +132,10 @@ class GenerateI18nValidatorFieldsMojo extends GenerateValidatorMojoSupport { fields.addAll(validator.getFields()); } - getLog().info(fields.size() + " field(s) detected."); + getLog().info(fields.size() + " validator files(s) detected."); - try (BufferedWriter writer = Files.newBufferedWriter(getOutputFile(), StandardCharsets.UTF_8)) { + generate(packageName, className, prefix, fields, getOutputFile()); - writer.write("// Generated by " + getClass().getName() + " at " + new Date() + "\n"); - writer.write("package " + packageName + ";\n"); - writer.write("\n"); - writer.write("\n"); - writer.write("import static org.nuiton.i18n.I18n.n;\n"); - writer.write("\n"); - writer.write("\n"); - writer.write("public class " + className + " {\n"); - writer.write("\n static {"); - writer.write("\n"); - - for (String field : fields) { - writer.write(" n(\"" + prefix + field + "\");\n"); - } - - writer.write("\n"); - writer.write(" }\n"); - writer.write("\n"); - writer.write("}\n"); - - } } diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorMojoSupport.java similarity index 65% copy from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java copy to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorMojoSupport.java index ca32b96..1f20700 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorMojoSupport.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L @@ -23,8 +23,6 @@ package fr.ird.observe.maven.plugins.checkapi; */ import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.nuiton.plugin.AbstractPlugin; import java.io.File; import java.io.IOException; @@ -38,19 +36,11 @@ import java.util.Collection; * * @author Tony Chemit - chemit@codelutin.com */ -public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implements ValidatorCacheRequest { - - @Parameter(defaultValue = "${project}", required = true, readonly = true) - private MavenProject project; - - @Parameter(defaultValue = "${project.basedir}/src/main/resources", required = true) - private File sourceRoot; +public abstract class GenerateValidatorMojoSupport extends ToolboxMojoSupport implements ValidatorCacheRequest { @Parameter(defaultValue = "${project.basedir}/src/main/validators/validators.xml", required = true) private File validatorsFile; - private Path outputFile; - private Collection<ValidatorsCache.ValidatorInfo> validators; @Override @@ -59,11 +49,8 @@ public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implem if (isSkip()) { return; } - if (getLog().isDebugEnabled()) { - setVerbose(true); - } - outputFile = createOutputFile(); + super.init(); validators = ValidatorsCache.get().getValidators(this); @@ -87,39 +74,17 @@ public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implem protected abstract boolean isSkip(); - @Override - public MavenProject getProject() { - return project; - } - - public File getSourceRoot() { - return sourceRoot; - } - public File getValidatorsFile() { return validatorsFile; } - public Path getOutputFile() { - return outputFile; - } - public Collection<ValidatorsCache.ValidatorInfo> getValidators() { return validators; } @Override - public Path getSourceRootPath() { - return getSourceRoot().toPath(); - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - - @Override public URLClassLoader getUrlClassLoader() throws MalformedURLException { - return initClassLoader(project, validatorsFile.getParentFile(), true, false, true, true, false); + return initClassLoader(getProject(), validatorsFile.getParentFile(), true, false, true, true, false); } + } diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorsDescriptorMojo.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorsDescriptorMojo.java similarity index 95% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorsDescriptorMojo.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorsDescriptorMojo.java index 7b3eec6..96a923a 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorsDescriptorMojo.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateValidatorsDescriptorMojo.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L @@ -56,7 +56,7 @@ class GenerateValidatorsDescriptorMojo extends GenerateValidatorMojoSupport { * The root directory where to generated. */ @Parameter(property = "generateValidatorsDescriptor.outputFile", defaultValue = "${project.build.outputDirectory}/META-INF/validators/${project.artifactId}.json", required = true) - private File outputFile = null; + private File outputFile; /** * Un flag pour activer le mode verbeux. @@ -64,7 +64,7 @@ class GenerateValidatorsDescriptorMojo extends GenerateValidatorMojoSupport { * @since 1.0.0 */ @Parameter(property = "generateValidatorsDescriptor.verbose", defaultValue = "${maven.verbose}") - private boolean verbose = false; + private boolean verbose; /** * A flag to skip the goal. @@ -72,7 +72,7 @@ class GenerateValidatorsDescriptorMojo extends GenerateValidatorMojoSupport { * @since 1.0.0 */ @Parameter(property = "generateValidatorsDescriptor.skip", defaultValue = "false") - private boolean skip = false; + private boolean skip; @Override protected Path createOutputFile() throws IOException { @@ -101,7 +101,7 @@ class GenerateValidatorsDescriptorMojo extends GenerateValidatorMojoSupport { fields.addAll(validator.getFields()); } - getLog().info(fields.size() + " field(s) detected."); + getLog().info(fields.size() + " validator files(s) detected."); ArrayList<ValidatorsCache.ValidatorInfo> validatorList = new ArrayList<>(getValidators()); diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MismatchMethodParameterNameException.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MismatchMethodParameterNameException.java similarity index 98% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MismatchMethodParameterNameException.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MismatchMethodParameterNameException.java index ac2f5a0..a32fbbf 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MismatchMethodParameterNameException.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MismatchMethodParameterNameException.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingClassException.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingClassException.java similarity index 96% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingClassException.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingClassException.java index 33abd96..b11edb0 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingClassException.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingClassException.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingMethodException.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingMethodException.java similarity index 95% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingMethodException.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingMethodException.java index 4a1e37a..bf1822a 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/MissingMethodException.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/MissingMethodException.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ToolboxMojoSupport.java similarity index 62% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ToolboxMojoSupport.java index ca32b96..ade6f05 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/GenerateValidatorMojoSupport.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ToolboxMojoSupport.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L @@ -26,19 +26,21 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.nuiton.plugin.AbstractPlugin; +import java.io.BufferedWriter; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collection; +import java.util.Date; +import java.util.Set; /** * Created on 31/08/16. * * @author Tony Chemit - chemit@codelutin.com */ -public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implements ValidatorCacheRequest { +public abstract class ToolboxMojoSupport extends AbstractPlugin { @Parameter(defaultValue = "${project}", required = true, readonly = true) private MavenProject project; @@ -46,13 +48,8 @@ public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implem @Parameter(defaultValue = "${project.basedir}/src/main/resources", required = true) private File sourceRoot; - @Parameter(defaultValue = "${project.basedir}/src/main/validators/validators.xml", required = true) - private File validatorsFile; - private Path outputFile; - private Collection<ValidatorsCache.ValidatorInfo> validators; - @Override protected void init() throws Exception { @@ -65,22 +62,6 @@ public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implem outputFile = createOutputFile(); - validators = ValidatorsCache.get().getValidators(this); - - } - - @Override - protected boolean checkSkip() { - if (isSkip()) { - getLog().info("Skipping goal (skip flag is on)."); - return false; - } - if (validators.isEmpty()) { - getLog().info("Skipping goal (no validator detected)."); - return false; - } - - return super.checkSkip(); } protected abstract Path createOutputFile() throws IOException; @@ -92,34 +73,48 @@ public abstract class GenerateValidatorMojoSupport extends AbstractPlugin implem return project; } - public File getSourceRoot() { - return sourceRoot; + @Override + public void setProject(MavenProject project) { + this.project = project; } - public File getValidatorsFile() { - return validatorsFile; + public File getSourceRoot() { + return sourceRoot; } public Path getOutputFile() { return outputFile; } - public Collection<ValidatorsCache.ValidatorInfo> getValidators() { - return validators; - } - - @Override public Path getSourceRootPath() { return getSourceRoot().toPath(); } - @Override - public void setProject(MavenProject project) { - this.project = project; - } + void generate(String packageName, String className, String prefix, Set<String> fields, Path outputFile) throws IOException { + + try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) { + + writer.write("// Generated by " + getClass().getName() + " at " + new Date() + "\n"); + writer.write("package " + packageName + ";\n"); + writer.write("\n"); + writer.write("\n"); + writer.write("import static org.nuiton.i18n.I18n.n;\n"); + writer.write("\n"); + writer.write("\n"); + writer.write("public class " + className + " {\n"); + writer.write("\n static {"); + writer.write("\n"); + + for (String typeName : fields) { + writer.write(" n(\"" + prefix + typeName + "\");\n"); + } + + writer.write("\n"); + writer.write(" }\n"); + writer.write("\n"); + writer.write("}\n"); + + } - @Override - public URLClassLoader getUrlClassLoader() throws MalformedURLException { - return initClassLoader(project, validatorsFile.getParentFile(), true, false, true, true, false); } } diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorCacheRequest.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorCacheRequest.java similarity index 96% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorCacheRequest.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorCacheRequest.java index 6c6f847..c11b164 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorCacheRequest.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorCacheRequest.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L diff --git a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorsCache.java b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorsCache.java similarity index 99% rename from maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorsCache.java rename to toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorsCache.java index 14f7e12..12db268 100644 --- a/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/checkapi/ValidatorsCache.java +++ b/toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ValidatorsCache.java @@ -1,4 +1,4 @@ -package fr.ird.observe.maven.plugins.checkapi; +package fr.ird.observe.maven.plugins.toolbox; /*- * #%L diff --git a/maven-plugin/src/main/resources/log4j.properties b/toolbox-maven-plugin/src/main/resources/log4j.properties similarity index 100% rename from maven-plugin/src/main/resources/log4j.properties rename to toolbox-maven-plugin/src/main/resources/log4j.properties -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.